stimulus-library 0.9.2 → 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.
- package/README.md +43 -43
- package/dist/controllers/ajax/async_block_controller.js +9 -20
- package/dist/controllers/ajax/lazy_block_controller.js +17 -30
- package/dist/controllers/ajax/load_block_controller.js +36 -47
- package/dist/controllers/ajax/poll_block_controller.js +10 -21
- package/dist/controllers/anchor_spy_controller.js +3 -3
- package/dist/controllers/back_link_controller.js +2 -2
- package/dist/controllers/clipboard_controller.js +3 -6
- package/dist/controllers/confirm_controller.js +3 -3
- package/dist/controllers/confirm_navigation_controller.js +1 -1
- package/dist/controllers/debug_controller.js +1 -1
- package/dist/controllers/disable_with_controller.js +7 -7
- package/dist/controllers/element_save_controller.js +8 -8
- package/dist/controllers/empty_dom_controller.js +3 -3
- package/dist/controllers/equalize_controller.js +1 -1
- package/dist/controllers/forms/auto_submit_form_controller.js +1 -1
- package/dist/controllers/forms/char_count_controller.js +4 -4
- package/dist/controllers/forms/checkbox_disable_inputs_controller.js +4 -4
- package/dist/controllers/forms/checkbox_enable_inputs_controller.js +4 -4
- package/dist/controllers/forms/checkbox_select_all_controller.js +1 -1
- package/dist/controllers/forms/checkbox_xor_controller.js +1 -1
- package/dist/controllers/forms/detect_dirty_controller.js +1 -1
- package/dist/controllers/forms/detect_dirty_form_controller.js +1 -1
- package/dist/controllers/forms/enable_inputs_controller.js +4 -4
- package/dist/controllers/forms/focus_steal_controller.js +3 -3
- package/dist/controllers/forms/form_rc_controller.js +7 -7
- package/dist/controllers/forms/form_save_controller.js +7 -7
- package/dist/controllers/forms/limited_selection_checkboxes_controller.js +2 -2
- package/dist/controllers/forms/navigate_form_errors_controller.js +38 -56
- package/dist/controllers/forms/nested_form_controller.js +6 -6
- package/dist/controllers/forms/password_confirm_controller.js +2 -2
- package/dist/controllers/forms/password_peek_controller.js +4 -4
- package/dist/controllers/forms/remote_form_controller.js +2 -2
- package/dist/controllers/forms/sync_inputs_controller.js +3 -3
- package/dist/controllers/forms/value_warn_controller.js +8 -8
- package/dist/controllers/forms/word_count_controller.js +3 -3
- package/dist/controllers/media/fallback_image_controller.js +2 -2
- package/dist/controllers/media/lightbox_image_controller.js +7 -10
- package/dist/controllers/media/media_player_controller.js +7 -18
- package/dist/controllers/persisted_dismissable_controller.js +3 -3
- package/dist/controllers/prefetch_controller.js +2 -3
- package/dist/controllers/print_button_controller.js +3 -3
- package/dist/controllers/refresh_page_controller.js +3 -3
- package/dist/controllers/scroll/scroll_container_controller.js +28 -53
- package/dist/controllers/scroll/scroll_into_focus_controller.js +5 -5
- package/dist/controllers/scroll/scroll_to_bottom_controller.js +8 -19
- package/dist/controllers/scroll/scroll_to_controller.js +6 -6
- package/dist/controllers/scroll/scroll_to_top_controller.js +8 -19
- package/dist/controllers/self_destruct_controller.js +1 -1
- package/dist/controllers/signal/base_controller.js +3 -3
- package/dist/controllers/signal/signal_action_controller.js +7 -4
- package/dist/controllers/signal/signal_disable_controller.js +17 -6
- package/dist/controllers/signal/signal_dom_children_controller.js +4 -4
- package/dist/controllers/signal/signal_enable_controller.js +19 -6
- package/dist/controllers/signal/signal_input_controller.js +5 -6
- package/dist/controllers/signal/signal_visibility_controller.js +13 -5
- package/dist/controllers/sticky_controller.js +3 -6
- package/dist/controllers/tables/table_sort_controller.js +5 -9
- package/dist/controllers/tables/table_truncate_controller.js +8 -8
- package/dist/controllers/teleport_controller.js +2 -2
- package/dist/controllers/temporary_state_controller.js +7 -11
- package/dist/controllers/toggle_class_controller.js +8 -8
- package/dist/controllers/trix_modifier_controller.js +1 -1
- package/dist/controllers/turbo_frame_rc_controller.js +8 -8
- package/dist/controllers/turbo_frame_refresh_controller.js +5 -5
- package/dist/controllers/utility/alert_controller.js +1 -1
- package/dist/controllers/utility/intersection_controller.js +1 -1
- package/dist/controllers/utility/interval_controller.js +1 -1
- package/dist/controllers/utility/presence_controller.js +1 -1
- package/dist/controllers/utility/print_controller.js +1 -1
- package/dist/controllers/utility/timeout_controller.js +1 -1
- package/dist/controllers/visual/clock_controller.js +1 -1
- package/dist/controllers/visual/countdown_controller.js +5 -8
- package/dist/controllers/visual/duration_controller.js +13 -13
- package/dist/controllers/visual/tabs_controller.js +3 -3
- package/dist/controllers/visual/time_distance_controller.js +3 -3
- package/dist/controllers/visual/tree_view_controller.js +4 -4
- package/dist/controllers/visual/tween_number_controller.js +6 -6
- package/dist/mixins/use_event_bus.js +1 -1
- package/dist/mixins/use_event_listener.js +1 -1
- package/dist/mixins/use_fullscreen.js +8 -17
- package/dist/mixins/use_intersection.js +4 -4
- package/dist/utilities/base_controller.js +1 -1
- package/dist/utilities/ephemeral_controller.js +3 -4
- package/dist/utilities/fetchRetry.js +9 -20
- package/dist/utilities/logging.js +11 -3
- package/dist/utilities/scroll.js +37 -64
- package/package.json +8 -8
- package/dist/controllers/forms/disable_inputs_controller.js +0 -21
- package/dist/controllers/media/fallback_iframe_controller.js +0 -44
- package/dist/controllers/signal/signal_attribute_sync_controller.js +0 -10
- package/dist/controllers/signal/signal_content_sync_controller.js +0 -9
- package/dist/controllers/tables/table_filter_controller.js +0 -53
package/README.md
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
# Stimulus-Library
|
|
2
|
-
|
|
3
|
-
[Documentation](https://sub-xaero.github.io/stimulus-library/) | [Full List of Controllers](https://sub-xaero.github.io/stimulus-library/)
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-

|
|
7
|
-

|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## Installation
|
|
11
|
-
|
|
12
|
-
To get started, you'll need to add the `stimulus-library` package to your project.
|
|
13
|
-
|
|
14
|
-
To do so, either add `stimulus-library` to your package.json manually
|
|
15
|
-
|
|
16
|
-
```json
|
|
17
|
-
{
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"stimulus-library": "latest"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
or run
|
|
25
|
-
`npm install --save stimulus-library` or `yarn add stimulus-library`
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Then, to get started, import and register the controllers you want to use.
|
|
29
|
-
|
|
30
|
-
*Please Note* as below, that when registering the name for the controller, you should use `kebab-case` and omit the `-controller` suffix.
|
|
31
|
-
|
|
32
|
-
```js
|
|
33
|
-
import { Application } from "@hotwired/stimulus";
|
|
34
|
-
import { AutoSubmitFormController } from "stimulus-library";
|
|
35
|
-
|
|
36
|
-
const application = Application.start();
|
|
37
|
-
application.register("auto-submit-form", AutoSubmitFormController);
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Tree-shaking
|
|
41
|
-
If you use the ESM builds of the library, this library fully supports tree-shaking,
|
|
42
|
-
only the controllers you directly import will be bundled with your application.
|
|
43
|
-
|
|
1
|
+
# Stimulus-Library
|
|
2
|
+
|
|
3
|
+
[Documentation](https://sub-xaero.github.io/stimulus-library/) | [Full List of Controllers](https://sub-xaero.github.io/stimulus-library/)
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
To get started, you'll need to add the `stimulus-library` package to your project.
|
|
13
|
+
|
|
14
|
+
To do so, either add `stimulus-library` to your package.json manually
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"stimulus-library": "latest"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
or run
|
|
25
|
+
`npm install --save stimulus-library` or `yarn add stimulus-library`
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Then, to get started, import and register the controllers you want to use.
|
|
29
|
+
|
|
30
|
+
*Please Note* as below, that when registering the name for the controller, you should use `kebab-case` and omit the `-controller` suffix.
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import { Application } from "@hotwired/stimulus";
|
|
34
|
+
import { AutoSubmitFormController } from "stimulus-library";
|
|
35
|
+
|
|
36
|
+
const application = Application.start();
|
|
37
|
+
application.register("auto-submit-form", AutoSubmitFormController);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Tree-shaking
|
|
41
|
+
If you use the ESM builds of the library, this library fully supports tree-shaking,
|
|
42
|
+
only the controllers you directly import will be bundled with your application.
|
|
43
|
+
|
|
@@ -1,30 +1,19 @@
|
|
|
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 { LoadBlockController } from "./load_block_controller";
|
|
11
2
|
export class AsyncBlockController extends LoadBlockController {
|
|
3
|
+
static targets = ["replace"];
|
|
4
|
+
static values = {
|
|
5
|
+
endpoint: String,
|
|
6
|
+
errorMessage: String,
|
|
7
|
+
selector: String,
|
|
8
|
+
maxRetries: Number,
|
|
9
|
+
};
|
|
12
10
|
get _errorMessage() {
|
|
13
11
|
return this.hasErrorMessageValue ? this.errorMessageValue : "This content failed to load";
|
|
14
12
|
}
|
|
15
13
|
// This is a simple controller to load a block of content when the page loads.
|
|
16
14
|
// It should be used to give a quick initial response before calling out to an
|
|
17
15
|
// an AJAX endpoint to do some expensive work.
|
|
18
|
-
connect() {
|
|
19
|
-
|
|
20
|
-
yield this.loadContent();
|
|
21
|
-
});
|
|
16
|
+
async connect() {
|
|
17
|
+
await this.loadContent();
|
|
22
18
|
}
|
|
23
19
|
}
|
|
24
|
-
AsyncBlockController.targets = ["replace"];
|
|
25
|
-
AsyncBlockController.values = {
|
|
26
|
-
endpoint: String,
|
|
27
|
-
errorMessage: String,
|
|
28
|
-
selector: String,
|
|
29
|
-
maxRetries: Number,
|
|
30
|
-
};
|
|
@@ -1,37 +1,24 @@
|
|
|
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 { LoadBlockController } from "./load_block_controller";
|
|
11
2
|
import { useIntersection } from "../../mixins/use_intersection";
|
|
12
3
|
export class LazyBlockController extends LoadBlockController {
|
|
13
|
-
connect() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
});
|
|
4
|
+
async connect() {
|
|
5
|
+
let element = this.el;
|
|
6
|
+
if ("IntersectionObserver" in window) {
|
|
7
|
+
let { observe, unobserve } = useIntersection(this, element, this.appear, null, { threshold: 0.3 });
|
|
8
|
+
this.observe = observe;
|
|
9
|
+
this.unobserve = unobserve;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
// Client doesn't support intersection observer, fallback to pre-loading
|
|
13
|
+
await this.loadContent();
|
|
14
|
+
}
|
|
26
15
|
}
|
|
27
|
-
appear(entry) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.unobserve();
|
|
33
|
-
}
|
|
16
|
+
async appear(entry) {
|
|
17
|
+
if (entry.target === this.el && entry.isIntersecting) {
|
|
18
|
+
await this.loadContent();
|
|
19
|
+
if (this.unobserve) {
|
|
20
|
+
this.unobserve();
|
|
34
21
|
}
|
|
35
|
-
}
|
|
22
|
+
}
|
|
36
23
|
}
|
|
37
24
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
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 { fetchRetry } from "../../utilities/fetchRetry";
|
|
12
3
|
export class LoadBlockController extends BaseController {
|
|
4
|
+
static targets = ["replace"];
|
|
5
|
+
static values = {
|
|
6
|
+
endpoint: String,
|
|
7
|
+
errorMessage: String,
|
|
8
|
+
selector: String,
|
|
9
|
+
maxRetries: Number,
|
|
10
|
+
};
|
|
13
11
|
get _errorMessage() {
|
|
14
12
|
return this.hasErrorMessageValue ? this.errorMessageValue : "This content failed to load";
|
|
15
13
|
}
|
|
@@ -18,46 +16,37 @@ export class LoadBlockController extends BaseController {
|
|
|
18
16
|
}
|
|
19
17
|
connect() {
|
|
20
18
|
}
|
|
21
|
-
loadContent(event = null) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!response.ok) {
|
|
33
|
-
failure();
|
|
34
|
-
}
|
|
35
|
-
let text = yield response.text();
|
|
36
|
-
let newEl = document.createElement("div");
|
|
37
|
-
newEl.innerHTML = text;
|
|
38
|
-
if (this.hasSelectorValue) {
|
|
39
|
-
let selectedContent = newEl.querySelectorAll(this.selectorValue);
|
|
40
|
-
el.replaceWith(...selectedContent);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
el.replaceWith(...newEl.children);
|
|
44
|
-
}
|
|
45
|
-
// Trigger event to show block has loaded
|
|
46
|
-
self.dispatchEvent(el, "ajax:success");
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
19
|
+
async loadContent(event = null) {
|
|
20
|
+
event?.preventDefault();
|
|
21
|
+
let self = this;
|
|
22
|
+
let el = this.hasReplaceTarget ? this.replaceTarget : this.el;
|
|
23
|
+
let failure = () => {
|
|
24
|
+
el.replaceWith(this._errorMessage);
|
|
25
|
+
self.dispatchEvent(el, "ajax:error");
|
|
26
|
+
};
|
|
27
|
+
try {
|
|
28
|
+
let response = await fetchRetry(this._maxRetries, this.endpointValue);
|
|
29
|
+
if (!response.ok) {
|
|
49
30
|
failure();
|
|
50
31
|
}
|
|
51
|
-
|
|
52
|
-
|
|
32
|
+
let text = await response.text();
|
|
33
|
+
let newEl = document.createElement("div");
|
|
34
|
+
newEl.innerHTML = text;
|
|
35
|
+
if (this.hasSelectorValue) {
|
|
36
|
+
let selectedContent = newEl.querySelectorAll(this.selectorValue);
|
|
37
|
+
el.replaceWith(...selectedContent);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
el.replaceWith(...newEl.children);
|
|
53
41
|
}
|
|
54
|
-
|
|
42
|
+
// Trigger event to show block has loaded
|
|
43
|
+
self.dispatchEvent(el, "ajax:success");
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
failure();
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
self.dispatchEvent(el, "ajax:complete");
|
|
50
|
+
}
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
|
-
LoadBlockController.targets = ["replace"];
|
|
58
|
-
LoadBlockController.values = {
|
|
59
|
-
endpoint: String,
|
|
60
|
-
errorMessage: String,
|
|
61
|
-
selector: String,
|
|
62
|
-
maxRetries: Number,
|
|
63
|
-
};
|
|
@@ -1,15 +1,14 @@
|
|
|
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 { LoadBlockController } from "./load_block_controller";
|
|
11
2
|
import { useInterval } from "../../mixins/use_interval";
|
|
12
3
|
export class PollBlockController extends LoadBlockController {
|
|
4
|
+
static targets = ["replace"];
|
|
5
|
+
static values = {
|
|
6
|
+
endpoint: String,
|
|
7
|
+
errorMessage: String,
|
|
8
|
+
selector: String,
|
|
9
|
+
maxRetries: Number,
|
|
10
|
+
seconds: Number,
|
|
11
|
+
};
|
|
13
12
|
connect() {
|
|
14
13
|
if (!this.hasSecondsValue) {
|
|
15
14
|
throw new Error("Required value `seconds` is missing");
|
|
@@ -19,17 +18,7 @@ export class PollBlockController extends LoadBlockController {
|
|
|
19
18
|
useInterval(this, this._timeout, this.secondsValue * 1000);
|
|
20
19
|
});
|
|
21
20
|
}
|
|
22
|
-
_timeout() {
|
|
23
|
-
|
|
24
|
-
yield this.loadContent();
|
|
25
|
-
});
|
|
21
|
+
async _timeout() {
|
|
22
|
+
await this.loadContent();
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
PollBlockController.targets = ["replace"];
|
|
29
|
-
PollBlockController.values = {
|
|
30
|
-
endpoint: String,
|
|
31
|
-
errorMessage: String,
|
|
32
|
-
selector: String,
|
|
33
|
-
maxRetries: Number,
|
|
34
|
-
seconds: Number,
|
|
35
|
-
};
|
|
@@ -3,6 +3,8 @@ import { useEventListener } from "../mixins/use_event_listener";
|
|
|
3
3
|
import { installClassMethods } from "../mixins/install_class_methods";
|
|
4
4
|
import "../polyfills/string.replaceAll";
|
|
5
5
|
export class AnchorSpyController extends BaseController {
|
|
6
|
+
static values = { key: String };
|
|
7
|
+
static classes = ["active", "inactive"];
|
|
6
8
|
get defaultActiveClasses() {
|
|
7
9
|
return ["active"];
|
|
8
10
|
}
|
|
@@ -27,7 +29,7 @@ export class AnchorSpyController extends BaseController {
|
|
|
27
29
|
});
|
|
28
30
|
}
|
|
29
31
|
write(event) {
|
|
30
|
-
event
|
|
32
|
+
event?.preventDefault();
|
|
31
33
|
this._anchor = this._key;
|
|
32
34
|
}
|
|
33
35
|
_checkAnchor() {
|
|
@@ -43,5 +45,3 @@ export class AnchorSpyController extends BaseController {
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
|
-
AnchorSpyController.values = { key: String };
|
|
47
|
-
AnchorSpyController.classes = ["active", "inactive"];
|
|
@@ -2,6 +2,7 @@ import { BaseController } from "../utilities/base_controller";
|
|
|
2
2
|
import { useTimeout } from "../mixins/use_timeout";
|
|
3
3
|
import { useEventListener } from "../mixins/use_event_listener";
|
|
4
4
|
export class BackLinkController extends BaseController {
|
|
5
|
+
static values = { timeout: Number, pages: Number };
|
|
5
6
|
get _pages() {
|
|
6
7
|
return this.hasPagesValue ? Math.abs(this.pagesValue) : 1;
|
|
7
8
|
}
|
|
@@ -12,7 +13,7 @@ export class BackLinkController extends BaseController {
|
|
|
12
13
|
useEventListener(this, this.el, "click", this.goBack);
|
|
13
14
|
}
|
|
14
15
|
goBack(event) {
|
|
15
|
-
event
|
|
16
|
+
event?.preventDefault();
|
|
16
17
|
history.go(-this._pages);
|
|
17
18
|
if (this.el.href) {
|
|
18
19
|
useTimeout(this, this.fallback, this._timeout);
|
|
@@ -22,4 +23,3 @@ export class BackLinkController extends BaseController {
|
|
|
22
23
|
window.location.href = this.el.href;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
BackLinkController.values = { timeout: Number, pages: Number };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { BaseController } from "../utilities/base_controller";
|
|
2
2
|
export class ClipboardController extends BaseController {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
static targets = ["source", "button", "copy", "fallback"];
|
|
4
|
+
static values = { removeUnused: Boolean };
|
|
5
|
+
_supported = false;
|
|
7
6
|
connect() {
|
|
8
7
|
this._supported = document.queryCommandSupported("copy");
|
|
9
8
|
if (this.hasRemoveUnusedValue && this.removeUnusedValue) {
|
|
@@ -31,5 +30,3 @@ export class ClipboardController extends BaseController {
|
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
|
-
ClipboardController.targets = ["source", "button", "copy", "fallback"];
|
|
35
|
-
ClipboardController.values = { removeUnused: Boolean };
|
|
@@ -2,6 +2,9 @@ import { BaseController } from '../utilities/base_controller';
|
|
|
2
2
|
import { isHTMLAnchorElement, isHTMLFormElement } from "../utilities/elements";
|
|
3
3
|
import { useEventListener } from "../mixins/use_event_listener";
|
|
4
4
|
export class ConfirmController extends BaseController {
|
|
5
|
+
static values = {
|
|
6
|
+
message: String,
|
|
7
|
+
};
|
|
5
8
|
get _message() {
|
|
6
9
|
return this.hasMessageValue ? this.messageValue : 'Are you sure?';
|
|
7
10
|
}
|
|
@@ -28,6 +31,3 @@ export class ConfirmController extends BaseController {
|
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
|
-
ConfirmController.values = {
|
|
32
|
-
message: String,
|
|
33
|
-
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseController } from "../utilities/base_controller";
|
|
2
2
|
import { useEventListener } from "../mixins/use_event_listener";
|
|
3
3
|
export class ConfirmNavigationController extends BaseController {
|
|
4
|
+
static values = { message: String };
|
|
4
5
|
get _message() {
|
|
5
6
|
return this.hasMessageValue ? this.messageValue : "Do you want to leave this page? Changes you made may not be saved";
|
|
6
7
|
}
|
|
@@ -26,4 +27,3 @@ export class ConfirmNavigationController extends BaseController {
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
ConfirmNavigationController.values = { message: String };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseController } from "../utilities/base_controller";
|
|
2
2
|
export class DebugController extends BaseController {
|
|
3
|
+
static targets = ["test"];
|
|
3
4
|
connect() {
|
|
4
5
|
console.log("Debug Controller", this, this.testTargets);
|
|
5
6
|
}
|
|
6
7
|
}
|
|
7
|
-
DebugController.targets = ["test"];
|
|
@@ -3,6 +3,10 @@ import { isTypeOfButtonableElement } from "../utilities/elements";
|
|
|
3
3
|
import { useEventListener } from "../mixins/use_event_listener";
|
|
4
4
|
import { useTemporaryContent } from "../mixins/use_temporary_content";
|
|
5
5
|
export class DisableWithController extends BaseController {
|
|
6
|
+
static values = {
|
|
7
|
+
message: String,
|
|
8
|
+
timeout: Number,
|
|
9
|
+
};
|
|
6
10
|
get _message() {
|
|
7
11
|
return this.hasMessageValue ? this.messageValue : 'Submitting...';
|
|
8
12
|
}
|
|
@@ -18,8 +22,8 @@ export class DisableWithController extends BaseController {
|
|
|
18
22
|
disable(event) {
|
|
19
23
|
let element = this.el;
|
|
20
24
|
if (this._isDisabled(element)) {
|
|
21
|
-
event
|
|
22
|
-
event
|
|
25
|
+
event?.preventDefault();
|
|
26
|
+
event?.stopImmediatePropagation();
|
|
23
27
|
}
|
|
24
28
|
else {
|
|
25
29
|
this._disable();
|
|
@@ -27,7 +31,7 @@ export class DisableWithController extends BaseController {
|
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
enable(event) {
|
|
30
|
-
event
|
|
34
|
+
event?.preventDefault();
|
|
31
35
|
let element = this.el;
|
|
32
36
|
if (this._isDisabled(element)) {
|
|
33
37
|
this._enable();
|
|
@@ -60,7 +64,3 @@ export class DisableWithController extends BaseController {
|
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
|
-
DisableWithController.values = {
|
|
64
|
-
message: String,
|
|
65
|
-
timeout: Number,
|
|
66
|
-
};
|
|
@@ -4,6 +4,14 @@ import _set from "lodash-es/set";
|
|
|
4
4
|
import { BaseController } from '../utilities/base_controller';
|
|
5
5
|
import { useLocalStorage } from "../mixins";
|
|
6
6
|
export class ElementSaveController extends BaseController {
|
|
7
|
+
static targets = [
|
|
8
|
+
"element",
|
|
9
|
+
];
|
|
10
|
+
static values = {
|
|
11
|
+
id: String,
|
|
12
|
+
attributes: String,
|
|
13
|
+
restoreOnLoad: Boolean,
|
|
14
|
+
};
|
|
7
15
|
get _id() {
|
|
8
16
|
if (this.hasIdValue) {
|
|
9
17
|
return this.idValue;
|
|
@@ -70,11 +78,3 @@ export class ElementSaveController extends BaseController {
|
|
|
70
78
|
}
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
|
-
ElementSaveController.targets = [
|
|
74
|
-
"element",
|
|
75
|
-
];
|
|
76
|
-
ElementSaveController.values = {
|
|
77
|
-
id: String,
|
|
78
|
-
attributes: String,
|
|
79
|
-
restoreOnLoad: Boolean,
|
|
80
|
-
};
|
|
@@ -2,6 +2,9 @@ import { useMutationObserver } from "../mixins/use_mutation_observer";
|
|
|
2
2
|
import { BaseController } from "../utilities/base_controller";
|
|
3
3
|
import { installClassMethods } from "../mixins/install_class_methods";
|
|
4
4
|
export class EmptyDomController extends BaseController {
|
|
5
|
+
static targets = ["container"];
|
|
6
|
+
static classes = ["empty", "notEmpty"];
|
|
7
|
+
static values = { scopeSelector: String };
|
|
5
8
|
get _container() {
|
|
6
9
|
return this.hasContainerTarget ? this.containerTarget : this.el;
|
|
7
10
|
}
|
|
@@ -37,6 +40,3 @@ export class EmptyDomController extends BaseController {
|
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
|
-
EmptyDomController.targets = ["container"];
|
|
41
|
-
EmptyDomController.classes = ["empty", "notEmpty"];
|
|
42
|
-
EmptyDomController.values = { scopeSelector: String };
|
|
@@ -2,6 +2,7 @@ import { BaseController } from "../utilities/base_controller";
|
|
|
2
2
|
import debounce from "lodash-es/debounce";
|
|
3
3
|
import { useIntersection } from "../mixins/use_intersection";
|
|
4
4
|
export class EqualizeController extends BaseController {
|
|
5
|
+
static targets = ["watch"];
|
|
5
6
|
initialize() {
|
|
6
7
|
this._equalize = debounce(this._equalize.bind(this), 100);
|
|
7
8
|
this.observer = new ResizeObserver((_entries) => this._equalize());
|
|
@@ -36,4 +37,3 @@ export class EqualizeController extends BaseController {
|
|
|
36
37
|
Array.from(this.watchTargets).forEach(target => target.style.minHeight = "");
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
EqualizeController.targets = ["watch"];
|
|
@@ -2,6 +2,7 @@ import { BaseController } from "../../utilities/base_controller";
|
|
|
2
2
|
import { requestSubmit } from "../../utilities/request_submit";
|
|
3
3
|
import { useEventListener } from "../../mixins/use_event_listener";
|
|
4
4
|
export class AutoSubmitFormController extends BaseController {
|
|
5
|
+
static values = { submitMode: String, eventMode: String, debounceInterval: Number };
|
|
5
6
|
get _eventModes() {
|
|
6
7
|
if (this.hasEventModeValue) {
|
|
7
8
|
let modes = this.eventModeValue.split(' ').map(mode => mode.trim());
|
|
@@ -59,4 +60,3 @@ export class AutoSubmitFormController extends BaseController {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
|
-
AutoSubmitFormController.values = { submitMode: String, eventMode: String, debounceInterval: Number };
|
|
@@ -2,6 +2,10 @@ import { BaseController } from "../../utilities/base_controller";
|
|
|
2
2
|
import { useEventListener } from "../../mixins/use_event_listener";
|
|
3
3
|
import { installClassMethods } from "../../mixins/install_class_methods";
|
|
4
4
|
export class CharCountController extends BaseController {
|
|
5
|
+
// Config
|
|
6
|
+
static targets = ["input", "output"];
|
|
7
|
+
static values = { min: Number, max: Number };
|
|
8
|
+
static classes = ["error"];
|
|
5
9
|
connect() {
|
|
6
10
|
installClassMethods(this);
|
|
7
11
|
requestAnimationFrame(() => {
|
|
@@ -31,7 +35,3 @@ export class CharCountController extends BaseController {
|
|
|
31
35
|
return count >= min && count <= max;
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
|
-
// Config
|
|
35
|
-
CharCountController.targets = ["input", "output"];
|
|
36
|
-
CharCountController.values = { min: Number, max: Number };
|
|
37
|
-
CharCountController.classes = ["error"];
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { BaseController } from "../../utilities/base_controller";
|
|
2
2
|
export class CheckboxDisableInputsController extends BaseController {
|
|
3
|
+
static targets = ["disabler", "disable"];
|
|
4
|
+
static values = {
|
|
5
|
+
clear: Boolean,
|
|
6
|
+
};
|
|
3
7
|
connect() {
|
|
4
8
|
this.toggle();
|
|
5
9
|
}
|
|
@@ -26,7 +30,3 @@ export class CheckboxDisableInputsController extends BaseController {
|
|
|
26
30
|
});
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
|
-
CheckboxDisableInputsController.targets = ["disabler", "disable"];
|
|
30
|
-
CheckboxDisableInputsController.values = {
|
|
31
|
-
clear: Boolean,
|
|
32
|
-
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { BaseController } from "../../utilities/base_controller";
|
|
2
2
|
export class CheckboxEnableInputsController extends BaseController {
|
|
3
|
+
static targets = ["enabler", "enable"];
|
|
4
|
+
static values = {
|
|
5
|
+
clear: Boolean,
|
|
6
|
+
};
|
|
3
7
|
connect() {
|
|
4
8
|
this.toggle();
|
|
5
9
|
}
|
|
@@ -26,7 +30,3 @@ export class CheckboxEnableInputsController extends BaseController {
|
|
|
26
30
|
});
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
|
-
CheckboxEnableInputsController.targets = ["enabler", "enable"];
|
|
30
|
-
CheckboxEnableInputsController.values = {
|
|
31
|
-
clear: Boolean,
|
|
32
|
-
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseController } from '../../utilities/base_controller';
|
|
2
2
|
import { useCollectionEventListener, useEventListener } from "../../mixins/use_event_listener";
|
|
3
3
|
export class CheckboxSelectAllController extends BaseController {
|
|
4
|
+
static targets = ['selectAll', 'checkbox'];
|
|
4
5
|
get _checked() {
|
|
5
6
|
return this._enabled.filter(checkbox => checkbox.checked);
|
|
6
7
|
}
|
|
@@ -32,4 +33,3 @@ export class CheckboxSelectAllController extends BaseController {
|
|
|
32
33
|
this.selectAllTarget.indeterminate = checkboxesCheckedCount > 0 && checkboxesCheckedCount < checkboxesCount;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
CheckboxSelectAllController.targets = ['selectAll', 'checkbox'];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseController } from "../../utilities/base_controller";
|
|
2
2
|
import { useCollectionEventListener } from "../../mixins";
|
|
3
3
|
export class CheckboxXORController extends BaseController {
|
|
4
|
+
static targets = ["checkbox"];
|
|
4
5
|
connect() {
|
|
5
6
|
useCollectionEventListener(this, this.checkboxTargets, "change", this._update);
|
|
6
7
|
}
|
|
@@ -21,4 +22,3 @@ export class CheckboxXORController extends BaseController {
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
CheckboxXORController.targets = ["checkbox"];
|
|
@@ -12,7 +12,7 @@ export class DetectDirtyController extends BaseController {
|
|
|
12
12
|
useEventListener(this, element, ["input", "change"], this._checkDirty, { debounce: 10 });
|
|
13
13
|
}
|
|
14
14
|
restore(event) {
|
|
15
|
-
event
|
|
15
|
+
event?.preventDefault();
|
|
16
16
|
this._restoreElementFromLoadValue();
|
|
17
17
|
}
|
|
18
18
|
_getElementValue() {
|
|
@@ -15,7 +15,7 @@ export class DetectDirtyFormController extends BaseController {
|
|
|
15
15
|
useEventListener(this, element, ["input", "change"], this._checkDirty, { debounce: 10 });
|
|
16
16
|
}
|
|
17
17
|
restore(event) {
|
|
18
|
-
event
|
|
18
|
+
event?.preventDefault();
|
|
19
19
|
this._formElements.forEach(element => this._restoreElementFromLoadValue(element));
|
|
20
20
|
}
|
|
21
21
|
_getElementValue(element) {
|