stimulus-library 0.3.19 → 0.4.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.
- package/CHANGELOG.md +14 -0
- package/dist/controllers/ajax/async_block_controller.d.ts +18 -18
- package/dist/controllers/ajax/lazy_block_controller.d.ts +9 -9
- package/dist/controllers/ajax/load_block_controller.d.ts +19 -19
- package/dist/controllers/ajax/poll_block_controller.d.ts +16 -16
- package/dist/controllers/anchor_spy_controller.d.ts +15 -15
- package/dist/controllers/back_link_controller.d.ts +19 -19
- package/dist/controllers/clipboard_controller.d.ts +18 -18
- package/dist/controllers/confirm_controller.d.ts +13 -13
- package/dist/controllers/confirm_navigation_controller.d.ts +15 -15
- package/dist/controllers/debug_controller.d.ts +6 -6
- package/dist/controllers/disable_with_controller.d.ts +25 -25
- package/dist/controllers/dismissable_controller.d.ts +6 -6
- package/dist/controllers/element_save_controller.d.ts +25 -25
- package/dist/controllers/empty_dom_controller.d.ts +29 -29
- package/dist/controllers/forms/auto_submit_form_controller.d.ts +15 -14
- package/dist/controllers/forms/auto_submit_form_controller.d.ts.map +1 -1
- package/dist/controllers/forms/autosize_controller.d.ts +9 -9
- package/dist/controllers/forms/char_count_controller.d.ts +26 -26
- package/dist/controllers/forms/checkbox_select_all_controller.d.ts +14 -14
- package/dist/controllers/forms/detect_dirty_controller.d.ts +16 -16
- package/dist/controllers/forms/detect_dirty_form_controller.d.ts +19 -19
- package/dist/controllers/forms/disable_inputs_controller.d.ts +16 -16
- package/dist/controllers/forms/enable_inputs_controller.d.ts +16 -16
- package/dist/controllers/forms/form_rc_controller.d.ts +13 -7
- package/dist/controllers/forms/form_rc_controller.d.ts.map +1 -1
- package/dist/controllers/forms/form_save_controller.d.ts +33 -33
- package/dist/controllers/forms/limited_selection_checkboxes_controller.d.ts +17 -17
- package/dist/controllers/forms/navigate_form_errors_controller.d.ts +34 -34
- package/dist/controllers/forms/nested_form_controller.d.ts +21 -21
- package/dist/controllers/forms/password_confirm_controller.d.ts +17 -17
- package/dist/controllers/forms/password_peek_controller.d.ts +8 -8
- package/dist/controllers/forms/remote_form_controller.d.ts +13 -13
- package/dist/controllers/forms/sync_inputs_controller.d.ts +21 -21
- package/dist/controllers/forms/value_warn_controller.d.ts +39 -39
- package/dist/controllers/forms/word_count_controller.d.ts +26 -26
- package/dist/controllers/media/fallback_image_controller.d.ts +27 -27
- package/dist/controllers/media/lightbox_image_controller.d.ts +29 -29
- package/dist/controllers/media/media_player_controller.d.ts +12 -12
- package/dist/controllers/prefetch_controller.d.ts +18 -18
- package/dist/controllers/responsive_iframe_controller.d.ts +23 -23
- package/dist/controllers/scroll/scroll_container_controller.d.ts +21 -21
- package/dist/controllers/scroll/scroll_into_focus_controller.d.ts +15 -15
- package/dist/controllers/scroll/scroll_to_bottom_controller.d.ts +11 -11
- package/dist/controllers/scroll/scroll_to_controller.d.ts +17 -17
- package/dist/controllers/scroll/scroll_to_top_controller.d.ts +11 -11
- package/dist/controllers/self_destruct_controller.d.ts +10 -10
- package/dist/controllers/sticky_controller.d.ts +19 -19
- package/dist/controllers/tables/table_sort_controller.d.ts +20 -20
- package/dist/controllers/tables/table_truncate_controller.d.ts +26 -26
- package/dist/controllers/teleport_controller.d.ts +15 -15
- package/dist/controllers/temporary_state_controller.d.ts +28 -28
- package/dist/controllers/toggle_class_controller.d.ts +35 -35
- package/dist/controllers/turbo_frame_rc_controller.d.ts +20 -20
- package/dist/controllers/turbo_frame_refresh_controller.d.ts +16 -16
- package/dist/controllers/utility/intersection_controller.d.ts +13 -13
- package/dist/controllers/utility/interval_controller.d.ts +13 -13
- package/dist/controllers/utility/presence_controller.d.ts +5 -5
- package/dist/controllers/utility/timeout_controller.d.ts +12 -12
- package/dist/controllers/utility/user_focus_controller.d.ts +10 -10
- package/dist/controllers/visual/clock_controller.d.ts +18 -18
- package/dist/controllers/visual/countdown_controller.d.ts +53 -53
- package/dist/controllers/visual/duration_controller.d.ts +27 -27
- package/dist/controllers/visual/tabs_controller.d.ts +37 -37
- package/dist/controllers/visual/time_distance_controller.d.ts +18 -18
- package/dist/controllers/visual/tree_view_controller.d.ts +29 -29
- package/dist/index.d.ts +66 -66
- package/dist/stimulus-library.cjs.js +2 -0
- package/dist/stimulus-library.cjs.js.map +1 -0
- package/dist/stimulus-library.es.js +2 -0
- package/dist/stimulus-library.es.js.map +1 -0
- package/dist/stimulus-library.umd.js +1 -1
- package/dist/stimulus-library.umd.js.map +1 -1
- package/dist/utilities/base_controller.d.ts +13 -13
- package/dist/utilities/base_controller.d.ts.map +1 -1
- package/dist/utilities/elements.d.ts +13 -13
- package/dist/utilities/ephemeral_controller.d.ts +5 -5
- package/dist/utilities/event_bus.d.ts +3 -3
- package/dist/utilities/requestSubmit.d.ts +2 -2
- package/dist/utilities/scroll.d.ts +10 -10
- package/dist/utilities/turbo.d.ts +1 -1
- package/package.json +16 -10
- package/dist/stimulus-library.js +0 -2
- package/dist/stimulus-library.js.map +0 -1
- package/dist/stimulus-library.modern.js +0 -2
- package/dist/stimulus-library.modern.js.map +0 -1
- package/dist/stimulus-library.module.js +0 -2
- package/dist/stimulus-library.module.js.map +0 -1
- package/src/controllers/ajax/async_block_controller.ts +0 -28
- package/src/controllers/ajax/lazy_block_controller.ts +0 -31
- package/src/controllers/ajax/load_block_controller.ts +0 -59
- package/src/controllers/ajax/poll_block_controller.ts +0 -32
- package/src/controllers/anchor_spy_controller.ts +0 -47
- package/src/controllers/back_link_controller.ts +0 -49
- package/src/controllers/clipboard_controller.ts +0 -47
- package/src/controllers/confirm_controller.ts +0 -50
- package/src/controllers/confirm_navigation_controller.ts +0 -51
- package/src/controllers/debug_controller.ts +0 -11
- package/src/controllers/disable_with_controller.ts +0 -116
- package/src/controllers/dismissable_controller.ts +0 -12
- package/src/controllers/element_save_controller.ts +0 -93
- package/src/controllers/empty_dom_controller.ts +0 -105
- package/src/controllers/forms/auto_submit_form_controller.ts +0 -59
- package/src/controllers/forms/autosize_controller.ts +0 -41
- package/src/controllers/forms/char_count_controller.ts +0 -91
- package/src/controllers/forms/checkbox_select_all_controller.ts +0 -57
- package/src/controllers/forms/detect_dirty_controller.ts +0 -116
- package/src/controllers/forms/detect_dirty_form_controller.ts +0 -127
- package/src/controllers/forms/disable_inputs_controller.ts +0 -44
- package/src/controllers/forms/enable_inputs_controller.ts +0 -44
- package/src/controllers/forms/form_rc_controller.ts +0 -20
- package/src/controllers/forms/form_save_controller.ts +0 -141
- package/src/controllers/forms/limited_selection_checkboxes_controller.ts +0 -44
- package/src/controllers/forms/navigate_form_errors_controller.ts +0 -144
- package/src/controllers/forms/nested_form_controller.ts +0 -68
- package/src/controllers/forms/password_confirm_controller.ts +0 -68
- package/src/controllers/forms/password_peek_controller.ts +0 -27
- package/src/controllers/forms/remote_form_controller.ts +0 -34
- package/src/controllers/forms/sync_inputs_controller.ts +0 -89
- package/src/controllers/forms/value_warn_controller.ts +0 -107
- package/src/controllers/forms/word_count_controller.ts +0 -86
- package/src/controllers/media/fallback_image_controller.ts +0 -108
- package/src/controllers/media/lightbox_image_controller.ts +0 -89
- package/src/controllers/media/media_player_controller.ts +0 -37
- package/src/controllers/prefetch_controller.ts +0 -99
- package/src/controllers/responsive_iframe_controller.ts +0 -75
- package/src/controllers/scroll/scroll_container_controller.ts +0 -73
- package/src/controllers/scroll/scroll_into_focus_controller.ts +0 -34
- package/src/controllers/scroll/scroll_to_bottom_controller.ts +0 -35
- package/src/controllers/scroll/scroll_to_controller.ts +0 -38
- package/src/controllers/scroll/scroll_to_top_controller.ts +0 -35
- package/src/controllers/self_destruct_controller.ts +0 -23
- package/src/controllers/sticky_controller.ts +0 -84
- package/src/controllers/tables/table_sort_controller.ts +0 -105
- package/src/controllers/tables/table_truncate_controller.ts +0 -106
- package/src/controllers/teleport_controller.ts +0 -64
- package/src/controllers/temporary_state_controller.ts +0 -82
- package/src/controllers/toggle_class_controller.ts +0 -149
- package/src/controllers/turbo_frame_rc_controller.ts +0 -77
- package/src/controllers/turbo_frame_refresh_controller.ts +0 -51
- package/src/controllers/utility/intersection_controller.ts +0 -51
- package/src/controllers/utility/interval_controller.ts +0 -34
- package/src/controllers/utility/presence_controller.ts +0 -13
- package/src/controllers/utility/timeout_controller.ts +0 -30
- package/src/controllers/utility/user_focus_controller.ts +0 -40
- package/src/controllers/visual/clock_controller.ts +0 -75
- package/src/controllers/visual/countdown_controller.ts +0 -198
- package/src/controllers/visual/duration_controller.ts +0 -106
- package/src/controllers/visual/tabs_controller.ts +0 -162
- package/src/controllers/visual/time_distance_controller.ts +0 -66
- package/src/controllers/visual/tree_view_controller.ts +0 -154
- package/src/index.ts +0 -71
- package/src/utilities/base_controller.ts +0 -143
- package/src/utilities/elements.ts +0 -47
- package/src/utilities/ephemeral_controller.ts +0 -45
- package/src/utilities/event_bus.ts +0 -3
- package/src/utilities/requestSubmit.ts +0 -23
- package/src/utilities/scroll.ts +0 -101
- package/src/utilities/turbo.ts +0 -3
- package/src/utilities/types.d.ts +0 -4
- package/tsconfig.json +0 -27
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {EphemeralController} from "../../utilities/ephemeral_controller";
|
|
2
|
-
import {scrollToElement} from "../../utilities/scroll";
|
|
3
|
-
|
|
4
|
-
export class ScrollIntoFocusController extends EphemeralController {
|
|
5
|
-
|
|
6
|
-
static values = {
|
|
7
|
-
behavior: String,
|
|
8
|
-
block: String,
|
|
9
|
-
inline: String,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
declare behaviorValue: ScrollBehavior;
|
|
13
|
-
declare hasBehaviorValue: boolean;
|
|
14
|
-
declare blockValue: ScrollLogicalPosition;
|
|
15
|
-
declare hasBlockValue: boolean;
|
|
16
|
-
declare inlineValue: ScrollLogicalPosition;
|
|
17
|
-
declare hasInlineValue: boolean;
|
|
18
|
-
|
|
19
|
-
connect() {
|
|
20
|
-
requestAnimationFrame(() => {
|
|
21
|
-
// Attempt smooth scrolling, with polyfill
|
|
22
|
-
scrollToElement(
|
|
23
|
-
this.el,
|
|
24
|
-
{
|
|
25
|
-
behavior: this.hasBehaviorValue ? this.behaviorValue : "smooth",
|
|
26
|
-
block: this.hasBlockValue ? this.blockValue : "center",
|
|
27
|
-
inline: this.hasInlineValue ? this.inlineValue : "center",
|
|
28
|
-
},
|
|
29
|
-
).catch(() => this.el.scrollIntoView()); // Fallback to snap-scrolling
|
|
30
|
-
this._cleanupSelf();
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {BaseController} from "../../utilities/base_controller";
|
|
2
|
-
import {getScrollParent, scrollAbsoluteBottom} from "../../utilities/scroll";
|
|
3
|
-
|
|
4
|
-
export class ScrollToBottomController extends BaseController {
|
|
5
|
-
|
|
6
|
-
static values = {
|
|
7
|
-
mode: String,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
declare modeValue: "nearest" | "document";
|
|
11
|
-
declare hasModeValue: boolean;
|
|
12
|
-
|
|
13
|
-
get _mode(): "nearest" | "document" {
|
|
14
|
-
return this.hasModeValue ? this.modeValue : "document";
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get _scrollTarget(): HTMLElement | Window | null {
|
|
18
|
-
let target: null | HTMLElement | Window;
|
|
19
|
-
if (this._mode == "document") {
|
|
20
|
-
target = window;
|
|
21
|
-
} else {
|
|
22
|
-
target = getScrollParent(this.el);
|
|
23
|
-
}
|
|
24
|
-
return target;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async scroll(event?: Event) {
|
|
28
|
-
event?.preventDefault();
|
|
29
|
-
if (this._scrollTarget) {
|
|
30
|
-
await scrollAbsoluteBottom(this._scrollTarget);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import {BaseController} from "../../utilities/base_controller";
|
|
2
|
-
import {scrollToElement} from "../../utilities/scroll";
|
|
3
|
-
|
|
4
|
-
export class ScrollToController extends BaseController {
|
|
5
|
-
|
|
6
|
-
static values = {
|
|
7
|
-
selector: String,
|
|
8
|
-
behavior: String,
|
|
9
|
-
block: String,
|
|
10
|
-
inline: String,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
declare selectorValue: string;
|
|
14
|
-
declare behaviorValue: ScrollBehavior;
|
|
15
|
-
declare hasBehaviorValue: boolean;
|
|
16
|
-
declare blockValue: ScrollLogicalPosition;
|
|
17
|
-
declare hasBlockValue: boolean;
|
|
18
|
-
declare inlineValue: ScrollLogicalPosition;
|
|
19
|
-
declare hasInlineValue: boolean;
|
|
20
|
-
|
|
21
|
-
scroll() {
|
|
22
|
-
let target = document.querySelector(this.selectorValue);
|
|
23
|
-
if (!target) {
|
|
24
|
-
console.warn(`Could not find target for '${this.selectorValue}'`);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
scrollToElement(
|
|
29
|
-
target!,
|
|
30
|
-
{
|
|
31
|
-
behavior: this.hasBehaviorValue ? this.behaviorValue : "smooth",
|
|
32
|
-
block: this.hasBlockValue ? this.blockValue : "center",
|
|
33
|
-
inline: this.hasInlineValue ? this.inlineValue : "center",
|
|
34
|
-
},
|
|
35
|
-
).catch(() => target!.scrollIntoView()); // Fallback to snap-scrolling
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {BaseController} from "../../utilities/base_controller";
|
|
2
|
-
import {getScrollParent, scrollAbsoluteTop} from "../../utilities/scroll";
|
|
3
|
-
|
|
4
|
-
export class ScrollToTopController extends BaseController {
|
|
5
|
-
|
|
6
|
-
static values = {
|
|
7
|
-
mode: String,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
declare modeValue: "nearest" | "document";
|
|
11
|
-
declare hasModeValue: boolean;
|
|
12
|
-
|
|
13
|
-
get _mode(): "nearest" | "document" {
|
|
14
|
-
return this.hasModeValue ? this.modeValue : "document";
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get _scrollTarget(): HTMLElement | Window | null {
|
|
18
|
-
let target: null | HTMLElement | Window;
|
|
19
|
-
if (this._mode == "document") {
|
|
20
|
-
target = window;
|
|
21
|
-
} else {
|
|
22
|
-
target = getScrollParent(this.el);
|
|
23
|
-
}
|
|
24
|
-
return target;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async scroll(event?: Event) {
|
|
28
|
-
event?.preventDefault();
|
|
29
|
-
if (this._scrollTarget) {
|
|
30
|
-
await scrollAbsoluteTop(this._scrollTarget);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {BaseController} from "../utilities/base_controller";
|
|
2
|
-
|
|
3
|
-
export class SelfDestructController extends BaseController {
|
|
4
|
-
|
|
5
|
-
static values = {seconds: Number};
|
|
6
|
-
|
|
7
|
-
declare readonly secondsValue: number;
|
|
8
|
-
_timeout: null | ReturnType<typeof window.setTimeout> = null;
|
|
9
|
-
|
|
10
|
-
connect() {
|
|
11
|
-
requestAnimationFrame(() => {
|
|
12
|
-
// Only start countdown on first paint
|
|
13
|
-
this._timeout = setTimeout(() => this.el.remove(), this.secondsValue * 1000);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
disconnect() {
|
|
18
|
-
if (this._timeout) {
|
|
19
|
-
clearTimeout(this._timeout);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import {BaseController} from "../utilities/base_controller";
|
|
2
|
-
|
|
3
|
-
export class StickyController extends BaseController {
|
|
4
|
-
|
|
5
|
-
static classes = ["stuck"];
|
|
6
|
-
static values = {mode: String};
|
|
7
|
-
|
|
8
|
-
declare readonly stuckClass: string;
|
|
9
|
-
declare readonly hasStuckClass: boolean;
|
|
10
|
-
|
|
11
|
-
declare readonly hasModeValue: "top" | "bottom";
|
|
12
|
-
declare readonly modeValue: "top" | "bottom";
|
|
13
|
-
|
|
14
|
-
_magicElement: HTMLDivElement | null = null;
|
|
15
|
-
|
|
16
|
-
get _stuckClasses(): string[] {
|
|
17
|
-
return this.stuckClass.split(' ');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get _defaultStuckClasses(): string[] {
|
|
21
|
-
return ["stuck"];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get _mode(): "top" | "bottom" {
|
|
25
|
-
return this.hasModeValue ? this.modeValue : "top";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
createMagicElement() {
|
|
29
|
-
// Magic element placed next to the sticky el that acts as an external border.
|
|
30
|
-
// When the magic element is off the page, we know that the sticky el is "stuck"
|
|
31
|
-
if (this._magicElement !== null) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this._magicElement = document.createElement("div");
|
|
36
|
-
switch (this._mode) {
|
|
37
|
-
case "top":
|
|
38
|
-
this.el.insertAdjacentElement("beforebegin", this._magicElement);
|
|
39
|
-
break;
|
|
40
|
-
case "bottom":
|
|
41
|
-
this.el.insertAdjacentElement("afterend", this._magicElement);
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
connect() {
|
|
47
|
-
let element = this.el;
|
|
48
|
-
this.createMagicElement();
|
|
49
|
-
|
|
50
|
-
const observer = new IntersectionObserver(entries => {
|
|
51
|
-
entries.forEach(entry => {
|
|
52
|
-
if (entry.target !== this._magicElement) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (entry.intersectionRatio === 0) {
|
|
56
|
-
this._addStuckClasses();
|
|
57
|
-
} else if (entry.intersectionRatio === 1) {
|
|
58
|
-
this._removeStuckClasses();
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
}, {
|
|
63
|
-
threshold: [0, 1],
|
|
64
|
-
});
|
|
65
|
-
observer.observe(this._magicElement!);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
private _addStuckClasses(el: HTMLElement = this.el) {
|
|
69
|
-
if (this.hasStuckClass) {
|
|
70
|
-
el.classList.add(...this._stuckClasses);
|
|
71
|
-
} else {
|
|
72
|
-
el.classList.add(...this._defaultStuckClasses);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private _removeStuckClasses(el: HTMLElement = this.el) {
|
|
77
|
-
if (this.hasStuckClass) {
|
|
78
|
-
el.classList.remove(...this._stuckClasses);
|
|
79
|
-
} else {
|
|
80
|
-
el.classList.remove(...this._defaultStuckClasses);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import {BaseController} from "../../utilities/base_controller";
|
|
2
|
-
|
|
3
|
-
export class TableSortController extends BaseController {
|
|
4
|
-
|
|
5
|
-
static values = {startSort: Number};
|
|
6
|
-
|
|
7
|
-
declare readonly startSortValue: number;
|
|
8
|
-
declare readonly hasStartSortValue: boolean;
|
|
9
|
-
_lastIndex: number | null = null;
|
|
10
|
-
_reverse: boolean = false;
|
|
11
|
-
|
|
12
|
-
get _tableHead(): HTMLTableSectionElement {
|
|
13
|
-
let head = (this.el as HTMLTableElement).tHead;
|
|
14
|
-
if (head == null) {
|
|
15
|
-
throw new Error('Expected table to have a <thead> element.');
|
|
16
|
-
}
|
|
17
|
-
return head;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get _tableHeaders(): HTMLTableHeaderCellElement[] {
|
|
21
|
-
let rows = this._tableHead.rows;
|
|
22
|
-
if (rows.length == 0) {
|
|
23
|
-
throw new Error('Expected table to have a <thead> element with at least one row.');
|
|
24
|
-
}
|
|
25
|
-
return Array.from(rows[0].cells);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get _tableBody() {
|
|
29
|
-
return (this.el as HTMLTableElement).tBodies[0];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get _tableRows(): HTMLTableRowElement[] {
|
|
33
|
-
return Array.from(this._tableBody.rows);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
initialize() {
|
|
37
|
-
this.sort = this.sort.bind(this);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
connect() {
|
|
41
|
-
requestAnimationFrame(() => {
|
|
42
|
-
this._tableHeaders.forEach(cell => cell.addEventListener("click", this.sort));
|
|
43
|
-
if (this.hasStartSortValue) {
|
|
44
|
-
this._sortByColumn(this.startSortValue);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
disconnect() {
|
|
50
|
-
this._tableHeaders.forEach(cell => cell.removeEventListener("click", this.sort));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
sort(event: Event) {
|
|
54
|
-
event.preventDefault();
|
|
55
|
-
let headerCell = event.target! as HTMLTableHeaderCellElement;
|
|
56
|
-
let headerCellIndex = this._indexOfHeaderCell(headerCell);
|
|
57
|
-
this._sortByColumn(headerCellIndex);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private _indexOfHeaderCell(cell: HTMLTableHeaderCellElement) {
|
|
61
|
-
return this._tableHeaders.indexOf(cell);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private _sortByColumn(index: number) {
|
|
65
|
-
this._reverse = index === this._lastIndex && !this._reverse;
|
|
66
|
-
let frag = document.createDocumentFragment();
|
|
67
|
-
let rows = this._tableRows;
|
|
68
|
-
|
|
69
|
-
let newRows = rows.sort((row, otherRow) => {
|
|
70
|
-
let cells = Array.from(row.cells);
|
|
71
|
-
let otherCells = Array.from(otherRow.cells);
|
|
72
|
-
|
|
73
|
-
// TODO: Handle colspans?
|
|
74
|
-
let x = cells[index]?.innerText || "";
|
|
75
|
-
let y = otherCells[index]?.innerText || "";
|
|
76
|
-
|
|
77
|
-
let sortVal = x.localeCompare(y, "en", {sensitivity: "base", numeric: true, caseFirst: "upper"});
|
|
78
|
-
|
|
79
|
-
if (row.dataset.sortTop || otherRow.dataset.sortBottom) {
|
|
80
|
-
if (row.dataset.sortTop && otherRow.dataset.sortTop) {
|
|
81
|
-
return sortVal;
|
|
82
|
-
}
|
|
83
|
-
return -1;
|
|
84
|
-
}
|
|
85
|
-
if (row.dataset.sortBottom || otherRow.dataset.sortTop) {
|
|
86
|
-
if (row.dataset.sortBottom && otherRow.dataset.sortBottom) {
|
|
87
|
-
return sortVal;
|
|
88
|
-
}
|
|
89
|
-
return 1;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (this._reverse) {
|
|
93
|
-
return sortVal > 0 ? -1 : 1;
|
|
94
|
-
}
|
|
95
|
-
return sortVal;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
newRows.forEach(row => frag.appendChild(row));
|
|
99
|
-
|
|
100
|
-
this._tableBody.innerHTML = "";
|
|
101
|
-
this._tableBody.appendChild(frag);
|
|
102
|
-
this._lastIndex = index;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import {useMutation} from "stimulus-use";
|
|
2
|
-
import {BaseController} from "../../utilities/base_controller";
|
|
3
|
-
|
|
4
|
-
export class TableTruncateController extends BaseController {
|
|
5
|
-
|
|
6
|
-
static targets = ["showMore"];
|
|
7
|
-
static values = {
|
|
8
|
-
limit: Number,
|
|
9
|
-
truncated: Boolean,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
declare readonly showMoreTarget: HTMLElement;
|
|
13
|
-
declare limitValue: number;
|
|
14
|
-
declare readonly hasLimitValue: boolean;
|
|
15
|
-
declare truncatedValue: boolean;
|
|
16
|
-
declare readonly hasTruncatedValue: boolean;
|
|
17
|
-
|
|
18
|
-
get _truncated(): boolean {
|
|
19
|
-
return this.hasTruncatedValue ? this.truncatedValue : false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
set _truncated(value) {
|
|
23
|
-
this.truncatedValue = value;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get _tableBody(): HTMLTableSectionElement {
|
|
27
|
-
return (this.el as HTMLTableElement).tBodies[0];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get _tableRows(): HTMLTableRowElement[] {
|
|
31
|
-
return Array.from(this._tableBody.rows);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get _limit(): number {
|
|
35
|
-
return this.hasLimitValue ? this.limitValue : 20;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
initialize() {
|
|
39
|
-
this.truncate = this.truncate.bind(this);
|
|
40
|
-
this.expand = this.expand.bind(this);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
connect() {
|
|
44
|
-
useMutation(this, {childList: true, element: this._tableBody});
|
|
45
|
-
|
|
46
|
-
requestAnimationFrame(() => {
|
|
47
|
-
this.truncate();
|
|
48
|
-
this.showMoreTarget.addEventListener("click", this.expand);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
truncate(event?: Event) {
|
|
53
|
-
event?.preventDefault();
|
|
54
|
-
this._truncated = true;
|
|
55
|
-
if (this._tableRows.length >= this._limit) {
|
|
56
|
-
this._tableRows.slice(this._limit).forEach((el) => {
|
|
57
|
-
if (el !== this.showMoreTarget) {
|
|
58
|
-
this._hideElement(el);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
this._showElement(this.showMoreTarget);
|
|
62
|
-
} else {
|
|
63
|
-
this._hideElement(this.showMoreTarget);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
expand(event?: Event) {
|
|
68
|
-
this._truncated = false;
|
|
69
|
-
event?.preventDefault();
|
|
70
|
-
this._tableRows.slice(this._limit).forEach((el) => {
|
|
71
|
-
if (el !== this.showMoreTarget) {
|
|
72
|
-
this._showElement(el);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
this._hideElement(this.showMoreTarget);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
mutate(entries: MutationRecord[]) {
|
|
79
|
-
if (this._truncated) {
|
|
80
|
-
this._reTruncate();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private _showElement(el: HTMLElement): void {
|
|
85
|
-
el.style.display = "";
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private _hideElement(el: HTMLElement): void {
|
|
89
|
-
el.style.display = "none";
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private _reTruncate() {
|
|
93
|
-
this._tableRows.slice(0, this._limit).forEach((el) => {
|
|
94
|
-
if (el !== this.showMoreTarget) {
|
|
95
|
-
this._showElement(el);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
this._tableRows.slice(this._limit).forEach((el) => {
|
|
99
|
-
if (el !== this.showMoreTarget) {
|
|
100
|
-
this._hideElement(el);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
this._showElement(this.showMoreTarget);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {EphemeralController} from "../utilities/ephemeral_controller";
|
|
2
|
-
|
|
3
|
-
export class TeleportController extends EphemeralController {
|
|
4
|
-
|
|
5
|
-
static values = {target: String, insert: String, immediate: Boolean};
|
|
6
|
-
|
|
7
|
-
declare readonly immediateValue: boolean;
|
|
8
|
-
declare readonly hasImmediateValue: boolean;
|
|
9
|
-
declare readonly targetValue: string;
|
|
10
|
-
declare readonly hasInsertValue: boolean;
|
|
11
|
-
declare readonly insertValue: InsertPosition | "replaceOuter" | "replaceInner" | "prepend" | "append";
|
|
12
|
-
|
|
13
|
-
connect() {
|
|
14
|
-
if (!this.hasInsertValue) {
|
|
15
|
-
throw new Error("`insert` value was not specified");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
requestAnimationFrame(() => {
|
|
19
|
-
if (this.hasImmediateValue && this.immediateValue) {
|
|
20
|
-
this.execute();
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
execute(event?: Event) {
|
|
26
|
-
event?.preventDefault();
|
|
27
|
-
let element = this.el;
|
|
28
|
-
let destination = document.querySelector(this.targetValue);
|
|
29
|
-
|
|
30
|
-
if (destination == null) {
|
|
31
|
-
this.dispatch(element, "teleport:error");
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let copy = element.cloneNode(true) as HTMLElement;
|
|
36
|
-
this.cleanup(copy);
|
|
37
|
-
|
|
38
|
-
switch (this.insertValue) {
|
|
39
|
-
case "beforebegin":
|
|
40
|
-
case "beforeend":
|
|
41
|
-
case "afterend":
|
|
42
|
-
case "afterbegin":
|
|
43
|
-
destination.insertAdjacentHTML(this.insertValue, copy.outerHTML);
|
|
44
|
-
break;
|
|
45
|
-
case "replaceOuter":
|
|
46
|
-
destination.outerHTML = copy.outerHTML;
|
|
47
|
-
break;
|
|
48
|
-
case "replaceInner":
|
|
49
|
-
destination.innerHTML = copy.outerHTML;
|
|
50
|
-
break;
|
|
51
|
-
case "prepend":
|
|
52
|
-
destination.insertAdjacentHTML("afterbegin", copy.outerHTML);
|
|
53
|
-
break;
|
|
54
|
-
case "append":
|
|
55
|
-
destination.insertAdjacentHTML("beforeend", copy.outerHTML);
|
|
56
|
-
break;
|
|
57
|
-
default:
|
|
58
|
-
throw new Error("`insert` value was not specified");
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
element.remove();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {camelCase, get as _get, set as _set} from "lodash-es";
|
|
2
|
-
import {EphemeralController} from "../utilities/ephemeral_controller";
|
|
3
|
-
|
|
4
|
-
export class TemporaryStateController extends EphemeralController {
|
|
5
|
-
|
|
6
|
-
static values = {
|
|
7
|
-
attribute: String,
|
|
8
|
-
seconds: Number,
|
|
9
|
-
value: String,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
declare readonly hasSecondsValue: boolean;
|
|
13
|
-
declare readonly secondsValue: number;
|
|
14
|
-
declare readonly attributeValue: string;
|
|
15
|
-
declare readonly hasAttributeValue: boolean;
|
|
16
|
-
declare readonly valueValue: string;
|
|
17
|
-
declare readonly hasValueValue: boolean;
|
|
18
|
-
_timeout: null | ReturnType<typeof window.setTimeout> = null;
|
|
19
|
-
_previousState: { [index: string]: any } = {};
|
|
20
|
-
|
|
21
|
-
get _value(): string {
|
|
22
|
-
if (this.hasValueValue) {
|
|
23
|
-
return this.valueValue;
|
|
24
|
-
}
|
|
25
|
-
throw new Error("Expected `valueValue` to be present");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get _attribute(): string {
|
|
29
|
-
if (this.hasAttributeValue) {
|
|
30
|
-
return this.attributeValue;
|
|
31
|
-
}
|
|
32
|
-
throw new Error("Expected `attributeValue` to be present");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get _seconds(): number {
|
|
36
|
-
if (this.hasSecondsValue) {
|
|
37
|
-
return this.secondsValue * 1000;
|
|
38
|
-
}
|
|
39
|
-
throw new Error("Expected `secondsValue` to be present");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
initialize() {
|
|
43
|
-
this.setState = this.setState.bind(this);
|
|
44
|
-
this.removeState = this.removeState.bind(this);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
connect() {
|
|
48
|
-
this.setState();
|
|
49
|
-
this._timeout = setTimeout(this.removeState, this._seconds);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
disconnect() {
|
|
53
|
-
this.removeState();
|
|
54
|
-
if (this._timeout) {
|
|
55
|
-
clearTimeout(this._timeout);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
setState() {
|
|
60
|
-
this._previousState[this._attribute] = _get(this.el, this._attribute);
|
|
61
|
-
_set(this.el, this._attribute, this.valueValue);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
removeState() {
|
|
65
|
-
_set(this.el, this._attribute, this._previousState[this._attribute]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function applyTemporaryState(element: HTMLElement, propertyString: string, value: any, seconds: number, controllerIdentifier = "temporary-state") {
|
|
71
|
-
if (!element.dataset.controller || !element.dataset.controller?.includes(controllerIdentifier)) {
|
|
72
|
-
element.dataset.controller = (element.dataset.controller || '' + ` ${controllerIdentifier} `).trim().replaceAll(' ', ' ');
|
|
73
|
-
}
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
element[camelCase(`${controllerIdentifier}-attribute-value`)] = propertyString;
|
|
76
|
-
// @ts-ignore
|
|
77
|
-
element[camelCase(`${controllerIdentifier}-seconds-value`)] = seconds.toString();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function applyTemporaryClass(element: HTMLElement, value: any, seconds: number) {
|
|
81
|
-
applyTemporaryState(element, 'className', value, seconds);
|
|
82
|
-
}
|