stimulus-library 0.6.4 → 0.7.2
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 +55 -0
- package/dist/controllers/disable_with_controller.d.ts +0 -3
- package/dist/controllers/disable_with_controller.d.ts.map +1 -1
- package/dist/controllers/element_save_controller.d.ts +5 -0
- package/dist/controllers/element_save_controller.d.ts.map +1 -1
- package/dist/controllers/forms/auto_submit_form_controller.d.ts +3 -2
- package/dist/controllers/forms/auto_submit_form_controller.d.ts.map +1 -1
- package/dist/controllers/prefetch_controller.d.ts.map +1 -1
- package/dist/controllers/signal/index.d.ts +1 -0
- package/dist/controllers/signal/index.d.ts.map +1 -1
- package/dist/controllers/signal/signal_dom_children_controller.d.ts +17 -0
- package/dist/controllers/signal/signal_dom_children_controller.d.ts.map +1 -0
- package/dist/controllers/signal/signal_input_controller.d.ts.map +1 -1
- package/dist/controllers/signal/signal_visibility_controller.d.ts.map +1 -1
- package/dist/controllers/utility/intersection_controller.d.ts.map +1 -1
- package/dist/controllers/visual/tree_view_controller.d.ts.map +1 -1
- package/dist/mixins/index.d.ts +2 -1
- package/dist/mixins/index.d.ts.map +1 -1
- package/dist/mixins/install_class_methods.d.ts.map +1 -1
- package/dist/mixins/use_localstorage.d.ts +14 -8
- package/dist/mixins/use_localstorage.d.ts.map +1 -1
- package/dist/mixins/use_temporary_content.d.ts +6 -0
- package/dist/mixins/use_temporary_content.d.ts.map +1 -0
- package/dist/stimulus-library.cjs.js +1 -1
- package/dist/stimulus-library.cjs.js.map +1 -1
- package/dist/stimulus-library.es.js +371 -240
- package/dist/stimulus-library.es.js.map +1 -1
- package/dist/stimulus-library.umd.js +1 -1
- package/dist/stimulus-library.umd.js.map +1 -1
- package/dist/utilities/base_controller.d.ts +1 -4
- package/dist/utilities/base_controller.d.ts.map +1 -1
- package/dist/utilities/elements.d.ts +28 -0
- package/dist/utilities/elements.d.ts.map +1 -1
- package/dist/utilities/events.d.ts +3 -0
- package/dist/utilities/events.d.ts.map +1 -0
- package/dist/utilities/logging.d.ts +6 -0
- package/dist/utilities/logging.d.ts.map +1 -0
- package/package.json +8 -8
|
@@ -21,6 +21,103 @@ var __publicField = (obj, key, value) => {
|
|
|
21
21
|
import { Controller } from "stimulus";
|
|
22
22
|
import { camelCase, debounce, upperFirst, clamp, get, set } from "lodash-es";
|
|
23
23
|
import { isPast, intervalToDuration, formatDuration, toDate, formatDistanceToNow } from "date-fns";
|
|
24
|
+
function logProperty(prop) {
|
|
25
|
+
switch (prop) {
|
|
26
|
+
case "application":
|
|
27
|
+
case "el":
|
|
28
|
+
case "element":
|
|
29
|
+
case "constructor":
|
|
30
|
+
case "initialize":
|
|
31
|
+
case "log":
|
|
32
|
+
case "logEvent":
|
|
33
|
+
case "dispatch":
|
|
34
|
+
case "data":
|
|
35
|
+
case "valueDescriptorMap":
|
|
36
|
+
case "mutate":
|
|
37
|
+
case "identifier":
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (/^_.*?$/.test(prop)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (/^.*?Target(s)?$/.test(prop)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (/^.*?Value$/.test(prop)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (/^.*?ValueChanged$/.test(prop)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (/^.*?Class$/.test(prop)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (/^.*?Classes$/.test(prop)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (/^.*?ClassesPresent$/.test(prop)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
function log(controller, functionName, args = {}) {
|
|
64
|
+
if (!controller.application.debug) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
let logger = console;
|
|
68
|
+
logger.groupCollapsed(...colorize(controller.identifier, "#3B82F6"), `#${functionName}`);
|
|
69
|
+
logger.log(__spreadValues({
|
|
70
|
+
element: controller.element,
|
|
71
|
+
controller
|
|
72
|
+
}, args));
|
|
73
|
+
logger.groupEnd();
|
|
74
|
+
}
|
|
75
|
+
function warn(controller, warning, args = {}) {
|
|
76
|
+
if (!controller.application.debug) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
let logger = console;
|
|
80
|
+
logger.groupCollapsed(...colorize(controller.identifier, "#F39B1AFF"), `!! ${warning} !!`);
|
|
81
|
+
logger.warn(__spreadValues({
|
|
82
|
+
element: controller.element,
|
|
83
|
+
controller
|
|
84
|
+
}, args));
|
|
85
|
+
logger.groupEnd();
|
|
86
|
+
}
|
|
87
|
+
function logEvent(controller, eventName, event, element) {
|
|
88
|
+
if (!controller.application.debug) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
let logger = console;
|
|
92
|
+
logger.groupCollapsed(...colorizeMany([
|
|
93
|
+
{ text: controller.identifier, color: "#3B82F6" },
|
|
94
|
+
{ text: eventName, color: "#0be000" }
|
|
95
|
+
]), event.detail);
|
|
96
|
+
logger.log(...colorize("Dispatched on", "#3b82f6"), element);
|
|
97
|
+
logger.log(...colorize("event", "#3b82f6"), event);
|
|
98
|
+
logger.log(...colorize("event details", "#3b82f6"), event.detail);
|
|
99
|
+
logger.groupEnd();
|
|
100
|
+
}
|
|
101
|
+
function colorize(text, color) {
|
|
102
|
+
return colorizeMany([{ text, color }]);
|
|
103
|
+
}
|
|
104
|
+
function colorizeMany(texts) {
|
|
105
|
+
let str = "";
|
|
106
|
+
let colors = texts.flatMap((x) => {
|
|
107
|
+
str += `%c${x.text}%c `;
|
|
108
|
+
return [`color: ${x.color}`, "color: unset"];
|
|
109
|
+
});
|
|
110
|
+
return [str, ...colors];
|
|
111
|
+
}
|
|
112
|
+
function dispatchEvent(controller, element, eventName, options = {}) {
|
|
113
|
+
let mergedOptions = Object.assign({}, { bubbles: true, cancelable: true, detail: { target: element } }, options);
|
|
114
|
+
if (!mergedOptions.detail.target) {
|
|
115
|
+
mergedOptions.detail.target = element;
|
|
116
|
+
}
|
|
117
|
+
let event = new CustomEvent(eventName, mergedOptions);
|
|
118
|
+
logEvent(controller, eventName, event, element);
|
|
119
|
+
element.dispatchEvent(event);
|
|
120
|
+
}
|
|
24
121
|
class BaseController extends Controller {
|
|
25
122
|
constructor(context) {
|
|
26
123
|
super(context);
|
|
@@ -31,18 +128,21 @@ class BaseController extends Controller {
|
|
|
31
128
|
get: (obj, prop) => {
|
|
32
129
|
let returnVal = Reflect.get(obj, prop);
|
|
33
130
|
let self = this;
|
|
131
|
+
if ("logFormattedMessage" in this.application) {
|
|
132
|
+
return returnVal;
|
|
133
|
+
}
|
|
34
134
|
if (logProperty(prop.toString())) {
|
|
35
135
|
if (typeof returnVal == "function") {
|
|
36
136
|
return new Proxy(returnVal, {
|
|
37
137
|
apply(target, thisArg, argArray) {
|
|
38
|
-
|
|
138
|
+
log(self, prop.toString(), {
|
|
39
139
|
args: argArray
|
|
40
140
|
});
|
|
41
141
|
return Reflect.apply(target, thisArg, argArray);
|
|
42
142
|
}
|
|
43
143
|
});
|
|
44
144
|
} else {
|
|
45
|
-
|
|
145
|
+
log(this, prop.toString());
|
|
46
146
|
}
|
|
47
147
|
}
|
|
48
148
|
return returnVal;
|
|
@@ -65,88 +165,10 @@ class BaseController extends Controller {
|
|
|
65
165
|
const element = document.head.querySelector(`meta[name="${name}"]`);
|
|
66
166
|
return (element == null ? void 0 : element.getAttribute("content")) || null;
|
|
67
167
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (!!mergedOptions.detail.target) {
|
|
71
|
-
mergedOptions.detail.target = element;
|
|
72
|
-
}
|
|
73
|
-
let event = new CustomEvent(eventName, mergedOptions);
|
|
74
|
-
this.logEvent(eventName, event, element);
|
|
75
|
-
element.dispatchEvent(event);
|
|
76
|
-
}
|
|
77
|
-
log(functionName, args = {}) {
|
|
78
|
-
if (!this.application.debug) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
let logger = console;
|
|
82
|
-
logger.groupCollapsed(`%c${this.identifier} %c#${functionName}`, "color: #3B82F6", "color: unset");
|
|
83
|
-
logger.log(__spreadValues({
|
|
84
|
-
element: this.element,
|
|
85
|
-
controller: this
|
|
86
|
-
}, args));
|
|
87
|
-
logger.groupEnd();
|
|
88
|
-
}
|
|
89
|
-
warn(warning, args = {}) {
|
|
90
|
-
if (!this.application.debug) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
let logger = console;
|
|
94
|
-
logger.groupCollapsed(`%c${this.identifier} %c#${warning}`, "color: F39B1AFF", "color: unset");
|
|
95
|
-
logger.warn(__spreadValues({
|
|
96
|
-
element: this.element,
|
|
97
|
-
controller: this
|
|
98
|
-
}, args));
|
|
99
|
-
logger.groupEnd();
|
|
100
|
-
}
|
|
101
|
-
logEvent(eventName, event, element) {
|
|
102
|
-
if (!this.application.debug) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
let logger = console;
|
|
106
|
-
logger.groupCollapsed(`%c${this.identifier} %c${eventName}%c`, "color: #3B82F6", "color: #0be000", "color: unset");
|
|
107
|
-
logger.log({ element });
|
|
108
|
-
logger.groupEnd();
|
|
168
|
+
dispatchEvent(element, eventName, options = {}) {
|
|
169
|
+
dispatchEvent(this, element, eventName, options);
|
|
109
170
|
}
|
|
110
171
|
}
|
|
111
|
-
function logProperty(prop) {
|
|
112
|
-
switch (prop) {
|
|
113
|
-
case "application":
|
|
114
|
-
case "el":
|
|
115
|
-
case "element":
|
|
116
|
-
case "constructor":
|
|
117
|
-
case "initialize":
|
|
118
|
-
case "log":
|
|
119
|
-
case "logEvent":
|
|
120
|
-
case "dispatch":
|
|
121
|
-
case "data":
|
|
122
|
-
case "valueDescriptorMap":
|
|
123
|
-
case "mutate":
|
|
124
|
-
case "identifier":
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
if (/^_.*?$/.test(prop)) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
if (/^.*?Target(s)?$/.test(prop)) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
if (/^.*?Value$/.test(prop)) {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
if (/^.*?ValueChanged$/.test(prop)) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
if (/^.*?Class$/.test(prop)) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
if (/^.*?Classes$/.test(prop)) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
if (/^.*?ClassesPresent$/.test(prop)) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
172
|
class EphemeralController extends BaseController {
|
|
151
173
|
_cleanupSelf() {
|
|
152
174
|
this.cleanup(this.el);
|
|
@@ -299,6 +321,9 @@ function isHTMLFormElement(element) {
|
|
|
299
321
|
function isHTMLInputElement(element) {
|
|
300
322
|
return element.nodeName == "INPUT";
|
|
301
323
|
}
|
|
324
|
+
function isHTMLLabelElement(element) {
|
|
325
|
+
return element.nodeName == "LABEL";
|
|
326
|
+
}
|
|
302
327
|
function isHTMLTextAreaElement(element) {
|
|
303
328
|
return element.nodeName == "TEXTAREA";
|
|
304
329
|
}
|
|
@@ -311,6 +336,33 @@ function isHTMLSelectElement(element) {
|
|
|
311
336
|
function isHTMLImageElement(element) {
|
|
312
337
|
return element.nodeName == "IMG";
|
|
313
338
|
}
|
|
339
|
+
function isHTMLButtonInputElement(element) {
|
|
340
|
+
return element.nodeName == "INPUT" && element.type == "button";
|
|
341
|
+
}
|
|
342
|
+
function isHTMLSubmitInputElement(element) {
|
|
343
|
+
return element.nodeName == "INPUT" && element.type == "submit";
|
|
344
|
+
}
|
|
345
|
+
function isHTMLResetInputElement(element) {
|
|
346
|
+
return element.nodeName == "INPUT" && element.type == "reset";
|
|
347
|
+
}
|
|
348
|
+
function isHTMLButtonButtonElement(element) {
|
|
349
|
+
return element.nodeName == "BUTTON" && element.type == "button";
|
|
350
|
+
}
|
|
351
|
+
function isHTMLSubmitButtonElement(element) {
|
|
352
|
+
return element.nodeName == "BUTTON" && element.type == "submit";
|
|
353
|
+
}
|
|
354
|
+
function isHTMLResetButtonElement(element) {
|
|
355
|
+
return element.nodeName == "BUTTON" && element.type == "reset";
|
|
356
|
+
}
|
|
357
|
+
function isTypeOfResetButtonElement(element) {
|
|
358
|
+
return isHTMLResetButtonElement(element) || isHTMLResetInputElement(element);
|
|
359
|
+
}
|
|
360
|
+
function isTypeOfSubmitButtonElement(element) {
|
|
361
|
+
return isHTMLSubmitButtonElement(element) || isHTMLSubmitInputElement(element);
|
|
362
|
+
}
|
|
363
|
+
function isTypeOfButtonableElement(element) {
|
|
364
|
+
return isTypeOfResetButtonElement(element) || isTypeOfSubmitButtonElement(element) || isHTMLButtonButtonElement(element);
|
|
365
|
+
}
|
|
314
366
|
function isElementCheckable(element) {
|
|
315
367
|
return isHTMLInputElement(element) && (element.type === "radio" || element.type === "checkbox");
|
|
316
368
|
}
|
|
@@ -566,108 +618,129 @@ function useInjectedElement(controller, targetElement, insertPosition, element,
|
|
|
566
618
|
let [nodes, teardown] = useInjectedFragment(controller, targetElement, insertPosition, fragment, options);
|
|
567
619
|
return [nodes[0], teardown];
|
|
568
620
|
}
|
|
621
|
+
function useInterval(controller, handler, interval) {
|
|
622
|
+
handler = handler.bind(controller);
|
|
623
|
+
let intervalHandle = null;
|
|
624
|
+
let setup = () => intervalHandle = setInterval(handler, interval);
|
|
625
|
+
let teardown = () => {
|
|
626
|
+
if (intervalHandle !== null) {
|
|
627
|
+
clearInterval(intervalHandle);
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
useMixin(controller, setup, teardown);
|
|
631
|
+
return teardown;
|
|
632
|
+
}
|
|
569
633
|
const StorageSerializers = {
|
|
570
634
|
boolean: {
|
|
571
|
-
|
|
572
|
-
|
|
635
|
+
deserialize: (v) => v === "true",
|
|
636
|
+
serialize: (v) => String(v),
|
|
637
|
+
isEmpty: (v) => v === "" || v === null
|
|
573
638
|
},
|
|
574
639
|
object: {
|
|
575
|
-
|
|
576
|
-
|
|
640
|
+
deserialize: (v) => JSON.parse(v),
|
|
641
|
+
serialize: (v) => JSON.stringify(v),
|
|
642
|
+
isEmpty: (v) => {
|
|
643
|
+
const values = Object.values(JSON.parse(v));
|
|
644
|
+
return values.length === 0 || values.every((v2) => v2 === "" || v2 === null);
|
|
645
|
+
}
|
|
577
646
|
},
|
|
578
647
|
number: {
|
|
579
|
-
|
|
580
|
-
|
|
648
|
+
deserialize: (v) => Number.parseFloat(v),
|
|
649
|
+
serialize: (v) => String(v),
|
|
650
|
+
isEmpty: (v) => v === "" || v === null
|
|
581
651
|
},
|
|
582
652
|
any: {
|
|
583
|
-
|
|
584
|
-
|
|
653
|
+
deserialize: (v) => v,
|
|
654
|
+
serialize: (v) => String(v),
|
|
655
|
+
isEmpty: (v) => v === "" || v === null
|
|
585
656
|
},
|
|
586
657
|
string: {
|
|
587
|
-
|
|
588
|
-
|
|
658
|
+
deserialize: (v) => v,
|
|
659
|
+
serialize: (v) => String(v),
|
|
660
|
+
isEmpty: (v) => v === "" || v === null
|
|
589
661
|
},
|
|
590
662
|
map: {
|
|
591
|
-
|
|
592
|
-
|
|
663
|
+
deserialize: (v) => new Map(JSON.parse(v)),
|
|
664
|
+
serialize: (v) => JSON.stringify(Array.from(v.entries())),
|
|
665
|
+
isEmpty: (v) => {
|
|
666
|
+
const values = Array.from(v.values());
|
|
667
|
+
return values.length === 0 || values.every((v2) => v2 === "" || v2 === null);
|
|
668
|
+
}
|
|
593
669
|
},
|
|
594
670
|
set: {
|
|
595
|
-
|
|
596
|
-
|
|
671
|
+
deserialize: (v) => new Set(JSON.parse(v)),
|
|
672
|
+
serialize: (v) => JSON.stringify(Array.from(v.entries())),
|
|
673
|
+
isEmpty: (v) => {
|
|
674
|
+
const values = Array.from(v.values());
|
|
675
|
+
return values.length === 0 || values.every((v2) => v2 === "" || v2 === null);
|
|
676
|
+
}
|
|
597
677
|
}
|
|
598
678
|
};
|
|
599
|
-
function useLocalStorage(controller, key, defaultValue, opts) {
|
|
600
|
-
let type
|
|
679
|
+
function useLocalStorage(controller, key, defaultValue, opts = { writeDefaults: true }) {
|
|
680
|
+
let type;
|
|
601
681
|
let { writeDefaults } = opts;
|
|
602
682
|
if (defaultValue == null) {
|
|
603
683
|
type = "any";
|
|
604
|
-
}
|
|
605
|
-
if (defaultValue instanceof Set) {
|
|
684
|
+
} else if (defaultValue instanceof Set) {
|
|
606
685
|
type = "set";
|
|
607
|
-
}
|
|
608
|
-
if (defaultValue instanceof Map) {
|
|
686
|
+
} else if (defaultValue instanceof Map) {
|
|
609
687
|
type = "map";
|
|
610
|
-
}
|
|
611
|
-
if (typeof defaultValue === "boolean") {
|
|
688
|
+
} else if (typeof defaultValue === "boolean") {
|
|
612
689
|
type = "boolean";
|
|
613
|
-
}
|
|
614
|
-
if (typeof defaultValue === "string") {
|
|
690
|
+
} else if (typeof defaultValue === "string") {
|
|
615
691
|
type = "string";
|
|
616
|
-
}
|
|
617
|
-
if (typeof defaultValue === "object") {
|
|
692
|
+
} else if (typeof defaultValue === "object") {
|
|
618
693
|
type = "object";
|
|
619
|
-
}
|
|
620
|
-
if (Array.isArray(defaultValue)) {
|
|
694
|
+
} else if (Array.isArray(defaultValue)) {
|
|
621
695
|
type = "object";
|
|
622
|
-
}
|
|
623
|
-
if (!Number.isNaN(defaultValue)) {
|
|
696
|
+
} else if (!Number.isNaN(defaultValue)) {
|
|
624
697
|
type = "number";
|
|
698
|
+
} else {
|
|
699
|
+
type = "any";
|
|
625
700
|
}
|
|
626
701
|
let data = reactive({
|
|
627
702
|
value: defaultValue
|
|
628
703
|
});
|
|
629
704
|
let storage = localStorage;
|
|
630
705
|
const serializer = StorageSerializers[type];
|
|
631
|
-
const read = (
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
if (rawValue == null) {
|
|
638
|
-
data.value = defaultValue;
|
|
639
|
-
if (writeDefaults && defaultValue !== null) {
|
|
640
|
-
storage.setItem(key, serializer.write(defaultValue));
|
|
641
|
-
}
|
|
642
|
-
} else {
|
|
643
|
-
data.value = serializer.read(rawValue);
|
|
706
|
+
const read = () => {
|
|
707
|
+
const rawValue = storage.getItem(key);
|
|
708
|
+
if (rawValue == null) {
|
|
709
|
+
data.value = defaultValue;
|
|
710
|
+
if (writeDefaults && defaultValue !== null) {
|
|
711
|
+
storage.setItem(key, serializer.serialize(defaultValue));
|
|
644
712
|
}
|
|
645
|
-
}
|
|
713
|
+
} else {
|
|
714
|
+
data.value = serializer.deserialize(rawValue);
|
|
646
715
|
}
|
|
716
|
+
return data.value;
|
|
717
|
+
};
|
|
718
|
+
const write = (value) => {
|
|
719
|
+
storage.setItem(key, serializer.serialize(value));
|
|
720
|
+
data.value = value;
|
|
721
|
+
};
|
|
722
|
+
const clear = () => {
|
|
723
|
+
storage.removeItem(key);
|
|
724
|
+
data.value = defaultValue;
|
|
725
|
+
return data.value;
|
|
726
|
+
};
|
|
727
|
+
const isEmpty = () => {
|
|
728
|
+
let rawValue = storage.getItem(key);
|
|
729
|
+
return serializer.isEmpty(rawValue);
|
|
647
730
|
};
|
|
648
731
|
read();
|
|
649
732
|
return {
|
|
650
733
|
get value() {
|
|
651
|
-
return
|
|
734
|
+
return read();
|
|
652
735
|
},
|
|
653
736
|
set value(value) {
|
|
654
|
-
|
|
655
|
-
storage.setItem(key, serializer.write(value));
|
|
737
|
+
write(value);
|
|
656
738
|
},
|
|
657
|
-
read
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
handler = handler.bind(controller);
|
|
662
|
-
let intervalHandle = null;
|
|
663
|
-
let setup = () => intervalHandle = setInterval(handler, interval);
|
|
664
|
-
let teardown = () => {
|
|
665
|
-
if (intervalHandle !== null) {
|
|
666
|
-
clearInterval(intervalHandle);
|
|
667
|
-
}
|
|
739
|
+
read,
|
|
740
|
+
clear,
|
|
741
|
+
write,
|
|
742
|
+
isEmpty
|
|
668
743
|
};
|
|
669
|
-
useMixin(controller, setup, teardown);
|
|
670
|
-
return teardown;
|
|
671
744
|
}
|
|
672
745
|
function useTimeout(controller, handler, timeout) {
|
|
673
746
|
let controllerDisconnect;
|
|
@@ -688,6 +761,40 @@ function useTimeout(controller, handler, timeout) {
|
|
|
688
761
|
controllerDisconnect = useMixin(controller, setup, teardown);
|
|
689
762
|
return teardown;
|
|
690
763
|
}
|
|
764
|
+
function useTemporaryContent(controller, target, content, timeout, teardownCallback) {
|
|
765
|
+
const setContent = (element, text) => {
|
|
766
|
+
if (isHTMLInputElement(element)) {
|
|
767
|
+
element.value = text;
|
|
768
|
+
} else {
|
|
769
|
+
element.textContent = text;
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
const getContent = (element) => {
|
|
773
|
+
return isHTMLInputElement(element) ? element.value : element.innerHTML;
|
|
774
|
+
};
|
|
775
|
+
let cleanupTimeout = () => void 0;
|
|
776
|
+
let originalText = getContent(target);
|
|
777
|
+
const teardown = () => {
|
|
778
|
+
setContent(target, originalText);
|
|
779
|
+
cleanupTimeout();
|
|
780
|
+
if (teardownCallback) {
|
|
781
|
+
teardownCallback.call(controller);
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
const setup = () => {
|
|
785
|
+
setContent(target, content);
|
|
786
|
+
if (timeout !== void 0) {
|
|
787
|
+
cleanupTimeout = useTimeout(controller, teardown, timeout);
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
useMixin(controller, setup, teardown);
|
|
791
|
+
return {
|
|
792
|
+
teardown,
|
|
793
|
+
update(newContent) {
|
|
794
|
+
setContent(target, newContent);
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
}
|
|
691
798
|
async function fetchRetry(n, input, init) {
|
|
692
799
|
try {
|
|
693
800
|
return await fetch(input, init);
|
|
@@ -713,7 +820,7 @@ class LoadBlockController extends BaseController {
|
|
|
713
820
|
let el = this.hasReplaceTarget ? this.replaceTarget : this.el;
|
|
714
821
|
let failure = () => {
|
|
715
822
|
el.replaceWith(this._errorMessage);
|
|
716
|
-
self.
|
|
823
|
+
self.dispatchEvent(el, "ajax:error");
|
|
717
824
|
};
|
|
718
825
|
try {
|
|
719
826
|
let response = await fetchRetry(this._maxRetries, this.endpointValue);
|
|
@@ -729,11 +836,11 @@ class LoadBlockController extends BaseController {
|
|
|
729
836
|
} else {
|
|
730
837
|
el.replaceWith(...newEl.children);
|
|
731
838
|
}
|
|
732
|
-
self.
|
|
839
|
+
self.dispatchEvent(el, "ajax:success");
|
|
733
840
|
} catch (e) {
|
|
734
841
|
failure();
|
|
735
842
|
} finally {
|
|
736
|
-
self.
|
|
843
|
+
self.dispatchEvent(el, "ajax:complete");
|
|
737
844
|
}
|
|
738
845
|
}
|
|
739
846
|
}
|
|
@@ -845,18 +952,22 @@ __publicField(PollBlockController, "values", {
|
|
|
845
952
|
seconds: Number
|
|
846
953
|
});
|
|
847
954
|
class AutoSubmitFormController extends BaseController {
|
|
848
|
-
get
|
|
955
|
+
get _eventModes() {
|
|
849
956
|
if (this.hasEventModeValue) {
|
|
850
|
-
|
|
957
|
+
let modes = this.eventModeValue.split(" ").map((mode) => mode.trim());
|
|
958
|
+
if (modes.length === 1 && modes[0] === "debounced") {
|
|
959
|
+
return ["change", "input"];
|
|
960
|
+
}
|
|
961
|
+
if (!modes.every((mode) => ["change", "input"].includes(mode))) {
|
|
851
962
|
throw new Error(`The modeValue provided '${this.eventModeValue}' is not one of the recognised configuration options`);
|
|
852
963
|
}
|
|
853
|
-
return
|
|
964
|
+
return modes;
|
|
854
965
|
} else {
|
|
855
|
-
return "change";
|
|
966
|
+
return ["change"];
|
|
856
967
|
}
|
|
857
968
|
}
|
|
858
969
|
get _debounceTimeout() {
|
|
859
|
-
return this.hasDebounceIntervalValue ? this.debounceIntervalValue :
|
|
970
|
+
return this.hasDebounceIntervalValue ? this.debounceIntervalValue : -1;
|
|
860
971
|
}
|
|
861
972
|
get _mode() {
|
|
862
973
|
if (this.hasSubmitModeValue) {
|
|
@@ -874,13 +985,18 @@ class AutoSubmitFormController extends BaseController {
|
|
|
874
985
|
return inputTypes.map((type) => type.concat(ignore)).join(",");
|
|
875
986
|
}
|
|
876
987
|
get inputElements() {
|
|
877
|
-
|
|
988
|
+
let subElements = Array.from(this.element.querySelectorAll(this._cssSelector));
|
|
989
|
+
subElements = subElements.filter((el) => !this._ancestorIsTrix(el));
|
|
990
|
+
return subElements;
|
|
878
991
|
}
|
|
879
992
|
connect() {
|
|
880
993
|
this.inputElements.forEach((el) => {
|
|
881
|
-
return useEventListener(this, el, this.
|
|
994
|
+
return useEventListener(this, el, this._eventModes, this.submit, { debounce: this._debounceTimeout && this._debounceTimeout > 0 ? this._debounceTimeout : void 0 });
|
|
882
995
|
});
|
|
883
996
|
}
|
|
997
|
+
_ancestorIsTrix(element) {
|
|
998
|
+
return element.closest("trix-toolbar") !== null && element.closest("trix-editor") !== null;
|
|
999
|
+
}
|
|
884
1000
|
submit() {
|
|
885
1001
|
let el = this.el;
|
|
886
1002
|
if (this._mode == "request") {
|
|
@@ -948,12 +1064,10 @@ function addMethodsForClassDefinition(controller, name) {
|
|
|
948
1064
|
[`remove${pascalCase(name)}Classes`]: (element = defaultElement) => element.classList.remove(...classOrDefault()),
|
|
949
1065
|
[`${name}ClassesPresent`]: (element = defaultElement) => classOrDefault().every((klass) => element.classList.contains(klass))
|
|
950
1066
|
};
|
|
951
|
-
console.log(methods);
|
|
952
1067
|
Object.assign(controller, methods);
|
|
953
1068
|
}
|
|
954
1069
|
function installClassMethods(controller) {
|
|
955
1070
|
let classes = controller.constructor.classes || [];
|
|
956
|
-
console.log(classes);
|
|
957
1071
|
classes.forEach((classDefinition) => addMethodsForClassDefinition(controller, classDefinition));
|
|
958
1072
|
}
|
|
959
1073
|
class CharCountController extends BaseController {
|
|
@@ -1097,7 +1211,7 @@ class CheckboxXORController extends BaseController {
|
|
|
1097
1211
|
if (target.checked) {
|
|
1098
1212
|
others.forEach((checkbox) => {
|
|
1099
1213
|
checkbox.checked = false;
|
|
1100
|
-
this.
|
|
1214
|
+
this.dispatchEvent(this.el, "change");
|
|
1101
1215
|
});
|
|
1102
1216
|
}
|
|
1103
1217
|
}
|
|
@@ -1433,7 +1547,7 @@ class FormSaveController extends BaseController {
|
|
|
1433
1547
|
}
|
|
1434
1548
|
_clear() {
|
|
1435
1549
|
localStorage.removeItem(this._formIdentifier);
|
|
1436
|
-
this.
|
|
1550
|
+
this.dispatchEvent(this.el, `form-save:cleared`);
|
|
1437
1551
|
}
|
|
1438
1552
|
clear(event) {
|
|
1439
1553
|
event == null ? void 0 : event.preventDefault();
|
|
@@ -1443,7 +1557,7 @@ class FormSaveController extends BaseController {
|
|
|
1443
1557
|
event.preventDefault();
|
|
1444
1558
|
let data = this._formData;
|
|
1445
1559
|
localStorage.setItem(this._formIdentifier, JSON.stringify(data[this._formIdentifier]));
|
|
1446
|
-
this.
|
|
1560
|
+
this.dispatchEvent(this.el, `form-save:save:success`);
|
|
1447
1561
|
}
|
|
1448
1562
|
restore(event) {
|
|
1449
1563
|
event == null ? void 0 : event.preventDefault();
|
|
@@ -1463,9 +1577,9 @@ class FormSaveController extends BaseController {
|
|
|
1463
1577
|
}
|
|
1464
1578
|
}
|
|
1465
1579
|
}
|
|
1466
|
-
this.
|
|
1580
|
+
this.dispatchEvent(this.el, `form-save:restore:success`);
|
|
1467
1581
|
} else {
|
|
1468
|
-
this.
|
|
1582
|
+
this.dispatchEvent(this.el, `form-save:restore:empty`);
|
|
1469
1583
|
}
|
|
1470
1584
|
}
|
|
1471
1585
|
}
|
|
@@ -1484,13 +1598,13 @@ class LimitedSelectionCheckboxesController extends BaseController {
|
|
|
1484
1598
|
if (tickedInputs > this.maxValue) {
|
|
1485
1599
|
event.preventDefault();
|
|
1486
1600
|
target.checked = false;
|
|
1487
|
-
this.
|
|
1488
|
-
this.
|
|
1601
|
+
this.dispatchEvent(target, "change");
|
|
1602
|
+
this.dispatchEvent(target, "limited-selection:too-many");
|
|
1489
1603
|
if (this.hasErrorTarget && this.hasMessageValue) {
|
|
1490
1604
|
this.errorTarget.innerHTML = this.messageValue;
|
|
1491
1605
|
}
|
|
1492
1606
|
} else {
|
|
1493
|
-
this.
|
|
1607
|
+
this.dispatchEvent(target, "limited-selection:selection");
|
|
1494
1608
|
if (this.hasErrorTarget) {
|
|
1495
1609
|
this.errorTarget.innerHTML = "";
|
|
1496
1610
|
}
|
|
@@ -1685,10 +1799,10 @@ class PasswordConfirmController extends BaseController {
|
|
|
1685
1799
|
_checkPasswordsMatch() {
|
|
1686
1800
|
let element = this.el;
|
|
1687
1801
|
if (this._allPasswordsMatch()) {
|
|
1688
|
-
this.
|
|
1802
|
+
this.dispatchEvent(element, "password-confirm:match");
|
|
1689
1803
|
this.passwordTargets.forEach((el) => this.removeErrorClasses(el));
|
|
1690
1804
|
} else {
|
|
1691
|
-
this.
|
|
1805
|
+
this.dispatchEvent(element, "password-confirm:no-match");
|
|
1692
1806
|
this.passwordTargets.forEach((el) => this.addErrorClasses(el));
|
|
1693
1807
|
}
|
|
1694
1808
|
}
|
|
@@ -1730,7 +1844,7 @@ class RemoteFormController extends BaseController {
|
|
|
1730
1844
|
throw new Error("expected form to have a DOM parent, could not execute replaceChild");
|
|
1731
1845
|
}
|
|
1732
1846
|
parentNode.replaceChild(newElement, this.el);
|
|
1733
|
-
this.
|
|
1847
|
+
this.dispatchEvent(newElement, "remote-form:replace");
|
|
1734
1848
|
} else {
|
|
1735
1849
|
console.log("Unknown", data);
|
|
1736
1850
|
}
|
|
@@ -1908,11 +2022,11 @@ class FallbackImageController extends BaseController {
|
|
|
1908
2022
|
let element = this.el;
|
|
1909
2023
|
this.addFailClasses();
|
|
1910
2024
|
if (this.hasPlaceholderValue && element.src !== this.placeholderValue) {
|
|
1911
|
-
this.
|
|
2025
|
+
this.dispatchEvent(element, "fallback-image:placeholder");
|
|
1912
2026
|
element.src = this.placeholderValue;
|
|
1913
2027
|
element.onerror = this._fail;
|
|
1914
2028
|
} else {
|
|
1915
|
-
this.
|
|
2029
|
+
this.dispatchEvent(element, "fallback-image:fail");
|
|
1916
2030
|
element.style.display = "none";
|
|
1917
2031
|
}
|
|
1918
2032
|
}
|
|
@@ -2738,9 +2852,11 @@ function _predicateForExpression(expression) {
|
|
|
2738
2852
|
throw new Error(`Could not find operator in expression: ${expression}`);
|
|
2739
2853
|
}
|
|
2740
2854
|
let expressionValue = expression.split(operator)[1].trim();
|
|
2741
|
-
let isNumber =
|
|
2742
|
-
|
|
2743
|
-
|
|
2855
|
+
let isNumber = /^-?\d*(\.\d+)?$/.test(expressionValue);
|
|
2856
|
+
if (isNumber) {
|
|
2857
|
+
expressionValue = parseFloat(expressionValue);
|
|
2858
|
+
}
|
|
2859
|
+
if (expressionValue === "") {
|
|
2744
2860
|
throw new Error(`Could not find a value in expression: ${expression}`);
|
|
2745
2861
|
}
|
|
2746
2862
|
let notEmpty = (signalValue) => signalValue !== "";
|
|
@@ -2781,13 +2897,13 @@ class SignalActionController extends BaseController {
|
|
|
2781
2897
|
_onSignal(payload) {
|
|
2782
2898
|
let value = payload.value;
|
|
2783
2899
|
if (!this.hasWhenValue) {
|
|
2784
|
-
this.
|
|
2900
|
+
this.dispatchEvent(this.el, signalEventName(this.nameValue, "match"));
|
|
2785
2901
|
return;
|
|
2786
2902
|
}
|
|
2787
2903
|
if (this._predicates.every((predicate) => predicate(value))) {
|
|
2788
|
-
this.
|
|
2904
|
+
this.dispatchEvent(this.el, signalEventName(this.nameValue, "match"), { detail: { element: this.el, value } });
|
|
2789
2905
|
} else {
|
|
2790
|
-
this.
|
|
2906
|
+
this.dispatchEvent(this.el, signalEventName(this.nameValue, "no-match"), { detail: { element: this.el, value } });
|
|
2791
2907
|
}
|
|
2792
2908
|
}
|
|
2793
2909
|
}
|
|
@@ -2795,17 +2911,57 @@ __publicField(SignalActionController, "values", {
|
|
|
2795
2911
|
name: String,
|
|
2796
2912
|
when: String
|
|
2797
2913
|
});
|
|
2914
|
+
function useMutationObserver(controller, element, handler, options) {
|
|
2915
|
+
handler = handler.bind(controller);
|
|
2916
|
+
let observer = new MutationObserver(handler);
|
|
2917
|
+
let setup = () => observer.observe(element, options);
|
|
2918
|
+
let teardown = () => observer.disconnect();
|
|
2919
|
+
useMixin(controller, setup, teardown);
|
|
2920
|
+
return teardown;
|
|
2921
|
+
}
|
|
2922
|
+
class SignalDomChildrenController extends BaseController {
|
|
2923
|
+
get _children() {
|
|
2924
|
+
if (this.hasScopeSelectorValue) {
|
|
2925
|
+
return Array.from(this.el.querySelectorAll(this.scopeSelectorValue));
|
|
2926
|
+
} else {
|
|
2927
|
+
return Array.from(this.el.children);
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
get _name() {
|
|
2931
|
+
if (this.hasNameValue) {
|
|
2932
|
+
return this.nameValue;
|
|
2933
|
+
} else {
|
|
2934
|
+
throw new Error("SignalEmptyDomController requires a nameValue to be provided");
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
connect() {
|
|
2938
|
+
useEventBus(this, signalConnectEvent(this._name), this.emitChildCount);
|
|
2939
|
+
EventBus.emit(signalConnectEvent(this._name));
|
|
2940
|
+
useMutationObserver(this, this.el, this.mutate, { childList: true });
|
|
2941
|
+
this.emitChildCount();
|
|
2942
|
+
}
|
|
2943
|
+
mutate(entries) {
|
|
2944
|
+
this.emitChildCount();
|
|
2945
|
+
}
|
|
2946
|
+
emitChildCount() {
|
|
2947
|
+
let childCount = this._children.length;
|
|
2948
|
+
EventBus.emit(signalValueEvent(this._name), { element: this.el, value: childCount.toString() });
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
__publicField(SignalDomChildrenController, "values", {
|
|
2952
|
+
name: String,
|
|
2953
|
+
scopeSelector: String
|
|
2954
|
+
});
|
|
2798
2955
|
class SignalInputController extends BaseController {
|
|
2799
2956
|
get _debounceTimeout() {
|
|
2800
|
-
return this.hasDebounceIntervalValue ? this.debounceIntervalValue :
|
|
2957
|
+
return this.hasDebounceIntervalValue ? this.debounceIntervalValue : 1;
|
|
2801
2958
|
}
|
|
2802
2959
|
get _name() {
|
|
2803
2960
|
return this.hasNameValue ? this.nameValue : this.element.name;
|
|
2804
2961
|
}
|
|
2805
2962
|
connect() {
|
|
2806
2963
|
useEventBus(this, signalConnectEvent(this._name), () => this.emitValue());
|
|
2807
|
-
|
|
2808
|
-
useEventListener(this, this.el, "change", this.emitValue);
|
|
2964
|
+
useEventListeners(this, this.el, ["input", "change"], this.emitValue, { debounce: this._debounceTimeout || void 0 });
|
|
2809
2965
|
requestAnimationFrame(() => this.emitValue());
|
|
2810
2966
|
}
|
|
2811
2967
|
emitValue() {
|
|
@@ -2817,6 +2973,7 @@ class SignalInputController extends BaseController {
|
|
|
2817
2973
|
let selectedValue = (_a = getAllRadiosInGroup(this.el).find((el) => el.checked)) == null ? void 0 : _a.value;
|
|
2818
2974
|
value = selectedValue ? selectedValue : "";
|
|
2819
2975
|
}
|
|
2976
|
+
this.dispatchEvent(this.el, signalValueEvent(this._name), { detail: { value } });
|
|
2820
2977
|
EventBus.emit(signalValueEvent(this._name), { element: this.el, value });
|
|
2821
2978
|
}
|
|
2822
2979
|
}
|
|
@@ -2847,8 +3004,10 @@ class SignalVisibilityController extends BaseController {
|
|
|
2847
3004
|
return;
|
|
2848
3005
|
}
|
|
2849
3006
|
if (this._predicates.every((predicate) => predicate(value))) {
|
|
3007
|
+
this.dispatchEvent(this.el, "signal-visibility:show", { detail: { predicate: this.showValue, value } });
|
|
2850
3008
|
this.removeHideClasses(this.el);
|
|
2851
3009
|
} else {
|
|
3010
|
+
this.dispatchEvent(this.el, "signal-visibility:hide", { detail: { predicate: this.showValue, value } });
|
|
2852
3011
|
this.addHideClasses(this.el);
|
|
2853
3012
|
}
|
|
2854
3013
|
}
|
|
@@ -2896,7 +3055,7 @@ class TableSortController extends BaseController {
|
|
|
2896
3055
|
event.preventDefault();
|
|
2897
3056
|
let headerCell = event.target;
|
|
2898
3057
|
let headerCellIndex = this._indexOfHeaderCell(headerCell);
|
|
2899
|
-
if (headerCell.dataset.
|
|
3058
|
+
if (headerCell.dataset.sortable == "false") {
|
|
2900
3059
|
return;
|
|
2901
3060
|
}
|
|
2902
3061
|
if (headerCell.dataset.sort == "asc") {
|
|
@@ -2951,14 +3110,6 @@ class TableSortController extends BaseController {
|
|
|
2951
3110
|
}
|
|
2952
3111
|
}
|
|
2953
3112
|
__publicField(TableSortController, "values", { startSort: Number });
|
|
2954
|
-
function useMutationObserver(controller, element, handler, options) {
|
|
2955
|
-
handler = handler.bind(controller);
|
|
2956
|
-
let observer = new MutationObserver(handler);
|
|
2957
|
-
let setup = () => observer.observe(element, options);
|
|
2958
|
-
let teardown = () => observer.disconnect();
|
|
2959
|
-
useMixin(controller, setup, teardown);
|
|
2960
|
-
return teardown;
|
|
2961
|
-
}
|
|
2962
3113
|
class TableTruncateController extends BaseController {
|
|
2963
3114
|
get _truncated() {
|
|
2964
3115
|
return this.hasTruncatedValue ? this.truncatedValue : false;
|
|
@@ -3062,10 +3213,10 @@ class IntersectionController extends BaseController {
|
|
|
3062
3213
|
useIntersection(this, this.el, this.appear, this.disappear, { threshold: this._threshold });
|
|
3063
3214
|
}
|
|
3064
3215
|
appear(entry) {
|
|
3065
|
-
|
|
3216
|
+
dispatchEvent(this, this.el, "intersection:appear");
|
|
3066
3217
|
}
|
|
3067
3218
|
disappear(entry) {
|
|
3068
|
-
|
|
3219
|
+
dispatchEvent(this, this.el, "intersection:disappear");
|
|
3069
3220
|
}
|
|
3070
3221
|
}
|
|
3071
3222
|
__publicField(IntersectionController, "values", { threshold: String });
|
|
@@ -3079,7 +3230,7 @@ class IntervalController extends BaseController {
|
|
|
3079
3230
|
});
|
|
3080
3231
|
}
|
|
3081
3232
|
_interval() {
|
|
3082
|
-
this.
|
|
3233
|
+
this.dispatchEvent(this.el, "interval:action");
|
|
3083
3234
|
}
|
|
3084
3235
|
}
|
|
3085
3236
|
__publicField(IntervalController, "values", { seconds: Number });
|
|
@@ -3094,10 +3245,10 @@ class PresenceController extends BaseController {
|
|
|
3094
3245
|
return [this.name, "presence", "removed"].filter((el) => !!el).join(":");
|
|
3095
3246
|
}
|
|
3096
3247
|
connect() {
|
|
3097
|
-
this.
|
|
3248
|
+
this.dispatchEvent(this.el, this._addedEventName);
|
|
3098
3249
|
}
|
|
3099
3250
|
disconnect() {
|
|
3100
|
-
this.
|
|
3251
|
+
this.dispatchEvent(this.el, this._removedEventName);
|
|
3101
3252
|
}
|
|
3102
3253
|
}
|
|
3103
3254
|
__publicField(PresenceController, "values", { name: String });
|
|
@@ -3114,7 +3265,7 @@ class TimeoutController extends BaseController {
|
|
|
3114
3265
|
});
|
|
3115
3266
|
}
|
|
3116
3267
|
_timeout() {
|
|
3117
|
-
this.
|
|
3268
|
+
this.dispatchEvent(this.el, "timeout");
|
|
3118
3269
|
}
|
|
3119
3270
|
}
|
|
3120
3271
|
__publicField(TimeoutController, "values", { seconds: Number });
|
|
@@ -3127,10 +3278,10 @@ class UserFocusController extends BaseController {
|
|
|
3127
3278
|
});
|
|
3128
3279
|
}
|
|
3129
3280
|
appear() {
|
|
3130
|
-
this.
|
|
3281
|
+
this.dispatchEvent(this.el, "user-focus:active");
|
|
3131
3282
|
}
|
|
3132
3283
|
away() {
|
|
3133
|
-
this.
|
|
3284
|
+
this.dispatchEvent(this.el, "user-focus:away");
|
|
3134
3285
|
}
|
|
3135
3286
|
_handleVisibility() {
|
|
3136
3287
|
this._documentIsActive() ? this.appear() : this.away();
|
|
@@ -3207,7 +3358,7 @@ class CountdownController extends BaseController {
|
|
|
3207
3358
|
this._clearTick();
|
|
3208
3359
|
this.removeCountingDownClasses();
|
|
3209
3360
|
this.addEndedClasses();
|
|
3210
|
-
this.
|
|
3361
|
+
this.dispatchEvent(this.el, "countdown:ended");
|
|
3211
3362
|
} else {
|
|
3212
3363
|
distance = intervalToDuration({ start: this._deadlineDate, end: now });
|
|
3213
3364
|
}
|
|
@@ -3539,7 +3690,6 @@ class TreeViewController extends BaseController {
|
|
|
3539
3690
|
return el.querySelectorAll("ul, ol").length > 0;
|
|
3540
3691
|
}
|
|
3541
3692
|
mutate(entries) {
|
|
3542
|
-
console.log("mutate", entries);
|
|
3543
3693
|
for (const mutation of entries) {
|
|
3544
3694
|
if (mutation.type === "childList") {
|
|
3545
3695
|
Array.from(mutation.addedNodes || []).forEach((el) => this._setupNode(el));
|
|
@@ -3581,11 +3731,11 @@ class AnchorSpyController extends BaseController {
|
|
|
3581
3731
|
}
|
|
3582
3732
|
_checkAnchor() {
|
|
3583
3733
|
if (this._key === this._anchor) {
|
|
3584
|
-
this.
|
|
3734
|
+
this.dispatchEvent(this.el, "anchor-spy:active");
|
|
3585
3735
|
this.addActiveClasses(this.el);
|
|
3586
3736
|
this.removeInactiveClasses(this.el);
|
|
3587
3737
|
} else {
|
|
3588
|
-
this.
|
|
3738
|
+
this.dispatchEvent(this.el, "anchor-spy:inactive");
|
|
3589
3739
|
this.addInactiveClasses(this.el);
|
|
3590
3740
|
this.removeActiveClasses(this.el);
|
|
3591
3741
|
}
|
|
@@ -3669,7 +3819,7 @@ class ConfirmController extends BaseController {
|
|
|
3669
3819
|
confirm(event) {
|
|
3670
3820
|
if (!window.confirm(this._message)) {
|
|
3671
3821
|
event.preventDefault();
|
|
3672
|
-
this.
|
|
3822
|
+
this.dispatchEvent(this.el, "confirm:cancelled");
|
|
3673
3823
|
}
|
|
3674
3824
|
}
|
|
3675
3825
|
}
|
|
@@ -3710,10 +3860,6 @@ class DebugController extends BaseController {
|
|
|
3710
3860
|
}
|
|
3711
3861
|
__publicField(DebugController, "targets", ["test"]);
|
|
3712
3862
|
class DisableWithController extends BaseController {
|
|
3713
|
-
constructor() {
|
|
3714
|
-
super(...arguments);
|
|
3715
|
-
__publicField(this, "_cacheText");
|
|
3716
|
-
}
|
|
3717
3863
|
get _message() {
|
|
3718
3864
|
return this.hasMessageValue ? this.messageValue : "Submitting...";
|
|
3719
3865
|
}
|
|
@@ -3732,44 +3878,27 @@ class DisableWithController extends BaseController {
|
|
|
3732
3878
|
event == null ? void 0 : event.preventDefault();
|
|
3733
3879
|
event == null ? void 0 : event.stopImmediatePropagation();
|
|
3734
3880
|
} else {
|
|
3735
|
-
this._cacheText = this._getElText(element);
|
|
3736
|
-
this._setElText(element, this._message);
|
|
3737
3881
|
this._disable();
|
|
3738
|
-
|
|
3882
|
+
useTemporaryContent(this, element, this._message, this._timeout, this._enable);
|
|
3739
3883
|
}
|
|
3740
3884
|
}
|
|
3741
3885
|
enable(event) {
|
|
3742
3886
|
event == null ? void 0 : event.preventDefault();
|
|
3743
3887
|
let element = this.el;
|
|
3744
3888
|
if (this._isDisabled(element)) {
|
|
3745
|
-
this._setElText(element, this._cacheText);
|
|
3746
3889
|
this._enable();
|
|
3747
3890
|
}
|
|
3748
3891
|
}
|
|
3749
3892
|
_isDisabled(el) {
|
|
3750
|
-
if (
|
|
3893
|
+
if (isTypeOfButtonableElement(el)) {
|
|
3751
3894
|
return el.disabled;
|
|
3752
3895
|
} else {
|
|
3753
3896
|
return el.dataset.disabled == "true";
|
|
3754
3897
|
}
|
|
3755
3898
|
}
|
|
3756
|
-
_getElText(el) {
|
|
3757
|
-
if (isHTMLInputElement(el) && el.type == "submit") {
|
|
3758
|
-
return el.value;
|
|
3759
|
-
} else {
|
|
3760
|
-
return el.innerText;
|
|
3761
|
-
}
|
|
3762
|
-
}
|
|
3763
|
-
_setElText(el, str) {
|
|
3764
|
-
if (isHTMLInputElement(el) && el.type == "submit") {
|
|
3765
|
-
el.value = str;
|
|
3766
|
-
} else if (isHTMLButtonElement(el) || isHTMLAnchorElement(el)) {
|
|
3767
|
-
el.innerText = str;
|
|
3768
|
-
}
|
|
3769
|
-
}
|
|
3770
3899
|
_disable() {
|
|
3771
3900
|
let el = this.el;
|
|
3772
|
-
if (
|
|
3901
|
+
if (isTypeOfButtonableElement(el)) {
|
|
3773
3902
|
el.disabled = true;
|
|
3774
3903
|
} else {
|
|
3775
3904
|
el.dataset.disabled = "true";
|
|
@@ -3777,7 +3906,7 @@ class DisableWithController extends BaseController {
|
|
|
3777
3906
|
}
|
|
3778
3907
|
_enable() {
|
|
3779
3908
|
let el = this.el;
|
|
3780
|
-
if (
|
|
3909
|
+
if (isTypeOfButtonableElement(el)) {
|
|
3781
3910
|
el.disabled = false;
|
|
3782
3911
|
} else {
|
|
3783
3912
|
el.dataset.disabled = void 0;
|
|
@@ -3817,7 +3946,11 @@ class ElementSaveController extends BaseController {
|
|
|
3817
3946
|
get _element() {
|
|
3818
3947
|
return this.hasElementTarget ? this.elementTarget : this.el;
|
|
3819
3948
|
}
|
|
3949
|
+
initialize() {
|
|
3950
|
+
this.save = debounce(this.save.bind(this), 300);
|
|
3951
|
+
}
|
|
3820
3952
|
connect() {
|
|
3953
|
+
this._store = useLocalStorage(this, this._uniqueIdentifier, {});
|
|
3821
3954
|
requestAnimationFrame(() => {
|
|
3822
3955
|
if (this._restoreOnLoad) {
|
|
3823
3956
|
this.restore();
|
|
@@ -3828,8 +3961,8 @@ class ElementSaveController extends BaseController {
|
|
|
3828
3961
|
if (event) {
|
|
3829
3962
|
event.preventDefault();
|
|
3830
3963
|
}
|
|
3831
|
-
|
|
3832
|
-
this.
|
|
3964
|
+
this._store.clear();
|
|
3965
|
+
this.dispatchEvent(this._element, `element-save:cleared`);
|
|
3833
3966
|
}
|
|
3834
3967
|
save(event) {
|
|
3835
3968
|
if (event) {
|
|
@@ -3839,22 +3972,20 @@ class ElementSaveController extends BaseController {
|
|
|
3839
3972
|
let attributes = this.attributesValue.split(" ");
|
|
3840
3973
|
let data = {};
|
|
3841
3974
|
attributes.forEach((attr) => data[attr] = get(element, attr));
|
|
3842
|
-
|
|
3843
|
-
this.
|
|
3975
|
+
this._store.value = data;
|
|
3976
|
+
this.dispatchEvent(element, `element-save:save:success`);
|
|
3844
3977
|
}
|
|
3845
3978
|
restore(event) {
|
|
3846
3979
|
if (event) {
|
|
3847
3980
|
event.preventDefault();
|
|
3848
3981
|
}
|
|
3849
3982
|
let element = this._element;
|
|
3850
|
-
if (
|
|
3851
|
-
const savedData =
|
|
3852
|
-
Object.keys(savedData).forEach((attr) =>
|
|
3853
|
-
|
|
3854
|
-
});
|
|
3855
|
-
this.dispatch(element, `element-save:restore:success`);
|
|
3983
|
+
if (!this._store.isEmpty()) {
|
|
3984
|
+
const savedData = this._store.value;
|
|
3985
|
+
Object.keys(savedData).forEach((attr) => set(element, attr, savedData[attr]));
|
|
3986
|
+
this.dispatchEvent(element, `element-save:restore:success`);
|
|
3856
3987
|
} else {
|
|
3857
|
-
this.
|
|
3988
|
+
this.dispatchEvent(element, `element-save:restore:empty`);
|
|
3858
3989
|
}
|
|
3859
3990
|
}
|
|
3860
3991
|
}
|
|
@@ -3892,11 +4023,11 @@ class EmptyDomController extends BaseController {
|
|
|
3892
4023
|
if (children.length === 0) {
|
|
3893
4024
|
this.removeNotEmptyClasses();
|
|
3894
4025
|
this.addEmptyClasses();
|
|
3895
|
-
this.
|
|
4026
|
+
this.dispatchEvent(element, "dom:empty");
|
|
3896
4027
|
} else {
|
|
3897
4028
|
this.addNotEmptyClasses();
|
|
3898
4029
|
this.removeEmptyClasses();
|
|
3899
|
-
this.
|
|
4030
|
+
this.dispatchEvent(element, "dom:not-empty", { detail: { count: children.length } });
|
|
3900
4031
|
}
|
|
3901
4032
|
}
|
|
3902
4033
|
}
|
|
@@ -3925,11 +4056,11 @@ class PrefetchController extends BaseController {
|
|
|
3925
4056
|
}
|
|
3926
4057
|
if (connection) {
|
|
3927
4058
|
if (connection.saveData) {
|
|
3928
|
-
|
|
4059
|
+
warn(this, "Data Saving is enabled");
|
|
3929
4060
|
return false;
|
|
3930
4061
|
}
|
|
3931
4062
|
if (/2g/.test(connection.effectiveType)) {
|
|
3932
|
-
|
|
4063
|
+
warn(this, "Network is too slow");
|
|
3933
4064
|
return false;
|
|
3934
4065
|
}
|
|
3935
4066
|
}
|
|
@@ -4080,7 +4211,7 @@ class TeleportController extends EphemeralController {
|
|
|
4080
4211
|
let element = this.el;
|
|
4081
4212
|
let destination = document.querySelector(this.targetValue);
|
|
4082
4213
|
if (destination == null) {
|
|
4083
|
-
this.
|
|
4214
|
+
this.dispatchEvent(element, "teleport:error");
|
|
4084
4215
|
return;
|
|
4085
4216
|
}
|
|
4086
4217
|
let copy = element.cloneNode(true);
|
|
@@ -4581,5 +4712,5 @@ __publicField(TurboFrameRefreshController, "values", {
|
|
|
4581
4712
|
interval: Number,
|
|
4582
4713
|
poll: Boolean
|
|
4583
4714
|
});
|
|
4584
|
-
export { AlertController, AnchorSpyController, AsyncBlockController, AutoSubmitFormController, AutosizeController, BackLinkController, BaseController, CharCountController, CheckboxDisableInputsController, CheckboxEnableInputsController, CheckboxSelectAllController, CheckboxXORController, ClipboardController, ClockController, ConfirmController, ConfirmNavigationController, CountdownController, DebugController, DetectDirtyController, DetectDirtyFormController, DisableWithController, DismissableController, DurationController, ElementSaveController, EmptyDomController, EnableInputsController, EphemeralController, EventBus, FallbackImageController, FocusStealController, FormRcController, FormSaveController, FullscreenController, IntersectionController, IntervalController, LazyBlockController, LightboxImageController, LimitedSelectionCheckboxesController, LoadBlockController, MediaPlayerController, NavigateFormErrorsController, NestedFormController, PasswordConfirmController, PasswordPeekController, PollBlockController, PrefetchController, PresenceController, PrintButtonController, PrintController, RemoteFormController, RemoveController, ResponsiveIframeBodyController, ResponsiveIframeWrapperController, ScrollContainerController, ScrollIntoFocusController, ScrollToBottomController, ScrollToController, ScrollToTopController, SelfDestructController, SignalActionController, SignalInputController, SignalVisibilityController, StickyController, StorageSerializers, SyncInputsController, TableSortController, TableTruncateController, TabsController, TeleportController, TemporaryStateController, TimeDistanceController, TimeoutController, ToggleClassController, TreeViewController, TrixModifierController, TurboFrameRCController, TurboFrameRefreshController, UserFocusController, ValueWarnController, WordCountController, applyTemporaryClass, applyTemporaryState, createHiddenButton, createHiddenInput, getAllRadiosInGroup, getOtherRadiosInGroup, getScrollParent, insertElement, insertHiddenButton, insertHiddenInput, isDirty, isElementCheckable, isElementInViewport, isFormDirty, isHTMLAnchorElement, isHTMLButtonElement, isHTMLFormElement, isHTMLImageElement, isHTMLInputElement, isHTMLLinkElement, isHTMLSelectElement, isHTMLTextAreaElement, isTurboFrame, isTypeOfFormInputElement, requestReset, requestSubmit, scrollAbsoluteBottom, scrollAbsoluteLeft, scrollAbsoluteRight, scrollAbsoluteTop, scrollDown, scrollLeft, scrollRight, scrollToElement, scrollUp, useCollectionEventListener, useCollectionEventListeners, useEventListener, useEventListeners, useFullscreen, useGeolocation, useInjectedElement, useInjectedFragment, useInjectedHTML, useInterval, useLocalStorage, useTimeout };
|
|
4715
|
+
export { AlertController, AnchorSpyController, AsyncBlockController, AutoSubmitFormController, AutosizeController, BackLinkController, BaseController, CharCountController, CheckboxDisableInputsController, CheckboxEnableInputsController, CheckboxSelectAllController, CheckboxXORController, ClipboardController, ClockController, ConfirmController, ConfirmNavigationController, CountdownController, DebugController, DetectDirtyController, DetectDirtyFormController, DisableWithController, DismissableController, DurationController, ElementSaveController, EmptyDomController, EnableInputsController, EphemeralController, EventBus, FallbackImageController, FocusStealController, FormRcController, FormSaveController, FullscreenController, IntersectionController, IntervalController, LazyBlockController, LightboxImageController, LimitedSelectionCheckboxesController, LoadBlockController, MediaPlayerController, NavigateFormErrorsController, NestedFormController, PasswordConfirmController, PasswordPeekController, PollBlockController, PrefetchController, PresenceController, PrintButtonController, PrintController, RemoteFormController, RemoveController, ResponsiveIframeBodyController, ResponsiveIframeWrapperController, ScrollContainerController, ScrollIntoFocusController, ScrollToBottomController, ScrollToController, ScrollToTopController, SelfDestructController, SignalActionController, SignalDomChildrenController, SignalInputController, SignalVisibilityController, StickyController, StorageSerializers, SyncInputsController, TableSortController, TableTruncateController, TabsController, TeleportController, TemporaryStateController, TimeDistanceController, TimeoutController, ToggleClassController, TreeViewController, TrixModifierController, TurboFrameRCController, TurboFrameRefreshController, UserFocusController, ValueWarnController, WordCountController, applyTemporaryClass, applyTemporaryState, createHiddenButton, createHiddenInput, getAllRadiosInGroup, getOtherRadiosInGroup, getScrollParent, insertElement, insertHiddenButton, insertHiddenInput, isDirty, isElementCheckable, isElementInViewport, isFormDirty, isHTMLAnchorElement, isHTMLButtonButtonElement, isHTMLButtonElement, isHTMLButtonInputElement, isHTMLFormElement, isHTMLImageElement, isHTMLInputElement, isHTMLLabelElement, isHTMLLinkElement, isHTMLResetButtonElement, isHTMLResetInputElement, isHTMLSelectElement, isHTMLSubmitButtonElement, isHTMLSubmitInputElement, isHTMLTextAreaElement, isTurboFrame, isTypeOfButtonableElement, isTypeOfFormInputElement, isTypeOfResetButtonElement, isTypeOfSubmitButtonElement, requestReset, requestSubmit, scrollAbsoluteBottom, scrollAbsoluteLeft, scrollAbsoluteRight, scrollAbsoluteTop, scrollDown, scrollLeft, scrollRight, scrollToElement, scrollUp, useCollectionEventListener, useCollectionEventListeners, useEventListener, useEventListeners, useFullscreen, useGeolocation, useInjectedElement, useInjectedFragment, useInjectedHTML, useInterval, useLocalStorage, useTemporaryContent, useTimeout };
|
|
4585
4716
|
//# sourceMappingURL=stimulus-library.es.js.map
|