Skip to content

Commit 8d192cb

Browse files
committed
Revert "Revert "comitting compiled assets""
This reverts commit 83c9128.
1 parent 83c9128 commit 8d192cb

File tree

86 files changed

+24446
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+24446
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import controller_0 from "../ux-live-component/live_controller.js";
2+
import "../ux-live-component/live.min.css";
3+
export const eagerControllers = {"live": controller_0};
4+
export const lazyControllers = {"login": () => import("../../controllers/login-controller.js")};
5+
export const isApplicationDebug = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { Application } from '@hotwired/stimulus';
2+
import { isApplicationDebug, eagerControllers, lazyControllers } from './controllers.js';
3+
4+
const controllerAttribute = 'data-controller';
5+
const loadControllers = (application, eagerControllers, lazyControllers) => {
6+
for (const name in eagerControllers) {
7+
registerController(name, eagerControllers[name], application);
8+
}
9+
const lazyControllerHandler = new StimulusLazyControllerHandler(application, lazyControllers);
10+
lazyControllerHandler.start();
11+
};
12+
const startStimulusApp = () => {
13+
const application = Application.start();
14+
application.debug = isApplicationDebug;
15+
loadControllers(application, eagerControllers, lazyControllers);
16+
return application;
17+
};
18+
class StimulusLazyControllerHandler {
19+
constructor(application, lazyControllers) {
20+
this.application = application;
21+
this.lazyControllers = lazyControllers;
22+
}
23+
start() {
24+
this.lazyLoadExistingControllers(document.documentElement);
25+
this.lazyLoadNewControllers(document.documentElement);
26+
}
27+
lazyLoadExistingControllers(element) {
28+
this.queryControllerNamesWithin(element).forEach((controllerName) => this.loadLazyController(controllerName));
29+
}
30+
async loadLazyController(name) {
31+
if (canRegisterController(name, this.application)) {
32+
if (this.lazyControllers[name] === undefined) {
33+
return;
34+
}
35+
const controllerModule = await this.lazyControllers[name]();
36+
registerController(name, controllerModule.default, this.application);
37+
}
38+
}
39+
lazyLoadNewControllers(element) {
40+
new MutationObserver((mutationsList) => {
41+
for (const { attributeName, target, type } of mutationsList) {
42+
switch (type) {
43+
case 'attributes': {
44+
if (attributeName === controllerAttribute &&
45+
target.getAttribute(controllerAttribute)) {
46+
extractControllerNamesFrom(target).forEach((controllerName) => this.loadLazyController(controllerName));
47+
}
48+
break;
49+
}
50+
case 'childList': {
51+
this.lazyLoadExistingControllers(target);
52+
}
53+
}
54+
}
55+
}).observe(element, {
56+
attributeFilter: [controllerAttribute],
57+
subtree: true,
58+
childList: true,
59+
});
60+
}
61+
queryControllerNamesWithin(element) {
62+
return Array.from(element.querySelectorAll(`[${controllerAttribute}]`))
63+
.map(extractControllerNamesFrom)
64+
.flat();
65+
}
66+
}
67+
function registerController(name, controller, application) {
68+
if (canRegisterController(name, application)) {
69+
application.register(name, controller);
70+
}
71+
}
72+
function extractControllerNamesFrom(element) {
73+
const controllerNameValue = element.getAttribute(controllerAttribute);
74+
if (!controllerNameValue) {
75+
return [];
76+
}
77+
return controllerNameValue.split(/\s+/).filter((content) => content.length);
78+
}
79+
function canRegisterController(name, application) {
80+
return !application.router.modulesByIdentifier.has(name);
81+
}
82+
83+
export { loadControllers, startStimulusApp };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[data-loading=""],[data-loading="delay|show"],[data-loading=show]{display:none}

0 commit comments

Comments
 (0)