phoenix_live_view 1.0.2 → 1.0.4
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/README.md +2 -10
- package/assets/js/phoenix_live_view/dom.js +6 -1
- package/assets/js/phoenix_live_view/dom_patch.js +9 -37
- package/assets/js/phoenix_live_view/element_ref.js +9 -0
- package/assets/js/phoenix_live_view/hooks.js +26 -5
- package/assets/js/phoenix_live_view/js.js +9 -13
- package/assets/js/phoenix_live_view/live_socket.js +22 -29
- package/assets/js/phoenix_live_view/utils.js +11 -0
- package/assets/js/phoenix_live_view/view.js +32 -17
- package/package.json +24 -6
- package/priv/static/phoenix_live_view.cjs.js +109 -105
- package/priv/static/phoenix_live_view.cjs.js.map +3 -3
- package/priv/static/phoenix_live_view.esm.js +109 -105
- package/priv/static/phoenix_live_view.esm.js.map +3 -3
- package/priv/static/phoenix_live_view.js +109 -105
- package/priv/static/phoenix_live_view.min.js +6 -6
- package/assets/package.json +0 -29
|
@@ -192,6 +192,16 @@ function detectDuplicateIds() {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
+
function detectInvalidStreamInserts(inserts) {
|
|
196
|
+
const errors = /* @__PURE__ */ new Set();
|
|
197
|
+
Object.keys(inserts).forEach((id) => {
|
|
198
|
+
const streamEl = document.getElementById(id);
|
|
199
|
+
if (streamEl && streamEl.parentElement && streamEl.parentElement.getAttribute("phx-update") !== "stream") {
|
|
200
|
+
errors.add(`The stream container with id "${streamEl.parentElement.id}" is missing the phx-update="stream" attribute. Ensure it is set for streams to work properly.`);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
errors.forEach((error) => console.error(error));
|
|
204
|
+
}
|
|
195
205
|
var debug = (view, kind, msg, obj) => {
|
|
196
206
|
if (view.liveSocket.isDebugEnabled()) {
|
|
197
207
|
console.log(`${view.id} ${kind}: ${msg} - `, obj);
|
|
@@ -418,7 +428,7 @@ var DOM = {
|
|
|
418
428
|
cids.forEach((cid) => {
|
|
419
429
|
this.filterWithinSameLiveView(this.all(node, `[${PHX_COMPONENT}="${cid}"]`), node).forEach((parent) => {
|
|
420
430
|
parentCids.add(cid);
|
|
421
|
-
this.all(parent, `[${PHX_COMPONENT}]`).map((el) => parseInt(el.getAttribute(PHX_COMPONENT))).forEach((childCID) => childrenCids.add(childCID));
|
|
431
|
+
this.filterWithinSameLiveView(this.all(parent, `[${PHX_COMPONENT}]`), parent).map((el) => parseInt(el.getAttribute(PHX_COMPONENT))).forEach((childCID) => childrenCids.add(childCID));
|
|
422
432
|
});
|
|
423
433
|
});
|
|
424
434
|
childrenCids.forEach((childCid) => parentCids.delete(childCid));
|
|
@@ -795,6 +805,9 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
|
|
|
795
805
|
return;
|
|
796
806
|
}
|
|
797
807
|
ops.forEach(([name, op, _stashed]) => this.putSticky(el, name, op));
|
|
808
|
+
},
|
|
809
|
+
isLocked(el) {
|
|
810
|
+
return el.hasAttribute && el.hasAttribute(PHX_REF_LOCK);
|
|
798
811
|
}
|
|
799
812
|
};
|
|
800
813
|
var dom_default = DOM;
|
|
@@ -1137,11 +1150,27 @@ var Hooks = {
|
|
|
1137
1150
|
mounted() {
|
|
1138
1151
|
this.focusStart = this.el.firstElementChild;
|
|
1139
1152
|
this.focusEnd = this.el.lastElementChild;
|
|
1140
|
-
this.focusStart.addEventListener("focus", () =>
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1153
|
+
this.focusStart.addEventListener("focus", (e) => {
|
|
1154
|
+
if (!e.relatedTarget || !this.el.contains(e.relatedTarget)) {
|
|
1155
|
+
const nextFocus = e.target.nextElementSibling;
|
|
1156
|
+
aria_default.attemptFocus(nextFocus) || aria_default.focusFirst(nextFocus);
|
|
1157
|
+
} else {
|
|
1158
|
+
aria_default.focusLast(this.el);
|
|
1159
|
+
}
|
|
1160
|
+
});
|
|
1161
|
+
this.focusEnd.addEventListener("focus", (e) => {
|
|
1162
|
+
if (!e.relatedTarget || !this.el.contains(e.relatedTarget)) {
|
|
1163
|
+
const nextFocus = e.target.previousElementSibling;
|
|
1164
|
+
aria_default.attemptFocus(nextFocus) || aria_default.focusLast(nextFocus);
|
|
1165
|
+
} else {
|
|
1166
|
+
aria_default.focusFirst(this.el);
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
if (!this.el.contains(document.activeElement)) {
|
|
1170
|
+
this.el.addEventListener("phx:show-end", () => this.el.focus());
|
|
1171
|
+
if (window.getComputedStyle(this.el).display !== "none") {
|
|
1172
|
+
aria_default.focusFirst(this.el);
|
|
1173
|
+
}
|
|
1145
1174
|
}
|
|
1146
1175
|
}
|
|
1147
1176
|
}
|
|
@@ -1287,6 +1316,16 @@ var hooks_default = Hooks;
|
|
|
1287
1316
|
|
|
1288
1317
|
// js/phoenix_live_view/element_ref.js
|
|
1289
1318
|
var ElementRef = class {
|
|
1319
|
+
static onUnlock(el, callback) {
|
|
1320
|
+
if (!dom_default.isLocked(el) && !el.closest(`[${PHX_REF_LOCK}]`)) {
|
|
1321
|
+
return callback();
|
|
1322
|
+
}
|
|
1323
|
+
const closestLock = el.closest(`[${PHX_REF_LOCK}]`);
|
|
1324
|
+
const ref = closestLock.closest(`[${PHX_REF_LOCK}]`).getAttribute(PHX_REF_LOCK);
|
|
1325
|
+
closestLock.addEventListener(`phx:undo-lock:${ref}`, () => {
|
|
1326
|
+
callback();
|
|
1327
|
+
}, { once: true });
|
|
1328
|
+
}
|
|
1290
1329
|
constructor(el) {
|
|
1291
1330
|
this.el = el;
|
|
1292
1331
|
this.loadingRef = el.hasAttribute(PHX_REF_LOADING) ? parseInt(el.getAttribute(PHX_REF_LOADING), 10) : null;
|
|
@@ -1429,7 +1468,7 @@ var DOMPostMorphRestorer = class {
|
|
|
1429
1468
|
}
|
|
1430
1469
|
};
|
|
1431
1470
|
|
|
1432
|
-
// node_modules/morphdom/dist/morphdom-esm.js
|
|
1471
|
+
// ../node_modules/morphdom/dist/morphdom-esm.js
|
|
1433
1472
|
var DOCUMENT_FRAGMENT_NODE = 11;
|
|
1434
1473
|
function morphAttrs(fromNode, toNode) {
|
|
1435
1474
|
var toNodeAttrs = toNode.attributes;
|
|
@@ -1938,37 +1977,7 @@ var morphdom_esm_default = morphdom;
|
|
|
1938
1977
|
|
|
1939
1978
|
// js/phoenix_live_view/dom_patch.js
|
|
1940
1979
|
var DOMPatch = class {
|
|
1941
|
-
|
|
1942
|
-
let focused = liveSocket.getActiveElement();
|
|
1943
|
-
let { selectionStart, selectionEnd } = focused && dom_default.hasSelectionRange(focused) ? focused : {};
|
|
1944
|
-
let phxUpdate = liveSocket.binding(PHX_UPDATE);
|
|
1945
|
-
let externalFormTriggered = null;
|
|
1946
|
-
morphdom_esm_default(container, clonedTree, {
|
|
1947
|
-
childrenOnly: false,
|
|
1948
|
-
onBeforeElUpdated: (fromEl, toEl) => {
|
|
1949
|
-
dom_default.syncPendingAttrs(fromEl, toEl);
|
|
1950
|
-
if (!container.isSameNode(fromEl) && fromEl.hasAttribute(PHX_REF_LOCK)) {
|
|
1951
|
-
return false;
|
|
1952
|
-
}
|
|
1953
|
-
if (dom_default.isIgnored(fromEl, phxUpdate)) {
|
|
1954
|
-
return false;
|
|
1955
|
-
}
|
|
1956
|
-
if (focused && focused.isSameNode(fromEl) && dom_default.isFormInput(fromEl)) {
|
|
1957
|
-
dom_default.mergeFocusedInput(fromEl, toEl);
|
|
1958
|
-
return false;
|
|
1959
|
-
}
|
|
1960
|
-
if (dom_default.isNowTriggerFormExternal(toEl, liveSocket.binding(PHX_TRIGGER_ACTION))) {
|
|
1961
|
-
externalFormTriggered = toEl;
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
});
|
|
1965
|
-
if (externalFormTriggered) {
|
|
1966
|
-
liveSocket.unload();
|
|
1967
|
-
Object.getPrototypeOf(externalFormTriggered).submit.call(externalFormTriggered);
|
|
1968
|
-
}
|
|
1969
|
-
liveSocket.silenceEvents(() => dom_default.restoreFocus(focused, selectionStart, selectionEnd));
|
|
1970
|
-
}
|
|
1971
|
-
constructor(view, container, id, html, streams, targetCID) {
|
|
1980
|
+
constructor(view, container, id, html, streams, targetCID, opts = {}) {
|
|
1972
1981
|
this.view = view;
|
|
1973
1982
|
this.liveSocket = view.liveSocket;
|
|
1974
1983
|
this.container = container;
|
|
@@ -1993,6 +2002,8 @@ var DOMPatch = class {
|
|
|
1993
2002
|
afterphxChildAdded: [],
|
|
1994
2003
|
aftertransitionsDiscarded: []
|
|
1995
2004
|
};
|
|
2005
|
+
this.withChildren = opts.withChildren || opts.undoRef || false;
|
|
2006
|
+
this.undoRef = opts.undoRef;
|
|
1996
2007
|
}
|
|
1997
2008
|
before(kind, callback) {
|
|
1998
2009
|
this.callbacks[`before${kind}`].push(callback);
|
|
@@ -2027,7 +2038,7 @@ var DOMPatch = class {
|
|
|
2027
2038
|
let updates = [];
|
|
2028
2039
|
let appendPrependUpdates = [];
|
|
2029
2040
|
let externalFormTriggered = null;
|
|
2030
|
-
function morph(targetContainer2, source, withChildren =
|
|
2041
|
+
function morph(targetContainer2, source, withChildren = this.withChildren) {
|
|
2031
2042
|
let morphCallbacks = {
|
|
2032
2043
|
// normally, we are running with childrenOnly, as the patch HTML for a LV
|
|
2033
2044
|
// does not include the LV attrs (data-phx-session, etc.)
|
|
@@ -2153,7 +2164,7 @@ var DOMPatch = class {
|
|
|
2153
2164
|
}
|
|
2154
2165
|
let isFocusedFormEl = focused && fromEl.isSameNode(focused) && dom_default.isFormInput(fromEl);
|
|
2155
2166
|
let focusedSelectChanged = isFocusedFormEl && this.isChangedSelect(fromEl, toEl);
|
|
2156
|
-
if (fromEl.hasAttribute(PHX_REF_SRC)) {
|
|
2167
|
+
if (fromEl.hasAttribute(PHX_REF_SRC) && fromEl.getAttribute(PHX_REF_LOCK) != this.undoRef) {
|
|
2157
2168
|
if (dom_default.isUploadInput(fromEl)) {
|
|
2158
2169
|
dom_default.mergeAttrs(fromEl, toEl, { isIgnored: true });
|
|
2159
2170
|
this.trackBefore("updated", fromEl, toEl);
|
|
@@ -2237,6 +2248,7 @@ var DOMPatch = class {
|
|
|
2237
2248
|
});
|
|
2238
2249
|
if (liveSocket.isDebugEnabled()) {
|
|
2239
2250
|
detectDuplicateIds();
|
|
2251
|
+
detectInvalidStreamInserts(this.streamInserts);
|
|
2240
2252
|
Array.from(document.querySelectorAll("input[name=id]")).forEach((node) => {
|
|
2241
2253
|
if (node.form) {
|
|
2242
2254
|
console.error('Detected an input with name="id" inside a form! This will cause problems when patching the DOM.\n', node);
|
|
@@ -2333,7 +2345,7 @@ var DOMPatch = class {
|
|
|
2333
2345
|
transitionPendingRemoves() {
|
|
2334
2346
|
let { pendingRemoves, liveSocket } = this;
|
|
2335
2347
|
if (pendingRemoves.length > 0) {
|
|
2336
|
-
liveSocket.transitionRemoves(pendingRemoves,
|
|
2348
|
+
liveSocket.transitionRemoves(pendingRemoves, () => {
|
|
2337
2349
|
pendingRemoves.forEach((el) => {
|
|
2338
2350
|
let child = dom_default.firstPhxChild(el);
|
|
2339
2351
|
if (child) {
|
|
@@ -2793,10 +2805,10 @@ var JS = {
|
|
|
2793
2805
|
view.liveSocket.pushHistoryPatch(e, href, replace ? "replace" : "push", sourceEl);
|
|
2794
2806
|
},
|
|
2795
2807
|
exec_focus(e, eventType, phxEvent, view, sourceEl, el) {
|
|
2796
|
-
|
|
2808
|
+
aria_default.attemptFocus(el);
|
|
2797
2809
|
},
|
|
2798
2810
|
exec_focus_first(e, eventType, phxEvent, view, sourceEl, el) {
|
|
2799
|
-
|
|
2811
|
+
aria_default.focusFirstInteractive(el) || aria_default.focusFirst(el);
|
|
2800
2812
|
},
|
|
2801
2813
|
exec_push_focus(e, eventType, phxEvent, view, sourceEl, el) {
|
|
2802
2814
|
window.requestAnimationFrame(() => focusStack.push(el || sourceEl));
|
|
@@ -2902,18 +2914,14 @@ var JS = {
|
|
|
2902
2914
|
}
|
|
2903
2915
|
} else {
|
|
2904
2916
|
if (this.isVisible(el)) {
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
el.dispatchEvent(new Event("phx:hide-end"));
|
|
2909
|
-
});
|
|
2917
|
+
el.dispatchEvent(new Event("phx:hide-start"));
|
|
2918
|
+
dom_default.putSticky(el, "toggle", (currentEl) => currentEl.style.display = "none");
|
|
2919
|
+
el.dispatchEvent(new Event("phx:hide-end"));
|
|
2910
2920
|
} else {
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
el.dispatchEvent(new Event("phx:show-end"));
|
|
2916
|
-
});
|
|
2921
|
+
el.dispatchEvent(new Event("phx:show-start"));
|
|
2922
|
+
let stickyDisplay = display || this.defaultDisplay(el);
|
|
2923
|
+
dom_default.putSticky(el, "toggle", (currentEl) => currentEl.style.display = stickyDisplay);
|
|
2924
|
+
el.dispatchEvent(new Event("phx:show-end"));
|
|
2917
2925
|
}
|
|
2918
2926
|
}
|
|
2919
2927
|
},
|
|
@@ -3571,7 +3579,11 @@ var View = class _View {
|
|
|
3571
3579
|
this.formsForRecovery = this.getFormsForRecovery();
|
|
3572
3580
|
}
|
|
3573
3581
|
if (this.isMain() && window.history.state === null) {
|
|
3574
|
-
|
|
3582
|
+
browser_default.pushState("replace", {
|
|
3583
|
+
type: "patch",
|
|
3584
|
+
id: this.id,
|
|
3585
|
+
position: this.liveSocket.currentHistoryPosition
|
|
3586
|
+
});
|
|
3575
3587
|
}
|
|
3576
3588
|
if (liveview_version !== this.liveSocket.version()) {
|
|
3577
3589
|
console.error(`LiveView asset version mismatch. JavaScript version ${this.liveSocket.version()} vs. server ${liveview_version}. To avoid issues, please ensure that your assets use the same version as the server.`);
|
|
@@ -3893,6 +3905,9 @@ var View = class _View {
|
|
|
3893
3905
|
}
|
|
3894
3906
|
addHook(el) {
|
|
3895
3907
|
let hookElId = ViewHook.elementID(el);
|
|
3908
|
+
if (el.getAttribute && !this.ownsElement(el)) {
|
|
3909
|
+
return;
|
|
3910
|
+
}
|
|
3896
3911
|
if (hookElId && !this.viewHooks[hookElId]) {
|
|
3897
3912
|
let hook = dom_default.getCustomElHook(el) || logError(`no hook found for custom element: ${el.id}`);
|
|
3898
3913
|
this.viewHooks[hookElId] = hook;
|
|
@@ -3902,9 +3917,6 @@ var View = class _View {
|
|
|
3902
3917
|
return;
|
|
3903
3918
|
} else {
|
|
3904
3919
|
let hookName = el.getAttribute(`data-phx-${PHX_HOOK}`) || el.getAttribute(this.binding(PHX_HOOK));
|
|
3905
|
-
if (hookName && !this.ownsElement(el)) {
|
|
3906
|
-
return;
|
|
3907
|
-
}
|
|
3908
3920
|
let callbacks = this.liveSocket.getHookCallbacks(hookName);
|
|
3909
3921
|
if (callbacks) {
|
|
3910
3922
|
if (!el.id) {
|
|
@@ -3919,9 +3931,10 @@ var View = class _View {
|
|
|
3919
3931
|
}
|
|
3920
3932
|
}
|
|
3921
3933
|
destroyHook(hook) {
|
|
3934
|
+
const hookId = ViewHook.elementID(hook.el);
|
|
3922
3935
|
hook.__destroyed();
|
|
3923
3936
|
hook.__cleanup__();
|
|
3924
|
-
delete this.viewHooks[
|
|
3937
|
+
delete this.viewHooks[hookId];
|
|
3925
3938
|
}
|
|
3926
3939
|
applyPendingUpdates() {
|
|
3927
3940
|
this.pendingDiffs.forEach(({ diff, events }) => this.update(diff, events));
|
|
@@ -4171,12 +4184,11 @@ var View = class _View {
|
|
|
4171
4184
|
undoElRef(el, ref, phxEvent) {
|
|
4172
4185
|
let elRef = new ElementRef(el);
|
|
4173
4186
|
elRef.maybeUndo(ref, phxEvent, (clonedTree) => {
|
|
4174
|
-
let
|
|
4175
|
-
|
|
4187
|
+
let patch = new DOMPatch(this, el, this.id, clonedTree, [], null, { undoRef: ref });
|
|
4188
|
+
const phxChildrenAdded = this.performPatch(patch, true);
|
|
4176
4189
|
dom_default.all(el, `[${PHX_REF_SRC}="${this.refSrc()}"]`, (child) => this.undoElRef(child, ref, phxEvent));
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
hook.__updated();
|
|
4190
|
+
if (phxChildrenAdded) {
|
|
4191
|
+
this.joinNewChildren();
|
|
4180
4192
|
}
|
|
4181
4193
|
});
|
|
4182
4194
|
}
|
|
@@ -4392,15 +4404,17 @@ var View = class _View {
|
|
|
4392
4404
|
};
|
|
4393
4405
|
this.pushWithReply(refGenerator, "event", event).then(({ resp }) => {
|
|
4394
4406
|
if (dom_default.isUploadInput(inputEl) && dom_default.isAutoUpload(inputEl)) {
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4407
|
+
ElementRef.onUnlock(inputEl, () => {
|
|
4408
|
+
if (LiveUploader.filesAwaitingPreflight(inputEl).length > 0) {
|
|
4409
|
+
let [ref, _els] = refGenerator();
|
|
4410
|
+
this.undoRefs(ref, phxEvent, [inputEl.form]);
|
|
4411
|
+
this.uploadFiles(inputEl.form, phxEvent, targetCtx, ref, cid, (_uploads) => {
|
|
4412
|
+
callback && callback(resp);
|
|
4413
|
+
this.triggerAwaitingSubmit(inputEl.form, phxEvent);
|
|
4414
|
+
this.undoRefs(ref, phxEvent);
|
|
4415
|
+
});
|
|
4416
|
+
}
|
|
4417
|
+
});
|
|
4404
4418
|
} else {
|
|
4405
4419
|
callback && callback(resp);
|
|
4406
4420
|
}
|
|
@@ -4751,7 +4765,7 @@ var LiveSocket = class {
|
|
|
4751
4765
|
}
|
|
4752
4766
|
// public
|
|
4753
4767
|
version() {
|
|
4754
|
-
return "1.0.
|
|
4768
|
+
return "1.0.4";
|
|
4755
4769
|
}
|
|
4756
4770
|
isProfileEnabled() {
|
|
4757
4771
|
return this.sessionStorage.getItem(PHX_LV_PROFILE) === "true";
|
|
@@ -4948,7 +4962,9 @@ var LiveSocket = class {
|
|
|
4948
4962
|
dom_default.all(document, `${PHX_VIEW_SELECTOR}:not([${PHX_PARENT_ID}])`, (rootEl) => {
|
|
4949
4963
|
if (!this.getRootById(rootEl.id)) {
|
|
4950
4964
|
let view = this.newRootView(rootEl);
|
|
4951
|
-
|
|
4965
|
+
if (!dom_default.isPhxSticky(rootEl)) {
|
|
4966
|
+
view.setHref(this.getHref());
|
|
4967
|
+
}
|
|
4952
4968
|
view.join();
|
|
4953
4969
|
if (rootEl.hasAttribute(PHX_MAIN)) {
|
|
4954
4970
|
this.main = view;
|
|
@@ -4966,20 +4982,21 @@ var LiveSocket = class {
|
|
|
4966
4982
|
browser_default.redirect(to, flash);
|
|
4967
4983
|
}
|
|
4968
4984
|
replaceMain(href, flash, callback = null, linkRef = this.setPendingLink(href)) {
|
|
4969
|
-
|
|
4985
|
+
const liveReferer = this.currentLocation.href;
|
|
4970
4986
|
this.outgoingMainEl = this.outgoingMainEl || this.main.el;
|
|
4971
|
-
|
|
4972
|
-
|
|
4987
|
+
const stickies = dom_default.findPhxSticky(document) || [];
|
|
4988
|
+
const removeEls = dom_default.all(this.outgoingMainEl, `[${this.binding("remove")}]`).filter((el) => !dom_default.isChildOfAny(el, stickies));
|
|
4989
|
+
const newMainEl = dom_default.cloneNode(this.outgoingMainEl, "");
|
|
4973
4990
|
this.main.showLoader(this.loaderTimeout);
|
|
4974
4991
|
this.main.destroy();
|
|
4975
4992
|
this.main = this.newRootView(newMainEl, flash, liveReferer);
|
|
4976
4993
|
this.main.setRedirect(href);
|
|
4977
|
-
this.transitionRemoves(removeEls
|
|
4994
|
+
this.transitionRemoves(removeEls);
|
|
4978
4995
|
this.main.join((joinCount, onDone) => {
|
|
4979
4996
|
if (joinCount === 1 && this.commitPendingLink(linkRef)) {
|
|
4980
4997
|
this.requestDOMUpdate(() => {
|
|
4981
4998
|
removeEls.forEach((el) => el.remove());
|
|
4982
|
-
|
|
4999
|
+
stickies.forEach((el) => newMainEl.appendChild(el));
|
|
4983
5000
|
this.outgoingMainEl.replaceWith(newMainEl);
|
|
4984
5001
|
this.outgoingMainEl = null;
|
|
4985
5002
|
callback && callback(linkRef);
|
|
@@ -4988,12 +5005,8 @@ var LiveSocket = class {
|
|
|
4988
5005
|
}
|
|
4989
5006
|
});
|
|
4990
5007
|
}
|
|
4991
|
-
transitionRemoves(elements,
|
|
5008
|
+
transitionRemoves(elements, callback) {
|
|
4992
5009
|
let removeAttr = this.binding("remove");
|
|
4993
|
-
if (skipSticky) {
|
|
4994
|
-
const stickies = dom_default.findPhxSticky(document) || [];
|
|
4995
|
-
elements = elements.filter((el) => !dom_default.isChildOfAny(el, stickies));
|
|
4996
|
-
}
|
|
4997
5010
|
let silenceEvents = (e) => {
|
|
4998
5011
|
e.preventDefault();
|
|
4999
5012
|
e.stopImmediatePropagation();
|
|
@@ -5262,7 +5275,7 @@ var LiveSocket = class {
|
|
|
5262
5275
|
if (!this.registerNewLocation(window.location)) {
|
|
5263
5276
|
return;
|
|
5264
5277
|
}
|
|
5265
|
-
let { type, backType, id,
|
|
5278
|
+
let { type, backType, id, scroll, position } = event.state || {};
|
|
5266
5279
|
let href = window.location.href;
|
|
5267
5280
|
let isForward = position > this.currentHistoryPosition;
|
|
5268
5281
|
type = isForward ? type : backType || type;
|
|
@@ -5270,17 +5283,13 @@ var LiveSocket = class {
|
|
|
5270
5283
|
this.sessionStorage.setItem(PHX_LV_HISTORY_POSITION, this.currentHistoryPosition.toString());
|
|
5271
5284
|
dom_default.dispatchEvent(window, "phx:navigate", { detail: { href, patch: type === "patch", pop: true, direction: isForward ? "forward" : "backward" } });
|
|
5272
5285
|
this.requestDOMUpdate(() => {
|
|
5286
|
+
const callback = () => {
|
|
5287
|
+
this.maybeScroll(scroll);
|
|
5288
|
+
};
|
|
5273
5289
|
if (this.main.isConnected() && (type === "patch" && id === this.main.id)) {
|
|
5274
|
-
this.main.pushLinkPatch(event, href, null,
|
|
5275
|
-
this.maybeScroll(scroll);
|
|
5276
|
-
});
|
|
5290
|
+
this.main.pushLinkPatch(event, href, null, callback);
|
|
5277
5291
|
} else {
|
|
5278
|
-
this.replaceMain(href, null,
|
|
5279
|
-
if (root) {
|
|
5280
|
-
this.replaceRootHistory();
|
|
5281
|
-
}
|
|
5282
|
-
this.maybeScroll(scroll);
|
|
5283
|
-
});
|
|
5292
|
+
this.replaceMain(href, null, callback);
|
|
5284
5293
|
}
|
|
5285
5294
|
});
|
|
5286
5295
|
}, false);
|
|
@@ -5357,7 +5366,8 @@ var LiveSocket = class {
|
|
|
5357
5366
|
this.registerNewLocation(window.location);
|
|
5358
5367
|
}
|
|
5359
5368
|
historyRedirect(e, href, linkState, flash, targetEl) {
|
|
5360
|
-
|
|
5369
|
+
const clickLoading = targetEl && e.isTrusted && e.type !== "popstate";
|
|
5370
|
+
if (clickLoading) {
|
|
5361
5371
|
targetEl.classList.add("phx-click-loading");
|
|
5362
5372
|
}
|
|
5363
5373
|
if (!this.isConnected() || !this.main.isMain()) {
|
|
@@ -5383,19 +5393,13 @@ var LiveSocket = class {
|
|
|
5383
5393
|
dom_default.dispatchEvent(window, "phx:navigate", { detail: { href, patch: false, pop: false, direction: "forward" } });
|
|
5384
5394
|
this.registerNewLocation(window.location);
|
|
5385
5395
|
}
|
|
5396
|
+
if (clickLoading) {
|
|
5397
|
+
targetEl.classList.remove("phx-click-loading");
|
|
5398
|
+
}
|
|
5386
5399
|
done();
|
|
5387
5400
|
});
|
|
5388
5401
|
});
|
|
5389
5402
|
}
|
|
5390
|
-
replaceRootHistory() {
|
|
5391
|
-
browser_default.pushState("replace", {
|
|
5392
|
-
root: true,
|
|
5393
|
-
type: "patch",
|
|
5394
|
-
id: this.main.id,
|
|
5395
|
-
position: this.currentHistoryPosition
|
|
5396
|
-
// Preserve current position
|
|
5397
|
-
});
|
|
5398
|
-
}
|
|
5399
5403
|
registerNewLocation(newLocation) {
|
|
5400
5404
|
let { pathname, search } = this.currentLocation;
|
|
5401
5405
|
if (pathname + search === newLocation.pathname + newLocation.search) {
|