phoenix_live_view 0.19.0 → 0.19.2

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.
@@ -69,10 +69,13 @@ let DOM = {
69
69
  return !e.defaultPrevented && !this.wantsNewTab(e)
70
70
  },
71
71
 
72
- isNewPageHref(href, currentLocation){
72
+ isNewPageClick(e, currentLocation){
73
+ let href = e.target instanceof HTMLAnchorElement ? e.target.getAttribute("href") : null
74
+ let url
75
+
76
+ if(e.defaultPrevented || href === null || this.wantsNewTab(e)){ return false }
73
77
  if(href.startsWith("mailto:") || href.startsWith("tel:")){ return false }
74
78
 
75
- let url
76
79
  try {
77
80
  url = new URL(href)
78
81
  } catch(e) {
@@ -89,7 +92,7 @@ let DOM = {
89
92
  return url.hash === "" && !url.href.endsWith("#")
90
93
  }
91
94
  }
92
- return true
95
+ return url.protocol.startsWith("http")
93
96
  },
94
97
 
95
98
  markPhxChildDestroyed(el){
@@ -143,11 +143,18 @@ export default class DOMPatch {
143
143
  parent.insertBefore(child, sibling)
144
144
  }
145
145
  let children = limit !== null && Array.from(parent.children)
146
+ let childrenToRemove = []
146
147
  if(limit && limit < 0 && children.length > limit * -1){
147
- children.slice(0, children.length + limit).forEach(child => this.removeStreamChildElement(child))
148
+ childrenToRemove = children.slice(0, children.length + limit)
148
149
  } else if(limit && limit >= 0 && children.length > limit){
149
- children.slice(limit).forEach(child => this.removeStreamChildElement(child))
150
+ childrenToRemove = children.slice(limit)
150
151
  }
152
+ childrenToRemove.forEach(removeChild => {
153
+ // do not remove child as part of limit if we are re-adding it
154
+ if(!this.streamInserts[removeChild.id]){
155
+ this.removeStreamChildElement(removeChild)
156
+ }
157
+ })
151
158
  },
152
159
  onBeforeNodeAdded: (el) => {
153
160
  DOM.maybeAddPrivateHooks(el, phxViewportTop, phxViewportBottom)
@@ -167,7 +174,7 @@ export default class DOMPatch {
167
174
  externalFormTriggered = el
168
175
  }
169
176
 
170
- if(el.getAttribute && el.getAttribute("name")){
177
+ if(el.getAttribute && el.getAttribute("name") && DOM.isFormInput(el)){
171
178
  trackedInputs.push(el)
172
179
  }
173
180
  // nested view handling
@@ -196,6 +203,7 @@ export default class DOMPatch {
196
203
  this.maybeReOrderStream(el)
197
204
  },
198
205
  onBeforeElUpdated: (fromEl, toEl) => {
206
+ DOM.maybeAddPrivateHooks(toEl, phxViewportTop, phxViewportBottom)
199
207
  DOM.cleanChildNodes(toEl, phxUpdate)
200
208
  if(this.skipCIDSibling(toEl)){ return false }
201
209
  if(DOM.isPhxSticky(fromEl)){ return false }
@@ -243,10 +251,9 @@ export default class DOMPatch {
243
251
  appendPrependUpdates.push(new DOMPostMorphRestorer(fromEl, toEl, toEl.getAttribute(phxUpdate)))
244
252
  }
245
253
 
246
- DOM.maybeAddPrivateHooks(toEl, phxViewportTop, phxViewportBottom)
247
254
  DOM.syncAttrsToProps(toEl)
248
255
  DOM.applyStickyOperations(toEl)
249
- if(toEl.getAttribute("name")){
256
+ if(toEl.getAttribute("name") && DOM.isFormInput(toEl)){
250
257
  trackedInputs.push(toEl)
251
258
  }
252
259
  this.trackBefore("updated", fromEl, toEl)
@@ -638,13 +638,12 @@ export default class LiveSocket {
638
638
  }
639
639
  let phxEvent = target && target.getAttribute(click)
640
640
  if(!phxEvent){
641
- let href = e.target instanceof HTMLAnchorElement ? e.target.getAttribute("href") : null
642
- if(!capture && href !== null && !DOM.wantsNewTab(e) && DOM.isNewPageHref(href, window.location)){
643
- this.unload()
644
- }
641
+ if(!capture && DOM.isNewPageClick(e, window.location)){ this.unload() }
645
642
  return
646
643
  }
644
+
647
645
  if(target.getAttribute("href") === "#"){ e.preventDefault() }
646
+
648
647
  // noop if we are in the middle of awaiting an ack for this el already
649
648
  if(target.hasAttribute(PHX_REF)){ return }
650
649
 
@@ -849,7 +849,7 @@ export default class View {
849
849
  let name = el.attributes[i].name
850
850
  if(name.startsWith(prefix)){ meta[name.replace(prefix, "")] = el.getAttribute(name) }
851
851
  }
852
- if(el.value !== undefined){
852
+ if(el.value !== undefined && !(el instanceof HTMLFormElement)){
853
853
  if(!meta){ meta = {} }
854
854
  meta.value = el.value
855
855
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phoenix_live_view",
3
- "version": "0.19.0",
3
+ "version": "0.19.2",
4
4
  "description": "The Phoenix LiveView JavaScript client.",
5
5
  "license": "MIT",
6
6
  "repository": {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phoenix_live_view",
3
- "version": "0.19.0",
3
+ "version": "0.19.2",
4
4
  "description": "The Phoenix LiveView JavaScript client.",
5
5
  "license": "MIT",
6
6
  "module": "./priv/static/phoenix_live_view.esm.js",
@@ -318,17 +318,21 @@ var DOM = {
318
318
  isUnloadableFormSubmit(e) {
319
319
  return !e.defaultPrevented && !this.wantsNewTab(e);
320
320
  },
321
- isNewPageHref(href, currentLocation) {
321
+ isNewPageClick(e, currentLocation) {
322
+ let href = e.target instanceof HTMLAnchorElement ? e.target.getAttribute("href") : null;
323
+ let url;
324
+ if (e.defaultPrevented || href === null || this.wantsNewTab(e)) {
325
+ return false;
326
+ }
322
327
  if (href.startsWith("mailto:") || href.startsWith("tel:")) {
323
328
  return false;
324
329
  }
325
- let url;
326
330
  try {
327
331
  url = new URL(href);
328
- } catch (e) {
332
+ } catch (e2) {
329
333
  try {
330
334
  url = new URL(href, currentLocation);
331
- } catch (e2) {
335
+ } catch (e3) {
332
336
  return true;
333
337
  }
334
338
  }
@@ -337,7 +341,7 @@ var DOM = {
337
341
  return url.hash === "" && !url.href.endsWith("#");
338
342
  }
339
343
  }
340
- return true;
344
+ return url.protocol.startsWith("http");
341
345
  },
342
346
  markPhxChildDestroyed(el) {
343
347
  if (this.isPhxChild(el)) {
@@ -1792,11 +1796,17 @@ var DOMPatch = class {
1792
1796
  parent.insertBefore(child, sibling);
1793
1797
  }
1794
1798
  let children = limit !== null && Array.from(parent.children);
1799
+ let childrenToRemove = [];
1795
1800
  if (limit && limit < 0 && children.length > limit * -1) {
1796
- children.slice(0, children.length + limit).forEach((child2) => this.removeStreamChildElement(child2));
1801
+ childrenToRemove = children.slice(0, children.length + limit);
1797
1802
  } else if (limit && limit >= 0 && children.length > limit) {
1798
- children.slice(limit).forEach((child2) => this.removeStreamChildElement(child2));
1803
+ childrenToRemove = children.slice(limit);
1799
1804
  }
1805
+ childrenToRemove.forEach((removeChild) => {
1806
+ if (!this.streamInserts[removeChild.id]) {
1807
+ this.removeStreamChildElement(removeChild);
1808
+ }
1809
+ });
1800
1810
  },
1801
1811
  onBeforeNodeAdded: (el) => {
1802
1812
  dom_default.maybeAddPrivateHooks(el, phxViewportTop, phxViewportBottom);
@@ -1815,7 +1825,7 @@ var DOMPatch = class {
1815
1825
  if (dom_default.isNowTriggerFormExternal(el, phxTriggerExternal)) {
1816
1826
  externalFormTriggered = el;
1817
1827
  }
1818
- if (el.getAttribute && el.getAttribute("name")) {
1828
+ if (el.getAttribute && el.getAttribute("name") && dom_default.isFormInput(el)) {
1819
1829
  trackedInputs.push(el);
1820
1830
  }
1821
1831
  if (dom_default.isPhxChild(el) && view.ownsElement(el) || dom_default.isPhxSticky(el) && view.ownsElement(el.parentNode)) {
@@ -1847,6 +1857,7 @@ var DOMPatch = class {
1847
1857
  this.maybeReOrderStream(el);
1848
1858
  },
1849
1859
  onBeforeElUpdated: (fromEl, toEl) => {
1860
+ dom_default.maybeAddPrivateHooks(toEl, phxViewportTop, phxViewportBottom);
1850
1861
  dom_default.cleanChildNodes(toEl, phxUpdate);
1851
1862
  if (this.skipCIDSibling(toEl)) {
1852
1863
  return false;
@@ -1896,10 +1907,9 @@ var DOMPatch = class {
1896
1907
  if (dom_default.isPhxUpdate(toEl, phxUpdate, ["append", "prepend"])) {
1897
1908
  appendPrependUpdates.push(new DOMPostMorphRestorer(fromEl, toEl, toEl.getAttribute(phxUpdate)));
1898
1909
  }
1899
- dom_default.maybeAddPrivateHooks(toEl, phxViewportTop, phxViewportBottom);
1900
1910
  dom_default.syncAttrsToProps(toEl);
1901
1911
  dom_default.applyStickyOperations(toEl);
1902
- if (toEl.getAttribute("name")) {
1912
+ if (toEl.getAttribute("name") && dom_default.isFormInput(toEl)) {
1903
1913
  trackedInputs.push(toEl);
1904
1914
  }
1905
1915
  this.trackBefore("updated", fromEl, toEl);
@@ -3325,7 +3335,7 @@ var View = class {
3325
3335
  meta[name.replace(prefix, "")] = el.getAttribute(name);
3326
3336
  }
3327
3337
  }
3328
- if (el.value !== void 0) {
3338
+ if (el.value !== void 0 && !(el instanceof HTMLFormElement)) {
3329
3339
  if (!meta) {
3330
3340
  meta = {};
3331
3341
  }
@@ -4153,8 +4163,7 @@ var LiveSocket = class {
4153
4163
  }
4154
4164
  let phxEvent = target && target.getAttribute(click);
4155
4165
  if (!phxEvent) {
4156
- let href = e.target instanceof HTMLAnchorElement ? e.target.getAttribute("href") : null;
4157
- if (!capture && href !== null && !dom_default.wantsNewTab(e) && dom_default.isNewPageHref(href, window.location)) {
4166
+ if (!capture && dom_default.isNewPageClick(e, window.location)) {
4158
4167
  this.unload();
4159
4168
  }
4160
4169
  return;