phoenix_live_view 0.17.2 → 0.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -1
- package/README.md +14 -14
- package/assets/js/phoenix_live_view/constants.js +1 -0
- package/assets/js/phoenix_live_view/js.js +41 -29
- package/assets/js/phoenix_live_view/live_socket.js +5 -4
- package/assets/js/phoenix_live_view/rendered.js +21 -9
- package/assets/js/phoenix_live_view/utils.js +4 -1
- package/assets/js/phoenix_live_view/view.js +10 -7
- package/package.json +1 -1
- package/priv/static/phoenix_live_view.cjs.js +80 -49
- package/priv/static/phoenix_live_view.cjs.js.map +2 -2
- package/priv/static/phoenix_live_view.esm.js +80 -49
- package/priv/static/phoenix_live_view.esm.js.map +2 -2
- package/priv/static/phoenix_live_view.js +80 -49
- package/priv/static/phoenix_live_view.min.js +5 -5
|
@@ -105,6 +105,7 @@ var LiveView = (() => {
|
|
|
105
105
|
var EVENTS = "e";
|
|
106
106
|
var REPLY = "r";
|
|
107
107
|
var TITLE = "t";
|
|
108
|
+
var TEMPLATES = "p";
|
|
108
109
|
|
|
109
110
|
// js/phoenix_live_view/entry_uploader.js
|
|
110
111
|
var EntryUploader = class {
|
|
@@ -156,7 +157,10 @@ var LiveView = (() => {
|
|
|
156
157
|
|
|
157
158
|
// js/phoenix_live_view/utils.js
|
|
158
159
|
var logError = (msg, obj) => console.error && console.error(msg, obj);
|
|
159
|
-
var isCid = (cid) =>
|
|
160
|
+
var isCid = (cid) => {
|
|
161
|
+
let type = typeof cid;
|
|
162
|
+
return type === "number" || type === "string" && /^(0|[1-9]\d*)$/.test(cid);
|
|
163
|
+
};
|
|
160
164
|
function detectDuplicateIds() {
|
|
161
165
|
let ids = new Set();
|
|
162
166
|
let elems = document.querySelectorAll("*[id]");
|
|
@@ -1690,7 +1694,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
|
|
|
1690
1694
|
recursiveToString(rendered, components = rendered[COMPONENTS], onlyCids) {
|
|
1691
1695
|
onlyCids = onlyCids ? new Set(onlyCids) : null;
|
|
1692
1696
|
let output = { buffer: "", components, onlyCids };
|
|
1693
|
-
this.toOutputBuffer(rendered, output);
|
|
1697
|
+
this.toOutputBuffer(rendered, null, output);
|
|
1694
1698
|
return output.buffer;
|
|
1695
1699
|
}
|
|
1696
1700
|
componentCIDs(diff) {
|
|
@@ -1716,8 +1720,8 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
|
|
|
1716
1720
|
for (let cid in newc) {
|
|
1717
1721
|
newc[cid] = this.cachedFindComponent(cid, newc[cid], oldc, newc, cache);
|
|
1718
1722
|
}
|
|
1719
|
-
for (
|
|
1720
|
-
oldc[
|
|
1723
|
+
for (let cid in newc) {
|
|
1724
|
+
oldc[cid] = newc[cid];
|
|
1721
1725
|
}
|
|
1722
1726
|
diff[COMPONENTS] = newc;
|
|
1723
1727
|
}
|
|
@@ -1786,33 +1790,43 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
|
|
|
1786
1790
|
isNewFingerprint(diff = {}) {
|
|
1787
1791
|
return !!diff[STATIC];
|
|
1788
1792
|
}
|
|
1789
|
-
|
|
1793
|
+
templateStatic(part, templates) {
|
|
1794
|
+
if (typeof part === "number") {
|
|
1795
|
+
return templates[part];
|
|
1796
|
+
} else {
|
|
1797
|
+
return part;
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
toOutputBuffer(rendered, templates, output) {
|
|
1790
1801
|
if (rendered[DYNAMICS]) {
|
|
1791
|
-
return this.comprehensionToBuffer(rendered, output);
|
|
1802
|
+
return this.comprehensionToBuffer(rendered, templates, output);
|
|
1792
1803
|
}
|
|
1793
1804
|
let { [STATIC]: statics } = rendered;
|
|
1805
|
+
statics = this.templateStatic(statics, templates);
|
|
1794
1806
|
output.buffer += statics[0];
|
|
1795
1807
|
for (let i = 1; i < statics.length; i++) {
|
|
1796
|
-
this.dynamicToBuffer(rendered[i - 1], output);
|
|
1808
|
+
this.dynamicToBuffer(rendered[i - 1], templates, output);
|
|
1797
1809
|
output.buffer += statics[i];
|
|
1798
1810
|
}
|
|
1799
1811
|
}
|
|
1800
|
-
comprehensionToBuffer(rendered, output) {
|
|
1812
|
+
comprehensionToBuffer(rendered, templates, output) {
|
|
1801
1813
|
let { [DYNAMICS]: dynamics, [STATIC]: statics } = rendered;
|
|
1814
|
+
statics = this.templateStatic(statics, templates);
|
|
1815
|
+
let compTemplates = rendered[TEMPLATES];
|
|
1802
1816
|
for (let d = 0; d < dynamics.length; d++) {
|
|
1803
1817
|
let dynamic = dynamics[d];
|
|
1804
1818
|
output.buffer += statics[0];
|
|
1805
1819
|
for (let i = 1; i < statics.length; i++) {
|
|
1806
|
-
this.dynamicToBuffer(dynamic[i - 1], output);
|
|
1820
|
+
this.dynamicToBuffer(dynamic[i - 1], compTemplates, output);
|
|
1807
1821
|
output.buffer += statics[i];
|
|
1808
1822
|
}
|
|
1809
1823
|
}
|
|
1810
1824
|
}
|
|
1811
|
-
dynamicToBuffer(rendered, output) {
|
|
1825
|
+
dynamicToBuffer(rendered, templates, output) {
|
|
1812
1826
|
if (typeof rendered === "number") {
|
|
1813
1827
|
output.buffer += this.recursiveCIDToString(output.components, rendered, output.onlyCids);
|
|
1814
1828
|
} else if (isObject(rendered)) {
|
|
1815
|
-
this.toOutputBuffer(rendered, output);
|
|
1829
|
+
this.toOutputBuffer(rendered, templates, output);
|
|
1816
1830
|
} else {
|
|
1817
1831
|
output.buffer += rendered;
|
|
1818
1832
|
}
|
|
@@ -1998,18 +2012,20 @@ within:
|
|
|
1998
2012
|
this.addOrRemoveClasses(sourceEl, [], names, transition, time, view);
|
|
1999
2013
|
}
|
|
2000
2014
|
},
|
|
2001
|
-
exec_transition(eventType, phxEvent, view, sourceEl, { time, to,
|
|
2015
|
+
exec_transition(eventType, phxEvent, view, sourceEl, { time, to, transition }) {
|
|
2002
2016
|
let els = to ? dom_default.all(document, to) : [sourceEl];
|
|
2017
|
+
let [transition_start, running, transition_end] = transition;
|
|
2003
2018
|
els.forEach((el) => {
|
|
2004
|
-
this.addOrRemoveClasses(el,
|
|
2005
|
-
|
|
2019
|
+
let onStart = () => this.addOrRemoveClasses(el, transition_start.concat(running), []);
|
|
2020
|
+
let onDone = () => this.addOrRemoveClasses(el, transition_end, transition_start.concat(running));
|
|
2021
|
+
view.transition(time, onStart, onDone);
|
|
2006
2022
|
});
|
|
2007
2023
|
},
|
|
2008
2024
|
exec_toggle(eventType, phxEvent, view, sourceEl, { to, display, ins, outs, time }) {
|
|
2009
2025
|
if (to) {
|
|
2010
|
-
dom_default.all(document, to, (el) => this.toggle(eventType, view, el, display, ins
|
|
2026
|
+
dom_default.all(document, to, (el) => this.toggle(eventType, view, el, display, ins, outs, time));
|
|
2011
2027
|
} else {
|
|
2012
|
-
this.toggle(eventType, view, sourceEl, display, ins
|
|
2028
|
+
this.toggle(eventType, view, sourceEl, display, ins, outs, time);
|
|
2013
2029
|
}
|
|
2014
2030
|
},
|
|
2015
2031
|
exec_show(eventType, phxEvent, view, sourceEl, { to, display, transition, time }) {
|
|
@@ -2027,37 +2043,45 @@ within:
|
|
|
2027
2043
|
}
|
|
2028
2044
|
},
|
|
2029
2045
|
show(eventType, view, el, display, transition, time) {
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
this.toggle(eventType, view, el, display, transition, [], time);
|
|
2033
|
-
} else if (!isVisible) {
|
|
2034
|
-
this.toggle(eventType, view, el, display, [], [], null);
|
|
2046
|
+
if (!this.isVisible(el)) {
|
|
2047
|
+
this.toggle(eventType, view, el, display, transition, null, time);
|
|
2035
2048
|
}
|
|
2036
2049
|
},
|
|
2037
2050
|
hide(eventType, view, el, display, transition, time) {
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
this.toggle(eventType, view, el, display, [], transition, time);
|
|
2041
|
-
} else if (isVisible) {
|
|
2042
|
-
this.toggle(eventType, view, el, display, [], [], time);
|
|
2051
|
+
if (this.isVisible(el)) {
|
|
2052
|
+
this.toggle(eventType, view, el, display, null, transition, time);
|
|
2043
2053
|
}
|
|
2044
2054
|
},
|
|
2045
|
-
toggle(eventType, view, el, display,
|
|
2046
|
-
|
|
2055
|
+
toggle(eventType, view, el, display, ins, outs, time) {
|
|
2056
|
+
let [inClasses, inStartClasses, inEndClasses] = ins || [[], [], []];
|
|
2057
|
+
let [outClasses, outStartClasses, outEndClasses] = outs || [[], [], []];
|
|
2058
|
+
if (inClasses.length > 0 || outClasses.length > 0) {
|
|
2047
2059
|
if (this.isVisible(el)) {
|
|
2048
|
-
|
|
2049
|
-
|
|
2060
|
+
let onStart = () => {
|
|
2061
|
+
this.addOrRemoveClasses(el, outStartClasses, inClasses.concat(inStartClasses).concat(inEndClasses));
|
|
2062
|
+
window.requestAnimationFrame(() => {
|
|
2063
|
+
this.addOrRemoveClasses(el, outClasses, []);
|
|
2064
|
+
window.requestAnimationFrame(() => this.addOrRemoveClasses(el, outEndClasses, outStartClasses));
|
|
2065
|
+
});
|
|
2066
|
+
};
|
|
2067
|
+
view.transition(time, onStart, () => {
|
|
2068
|
+
this.addOrRemoveClasses(el, [], outClasses.concat(outEndClasses));
|
|
2050
2069
|
dom_default.putSticky(el, "toggle", (currentEl) => currentEl.style.display = "none");
|
|
2051
|
-
this.addOrRemoveClasses(el, [], out_classes);
|
|
2052
2070
|
});
|
|
2053
2071
|
} else {
|
|
2054
2072
|
if (eventType === "remove") {
|
|
2055
2073
|
return;
|
|
2056
2074
|
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2075
|
+
let onStart = () => {
|
|
2076
|
+
this.addOrRemoveClasses(el, inStartClasses, outClasses.concat(outStartClasses).concat(outEndClasses));
|
|
2077
|
+
dom_default.putSticky(el, "toggle", (currentEl) => currentEl.style.display = display || "block");
|
|
2078
|
+
window.requestAnimationFrame(() => {
|
|
2079
|
+
this.addOrRemoveClasses(el, inClasses, []);
|
|
2080
|
+
window.requestAnimationFrame(() => this.addOrRemoveClasses(el, inEndClasses, inStartClasses));
|
|
2081
|
+
});
|
|
2082
|
+
};
|
|
2083
|
+
view.transition(time, onStart, () => {
|
|
2084
|
+
this.addOrRemoveClasses(el, [], inClasses.concat(inEndClasses));
|
|
2061
2085
|
});
|
|
2062
2086
|
}
|
|
2063
2087
|
} else {
|
|
@@ -2066,9 +2090,11 @@ within:
|
|
|
2066
2090
|
}
|
|
2067
2091
|
},
|
|
2068
2092
|
addOrRemoveClasses(el, adds, removes, transition, time, view) {
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2093
|
+
let [transition_run, transition_start, transition_end] = transition || [[], [], []];
|
|
2094
|
+
if (transition_run.length > 0) {
|
|
2095
|
+
let onStart = () => this.addOrRemoveClasses(el, transition_start.concat(transition_run), []);
|
|
2096
|
+
let onDone = () => this.addOrRemoveClasses(el, adds.concat(transition_end), removes.concat(transition_run).concat(transition_start));
|
|
2097
|
+
return view.transition(time, onStart, onDone);
|
|
2072
2098
|
}
|
|
2073
2099
|
window.requestAnimationFrame(() => {
|
|
2074
2100
|
let [prevAdds, prevRemoves] = dom_default.getSticky(el, "classes", [[], []]);
|
|
@@ -2090,8 +2116,8 @@ within:
|
|
|
2090
2116
|
let style = window.getComputedStyle(el);
|
|
2091
2117
|
return !(style.opacity === 0 || style.display === "none");
|
|
2092
2118
|
},
|
|
2093
|
-
isToggledOut(el,
|
|
2094
|
-
return !this.isVisible(el) || this.hasAllClasses(el,
|
|
2119
|
+
isToggledOut(el, outClasses) {
|
|
2120
|
+
return !this.isVisible(el) || this.hasAllClasses(el, outClasses);
|
|
2095
2121
|
}
|
|
2096
2122
|
};
|
|
2097
2123
|
var js_default = JS;
|
|
@@ -2232,15 +2258,15 @@ within:
|
|
|
2232
2258
|
log(kind, msgCallback) {
|
|
2233
2259
|
this.liveSocket.log(this, kind, msgCallback);
|
|
2234
2260
|
}
|
|
2235
|
-
transition(time, onDone = function() {
|
|
2261
|
+
transition(time, onStart, onDone = function() {
|
|
2236
2262
|
}) {
|
|
2237
|
-
this.liveSocket.transition(time, onDone);
|
|
2263
|
+
this.liveSocket.transition(time, onStart, onDone);
|
|
2238
2264
|
}
|
|
2239
2265
|
withinTargets(phxTarget, callback) {
|
|
2240
2266
|
if (phxTarget instanceof HTMLElement || phxTarget instanceof SVGElement) {
|
|
2241
2267
|
return this.liveSocket.owner(phxTarget, (view) => callback(view, phxTarget));
|
|
2242
2268
|
}
|
|
2243
|
-
if (
|
|
2269
|
+
if (isCid(phxTarget)) {
|
|
2244
2270
|
let targets = dom_default.findComponentNodeList(this.el, phxTarget);
|
|
2245
2271
|
if (targets.length === 0) {
|
|
2246
2272
|
logError(`no component found matching phx-target of ${phxTarget}`);
|
|
@@ -2744,7 +2770,11 @@ within:
|
|
|
2744
2770
|
targetComponentID(target, targetCtx) {
|
|
2745
2771
|
if (isCid(targetCtx)) {
|
|
2746
2772
|
return targetCtx;
|
|
2747
|
-
}
|
|
2773
|
+
}
|
|
2774
|
+
let cidOrSelector = target.getAttribute(this.binding("target"));
|
|
2775
|
+
if (isCid(cidOrSelector)) {
|
|
2776
|
+
return parseInt(cidOrSelector);
|
|
2777
|
+
} else if (targetCtx && cidOrSelector !== null) {
|
|
2748
2778
|
return this.closestComponentID(targetCtx);
|
|
2749
2779
|
} else {
|
|
2750
2780
|
return null;
|
|
@@ -3020,7 +3050,7 @@ within:
|
|
|
3020
3050
|
return dom_default.all(this.el, `form[${phxChange}]`).filter((form) => form.id && this.ownsElement(form)).filter((form) => form.elements.length > 0).filter((form) => form.getAttribute(this.binding(PHX_AUTO_RECOVER)) !== "ignore").map((form) => {
|
|
3021
3051
|
let newForm = template.content.querySelector(`form[id="${form.id}"][${phxChange}="${form.getAttribute(phxChange)}"]`);
|
|
3022
3052
|
if (newForm) {
|
|
3023
|
-
return [form, newForm, this.
|
|
3053
|
+
return [form, newForm, this.targetComponentID(newForm)];
|
|
3024
3054
|
} else {
|
|
3025
3055
|
return [form, null, null];
|
|
3026
3056
|
}
|
|
@@ -3182,9 +3212,9 @@ within:
|
|
|
3182
3212
|
requestDOMUpdate(callback) {
|
|
3183
3213
|
this.transitions.after(callback);
|
|
3184
3214
|
}
|
|
3185
|
-
transition(time, onDone = function() {
|
|
3215
|
+
transition(time, onStart, onDone = function() {
|
|
3186
3216
|
}) {
|
|
3187
|
-
this.transitions.addTransition(time, onDone);
|
|
3217
|
+
this.transitions.addTransition(time, onStart, onDone);
|
|
3188
3218
|
}
|
|
3189
3219
|
onChannel(channel, event, cb) {
|
|
3190
3220
|
channel.on(event, (data) => {
|
|
@@ -3320,7 +3350,7 @@ within:
|
|
|
3320
3350
|
return view;
|
|
3321
3351
|
}
|
|
3322
3352
|
owner(childEl, callback) {
|
|
3323
|
-
let view = maybe(childEl.closest(PHX_VIEW_SELECTOR), (el) => this.getViewByEl(el));
|
|
3353
|
+
let view = maybe(childEl.closest(PHX_VIEW_SELECTOR), (el) => this.getViewByEl(el)) || this.main;
|
|
3324
3354
|
if (view) {
|
|
3325
3355
|
callback(view);
|
|
3326
3356
|
}
|
|
@@ -3730,7 +3760,8 @@ within:
|
|
|
3730
3760
|
this.pushPendingOp(callback);
|
|
3731
3761
|
}
|
|
3732
3762
|
}
|
|
3733
|
-
addTransition(time, onDone) {
|
|
3763
|
+
addTransition(time, onStart, onDone) {
|
|
3764
|
+
onStart();
|
|
3734
3765
|
let timer = setTimeout(() => {
|
|
3735
3766
|
this.transitions.delete(timer);
|
|
3736
3767
|
onDone();
|