phoenix_duskmoon 9.4.3 → 9.5.1
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/package.json +5 -5
- package/priv/static/assets/css/app.css +2 -0
- package/priv/static/assets/css/manifest.json +1 -0
- package/priv/static/assets/js/manifest.json +1 -0
- package/priv/static/assets/js/phoenix_duskmoon.js +1 -0
- package/priv/static/phoenix_duskmoon.css +0 -20079
- package/priv/static/phoenix_duskmoon.js +0 -161
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
// assets/js/phoenix_duskmoon.js
|
|
2
|
-
var DM_EVENTS = [
|
|
3
|
-
"dm-click",
|
|
4
|
-
"dm-change",
|
|
5
|
-
"dm-input",
|
|
6
|
-
"dm-focus",
|
|
7
|
-
"dm-blur",
|
|
8
|
-
"dm-submit",
|
|
9
|
-
"dm-select",
|
|
10
|
-
"dm-close",
|
|
11
|
-
"dm-open",
|
|
12
|
-
"dm-toggle"
|
|
13
|
-
];
|
|
14
|
-
var WebComponentHook = {
|
|
15
|
-
mounted() {
|
|
16
|
-
this._sendListeners = [];
|
|
17
|
-
this._setupEventBridging();
|
|
18
|
-
this._setupAutomaticForwarding();
|
|
19
|
-
},
|
|
20
|
-
updated() {
|
|
21
|
-
this._setupAutomaticForwarding();
|
|
22
|
-
},
|
|
23
|
-
destroyed() {
|
|
24
|
-
if (this._sendListeners) {
|
|
25
|
-
this._sendListeners.forEach(({ event, listener }) => {
|
|
26
|
-
this.el.removeEventListener(event, listener);
|
|
27
|
-
});
|
|
28
|
-
this._sendListeners = null;
|
|
29
|
-
}
|
|
30
|
-
DM_EVENTS.forEach((dmEvent) => {
|
|
31
|
-
const listenerKey = `_dm_listener_${dmEvent}`;
|
|
32
|
-
if (this[listenerKey]) {
|
|
33
|
-
this.el.removeEventListener(dmEvent, this[listenerKey]);
|
|
34
|
-
this[listenerKey] = null;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
_setupEventBridging() {
|
|
39
|
-
const attrs = this.el.attributes;
|
|
40
|
-
const phxTarget = this.el.getAttribute("phx-target");
|
|
41
|
-
const pushEvent = (event, payload, callback) => {
|
|
42
|
-
if (phxTarget) {
|
|
43
|
-
this.pushEventTo(phxTarget, event, payload, callback);
|
|
44
|
-
} else {
|
|
45
|
-
this.pushEvent(event, payload, callback);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
for (let i = 0;i < attrs.length; i++) {
|
|
49
|
-
const attr = attrs[i];
|
|
50
|
-
if (/^duskmoon-send-/.test(attr.name)) {
|
|
51
|
-
const eventName = attr.name.replace(/^duskmoon-send-/, "");
|
|
52
|
-
const [phxEvent, callbackName] = attr.value.split(";");
|
|
53
|
-
const listener = ({ detail }) => {
|
|
54
|
-
pushEvent(phxEvent, detail || {}, (response) => {
|
|
55
|
-
if (callbackName && typeof this[callbackName] === "function") {
|
|
56
|
-
this[callbackName](response, detail, eventName);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
this.el.addEventListener(eventName, listener);
|
|
61
|
-
this._sendListeners.push({ event: eventName, listener });
|
|
62
|
-
}
|
|
63
|
-
if (/^duskmoon-receive-/.test(attr.name)) {
|
|
64
|
-
const eventName = attr.name.replace(/^duskmoon-receive-/, "");
|
|
65
|
-
const handler = attr.value;
|
|
66
|
-
this.handleEvent(eventName, (payload) => {
|
|
67
|
-
if (handler && typeof this.el[handler] === "function") {
|
|
68
|
-
this.el[handler](payload);
|
|
69
|
-
} else {
|
|
70
|
-
this.el.dispatchEvent(new CustomEvent(eventName, {
|
|
71
|
-
detail: payload,
|
|
72
|
-
bubbles: true,
|
|
73
|
-
composed: true
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
if (attr.name === "duskmoon-receive") {
|
|
79
|
-
const [phxEvent, callbackName] = attr.value.split(";");
|
|
80
|
-
this.handleEvent(phxEvent, (payload) => {
|
|
81
|
-
if (typeof this.el[callbackName] === "function") {
|
|
82
|
-
this.el[callbackName](payload);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
_setupAutomaticForwarding() {
|
|
89
|
-
const phxTarget = this.el.getAttribute("phx-target");
|
|
90
|
-
DM_EVENTS.forEach((dmEvent) => {
|
|
91
|
-
const phxAttr = "phx-" + dmEvent.replace("dm-", "");
|
|
92
|
-
const phxEvent = this.el.getAttribute(phxAttr);
|
|
93
|
-
if (phxEvent) {
|
|
94
|
-
const listenerKey = `_dm_listener_${dmEvent}`;
|
|
95
|
-
if (this[listenerKey]) {
|
|
96
|
-
this.el.removeEventListener(dmEvent, this[listenerKey]);
|
|
97
|
-
}
|
|
98
|
-
this[listenerKey] = (e) => {
|
|
99
|
-
const detail = e.detail || {};
|
|
100
|
-
const payload = {
|
|
101
|
-
...detail,
|
|
102
|
-
value: this.el.value,
|
|
103
|
-
name: this.el.name,
|
|
104
|
-
checked: this.el.checked
|
|
105
|
-
};
|
|
106
|
-
if (phxTarget) {
|
|
107
|
-
this.pushEventTo(phxTarget, phxEvent, payload);
|
|
108
|
-
} else {
|
|
109
|
-
this.pushEvent(phxEvent, payload);
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
this.el.addEventListener(dmEvent, this[listenerKey]);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
var FormElementHook = {
|
|
118
|
-
...WebComponentHook,
|
|
119
|
-
mounted() {
|
|
120
|
-
WebComponentHook.mounted.call(this);
|
|
121
|
-
this._setupFormIntegration();
|
|
122
|
-
},
|
|
123
|
-
_setupFormIntegration() {
|
|
124
|
-
const name = this.el.getAttribute("name");
|
|
125
|
-
const feedbackFor = this.el.getAttribute("phx-feedback-for") || name;
|
|
126
|
-
if (feedbackFor) {
|
|
127
|
-
this._setupFeedbackObserver(feedbackFor);
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
destroyed() {
|
|
131
|
-
WebComponentHook.destroyed.call(this);
|
|
132
|
-
if (this._feedbackObserver) {
|
|
133
|
-
this._feedbackObserver.disconnect();
|
|
134
|
-
this._feedbackObserver = null;
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
_setupFeedbackObserver(feedbackFor) {
|
|
138
|
-
const form = this.el.closest("form");
|
|
139
|
-
if (!form)
|
|
140
|
-
return;
|
|
141
|
-
this._feedbackObserver = new MutationObserver((mutations) => {
|
|
142
|
-
mutations.forEach((mutation) => {
|
|
143
|
-
if (mutation.attributeName === "class") {
|
|
144
|
-
const hasNoFeedback = form.classList.contains("phx-no-feedback");
|
|
145
|
-
this.el.dispatchEvent(new CustomEvent("dm-feedback-change", {
|
|
146
|
-
detail: { showFeedback: !hasNoFeedback, field: feedbackFor }
|
|
147
|
-
}));
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
this._feedbackObserver.observe(form, { attributes: true, attributeFilter: ["class"] });
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
if (typeof window !== "undefined") {
|
|
155
|
-
window.__WebComponentHook__ = WebComponentHook;
|
|
156
|
-
window.__FormElementHook__ = FormElementHook;
|
|
157
|
-
}
|
|
158
|
-
export {
|
|
159
|
-
WebComponentHook,
|
|
160
|
-
FormElementHook
|
|
161
|
-
};
|