phoenix_live_view 1.1.30 → 1.1.32

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.
@@ -189,7 +189,7 @@ var LiveView = (() => {
189
189
  }
190
190
  upload() {
191
191
  this.uploadChannel.onError((reason) => this.error(reason));
192
- this.uploadChannel.join().receive("ok", (_data) => this.readNextChunk()).receive("error", (reason) => this.error(reason));
192
+ this.uploadChannel.join().receive("ok", (_data) => this.readNextChunk()).receive("error", ({ reason }) => this.error(reason));
193
193
  }
194
194
  isDone() {
195
195
  return this.offset >= this.entry.file.size;
@@ -232,6 +232,21 @@ var LiveView = (() => {
232
232
 
233
233
  // js/phoenix_live_view/utils.js
234
234
  var logError = (msg, obj) => console.error && console.error(msg, obj);
235
+ var ensureSameOrigin = (href, kind) => {
236
+ let url;
237
+ try {
238
+ url = new URL(href, window.location.href);
239
+ } catch (e) {
240
+ throw new Error(
241
+ `expected ${kind} destination to be a valid URL, got: ${href}`
242
+ );
243
+ }
244
+ if (url.origin !== window.location.origin) {
245
+ throw new Error(
246
+ `cannot ${kind} to "${href}" because its origin does not match the current origin "${window.location.origin}". Use window.location directly for cross-origin navigation.`
247
+ );
248
+ }
249
+ };
235
250
  var isCid = (cid) => {
236
251
  const type = typeof cid;
237
252
  return type === "number" || type === "string" && /^(0|[1-9]\d*)$/.test(cid);
@@ -652,7 +667,9 @@ var LiveView = (() => {
652
667
  if (this.once(el, "bind-debounce")) {
653
668
  el.addEventListener("blur", () => {
654
669
  clearTimeout(this.private(el, THROTTLED));
655
- this.triggerCycle(el, DEBOUNCE_TRIGGER);
670
+ if (asyncFilter()) {
671
+ this.triggerCycle(el, DEBOUNCE_TRIGGER);
672
+ }
656
673
  });
657
674
  }
658
675
  }
@@ -2760,7 +2777,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
2760
2777
  transitionPendingRemoves() {
2761
2778
  const { pendingRemoves, liveSocket } = this;
2762
2779
  if (pendingRemoves.length > 0) {
2763
- liveSocket.transitionRemoves(pendingRemoves, () => {
2780
+ liveSocket.transitionRemoves(pendingRemoves, this.view, () => {
2764
2781
  pendingRemoves.forEach((el) => {
2765
2782
  const child = dom_default.firstPhxChild(el);
2766
2783
  if (child) {
@@ -3901,6 +3918,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
3901
3918
  });
3902
3919
  },
3903
3920
  navigate(href, opts = {}) {
3921
+ ensureSameOrigin(href, "navigate");
3904
3922
  const customEvent = new CustomEvent("phx:exec");
3905
3923
  liveSocket.historyRedirect(
3906
3924
  customEvent,
@@ -3911,6 +3929,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
3911
3929
  );
3912
3930
  },
3913
3931
  patch(href, opts = {}) {
3932
+ ensureSameOrigin(href, "patch");
3914
3933
  const customEvent = new CustomEvent("phx:exec");
3915
3934
  liveSocket.pushHistoryPatch(
3916
3935
  customEvent,
@@ -4449,6 +4468,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
4449
4468
  if (container) {
4450
4469
  const [tag, attrs] = container;
4451
4470
  this.el = dom_default.replaceRootContainer(this.el, tag, attrs);
4471
+ dom_default.putPrivate(this.el, "view", this);
4452
4472
  }
4453
4473
  this.childJoins = 0;
4454
4474
  this.joinPending = true;
@@ -4531,6 +4551,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
4531
4551
  }
4532
4552
  attachTrueDocEl() {
4533
4553
  this.el = dom_default.byId(this.id);
4554
+ dom_default.putPrivate(this.el, "view", this);
4534
4555
  this.el.setAttribute(PHX_ROOT_ID, this.root.id);
4535
4556
  }
4536
4557
  // this is invoked for dead and live views, so we must filter by
@@ -4714,6 +4735,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
4714
4735
  rootEl.setAttribute(PHX_SESSION, this.getSession());
4715
4736
  rootEl.setAttribute(PHX_STATIC, this.getStatic());
4716
4737
  rootEl.setAttribute(PHX_PARENT_ID, this.parent ? this.parent.id : null);
4738
+ dom_default.putPrivate(rootEl, "view", this);
4717
4739
  const formsToRecover = (
4718
4740
  // we go over all forms in the new DOM; because this is only the HTML for the current
4719
4741
  // view, we can be sure that all forms are owned by this view:
@@ -5992,7 +6014,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
5992
6014
  }
5993
6015
  // public
5994
6016
  version() {
5995
- return "1.1.30";
6017
+ return "1.1.32";
5996
6018
  }
5997
6019
  isProfileEnabled() {
5998
6020
  return this.sessionStorage.getItem(PHX_LV_PROFILE) === "true";
@@ -6272,11 +6294,12 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
6272
6294
  `[${this.binding("remove")}]`
6273
6295
  ).filter((el) => !dom_default.isChildOfAny(el, stickies));
6274
6296
  const newMainEl = dom_default.cloneNode(this.outgoingMainEl, "");
6275
- this.main.showLoader(this.loaderTimeout);
6276
- this.main.destroy();
6297
+ const oldMainView = this.main;
6298
+ oldMainView.showLoader(this.loaderTimeout);
6299
+ oldMainView.destroy();
6277
6300
  this.main = this.newRootView(newMainEl, flash, liveReferer);
6278
6301
  this.main.setRedirect(href);
6279
- this.transitionRemoves(removeEls);
6302
+ this.transitionRemoves(removeEls, oldMainView);
6280
6303
  this.main.join((joinCount, onDone) => {
6281
6304
  if (joinCount === 1 && this.commitPendingLink(linkRef)) {
6282
6305
  this.requestDOMUpdate(() => {
@@ -6290,7 +6313,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
6290
6313
  }
6291
6314
  });
6292
6315
  }
6293
- transitionRemoves(elements, callback) {
6316
+ transitionRemoves(elements, view, callback) {
6294
6317
  const removeAttr = this.binding("remove");
6295
6318
  const silenceEvents = (e) => {
6296
6319
  e.preventDefault();
@@ -6300,7 +6323,8 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
6300
6323
  for (const event of this.boundEventNames) {
6301
6324
  el.addEventListener(event, silenceEvents, true);
6302
6325
  }
6303
- this.execJS(el, el.getAttribute(removeAttr), "remove");
6326
+ const e = new CustomEvent("phx:exec", { detail: { sourceElement: el } });
6327
+ js_default.exec(e, "remove", el.getAttribute(removeAttr), view, el);
6304
6328
  });
6305
6329
  this.requestDOMUpdate(() => {
6306
6330
  elements.forEach((el) => {
@@ -6323,7 +6347,7 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
6323
6347
  let view;
6324
6348
  const viewEl = dom_default.closestViewEl(childEl);
6325
6349
  if (viewEl) {
6326
- view = this.getViewByEl(viewEl);
6350
+ view = dom_default.private(viewEl, "view");
6327
6351
  } else {
6328
6352
  if (!childEl.isConnected) {
6329
6353
  return null;