phoenix_live_view 0.14.8 → 0.15.0

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 CHANGED
@@ -1,11 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.15.0 (2020-11-20)
4
+
5
+ ### Enhancements
6
+ - Add live uploads support for file progress, interactive file selection, and direct to cloud support
7
+ - Implement `Phoenix.LiveViewTest.open_browser/2` that opens up a browser with the LiveView page
8
+
9
+ ### Backwards incompatible changes
10
+ - Remove `@inner_content` in components and introduce `render_block` for rendering component `@inner_block`
11
+ - Remove `@live_module` in socket templates in favor of `@socket.view`
12
+
13
+ ### Bug fixes
14
+ - Make sure URLs are decoded after they are split
15
+ - Do not recover forms without inputs
16
+ - Fix race condition when components are removed and then immediately re-added before the client can notify their CIDs have been destroyed
17
+ - Do not render LiveView if only events/replies have been added to the socket
18
+ - Properly merge different components when sharing component subtrees on initial render
19
+ - Allow variables inside do-blocks to be tainted
20
+ - Fix `push_redirect` from mount hanging on the client and causing a fallback to full page reload when following a clicked `live_redirect` on the client
21
+
3
22
  ## 0.14.8 (2020-10-30)
4
23
 
5
24
  ### Bug fixes
6
25
  - Fix compatiblity with latest Plug
7
26
 
8
- ## 0.14.7
27
+ ## 0.14.7 (2020-09-25)
9
28
 
10
29
  ### Bug fixes
11
30
  - Fix `redirect(socket, external: ...)` when returned from an event
@@ -23,6 +23,11 @@ const PHX_LIVE_LINK = "data-phx-link"
23
23
  const PHX_TRACK_STATIC = "track-static"
24
24
  const PHX_LINK_STATE = "data-phx-link-state"
25
25
  const PHX_REF = "data-phx-ref"
26
+ const PHX_UPLOAD_REF = "data-phx-upload-ref"
27
+ const PHX_PREFLIGHTED_REFS = "data-phx-preflighted-refs"
28
+ const PHX_DONE_REFS = "data-phx-done-refs"
29
+ const PHX_DROP_TARGET = "drop-target"
30
+ const PHX_ACTIVE_ENTRY_REFS = "data-phx-active-refs"
26
31
  const PHX_SKIP = "data-phx-skip"
27
32
  const PHX_REMOVE = "data-phx-remove"
28
33
  const PHX_PAGE_LOADING = "page-loading"
@@ -56,6 +61,7 @@ const PHX_AUTO_RECOVER = "auto-recover"
56
61
  const PHX_LV_DEBUG = "phx:live-socket:debug"
57
62
  const PHX_LV_PROFILE = "phx:live-socket:profiling"
58
63
  const PHX_LV_LATENCY_SIM = "phx:live-socket:latency-sim"
64
+ const PHX_PROGRESS = "progress"
59
65
  const LOADER_TIMEOUT = 1
60
66
  const BEFORE_UNLOAD_LOADER_TIMEOUT = 200
61
67
  const BINDING_PREFIX = "phx-"
@@ -125,8 +131,297 @@ let isEmpty = (obj) => {
125
131
 
126
132
  let maybe = (el, callback) => el && callback(el)
127
133
 
134
+ class UploadEntry {
135
+ static isActive(fileEl, file){
136
+ let isNew = file._phxRef === undefined
137
+ let activeRefs = fileEl.getAttribute(PHX_ACTIVE_ENTRY_REFS).split(",")
138
+ let isActive = activeRefs.indexOf(LiveUploader.genFileRef(file)) >= 0
139
+ return file.size > 0 && (isNew || isActive)
140
+ }
141
+
142
+ static isPreflighted(fileEl, file){
143
+ let preflightedRefs = fileEl.getAttribute(PHX_PREFLIGHTED_REFS).split(",")
144
+ let isPreflighted = preflightedRefs.indexOf(LiveUploader.genFileRef(file)) >= 0
145
+ return isPreflighted && this.isActive(fileEl, file)
146
+ }
147
+
148
+ constructor(fileEl, file, view){
149
+ this.ref = LiveUploader.genFileRef(file)
150
+ this.fileEl = fileEl
151
+ this.file = file
152
+ this.view = view
153
+ this.meta = null
154
+ this._isCancelled = false
155
+ this._isDone = false
156
+ this._progress = 0
157
+ this._onDone = function(){}
158
+ }
159
+
160
+ metadata(){ return this.meta }
161
+
162
+ progress(progress){
163
+ this._progress = Math.floor(progress)
164
+ if(this._progress >= 100){
165
+ this._progress = 100
166
+ this._isDone = true
167
+ this.view.pushFileProgress(this.fileEl, this.ref, 100, () => {
168
+ LiveUploader.untrackFile(this.fileEl, this.file)
169
+ this._onDone()
170
+ })
171
+ } else {
172
+ this.view.pushFileProgress(this.fileEl, this.ref, this._progress)
173
+ }
174
+ }
175
+
176
+ cancel(){
177
+ this._isCancelled = true
178
+ this._isDone = true
179
+ this._onDone()
180
+ }
181
+
182
+ isDone(){ return this._isDone }
183
+
184
+ error(reason = "failed"){
185
+ this.view.pushFileProgress(this.fileEl, this.ref, {error: reason})
186
+ }
187
+
188
+ //private
189
+
190
+ onDone(callback){ this._onDone = callback }
191
+
192
+ toPreflightPayload(){
193
+ return {
194
+ last_modified: this.file.lastModified,
195
+ name: this.file.name,
196
+ size: this.file.size,
197
+ type: this.file.type,
198
+ ref: this.ref
199
+ }
200
+ }
201
+
202
+ uploader(uploaders){
203
+ if(this.meta.uploader){
204
+ let callback = uploaders[this.meta.uploader] || logError(`no uploader configured for ${this.meta.uploader}`)
205
+ return {name: this.meta.uploader, callback: callback}
206
+ } else {
207
+ return {name: "channel", callback: channelUploader}
208
+ }
209
+ }
210
+
211
+ zipPostFlight(resp){
212
+ this.meta = resp.entries[this.ref]
213
+ if(!this.meta){ logError(`no preflight upload response returned with ref ${this.ref}`, {input: this.fileEl, response: resp})}
214
+ }
215
+ }
216
+
217
+ let Hooks = {}
218
+ Hooks.LiveFileUpload = {
219
+ preflightedRefs(){ return this.el.getAttribute(PHX_PREFLIGHTED_REFS) },
220
+
221
+ mounted(){ this.preflightedWas = this.preflightedRefs() },
222
+
223
+ updated() {
224
+ let newPreflights = this.preflightedRefs()
225
+ if(this.preflightedWas !== newPreflights){
226
+ this.preflightedWas = newPreflights
227
+ if(newPreflights === ""){
228
+ this.__view.cancelSubmit(this.el.form)
229
+ }
230
+ }
231
+ }
232
+ }
233
+
234
+ Hooks.LiveImgPreview = {
235
+ mounted() {
236
+ this.ref = this.el.getAttribute("data-phx-entry-ref")
237
+ this.inputEl = document.getElementById(this.el.getAttribute(PHX_UPLOAD_REF))
238
+ LiveUploader.getEntryDataURL(this.inputEl, this.ref, url => this.el.src = url)
239
+ }
240
+ }
241
+
242
+ let liveUploaderFileRef = 0
243
+ class LiveUploader {
244
+ static genFileRef(file){
245
+ let ref = file._phxRef
246
+ if(ref !== undefined){
247
+ return ref
248
+ } else {
249
+ file._phxRef = (liveUploaderFileRef++).toString()
250
+ return file._phxRef
251
+ }
252
+ }
253
+
254
+ static getEntryDataURL(inputEl, ref, callback){
255
+ let file = this.activeFiles(inputEl).find(file => this.genFileRef(file) === ref)
256
+ let reader = new FileReader()
257
+ reader.onload = (e) => callback(e.target.result)
258
+ reader.readAsDataURL(file)
259
+ }
260
+
261
+ static hasUploadsInProgress(formEl){
262
+ let active = 0
263
+ DOM.all(formEl, `input[type="file"]`, input => {
264
+ if(input.getAttribute(PHX_PREFLIGHTED_REFS) !== input.getAttribute(PHX_DONE_REFS)){
265
+ active++
266
+ }
267
+ })
268
+ return active > 0
269
+ }
270
+
271
+ static serializeUploads(inputEl){
272
+ let files = this.activeFiles(inputEl, "serialize")
273
+ let fileData = {}
274
+ files.forEach(file => {
275
+ let entry = {path: inputEl.name}
276
+ let uploadRef = inputEl.getAttribute(PHX_UPLOAD_REF)
277
+ fileData[uploadRef] = fileData[uploadRef] || []
278
+ entry.ref = this.genFileRef(file)
279
+ entry.name = file.name
280
+ entry.type = file.type
281
+ entry.size = file.size
282
+ fileData[uploadRef].push(entry)
283
+ })
284
+ return fileData
285
+ }
286
+
287
+ static clearFiles(inputEl){
288
+ inputEl.value = null
289
+ DOM.putPrivate(inputEl, "files", [])
290
+ }
291
+
292
+ static untrackFile(inputEl, file){
293
+ DOM.putPrivate(inputEl, "files", DOM.private(inputEl, "files").filter(f => !Object.is(f, file)))
294
+ }
295
+
296
+ static trackFiles(inputEl, files){
297
+ if(inputEl.getAttribute("multiple") !== null){
298
+ let newFiles = files.filter(file => !this.activeFiles(inputEl).find(f => Object.is(f, file)))
299
+ DOM.putPrivate(inputEl, "files", this.activeFiles(inputEl).concat(newFiles))
300
+ inputEl.value = null
301
+ } else {
302
+ DOM.putPrivate(inputEl, "files", files)
303
+ }
304
+ }
305
+
306
+ static activeFileInputs(formEl){
307
+ let fileInputs = formEl.querySelectorAll(`input[type="file"]`)
308
+ return Array.from(fileInputs).filter(el => el.files && this.activeFiles(el).length > 0)
309
+ }
310
+
311
+ static activeFiles(input){
312
+ return (DOM.private(input, "files") || []).filter(f => UploadEntry.isActive(input, f))
313
+ }
314
+
315
+ static inputsAwaitingPreflight(formEl){
316
+ let fileInputs = formEl.querySelectorAll(`input[type="file"]`)
317
+ return Array.from(fileInputs).filter(input => this.filesAwaitingPreflight(input).length > 0)
318
+ }
319
+
320
+ static filesAwaitingPreflight(input){
321
+ return this.activeFiles(input).filter(f => !UploadEntry.isPreflighted(input, f))
322
+ }
323
+
324
+ constructor(inputEl, view, onComplete){
325
+ this.view = view
326
+ this.onComplete = onComplete
327
+ this._entries =
328
+ Array.from(LiveUploader.filesAwaitingPreflight(inputEl) || [])
329
+ .map(file => new UploadEntry(inputEl, file, view))
330
+
331
+ this.numEntriesInProgress = this._entries.length
332
+ }
333
+
334
+ entries(){ return this._entries }
335
+
336
+ initAdapterUpload(resp, onError, liveSocket){
337
+ this._entries =
338
+ this._entries.map(entry => {
339
+ entry.zipPostFlight(resp)
340
+ entry.onDone(() => {
341
+ this.numEntriesInProgress--
342
+ if(this.numEntriesInProgress === 0){ this.onComplete() }
343
+ })
344
+ return entry
345
+ })
346
+
347
+ let groupedEntries = this._entries.reduce((acc, entry) => {
348
+ let {name, callback} = entry.uploader(liveSocket.uploaders)
349
+ acc[name] = acc[name] || {callback: callback, entries: []}
350
+ acc[name].entries.push(entry)
351
+ return acc
352
+ }, {})
353
+
354
+ for(let name in groupedEntries){
355
+ let {callback, entries} = groupedEntries[name]
356
+ callback(entries, onError, resp, liveSocket)
357
+ }
358
+ }
359
+ }
360
+
361
+ let channelUploader = function(entries, onError, resp, liveSocket){
362
+ entries.forEach(entry => {
363
+ let entryUploader = new EntryUploader(entry, resp.config.chunk_size, liveSocket)
364
+ entryUploader.upload()
365
+ })
366
+ }
367
+
368
+ class EntryUploader {
369
+ constructor(entry, chunkSize, liveSocket){
370
+ this.liveSocket = liveSocket
371
+ this.entry = entry
372
+ this.offset = 0
373
+ this.chunkSize = chunkSize
374
+ this.uploadChannel = liveSocket.channel(`lvu:${entry.ref}`, {token: entry.metadata()})
375
+ }
376
+
377
+ upload(){
378
+ this.uploadChannel.join()
379
+ .receive("ok", data => this.readNextChunk())
380
+ .receive("error", reason => {
381
+ this.uploadChannel.leave()
382
+ this.entry.error()
383
+ })
384
+ }
385
+
386
+ isDone(){ return this.offset >= this.entry.file.size }
387
+
388
+ readNextChunk(){
389
+ let reader = new window.FileReader()
390
+ let blob = this.entry.file.slice(this.offset, this.chunkSize + this.offset)
391
+ reader.onload = (e) => {
392
+ if(e.target.error === null){
393
+ this.offset += e.target.result.byteLength
394
+ this.pushChunk(e.target.result)
395
+ } else {
396
+ return logError("Read error: " + e.target.error)
397
+ }
398
+ }
399
+ reader.readAsArrayBuffer(blob)
400
+ }
401
+
402
+ pushChunk(chunk){
403
+ if(!this.uploadChannel.isJoined()){ return }
404
+ this.uploadChannel.push("chunk", chunk)
405
+ .receive("ok", () => {
406
+ this.entry.progress((this.offset / this.entry.file.size) * 100)
407
+ if(!this.isDone()){
408
+ setTimeout(() => this.readNextChunk(), this.liveSocket.getLatencySim() || 0)
409
+ }
410
+ })
411
+ }
412
+ }
413
+
128
414
  let serializeForm = (form, meta = {}) => {
129
415
  let formData = new FormData(form)
416
+ let toRemove = []
417
+
418
+ formData.forEach((val, key, index) => {
419
+ if(val instanceof File){ toRemove.push(key) }
420
+ })
421
+
422
+ // Cleanup after building fileData
423
+ toRemove.forEach(key => formData.delete(key))
424
+
130
425
  let params = new URLSearchParams()
131
426
  for(let [key, val] of formData.entries()){ params.append(key, val) }
132
427
  for(let metaKey in meta){ params.append(metaKey, meta[metaKey]) }
@@ -418,9 +713,10 @@ export class LiveSocket {
418
713
  this.pendingLink = null
419
714
  this.currentLocation = clone(window.location)
420
715
  this.hooks = opts.hooks || {}
716
+ this.uploaders = opts.uploaders || {}
421
717
  this.loaderTimeout = opts.loaderTimeout || LOADER_TIMEOUT
422
718
  this.boundTopLevelEvents = false
423
- this.domCallbacks = opts.dom || {onBeforeElUpdated: closure()}
719
+ this.domCallbacks = Object.assign({onNodeAdded: closure(), onBeforeElUpdated: closure()}, opts.dom || {})
424
720
  window.addEventListener("unload", e => {
425
721
  this.unloaded = true
426
722
  })
@@ -511,9 +807,21 @@ export class LiveSocket {
511
807
  })
512
808
  }
513
809
 
514
- wrapPush(push){
810
+ wrapPush(view, opts, push){
515
811
  let latency = this.getLatencySim()
516
- if(!latency){ return push() }
812
+ if(!latency){
813
+ if(opts.timeout){
814
+ return push().receive("timeout", () => {
815
+ if(!view.isDestroyed()){
816
+ this.reloadWithJitter(view, () => {
817
+ this.log(view, "timeout", () => [`received timeout while communicating with server. Falling back to hard refresh for recovery`])
818
+ })
819
+ }
820
+ })
821
+ } else {
822
+ return push()
823
+ }
824
+ }
517
825
 
518
826
  console.log(`simulating ${latency}ms of latency from client to server`)
519
827
  let fakePush = {
@@ -526,13 +834,13 @@ export class LiveSocket {
526
834
  return fakePush
527
835
  }
528
836
 
529
- reloadWithJitter(view){
837
+ reloadWithJitter(view, log){
530
838
  view.destroy()
531
839
  this.disconnect()
532
840
  let [minMs, maxMs] = RELOAD_JITTER
533
841
  let afterMs = Math.floor(Math.random() * (maxMs - minMs + 1)) + minMs
534
842
  let tries = Browser.updateLocal(view.name(), CONSECUTIVE_RELOADS, 0, count => count + 1)
535
- this.log(view, "join", () => [`encountered ${tries} consecutive reloads`])
843
+ log ? log() : this.log(view, "join", () => [`encountered ${tries} consecutive reloads`])
536
844
  if(tries > MAX_RELOADS){
537
845
  this.log(view, "join", () => [`exceeded ${MAX_RELOADS} consecutive reloads. Entering failsafe mode`])
538
846
  afterMs = FAILSAFE_JITTER
@@ -546,7 +854,9 @@ export class LiveSocket {
546
854
  }, afterMs)
547
855
  }
548
856
 
549
- getHookCallbacks(hookName){ return this.hooks[hookName] }
857
+ getHookCallbacks(name){
858
+ return name && name.startsWith("Phoenix.") ? Hooks[name.split(".")[1]] : this.hooks[name]
859
+ }
550
860
 
551
861
  isUnloaded(){ return this.unloaded }
552
862
 
@@ -715,6 +1025,19 @@ export class LiveSocket {
715
1025
  view.pushEvent(type, targetEl, targetCtx, phxEvent, this.eventMeta(type, e, targetEl))
716
1026
  }
717
1027
  })
1028
+ window.addEventListener("dragover", e => e.preventDefault())
1029
+ window.addEventListener("drop", e => {
1030
+ e.preventDefault()
1031
+ let dropTargetId = maybe(closestPhxBinding(e.target, this.binding(PHX_DROP_TARGET)), trueTarget => {
1032
+ return trueTarget.getAttribute(this.binding(PHX_DROP_TARGET))
1033
+ })
1034
+ let dropTarget = dropTargetId && document.getElementById(dropTargetId)
1035
+ let files = Array.from(e.dataTransfer.files || [])
1036
+ if(!dropTarget || dropTarget.disabled || files.length === 0 || !(dropTarget.files instanceof FileList)){ return }
1037
+
1038
+ LiveUploader.trackFiles(dropTarget, files)
1039
+ dropTarget.dispatchEvent(new Event("input", {bubbles: true}))
1040
+ })
718
1041
  }
719
1042
 
720
1043
  eventMeta(eventName, e, targetEl){
@@ -1056,14 +1379,7 @@ export let DOM = {
1056
1379
  },
1057
1380
 
1058
1381
  findComponentNodeList(node, cid){
1059
- let phxChildren = this.all(node, PHX_VIEW_SELECTOR)
1060
- let result = this.all(node, `[${PHX_COMPONENT}="${cid}"]`)
1061
-
1062
- if(phxChildren.length === 0){
1063
- return result
1064
- } else {
1065
- return result.filter(element => !phxChildren.some(node => node.contains(element)))
1066
- }
1382
+ return this.filterWithinSameLiveView(this.all(node, `[${PHX_COMPONENT}="${cid}"]`), node)
1067
1383
  },
1068
1384
 
1069
1385
  findPhxChildrenInFragment(html, parentId){
@@ -1072,6 +1388,10 @@ export let DOM = {
1072
1388
  return this.findPhxChildren(template.content, parentId)
1073
1389
  },
1074
1390
 
1391
+ isIgnored(el, phxUpdate){
1392
+ return (el.getAttribute(phxUpdate) || el.getAttribute("data-phx-update")) === "ignore"
1393
+ },
1394
+
1075
1395
  isPhxUpdate(el, phxUpdate, updateTypes){
1076
1396
  return el.getAttribute && updateTypes.indexOf(el.getAttribute(phxUpdate)) >= 0
1077
1397
  },
@@ -1084,7 +1404,8 @@ export let DOM = {
1084
1404
  let initial = new Set(cids)
1085
1405
  return cids.reduce((acc, cid) => {
1086
1406
  let selector = `[${PHX_COMPONENT}="${cid}"] [${PHX_COMPONENT}]`
1087
- this.all(node, selector)
1407
+
1408
+ this.filterWithinSameLiveView(this.all(node, selector), node)
1088
1409
  .map(el => parseInt(el.getAttribute(PHX_COMPONENT)))
1089
1410
  .forEach(childCID => acc.delete(childCID))
1090
1411
 
@@ -1092,6 +1413,21 @@ export let DOM = {
1092
1413
  }, initial)
1093
1414
  },
1094
1415
 
1416
+ filterWithinSameLiveView(nodes, parent) {
1417
+ if(parent.querySelector(PHX_VIEW_SELECTOR)) {
1418
+ return nodes.filter(el => this.withinSameLiveView(el, parent))
1419
+ } else {
1420
+ return nodes
1421
+ }
1422
+ },
1423
+
1424
+ withinSameLiveView(node, parent){
1425
+ while(node = node.parentNode){
1426
+ if(node.isSameNode(parent)){ return true }
1427
+ if(node.getAttribute(PHX_VIEW)){ return false }
1428
+ }
1429
+ },
1430
+
1095
1431
  private(el, key){ return el[PHX_PRIVATE] && el[PHX_PRIVATE][key] },
1096
1432
 
1097
1433
  deletePrivate(el, key){ el[PHX_PRIVATE] && delete(el[PHX_PRIVATE][key]) },
@@ -1218,7 +1554,9 @@ export let DOM = {
1218
1554
  }
1219
1555
  },
1220
1556
 
1221
- mergeAttrs(target, source, exclude = []){
1557
+ mergeAttrs(target, source, opts = {}){
1558
+ let exclude = opts.exclude || []
1559
+ let isIgnored = opts.isIgnored
1222
1560
  let sourceAttrs = source.attributes
1223
1561
  for (let i = sourceAttrs.length - 1; i >= 0; i--){
1224
1562
  let name = sourceAttrs[i].name
@@ -1228,13 +1566,17 @@ export let DOM = {
1228
1566
  let targetAttrs = target.attributes
1229
1567
  for (let i = targetAttrs.length - 1; i >= 0; i--){
1230
1568
  let name = targetAttrs[i].name
1231
- if(!source.hasAttribute(name)){ target.removeAttribute(name) }
1569
+ if(isIgnored){
1570
+ if(name.startsWith("data-") && !source.hasAttribute(name)){ target.removeAttribute(name) }
1571
+ } else {
1572
+ if(!source.hasAttribute(name)){ target.removeAttribute(name) }
1573
+ }
1232
1574
  }
1233
1575
  },
1234
1576
 
1235
1577
  mergeFocusedInput(target, source){
1236
1578
  // skip selects because FF will reset highlighted index for any setAttribute
1237
- if(!(target instanceof HTMLSelectElement)){ DOM.mergeAttrs(target, source, ["value"]) }
1579
+ if(!(target instanceof HTMLSelectElement)){ DOM.mergeAttrs(target, source, {except: ["value"]}) }
1238
1580
  if(source.readOnly){
1239
1581
  target.setAttribute("readonly", true)
1240
1582
  } else {
@@ -1275,6 +1617,7 @@ export let DOM = {
1275
1617
  if(ref === null){ return true }
1276
1618
 
1277
1619
  if(DOM.isFormInput(fromEl) || fromEl.getAttribute(disableWith) !== null){
1620
+ if(fromEl.type === "file"){ DOM.mergeAttrs(fromEl, toEl, {isIgnored: true}) }
1278
1621
  DOM.putPrivate(fromEl, PHX_REF, toEl)
1279
1622
  return false
1280
1623
  } else {
@@ -1473,14 +1816,20 @@ class DOMPatch {
1473
1816
  onBeforeElUpdated: (fromEl, toEl) => {
1474
1817
  DOM.cleanChildNodes(toEl, phxUpdate)
1475
1818
  if(this.skipCIDSibling(toEl)){ return false }
1476
- if(fromEl.getAttribute(phxUpdate) === "ignore"){
1819
+ if(DOM.isIgnored(fromEl, phxUpdate)){
1477
1820
  this.trackBefore("updated", fromEl, toEl)
1478
- DOM.mergeAttrs(fromEl, toEl)
1821
+ DOM.mergeAttrs(fromEl, toEl, {isIgnored: true})
1479
1822
  updates.push(fromEl)
1480
1823
  return false
1481
1824
  }
1482
1825
  if(fromEl.type === "number" && (fromEl.validity && fromEl.validity.badInput)){ return false }
1483
- if(!DOM.syncPendingRef(fromEl, toEl, disableWith)){ return false }
1826
+ if(!DOM.syncPendingRef(fromEl, toEl, disableWith)){
1827
+ if(fromEl.type === "file"){
1828
+ this.trackBefore("updated", fromEl, toEl)
1829
+ updates.push(fromEl)
1830
+ }
1831
+ return false
1832
+ }
1484
1833
 
1485
1834
  // nested view handling
1486
1835
  if(DOM.isPhxChild(toEl)){
@@ -1599,6 +1948,7 @@ export class View {
1599
1948
  this.childJoins = 0
1600
1949
  this.loaderTimer = null
1601
1950
  this.pendingDiffs = []
1951
+ this.pruningCIDs = []
1602
1952
  this.href = href
1603
1953
  this.joinCount = this.parent ? this.parent.joinCount - 1 : 0
1604
1954
  this.joinPending = true
@@ -1607,6 +1957,8 @@ export class View {
1607
1957
  this.stopCallback = function(){}
1608
1958
  this.pendingJoinOps = this.parent ? null : []
1609
1959
  this.viewHooks = {}
1960
+ this.uploaders = {}
1961
+ this.formSubmits = []
1610
1962
  this.children = this.parent ? null : {}
1611
1963
  this.root.children[this.id] = {}
1612
1964
  this.channel = this.liveSocket.channel(`lv:${this.id}`, () => {
@@ -1728,7 +2080,6 @@ export class View {
1728
2080
 
1729
2081
  onJoin(resp){
1730
2082
  let {rendered} = resp
1731
- this.joinCount++
1732
2083
  this.childJoins = 0
1733
2084
  this.joinPending = true
1734
2085
  this.flash = null
@@ -1739,8 +2090,9 @@ export class View {
1739
2090
  let html = this.renderContainer(null, "join")
1740
2091
  this.dropPendingRefs()
1741
2092
  let forms = this.formsForRecovery(html)
2093
+ this.joinCount++
1742
2094
 
1743
- if(this.joinCount > 1 && forms.length > 0){
2095
+ if(forms.length > 0){
1744
2096
  forms.forEach((form, i) => {
1745
2097
  this.pushFormRecovery(form, resp => {
1746
2098
  if(i === forms.length - 1){
@@ -1804,7 +2156,7 @@ export class View {
1804
2156
  patch.markPrunableContentForRemoval()
1805
2157
  this.performPatch(patch, false)
1806
2158
  this.joinNewChildren()
1807
- DOM.all(this.el, `[${this.binding(PHX_HOOK)}]`, hookEl => {
2159
+ DOM.all(this.el, `[${this.binding(PHX_HOOK)}], [data-phx-${PHX_HOOK}]`, hookEl => {
1808
2160
  let hook = this.addHook(hookEl)
1809
2161
  if(hook){ hook.__trigger__("mounted") }
1810
2162
  })
@@ -1825,7 +2177,7 @@ export class View {
1825
2177
  triggerBeforeUpdateHook(fromEl, toEl){
1826
2178
  this.liveSocket.triggerDOM("onBeforeElUpdated", [fromEl, toEl])
1827
2179
  let hook = this.getHook(fromEl)
1828
- let isIgnored = hook && fromEl.getAttribute(this.binding(PHX_UPDATE)) === "ignore"
2180
+ let isIgnored = hook && DOM.isIgnored(fromEl, this.binding(PHX_UPDATE))
1829
2181
  if(hook && !fromEl.isEqualNode(toEl) && !(isIgnored && isEqualObj(fromEl.dataset, toEl.dataset))){
1830
2182
  hook.__trigger__("beforeUpdate")
1831
2183
  return hook
@@ -1840,6 +2192,8 @@ export class View {
1840
2192
  let updatedHookIds = new Set()
1841
2193
 
1842
2194
  patch.after("added", el => {
2195
+ this.liveSocket.triggerDOM("onNodeAdded", [el])
2196
+
1843
2197
  let newHook = this.addHook(el)
1844
2198
  if(newHook){ newHook.__trigger__("mounted") }
1845
2199
  })
@@ -1967,7 +2321,9 @@ export class View {
1967
2321
  renderContainer(diff, kind){
1968
2322
  return this.liveSocket.time(`toString diff (${kind})`, () => {
1969
2323
  let tag = this.el.tagName
1970
- let cids = diff ? this.rendered.componentCIDs(diff) : null
2324
+ // Don't skip any component in the diff nor any marked as pruned
2325
+ // (as they may have been added back)
2326
+ let cids = diff ? this.rendered.componentCIDs(diff).concat(this.pruningCIDs) : null
1971
2327
  let html = this.rendered.toString(cids)
1972
2328
  return `<${tag}>${html}</${tag}>`
1973
2329
  })
@@ -1984,7 +2340,7 @@ export class View {
1984
2340
  getHook(el){ return this.viewHooks[ViewHook.elementID(el)] }
1985
2341
 
1986
2342
  addHook(el){ if(ViewHook.elementID(el) || !el.getAttribute){ return }
1987
- let hookName = el.getAttribute(this.binding(PHX_HOOK))
2343
+ let hookName = el.getAttribute(`data-phx-${PHX_HOOK}`) || el.getAttribute(this.binding(PHX_HOOK))
1988
2344
  if(hookName && !this.ownsElement(el)){ return }
1989
2345
  let callbacks = this.liveSocket.getHookCallbacks(hookName)
1990
2346
 
@@ -2029,7 +2385,7 @@ export class View {
2029
2385
  this.onChannel("live_patch", (redir) => this.onLivePatch(redir))
2030
2386
  this.onChannel("live_redirect", (redir) => this.onLiveRedirect(redir))
2031
2387
  this.channel.onError(reason => this.onError(reason))
2032
- this.channel.onClose(() => this.onClose())
2388
+ this.channel.onClose(reason => this.onClose(reason))
2033
2389
  }
2034
2390
 
2035
2391
  destroyAllChildren(){
@@ -2063,7 +2419,7 @@ export class View {
2063
2419
  this.stopCallback = this.liveSocket.withPageLoading({to: this.href, kind: "initial"})
2064
2420
  }
2065
2421
  this.joinCallback = () => callback && callback(this, this.joinCount)
2066
- this.liveSocket.wrapPush(() => {
2422
+ this.liveSocket.wrapPush(this, {timeout: false}, () => {
2067
2423
  return this.channel.join()
2068
2424
  .receive("ok", data => this.onJoin(data))
2069
2425
  .receive("error", resp => this.onJoinError(resp))
@@ -2082,9 +2438,11 @@ export class View {
2082
2438
  return this.liveSocket.reloadWithJitter(this)
2083
2439
  }
2084
2440
 
2085
- onClose(){
2441
+ onClose(reason){
2086
2442
  if(this.isDestroyed()){ return }
2087
- if(this.isJoinPending() || this.liveSocket.hasPendingLink()){ return this.liveSocket.reloadWithJitter(this) }
2443
+ if(this.isJoinPending() || (this.liveSocket.hasPendingLink() && reason !== "leave")){
2444
+ return this.liveSocket.reloadWithJitter(this)
2445
+ }
2088
2446
  this.destroyAllChildren()
2089
2447
  this.liveSocket.dropActiveElement(this)
2090
2448
  // document.activeElement can be null in Internet Explorer 11
@@ -2095,7 +2453,7 @@ export class View {
2095
2453
  }
2096
2454
 
2097
2455
  onError(reason){
2098
- this.onClose()
2456
+ this.onClose(reason)
2099
2457
  this.log("error", () => ["view crashed", reason])
2100
2458
  if(!this.liveSocket.isUnloaded()){ this.displayError() }
2101
2459
  }
@@ -2115,7 +2473,7 @@ export class View {
2115
2473
 
2116
2474
  if(typeof(payload.cid) !== "number"){ delete payload.cid }
2117
2475
  return(
2118
- this.liveSocket.wrapPush(() => {
2476
+ this.liveSocket.wrapPush(this, {timeout: true}, () => {
2119
2477
  return this.channel.push(event, payload, PUSH_TIMEOUT).receive("ok", resp => {
2120
2478
  let hookReply = null
2121
2479
  if(ref !== null){ this.undoRefs(ref) }
@@ -2250,17 +2608,83 @@ export class View {
2250
2608
  })
2251
2609
  }
2252
2610
 
2611
+ pushFileProgress(fileEl, entryRef, progress, onReply = function(){}){
2612
+ this.liveSocket.withinOwners(fileEl.form, (view, targetCtx) => {
2613
+ view.pushWithReply(null, "progress", {
2614
+ event: fileEl.getAttribute(view.binding(PHX_PROGRESS)),
2615
+ ref: fileEl.getAttribute(PHX_UPLOAD_REF),
2616
+ entry_ref: entryRef,
2617
+ progress: progress,
2618
+ cid: view.targetComponentID(fileEl.form, targetCtx)
2619
+ }, onReply)
2620
+ })
2621
+ }
2622
+
2253
2623
  pushInput(inputEl, targetCtx, phxEvent, eventTarget, callback){
2254
- this.pushWithReply(() => this.putRef([inputEl, inputEl.form], "change"), "event", {
2624
+ let uploads
2625
+ let cid = this.targetComponentID(inputEl.form, targetCtx)
2626
+ let refGenerator = () => this.putRef([inputEl, inputEl.form], "change")
2627
+ let formData = serializeForm(inputEl.form, {_target: eventTarget.name})
2628
+ if(inputEl.files && inputEl.files.length > 0){
2629
+ LiveUploader.trackFiles(inputEl, Array.from(inputEl.files))
2630
+ }
2631
+ uploads = LiveUploader.serializeUploads(inputEl)
2632
+ let event = {
2255
2633
  type: "form",
2256
2634
  event: phxEvent,
2257
- value: serializeForm(inputEl.form, {_target: eventTarget.name}),
2258
- cid: this.targetComponentID(inputEl.form, targetCtx)
2259
- }, callback)
2635
+ value: formData,
2636
+ uploads: uploads,
2637
+ cid: cid
2638
+ }
2639
+ this.pushWithReply(refGenerator, "event", event, resp => {
2640
+ if(inputEl.type === "file" && inputEl.getAttribute("data-phx-auto-upload") !== null){
2641
+ if(LiveUploader.filesAwaitingPreflight(inputEl).length > 0) {
2642
+ let [ref, els] = refGenerator()
2643
+ this.uploadFiles(inputEl.form, targetCtx, ref, cid, (uploads) => {
2644
+ callback && callback(resp)
2645
+ this.triggerAwaitingSubmit(inputEl.form)
2646
+ })
2647
+ }
2648
+ } else {
2649
+ callback && callback(resp)
2650
+ }
2651
+ })
2652
+ }
2653
+
2654
+ triggerAwaitingSubmit(formEl){
2655
+ let awaitingSubmit = this.getScheduledSubmit(formEl)
2656
+ if(awaitingSubmit){
2657
+ let [el, ref, callback] = awaitingSubmit
2658
+ this.cancelSubmit(formEl)
2659
+ callback()
2660
+ }
2661
+ }
2662
+
2663
+ getScheduledSubmit(formEl){
2664
+ return this.formSubmits.find(([el, callback]) => el.isSameNode(formEl))
2665
+ }
2666
+
2667
+ scheduleSubmit(formEl, ref, callback){
2668
+ if(this.getScheduledSubmit(formEl)){ return true }
2669
+ this.formSubmits.push([formEl, ref, callback])
2670
+ }
2671
+
2672
+ cancelSubmit(formEl){
2673
+ this.formSubmits = this.formSubmits.filter(([el, ref, callback]) => {
2674
+ if(el.isSameNode(formEl)){
2675
+ this.undoRefs(ref)
2676
+ return false
2677
+ } else {
2678
+ return true
2679
+ }
2680
+ })
2260
2681
  }
2261
2682
 
2262
2683
  pushFormSubmit(formEl, targetCtx, phxEvent, onReply){
2263
- let filterIgnored = el => !closestPhxBinding(el, `${this.binding(PHX_UPDATE)}=ignore`, el.form)
2684
+ let filterIgnored = el => {
2685
+ let userIgnored = closestPhxBinding(el, `${this.binding(PHX_UPDATE)}=ignore`, el.form)
2686
+ return !(userIgnored || closestPhxBinding(el, `data-phx-update=ignore`, el.form))
2687
+ }
2264
2688
  let refGenerator = () => {
2265
2689
  let disables = DOM.all(formEl, `[${this.binding(PHX_DISABLE_WITH)}]`)
2266
2690
  let buttons = DOM.all(formEl, "button").filter(filterIgnored)
@@ -2273,16 +2697,76 @@ export class View {
2273
2697
  inputs.forEach(input => {
2274
2698
  input.setAttribute(PHX_READONLY, input.readOnly)
2275
2699
  input.readOnly = true
2700
+ if(input.files){
2701
+ input.setAttribute(PHX_DISABLED, input.disabled)
2702
+ input.disabled = true
2703
+ }
2276
2704
  })
2277
2705
  formEl.setAttribute(this.binding(PHX_PAGE_LOADING), "")
2278
2706
  return this.putRef([formEl].concat(disables).concat(buttons).concat(inputs), "submit")
2279
2707
  }
2280
- this.pushWithReply(refGenerator, "event", {
2281
- type: "form",
2282
- event: phxEvent,
2283
- value: serializeForm(formEl),
2284
- cid: this.targetComponentID(formEl, targetCtx)
2285
- }, onReply)
2708
+
2709
+ let cid = this.targetComponentID(formEl, targetCtx)
2710
+ if(LiveUploader.hasUploadsInProgress(formEl)){
2711
+ let [ref, els] = refGenerator()
2712
+ return this.scheduleSubmit(formEl, ref, () => this.pushFormSubmit(formEl, targetCtx, phxEvent, onReply))
2713
+ } else if(LiveUploader.inputsAwaitingPreflight(formEl).length > 0) {
2714
+ let [ref, els] = refGenerator()
2715
+ let proxyRefGen = () => [ref, els]
2716
+ this.uploadFiles(formEl, targetCtx, ref, cid, (uploads) => {
2717
+ let formData = serializeForm(formEl, {})
2718
+ this.pushWithReply(proxyRefGen, "event", {
2719
+ type: "form",
2720
+ event: phxEvent,
2721
+ value: formData,
2722
+ cid: cid
2723
+ }, onReply)
2724
+ })
2725
+ } else {
2726
+ let formData = serializeForm(formEl)
2727
+ this.pushWithReply(refGenerator, "event", {
2728
+ type: "form",
2729
+ event: phxEvent,
2730
+ value: formData,
2731
+ cid: cid
2732
+ }, onReply)
2733
+ }
2734
+ }
2735
+
2736
+ uploadFiles(formEl, targetCtx, ref, cid, onComplete){
2737
+ let joinCountAtUpload = this.joinCount
2738
+ let inputEls = LiveUploader.activeFileInputs(formEl)
2739
+
2740
+ // get each file input
2741
+ inputEls.forEach(inputEl => {
2742
+ let uploader = new LiveUploader(inputEl, this, onComplete)
2743
+ this.uploaders[inputEl] = uploader
2744
+ let entries = uploader.entries().map(entry => entry.toPreflightPayload())
2745
+
2746
+ let payload = {
2747
+ ref: inputEl.getAttribute(PHX_UPLOAD_REF),
2748
+ entries: entries,
2749
+ cid: this.targetComponentID(inputEl.form, targetCtx)
2750
+ }
2751
+
2752
+ this.log("upload", () => [`sending preflight request`, payload])
2753
+
2754
+ this.pushWithReply(null, "allow_upload", payload, resp => {
2755
+ this.log("upload", () => [`got preflight response`, resp])
2756
+ if(resp.error){
2757
+ this.undoRefs(ref)
2758
+ let [entry_ref, reason] = resp.error
2759
+ this.log("upload", () => [`error for entry ${entry_ref}`, reason])
2760
+ } else {
2761
+ let onError = (callback) => {
2762
+ this.channel.onError(() => {
2763
+ if(this.joinCount === joinCountAtUpload){ callback() }
2764
+ })
2765
+ }
2766
+ uploader.initAdapterUpload(resp, onError, this.liveSocket)
2767
+ }
2768
+ })
2769
+ })
2286
2770
  }
2287
2771
 
2288
2772
  pushFormRecovery(form, callback){
@@ -2309,6 +2793,8 @@ export class View {
2309
2793
  }
2310
2794
 
2311
2795
  formsForRecovery(html){
2796
+ if(this.joinCount <= 1){ return [] }
2797
+
2312
2798
  let phxChange = this.binding("change")
2313
2799
  let template = document.createElement("template")
2314
2800
  template.innerHTML = html
@@ -2316,18 +2802,35 @@ export class View {
2316
2802
  return(
2317
2803
  DOM.all(this.el, `form[${phxChange}]`)
2318
2804
  .filter(form => this.ownsElement(form))
2805
+ .filter(form => form.elements.length > 0)
2319
2806
  .filter(form => form.getAttribute(this.binding(PHX_AUTO_RECOVER)) !== "ignore")
2320
2807
  .filter(form => template.content.querySelector(`form[${phxChange}="${form.getAttribute(phxChange)}"]`))
2321
2808
  )
2322
2809
  }
2323
2810
 
2324
2811
  maybePushComponentsDestroyed(destroyedCIDs){
2325
- let completelyDestroyedCIDs = destroyedCIDs.filter(cid => {
2812
+ let willDestroyCIDs = destroyedCIDs.filter(cid => {
2326
2813
  return DOM.findComponentNodeList(this.el, cid).length === 0
2327
2814
  })
2328
- if(completelyDestroyedCIDs.length > 0){
2329
- this.pushWithReply(null, "cids_destroyed", {cids: completelyDestroyedCIDs}, () => {
2330
- this.rendered.pruneCIDs(completelyDestroyedCIDs)
2815
+ if(willDestroyCIDs.length > 0){
2816
+ this.pruningCIDs.push(...willDestroyCIDs)
2817
+
2818
+ this.pushWithReply(null, "cids_will_destroy", {cids: willDestroyCIDs}, () => {
2819
+ // The cids are either back on the page or they will be fully removed,
2820
+ // so we can remove them from the pruningCIDs.
2821
+ this.pruningCIDs = this.pruningCIDs.filter(cid => willDestroyCIDs.indexOf(cid) !== -1)
2822
+
2823
+ // See if any of the cids we wanted to destroy were added back,
2824
+ // if they were added back, we don't actually destroy them.
2825
+ let completelyDestroyCIDs = willDestroyCIDs.filter(cid => {
2826
+ return DOM.findComponentNodeList(this.el, cid).length === 0
2827
+ })
2828
+
2829
+ if(completelyDestroyCIDs.length > 0){
2830
+ this.pushWithReply(null, "cids_destroyed", {cids: completelyDestroyCIDs}, (resp) => {
2831
+ this.rendered.pruneCIDs(resp.cids)
2832
+ })
2833
+ }
2331
2834
  })
2332
2835
  }
2333
2836
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phoenix_live_view",
3
- "version": "0.14.8",
3
+ "version": "0.15.0",
4
4
  "description": "The Phoenix LiveView JavaScript client.",
5
5
  "license": "MIT",
6
6
  "main": "./priv/static/phoenix_live_view.js",
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.phoenix_live_view=t():e.phoenix_live_view=t()}(this,function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:i})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";n.r(t);var i,r=11;var o="http://www.w3.org/1999/xhtml",a="undefined"==typeof document?void 0:document,u=!!a&&"content"in a.createElement("template"),c=!!a&&a.createRange&&"createContextualFragment"in a.createRange();function s(e){return e=e.trim(),u?function(e){var t=a.createElement("template");return t.innerHTML=e,t.content.childNodes[0]}(e):c?function(e){return i||(i=a.createRange()).selectNode(a.body),i.createContextualFragment(e).childNodes[0]}(e):function(e){var t=a.createElement("body");return t.innerHTML=e,t.childNodes[0]}(e)}function l(e,t){var n,i,r=e.nodeName,o=t.nodeName;return r===o||(n=r.charCodeAt(0),i=o.charCodeAt(0),n<=90&&i>=97?r===o.toUpperCase():i<=90&&n>=97&&o===r.toUpperCase())}function d(e,t,n){e[n]!==t[n]&&(e[n]=t[n],e[n]?e.setAttribute(n,""):e.removeAttribute(n))}var h={OPTION:function(e,t){var n=e.parentNode;if(n){var i=n.nodeName.toUpperCase();"OPTGROUP"===i&&(i=(n=n.parentNode)&&n.nodeName.toUpperCase()),"SELECT"!==i||n.hasAttribute("multiple")||(e.hasAttribute("selected")&&!t.selected&&(e.setAttribute("selected","selected"),e.removeAttribute("selected")),n.selectedIndex=-1)}d(e,t,"selected")},INPUT:function(e,t){d(e,t,"checked"),d(e,t,"disabled"),e.value!==t.value&&(e.value=t.value),t.hasAttribute("value")||e.removeAttribute("value")},TEXTAREA:function(e,t){var n=t.value;e.value!==n&&(e.value=n);var i=e.firstChild;if(i){var r=i.nodeValue;if(r==n||!n&&r==e.placeholder)return;i.nodeValue=n}},SELECT:function(e,t){if(!t.hasAttribute("multiple")){for(var n,i,r=-1,o=0,a=e.firstChild;a;)if("OPTGROUP"===(i=a.nodeName&&a.nodeName.toUpperCase()))a=(n=a).firstChild;else{if("OPTION"===i){if(a.hasAttribute("selected")){r=o;break}o++}!(a=a.nextSibling)&&n&&(a=n.nextSibling,n=null)}e.selectedIndex=r}}},f=1,v=11,p=3,g=8;function m(){}function y(e){if(e)return e.getAttribute&&e.getAttribute("id")||e.id}var b=function(e){return function(t,n,i){if(i||(i={}),"string"==typeof n)if("#document"===t.nodeName||"HTML"===t.nodeName||"BODY"===t.nodeName){var r=n;(n=a.createElement("html")).innerHTML=r}else n=s(n);var u=i.getNodeKey||y,c=i.onBeforeNodeAdded||m,d=i.onNodeAdded||m,b=i.onBeforeElUpdated||m,k=i.onElUpdated||m,w=i.onBeforeNodeDiscarded||m,E=i.onNodeDiscarded||m,x=i.onBeforeElChildrenUpdated||m,S=!0===i.childrenOnly,A=Object.create(null),C=[];function P(e){C.push(e)}function L(e,t,n){!1!==w(e)&&(t&&t.removeChild(e),E(e),function e(t,n){if(t.nodeType===f)for(var i=t.firstChild;i;){var r=void 0;n&&(r=u(i))?P(r):(E(i),i.firstChild&&e(i,n)),i=i.nextSibling}}(e,n))}function T(e){d(e);for(var t=e.firstChild;t;){var n=t.nextSibling,i=u(t);if(i){var r=A[i];r&&l(t,r)?(t.parentNode.replaceChild(r,t),I(r,t)):T(t)}else T(t);t=n}}function I(t,n,i){var r=u(n);if(r&&delete A[r],!i){if(!1===b(t,n))return;if(e(t,n),k(t),!1===x(t,n))return}"TEXTAREA"!==t.nodeName?function(e,t){var n,i,r,o,s,d=t.firstChild,v=e.firstChild;e:for(;d;){for(o=d.nextSibling,n=u(d);v;){if(r=v.nextSibling,d.isSameNode&&d.isSameNode(v)){d=o,v=r;continue e}i=u(v);var m=v.nodeType,y=void 0;if(m===d.nodeType&&(m===f?(n?n!==i&&((s=A[n])?r===s?y=!1:(e.insertBefore(s,v),i?P(i):L(v,e,!0),v=s):y=!1):i&&(y=!1),(y=!1!==y&&l(v,d))&&I(v,d)):m!==p&&m!=g||(y=!0,v.nodeValue!==d.nodeValue&&(v.nodeValue=d.nodeValue))),y){d=o,v=r;continue e}i?P(i):L(v,e,!0),v=r}if(n&&(s=A[n])&&l(s,d))e.appendChild(s),I(s,d);else{var b=c(d);!1!==b&&(b&&(d=b),d.actualize&&(d=d.actualize(e.ownerDocument||a)),e.appendChild(d),T(d))}d=o,v=r}!function(e,t,n){for(;t;){var i=t.nextSibling;(n=u(t))?P(n):L(t,e,!0),t=i}}(e,v,i);var k=h[e.nodeName];k&&k(e,t)}(t,n):h.TEXTAREA(t,n)}!function e(t){if(t.nodeType===f||t.nodeType===v)for(var n=t.firstChild;n;){var i=u(n);i&&(A[i]=n),e(n),n=n.nextSibling}}(t);var D=t,_=D.nodeType,N=n.nodeType;if(!S)if(_===f)N===f?l(t,n)||(E(t),D=function(e,t){for(var n=e.firstChild;n;){var i=n.nextSibling;t.appendChild(n),n=i}return t}(t,function(e,t){return t&&t!==o?a.createElementNS(t,e):a.createElement(e)}(n.nodeName,n.namespaceURI))):D=n;else if(_===p||_===g){if(N===_)return D.nodeValue!==n.nodeValue&&(D.nodeValue=n.nodeValue),D;D=n}if(D===n)E(t);else{if(n.isSameNode&&n.isSameNode(D))return;if(I(D,n,S),C)for(var R=0,O=C.length;R<O;R++){var H=A[C[R]];H&&L(H,H.parentNode,!1)}}return!S&&D!==t&&t.parentNode&&(D.actualize&&(D=D.actualize(t.ownerDocument||a)),t.parentNode.replaceChild(D,t)),D}}(function(e,t){var n,i,o,a,u=t.attributes;if(t.nodeType!==r&&e.nodeType!==r){for(var c=u.length-1;c>=0;c--)i=(n=u[c]).name,o=n.namespaceURI,a=n.value,o?(i=n.localName||i,e.getAttributeNS(o,i)!==a&&("xmlns"===n.prefix&&(i=n.name),e.setAttributeNS(o,i,a))):e.getAttribute(i)!==a&&e.setAttribute(i,a);for(var s=e.attributes,l=s.length-1;l>=0;l--)i=(n=s[l]).name,(o=n.namespaceURI)?(i=n.localName||i,t.hasAttributeNS(o,i)||e.removeAttributeNS(o,i)):t.hasAttribute(i)||e.removeAttribute(i)}});function k(e){return I(e)||S(e)||D(e)||T()}function w(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,i)}return n}function E(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function x(e){return function(e){if(Array.isArray(e))return _(e)}(e)||S(e)||D(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}function A(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function C(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function P(e,t,n){return t&&C(e.prototype,t),n&&C(e,n),e}function L(e,t){return I(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],i=!0,r=!1,o=void 0;try{for(var a,u=e[Symbol.iterator]();!(i=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);i=!0);}catch(e){r=!0,o=e}finally{try{i||null==u.return||u.return()}finally{if(r)throw o}}return n}(e,t)||D(e,t)||T()}function T(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function I(e){if(Array.isArray(e))return e}function D(e,t){if(e){if("string"==typeof e)return _(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_(e,t):void 0}}function _(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}function N(e){"@babel/helpers - typeof";return(N="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}n.d(t,"debug",function(){return $}),n.d(t,"Rendered",function(){return te}),n.d(t,"LiveSocket",function(){return ne}),n.d(t,"Browser",function(){return ie}),n.d(t,"DOM",function(){return re}),n.d(t,"View",function(){return ue});var R=[1e3,3e3],O="data-phx-view",H=["phx-click-loading","phx-change-loading","phx-submit-loading","phx-keydown-loading","phx-keyup-loading","phx-blur-loading","phx-focus-loading"],j="data-phx-component",M="data-phx-ref",B="[".concat(O,"]"),U=["text","textarea","number","email","password","search","tel","url","date","time"],J=["checkbox","radio"],F="data-phx-static",V=1,q="phx-",W={debounce:300,throttle:300},K=function(e,t){return console.error&&console.error(e,t)};var $=function(e,t,n,i){e.liveSocket.isDebugEnabled()&&console.log("".concat(e.id," ").concat(t,": ").concat(n," - "),i)},X=function(e){return"function"==typeof e?e:function(){return e}},z=function(e){return JSON.parse(JSON.stringify(e))},G=function(e,t,n){do{if(e.matches("[".concat(t,"]")))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType&&!(n&&n.isSameNode(e)||e.matches(B)));return null},Y=function(e){return null!==e&&"object"===N(e)&&!(e instanceof Array)},Q=function(e){for(var t in e)return!1;return!0},Z=function(e,t){return e&&t(e)},ee=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=new FormData(e),r=new URLSearchParams,o=function(e){if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=D(e))){var t=0,n=function(){};return{s:n,n:function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}},e:function(e){throw e},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,r,o=!0,a=!1;return{s:function(){i=e[Symbol.iterator]()},n:function(){var e=i.next();return o=e.done,e},e:function(e){a=!0,r=e},f:function(){try{o||null==i.return||i.return()}finally{if(a)throw r}}}}(i.entries());try{for(o.s();!(t=o.n()).done;){var a=L(t.value,2),u=a[0],c=a[1];r.append(u,c)}}catch(e){o.e(e)}finally{o.f()}for(var s in n)r.append(s,n[s]);return r.toString()},te=function(){function e(t,n){A(this,e),this.viewId=t,this.rendered={},this.mergeDiff(n)}return P(e,null,[{key:"extract",value:function(e){var t=e.r,n=e.e,i=e.t;return delete e.r,delete e.e,delete e.t,{diff:e,title:i,reply:t||null,events:n||[]}}}]),P(e,[{key:"parentViewId",value:function(){return this.viewId}},{key:"toString",value:function(e){return this.recursiveToString(this.rendered,this.rendered.c,e)}},{key:"recursiveToString",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.c,n=arguments.length>2?arguments[2]:void 0,i={buffer:"",components:t,onlyCids:n=n?new Set(n):null};return this.toOutputBuffer(e,i),i.buffer}},{key:"componentCIDs",value:function(e){return Object.keys(e.c||{}).map(function(e){return parseInt(e)})}},{key:"isComponentOnlyDiff",value:function(e){return!!e.c&&1===Object.keys(e).length}},{key:"getComponent",value:function(e,t){return e.c[t]}},{key:"mergeDiff",value:function(e){var t=e.c;if(delete e.c,this.rendered=this.recursiveMerge(this.rendered,e),this.rendered.c=this.rendered.c||{},t){var n=this.rendered.c;for(var i in t){var r=t[i],o=r,a=o.s;if("number"==typeof a){for(;"number"==typeof a;)a=(o=a>0?t[a]:n[-a]).s;o=z(o),this.doRecursiveMerge(o,r),o.s=a}else o=n[i]||{},o=this.recursiveMerge(o,r);t[i]=o}for(var u in t)n[u]=t[u];e.c=t}}},{key:"recursiveMerge",value:function(e,t){return void 0!==t.s?t:(this.doRecursiveMerge(e,t),e)}},{key:"doRecursiveMerge",value:function(e,t){for(var n in t){var i=t[n],r=e[n];Y(i)&&void 0===i.s&&Y(r)?this.doRecursiveMerge(r,i):e[n]=i}}},{key:"componentToString",value:function(e){return this.recursiveCIDToString(this.rendered.c,e)}},{key:"pruneCIDs",value:function(e){var t=this;e.forEach(function(e){return delete t.rendered.c[e]})}},{key:"get",value:function(){return this.rendered}},{key:"isNewFingerprint",value:function(){return!!(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).s}},{key:"toOutputBuffer",value:function(e,t){if(e.d)return this.comprehensionToBuffer(e,t);var n=e.s;t.buffer+=n[0];for(var i=1;i<n.length;i++)this.dynamicToBuffer(e[i-1],t),t.buffer+=n[i]}},{key:"comprehensionToBuffer",value:function(e,t){for(var n=e.d,i=e.s,r=0;r<n.length;r++){var o=n[r];t.buffer+=i[0];for(var a=1;a<i.length;a++)this.dynamicToBuffer(o[a-1],t),t.buffer+=i[a]}}},{key:"dynamicToBuffer",value:function(e,t){"number"==typeof e?t.buffer+=this.recursiveCIDToString(t.components,e,t.onlyCids):Y(e)?this.toOutputBuffer(e,t):t.buffer+=e}},{key:"recursiveCIDToString",value:function(e,t,n){var i=this,r=e[t]||K("no component for CID ".concat(t),e),o=document.createElement("template");o.innerHTML=this.recursiveToString(r,e,n);var a=o.content,u=n&&!n.has(t),c=L(Array.from(a.childNodes).reduce(function(e,n,r){var a=L(e,2),c=a[0],s=a[1];return n.nodeType===Node.ELEMENT_NODE?n.getAttribute(j)?[c,!0]:(n.setAttribute(j,t),n.id||(n.id="".concat(i.parentViewId(),"-").concat(t,"-").concat(r)),u&&(n.setAttribute("data-phx-skip",""),n.innerHTML=""),[!0,s]):""!==n.nodeValue.trim()?(K("only HTML element tags are allowed at the root of components.\n\n"+'got: "'.concat(n.nodeValue.trim(),'"\n\n')+"within:\n",o.innerHTML.trim()),n.replaceWith(i.createSpan(n.nodeValue,t)),[!0,s]):(n.remove(),[c,s])},[!1,!1]),2),s=c[0],l=c[1];return s||l?!s&&l?(K("expected at least one HTML element tag directly inside a component, but only subcomponents were found. A component must render at least one HTML tag directly inside itself.",o.innerHTML.trim()),o.innerHTML):o.innerHTML:(K("expected at least one HTML element tag inside a component, but the component is empty:\n",o.innerHTML.trim()),this.createSpan("",t).outerHTML)}},{key:"createSpan",value:function(e,t){var n=document.createElement("span");return n.innerText=e,n.setAttribute(j,t),n}}]),e}(),ne=function(){function e(t,n){var i=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(A(this,e),this.unloaded=!1,!n||"Object"===n.constructor.name)throw new Error('\n a phoenix Socket must be provided as the second argument to the LiveSocket constructor. For example:\n\n import {Socket} from "phoenix"\n import {LiveSocket} from "phoenix_live_view"\n let liveSocket = new LiveSocket("/live", Socket, {...})\n ');this.socket=new n(t,r),this.bindingPrefix=r.bindingPrefix||q,this.opts=r,this.params=X(r.params||{}),this.viewLogger=r.viewLogger,this.metadataCallbacks=r.metadata||{},this.defaults=Object.assign(z(W),r.defaults||{}),this.activeElement=null,this.prevActive=null,this.silenced=!1,this.main=null,this.linkRef=0,this.roots={},this.href=window.location.href,this.pendingLink=null,this.currentLocation=z(window.location),this.hooks=r.hooks||{},this.loaderTimeout=r.loaderTimeout||V,this.boundTopLevelEvents=!1,this.domCallbacks=r.dom||{onBeforeElUpdated:X()},window.addEventListener("unload",function(e){i.unloaded=!0}),this.socket.onOpen(function(){i.isUnloaded()&&window.location.reload()})}return P(e,[{key:"isProfileEnabled",value:function(){return"true"===sessionStorage.getItem("phx:live-socket:profiling")}},{key:"isDebugEnabled",value:function(){return"true"===sessionStorage.getItem("phx:live-socket:debug")}},{key:"enableDebug",value:function(){sessionStorage.setItem("phx:live-socket:debug","true")}},{key:"enableProfiling",value:function(){sessionStorage.setItem("phx:live-socket:profiling","true")}},{key:"disableDebug",value:function(){sessionStorage.removeItem("phx:live-socket:debug")}},{key:"disableProfiling",value:function(){sessionStorage.removeItem("phx:live-socket:profiling")}},{key:"enableLatencySim",value:function(e){this.enableDebug(),console.log("latency simulator enabled for the duration of this browser session. Call disableLatencySim() to disable"),sessionStorage.setItem("phx:live-socket:latency-sim",e)}},{key:"disableLatencySim",value:function(){sessionStorage.removeItem("phx:live-socket:latency-sim")}},{key:"getLatencySim",value:function(){var e=sessionStorage.getItem("phx:live-socket:latency-sim");return e?parseInt(e):null}},{key:"getSocket",value:function(){return this.socket}},{key:"connect",value:function(){var e=this,t=function(){e.joinRootViews()&&(e.bindTopLevelEvents(),e.socket.connect())};["complete","loaded","interactive"].indexOf(document.readyState)>=0?t():document.addEventListener("DOMContentLoaded",function(){return t()})}},{key:"disconnect",value:function(e){this.socket.disconnect(e)}},{key:"triggerDOM",value:function(e,t){var n;(n=this.domCallbacks)[e].apply(n,x(t))}},{key:"time",value:function(e,t){if(!this.isProfileEnabled()||!console.time)return t();console.time(e);var n=t();return console.timeEnd(e),n}},{key:"log",value:function(e,t,n){if(this.viewLogger){var i=L(n(),2),r=i[0],o=i[1];this.viewLogger(e,t,r,o)}else if(this.isDebugEnabled()){var a=L(n(),2),u=a[0],c=a[1];$(e,t,u,c)}}},{key:"onChannel",value:function(e,t,n){var i=this;e.on(t,function(e){var t=i.getLatencySim();t?(console.log("simulating ".concat(t,"ms of latency from server to client")),setTimeout(function(){return n(e)},t)):n(e)})}},{key:"wrapPush",value:function(e){var t=this.getLatencySim();if(!t)return e();console.log("simulating ".concat(t,"ms of latency from client to server"));var n={receives:[],receive:function(e,t){this.receives.push([e,t])}};return setTimeout(function(){n.receives.reduce(function(e,t){var n=L(t,2),i=n[0],r=n[1];return e.receive(i,r)},e())},t),n}},{key:"reloadWithJitter",value:function(e){var t=this;e.destroy(),this.disconnect();var n=R[0],i=R[1],r=Math.floor(Math.random()*(i-n+1))+n,o=ie.updateLocal(e.name(),"consecutive-reloads",0,function(e){return e+1});this.log(e,"join",function(){return["encountered ".concat(o," consecutive reloads")]}),o>10&&(this.log(e,"join",function(){return["exceeded ".concat(10," consecutive reloads. Entering failsafe mode")]}),r=3e4),setTimeout(function(){t.hasPendingLink()?window.location=t.pendingLink:window.location.reload()},r)}},{key:"getHookCallbacks",value:function(e){return this.hooks[e]}},{key:"isUnloaded",value:function(){return this.unloaded}},{key:"isConnected",value:function(){return this.socket.isConnected()}},{key:"getBindingPrefix",value:function(){return this.bindingPrefix}},{key:"binding",value:function(e){return"".concat(this.getBindingPrefix()).concat(e)}},{key:"channel",value:function(e,t){return this.socket.channel(e,t)}},{key:"joinRootViews",value:function(){var e=this,t=!1;return re.all(document,"".concat(B,":not([").concat("data-phx-parent-id","])"),function(n){if(!e.getRootById(n.id)){var i=e.joinRootView(n,e.getHref());e.root=e.root||i,n.getAttribute("data-phx-main")&&(e.main=i)}t=!0}),t}},{key:"redirect",value:function(e,t){this.disconnect(),ie.redirect(e,t)}},{key:"replaceMain",value:function(e,t){var n=this,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:this.setPendingLink(e),o=this.main.el;this.main.showLoader(this.loaderTimeout),this.main.destroy(),ie.fetchPage(e,function(a,u){if(200!==a)return n.redirect(e);var c=document.createElement("template");c.innerHTML=u;var s=c.content.childNodes[0];if(!s||!n.isPhxView(s))return n.redirect(e);n.joinRootView(s,e,t,function(e,t){1===t&&(n.commitPendingLink(r)?(o.replaceWith(e.el),n.main=e,i&&i()):e.destroy())})})}},{key:"isPhxView",value:function(e){return e.getAttribute&&null!==e.getAttribute(O)}},{key:"joinRootView",value:function(e,t,n,i){var r=new ue(e,this,null,t,n);return this.roots[r.id]=r,r.join(i),r}},{key:"owner",value:function(e,t){var n=this,i=Z(e.closest(B),function(e){return n.getViewByEl(e)});i&&t(i)}},{key:"withinOwners",value:function(e,t){var n=this;this.owner(e,function(i){var r=e.getAttribute(n.binding("target"));null===r?t(i,e):i.withinTargets(r,t)})}},{key:"getViewByEl",value:function(e){var t=e.getAttribute("data-phx-root-id");return Z(this.getRootById(t),function(t){return t.getDescendentByEl(e)})}},{key:"getRootById",value:function(e){return this.roots[e]}},{key:"destroyAllViews",value:function(){for(var e in this.roots)this.roots[e].destroy(),delete this.roots[e]}},{key:"destroyViewByEl",value:function(e){var t=this.getRootById(e.getAttribute("data-phx-root-id"));t&&t.destroyDescendent(e.id)}},{key:"setActiveElement",value:function(e){var t=this;if(this.activeElement!==e){this.activeElement=e;var n=function(){e===t.activeElement&&(t.activeElement=null),e.removeEventListener("mouseup",t),e.removeEventListener("touchend",t)};e.addEventListener("mouseup",n),e.addEventListener("touchend",n)}}},{key:"getActiveElement",value:function(){return document.activeElement===document.body?this.activeElement||document.activeElement:document.activeElement||document.body}},{key:"dropActiveElement",value:function(e){this.prevActive&&e.ownsElement(this.prevActive)&&(this.prevActive=null)}},{key:"restorePreviouslyActiveFocus",value:function(){this.prevActive&&this.prevActive!==document.body&&this.prevActive.focus()}},{key:"blurActiveElement",value:function(){this.prevActive=this.getActiveElement(),this.prevActive!==document.body&&this.prevActive.blur()}},{key:"bindTopLevelEvents",value:function(){var e=this;this.boundTopLevelEvents||(this.boundTopLevelEvents=!0,window.addEventListener("pageshow",function(t){t.persisted&&(e.withPageLoading({to:window.location.href,kind:"redirect"}),window.location.reload())}),this.bindClicks(),this.bindNav(),this.bindForms(),this.bind({keyup:"keyup",keydown:"keydown"},function(t,n,i,r,o,a,u){var c=r.getAttribute(e.binding("key")),s=t.key&&t.key.toLowerCase();c&&c.toLowerCase()!==s||i.pushKey(r,o,n,a,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?w(Object(n),!0).forEach(function(t){E(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):w(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({key:t.key},e.eventMeta(n,t,r)))}),this.bind({blur:"focusout",focus:"focusin"},function(t,n,i,r,o,a,u){u||i.pushEvent(n,r,o,a,e.eventMeta(n,t,r))}),this.bind({blur:"blur",focus:"focus"},function(t,n,i,r,o,a,u){u&&"window"!==!u&&i.pushEvent(n,r,o,a,e.eventMeta(n,t,r))}))}},{key:"eventMeta",value:function(e,t,n){var i=this.metadataCallbacks[e];return i?i(t,n):{}}},{key:"setPendingLink",value:function(e){return this.linkRef++,this.pendingLink=e,this.linkRef}},{key:"commitPendingLink",value:function(e){return this.linkRef===e&&(this.href=this.pendingLink,this.pendingLink=null,!0)}},{key:"getHref",value:function(){return this.href}},{key:"hasPendingLink",value:function(){return!!this.pendingLink}},{key:"bind",value:function(e,t){var n=this,i=function(i){var r=e[i];n.on(r,function(e){var r=n.binding(i),o=n.binding("window-".concat(i)),a=e.target.getAttribute&&e.target.getAttribute(r);a?n.debounce(e.target,e,function(){n.withinOwners(e.target,function(n,r){t(e,i,n,e.target,r,a,null)})}):re.all(document,"[".concat(o,"]"),function(r){var a=r.getAttribute(o);n.debounce(r,e,function(){n.withinOwners(r,function(n,o){t(e,i,n,r,o,a,"window")})})})})};for(var r in e)i(r)}},{key:"bindClicks",value:function(){var e=this;[!0,!1].forEach(function(t){var n=t?e.binding("capture-click"):e.binding("click");window.addEventListener("click",function(i){var r=null,o=(r=t?i.target.matches("[".concat(n,"]"))?i.target:i.target.querySelector("[".concat(n,"]")):G(i.target,n))&&r.getAttribute(n);o&&("#"===r.getAttribute("href")&&i.preventDefault(),e.debounce(r,i,function(){e.withinOwners(r,function(t,n){t.pushEvent("click",r,n,o,e.eventMeta("click",i,r))})}))},t)})}},{key:"bindNav",value:function(){var e=this;if(ie.canPushState()){history.scrollRestoration&&(history.scrollRestoration="manual");var t=null;window.addEventListener("scroll",function(e){clearTimeout(t),t=setTimeout(function(){ie.updateCurrentState(function(e){return Object.assign(e,{scroll:window.scrollY})})},100)}),window.addEventListener("popstate",function(t){if(e.registerNewLocation(window.location)){var n=t.state||{},i=n.type,r=n.id,o=n.root,a=n.scroll,u=window.location.href;e.main.isConnected()&&"patch"===i&&r===e.main.id?e.main.pushLinkPatch(u,null):e.replaceMain(u,null,function(){o&&e.replaceRootHistory(),"number"==typeof a&&setTimeout(function(){window.scrollTo(0,a)},0)})}},!1),window.addEventListener("click",function(t){var n=G(t.target,"data-phx-link"),i=n&&n.getAttribute("data-phx-link"),r=t.metaKey||t.ctrlKey||1===t.button;if(i&&e.isConnected()&&e.main&&!r){var o=n.href,a=n.getAttribute("data-phx-link-state");if(t.preventDefault(),e.pendingLink!==o)if("patch"===i)e.pushHistoryPatch(o,a,n);else{if("redirect"!==i)throw new Error("expected ".concat("data-phx-link",' to be "patch" or "redirect", got: ').concat(i));e.historyRedirect(o,a)}}},!1)}}},{key:"withPageLoading",value:function(e,t){re.dispatchEvent(window,"phx:page-loading-start",e);var n=function(){return re.dispatchEvent(window,"phx:page-loading-stop",e)};return t?t(n):n}},{key:"pushHistoryPatch",value:function(e,t,n){var i=this;this.withPageLoading({to:e,kind:"patch"},function(r){i.main.pushLinkPatch(e,n,function(){i.historyPatch(e,t),r()})})}},{key:"historyPatch",value:function(e,t){ie.pushState(t,{type:"patch",id:this.main.id},e),this.registerNewLocation(window.location)}},{key:"historyRedirect",value:function(e,t,n){var i=this,r=window.scrollY;this.withPageLoading({to:e,kind:"redirect"},function(o){i.replaceMain(e,n,function(){ie.pushState(t,{type:"redirect",id:i.main.id,scroll:r},e),i.registerNewLocation(window.location),o()})})}},{key:"replaceRootHistory",value:function(){ie.pushState("replace",{root:!0,type:"patch",id:this.main.id})}},{key:"registerNewLocation",value:function(e){var t=this.currentLocation;return t.pathname+t.search!==e.pathname+e.search&&(this.currentLocation=z(e),!0)}},{key:"bindForms",value:function(){var e=this,t=0;this.on("submit",function(t){var n=t.target.getAttribute(e.binding("submit"));n&&(t.preventDefault(),t.target.disabled=!0,e.withinOwners(t.target,function(e,i){return e.submitForm(t.target,i,n)}))},!1);for(var n=function(){var n=r[i];e.on(n,function(i){var r=i.target,o=r.form&&r.form.getAttribute(e.binding("change"));if(o&&("number"!==r.type||!r.validity||!r.validity.badInput)){var a=t;t++;var u=re.private(r,"prev-iteration")||{},c=u.at,s=u.type;c===a-1&&n!==s||(re.putPrivate(r,"prev-iteration",{at:a,type:n}),e.debounce(r,i,function(){e.withinOwners(r.form,function(t,n){re.putPrivate(r,"phx-has-focused",!0),re.isTextualInput(r)||e.setActiveElement(r),t.pushInput(r,n,o,i.target)})}))}},!1)},i=0,r=["change","input"];i<r.length;i++)n()}},{key:"debounce",value:function(e,t,n){var i=this.binding("debounce"),r=this.binding("throttle"),o=this.defaults.debounce.toString(),a=this.defaults.throttle.toString();re.debounce(e,t,i,o,r,a,n)}},{key:"silenceEvents",value:function(e){this.silenced=!0,e(),this.silenced=!1}},{key:"on",value:function(e,t){var n=this;window.addEventListener(e,function(e){n.silenced||t(e)})}}]),e}(),ie={canPushState:function(){return void 0!==history.pushState},dropLocal:function(e,t){return window.localStorage.removeItem(this.localKey(e,t))},updateLocal:function(e,t,n,i){var r=this.getLocal(e,t),o=this.localKey(e,t),a=null===r?n:i(r);return window.localStorage.setItem(o,JSON.stringify(a)),a},getLocal:function(e,t){return JSON.parse(window.localStorage.getItem(this.localKey(e,t)))},fetchPage:function(e,t){var n=new XMLHttpRequest;n.open("GET",e,!0),n.timeout=3e4,n.setRequestHeader("content-type","text/html"),n.setRequestHeader("cache-control","max-age=0, no-cache, no-store, must-revalidate, post-check=0, pre-check=0"),n.setRequestHeader("x-requested-with","live-link"),n.onerror=function(){return t(400)},n.ontimeout=function(){return t(504)},n.onreadystatechange=function(){if(4===n.readyState){var i=new URL(e),r=i.pathname+i.search,o=Z(n.getResponseHeader("x-response-url")||n.responseURL,function(e){return new URL(e)}),a=o?o.pathname+o.search:null;return"live-link"!==n.getResponseHeader("x-requested-with")?t(400):null===o||a!=r?t(302):200!==n.status?t(n.status):void t(200,n.responseText)}},n.send()},updateCurrentState:function(e){this.canPushState()&&history.replaceState(e(history.state||{}),"",window.location.href)},pushState:function(e,t,n){if(this.canPushState()){if(n!==window.location.href){if("redirect"==t.type&&t.scroll){var i=history.state||{};i.scroll=t.scroll,history.replaceState(i,"",window.location.href)}delete t.scroll,history[e+"State"](t,"",n||null);var r=this.getHashTargetEl(window.location.hash);r?r.scrollIntoView():"redirect"===t.type&&window.scroll(0,0)}}else this.redirect(n)},setCookie:function(e,t){document.cookie="".concat(e,"=").concat(t)},getCookie:function(e){return document.cookie.replace(new RegExp("(?:(?:^|.*;s*)".concat(e,"s*=s*([^;]*).*$)|^.*$")),"$1")},redirect:function(e,t){t&&ie.setCookie("__phoenix_flash__",t+"; max-age=60000; path=/"),window.location=e},localKey:function(e,t){return"".concat(e,"-").concat(t)},getHashTargetEl:function(e){var t=e.toString().substring(1);if(""!==t)return document.getElementById(t)||document.querySelector('a[name="'.concat(t,'"]'))}},re={byId:function(e){return document.getElementById(e)||K("no id found for ".concat(e))},removeClass:function(e,t){e.classList.remove(t),0===e.classList.length&&e.removeAttribute("class")},all:function(e,t,n){var i=Array.from(e.querySelectorAll(t));return n?i.forEach(n):i},findComponentNodeList:function(e,t){var n=this.all(e,B),i=this.all(e,"[".concat(j,'="').concat(t,'"]'));return 0===n.length?i:i.filter(function(e){return!n.some(function(t){return t.contains(e)})})},findPhxChildrenInFragment:function(e,t){var n=document.createElement("template");return n.innerHTML=e,this.findPhxChildren(n.content,t)},isPhxUpdate:function(e,t,n){return e.getAttribute&&n.indexOf(e.getAttribute(t))>=0},findPhxChildren:function(e,t){return this.all(e,"".concat(B,"[").concat("data-phx-parent-id",'="').concat(t,'"]'))},findParentCIDs:function(e,t){var n=this,i=new Set(t);return t.reduce(function(t,i){var r="[".concat(j,'="').concat(i,'"] [').concat(j,"]");return n.all(e,r).map(function(e){return parseInt(e.getAttribute(j))}).forEach(function(e){return t.delete(e)}),t},i)},private:function(e,t){return e.phxPrivate&&e.phxPrivate[t]},deletePrivate:function(e,t){e.phxPrivate&&delete e.phxPrivate[t]},putPrivate:function(e,t,n){e.phxPrivate||(e.phxPrivate={}),e.phxPrivate[t]=n},copyPrivates:function(e,t){t.phxPrivate&&(e.phxPrivate=z(t.phxPrivate))},putTitle:function(e){var t=document.querySelector("title").dataset,n=t.prefix,i=t.suffix;document.title="".concat(n||"").concat(e).concat(i||"")},debounce:function(e,t,n,i,r,o,a){var u=this,c=e.getAttribute(n),s=e.getAttribute(r);""===c&&(c=i),""===s&&(s=o);var l=c||s;switch(l){case null:return a();case"blur":return void(this.once(e,"debounce-blur")&&e.addEventListener("blur",function(){return a()}));default:var d=parseInt(l),h=this.incCycle(e,"debounce-trigger",function(){return s?u.deletePrivate(e,"throttled"):a()});if(isNaN(d))return K("invalid throttle/debounce value: ".concat(l));if(s){var f=!1;if("keydown"===t.type){var v=this.private(e,"debounce-prev-key");this.putPrivate(e,"debounce-prev-key",t.key),f=v!==t.key}if(!f&&this.private(e,"throttled"))return!1;a(),this.putPrivate(e,"throttled",!0),setTimeout(function(){return u.triggerCycle(e,"debounce-trigger")},d)}else setTimeout(function(){return u.triggerCycle(e,"debounce-trigger",h)},d);e.form&&this.once(e.form,"bind-debounce")&&e.form.addEventListener("submit",function(t){Array.from(new FormData(e.form).entries(),function(t){var n=L(t,2),i=n[0],r=(n[1],e.form.querySelector('[name="'.concat(i,'"]')));u.incCycle(r,"debounce-trigger"),u.deletePrivate(r,"throttled")})}),this.once(e,"bind-debounce")&&e.addEventListener("blur",function(t){return u.triggerCycle(e,"debounce-trigger")})}},triggerCycle:function(e,t,n){var i=L(this.private(e,t),2),r=i[0],o=i[1];n||(n=r),n===r&&(this.incCycle(e,t),o())},once:function(e,t){return!0!==this.private(e,t)&&(this.putPrivate(e,t,!0),!0)},incCycle:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},i=L(this.private(e,t)||[0,n],2),r=i[0];i[1];return r++,this.putPrivate(e,t,[r,n]),r},discardError:function(e,t,n){var i=t.getAttribute&&t.getAttribute(n),r=i&&e.querySelector("#".concat(i));r&&(this.private(r,"phx-has-focused")||this.private(r.form,"phx-has-submitted")||t.classList.add("phx-no-feedback"))},isPhxChild:function(e){return e.getAttribute&&e.getAttribute("data-phx-parent-id")},dispatchEvent:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n});e.dispatchEvent(i)},cloneNode:function(e,t){if(void 0===t)return e.cloneNode(!0);var n=e.cloneNode(!1);return n.innerHTML=t,n},mergeAttrs:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],i=t.attributes,r=i.length-1;r>=0;r--){var o=i[r].name;n.indexOf(o)<0&&e.setAttribute(o,t.getAttribute(o))}for(var a=e.attributes,u=a.length-1;u>=0;u--){var c=a[u].name;t.hasAttribute(c)||e.removeAttribute(c)}},mergeFocusedInput:function(e,t){e instanceof HTMLSelectElement||re.mergeAttrs(e,t,["value"]),t.readOnly?e.setAttribute("readonly",!0):e.removeAttribute("readonly")},hasSelectionRange:function(e){return e.setSelectionRange&&("text"===e.type||"textarea"===e.type)},restoreFocus:function(e,t,n){if(re.isTextualInput(e)){var i=e.matches(":focus");e.readOnly&&e.blur(),i||e.focus(),this.hasSelectionRange(e)&&e.setSelectionRange(t,n)}},isFormInput:function(e){return/^(?:input|select|textarea)$/i.test(e.tagName)&&"button"!==e.type},syncAttrsToProps:function(e){e instanceof HTMLInputElement&&J.indexOf(e.type.toLocaleLowerCase())>=0&&(e.checked=null!==e.getAttribute("checked"))},isTextualInput:function(e){return U.indexOf(e.type)>=0},isNowTriggerFormExternal:function(e,t){return e.getAttribute&&null!==e.getAttribute(t)},syncPendingRef:function(e,t,n){var i=e.getAttribute(M);return null===i||(re.isFormInput(e)||null!==e.getAttribute(n)?(re.putPrivate(e,M,t),!1):(H.forEach(function(n){e.classList.contains(n)&&t.classList.add(n)}),t.setAttribute(M,i),!0))},cleanChildNodes:function(e,t){if(re.isPhxUpdate(e,t,["append","prepend"])){var n=[];e.childNodes.forEach(function(e){e.id||(e.nodeType===Node.TEXT_NODE&&""===e.nodeValue.trim()||K("only HTML element tags with an id are allowed inside containers with phx-update.\n\n"+'removing illegal node: "'.concat((e.outerHTML||e.nodeValue).trim(),'"\n\n')),n.push(e))}),n.forEach(function(e){return e.remove()})}}},oe=function(){function e(t,n,i){A(this,e);var r=new Set,o=new Set(x(n.children).map(function(e){return e.id})),a=[];Array.from(t.children).forEach(function(e){if(e.id&&(r.add(e.id),o.has(e.id))){var t=e.previousElementSibling&&e.previousElementSibling.id;a.push({elementId:e.id,previousElementId:t})}}),this.containerId=n.id,this.updateType=i,this.elementsToModify=a,this.elementIdsToAdd=x(o).filter(function(e){return!r.has(e)})}return P(e,[{key:"perform",value:function(){var e=re.byId(this.containerId);this.elementsToModify.forEach(function(t){t.previousElementId?Z(document.getElementById(t.previousElementId),function(e){Z(document.getElementById(t.elementId),function(t){t.previousElementSibling&&t.previousElementSibling.id==e.id||e.insertAdjacentElement("afterend",t)})}):Z(document.getElementById(t.elementId),function(t){null==t.previousElementSibling||e.insertAdjacentElement("afterbegin",t)})}),"prepend"==this.updateType&&this.elementIdsToAdd.reverse().forEach(function(t){Z(document.getElementById(t),function(t){return e.insertAdjacentElement("afterbegin",t)})})}}]),e}(),ae=function(){function e(t,n,i,r,o){A(this,e),this.view=t,this.liveSocket=t.liveSocket,this.container=n,this.id=i,this.rootID=t.root.id,this.html=r,this.targetCID=o,this.cidPatch="number"==typeof this.targetCID,this.callbacks={beforeadded:[],beforeupdated:[],beforediscarded:[],beforephxChildAdded:[],afteradded:[],afterupdated:[],afterdiscarded:[],afterphxChildAdded:[]}}return P(e,null,[{key:"patchEl",value:function(e,t,n){b(e,t,{childrenOnly:!1,onBeforeElUpdated:function(e,t){if(n&&n.isSameNode(e)&&re.isFormInput(e))return re.mergeFocusedInput(e,t),!1}})}}]),P(e,[{key:"before",value:function(e,t){this.callbacks["before".concat(e)].push(t)}},{key:"after",value:function(e,t){this.callbacks["after".concat(e)].push(t)}},{key:"trackBefore",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];this.callbacks["before".concat(e)].forEach(function(e){return e.apply(void 0,n)})}},{key:"trackAfter",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];this.callbacks["after".concat(e)].forEach(function(e){return e.apply(void 0,n)})}},{key:"markPrunableContentForRemoval",value:function(){re.all(this.container,"[phx-update=append] > *, [phx-update=prepend] > *",function(e){e.setAttribute("data-phx-remove","")})}},{key:"perform",value:function(){var e=this,t=this.view,n=this.liveSocket,i=this.container,r=this.html,o=this.isCIDPatch()?this.targetCIDContainer():i;if(!this.isCIDPatch()||o){var a=n.getActiveElement(),u=a&&re.hasSelectionRange(a)?a:{},c=u.selectionStart,s=u.selectionEnd,l=n.binding("update"),d=n.binding("feedback-for"),h=n.binding("disable-with"),f=n.binding("trigger-action"),v=[],p=[],g=[],m=null,y=n.time("premorph container prep",function(){return e.buildDiffHTML(i,r,l,o)});return this.trackBefore("added",i),this.trackBefore("updated",i,i),n.time("morphdom",function(){b(o,y,{childrenOnly:null===o.getAttribute(j),onBeforeNodeAdded:function(t){return re.discardError(o,t,d),e.trackBefore("added",t),t},onNodeAdded:function(n){re.isNowTriggerFormExternal(n,f)&&(m=n),re.isPhxChild(n)&&t.ownsElement(n)&&e.trackAfter("phxChildAdded",n),v.push(n)},onNodeDiscarded:function(t){re.isPhxChild(t)&&n.destroyViewByEl(t),e.trackAfter("discarded",t)},onBeforeNodeDiscarded:function(t){return!(!t.getAttribute||null===t.getAttribute("data-phx-remove"))||(null===t.parentNode||!re.isPhxUpdate(t.parentNode,l,["append","prepend"])||!t.id)&&(!e.skipCIDSibling(t)&&(e.trackBefore("discarded",t),!0))},onElUpdated:function(e){re.isNowTriggerFormExternal(e,f)&&(m=e),p.push(e)},onBeforeElUpdated:function(t,n){if(re.cleanChildNodes(n,l),e.skipCIDSibling(n))return!1;if("ignore"===t.getAttribute(l))return e.trackBefore("updated",t,n),re.mergeAttrs(t,n),p.push(t),!1;if("number"===t.type&&t.validity&&t.validity.badInput)return!1;if(!re.syncPendingRef(t,n,h))return!1;if(re.isPhxChild(n)){var i=t.getAttribute(F);return re.mergeAttrs(t,n),t.setAttribute(F,i),t.setAttribute("data-phx-root-id",e.rootID),!1}return re.copyPrivates(n,t),re.discardError(o,n,d),a&&t.isSameNode(a)&&re.isFormInput(t)&&!e.forceFocusedSelectUpdate(t,n)?(e.trackBefore("updated",t,n),re.mergeFocusedInput(t,n),re.syncAttrsToProps(t),p.push(t),!1):(re.isPhxUpdate(n,l,["append","prepend"])&&g.push(new oe(t,n,n.getAttribute(l))),re.syncAttrsToProps(n),e.trackBefore("updated",t,n),!0)}})}),n.isDebugEnabled()&&function(){for(var e=new Set,t=document.querySelectorAll("*[id]"),n=0,i=t.length;n<i;n++)e.has(t[n].id)?console.error("Multiple IDs detected: ".concat(t[n].id,". Ensure unique element ids.")):e.add(t[n].id)}(),g.length>0&&n.time("post-morph append/prepend restoration",function(){g.forEach(function(e){return e.perform()})}),n.silenceEvents(function(){return re.restoreFocus(a,c,s)}),re.dispatchEvent(document,"phx:update"),v.forEach(function(t){return e.trackAfter("added",t)}),p.forEach(function(t){return e.trackAfter("updated",t)}),m&&(n.disconnect(),m.submit()),!0}}},{key:"forceFocusedSelectUpdate",value:function(e,t){return!0===e.multiple||e.innerHTML!=t.innerHTML}},{key:"isCIDPatch",value:function(){return this.cidPatch}},{key:"skipCIDSibling",value:function(e){return e.nodeType===Node.ELEMENT_NODE&&null!==e.getAttribute("data-phx-skip")}},{key:"targetCIDContainer",value:function(){if(this.isCIDPatch()){var e=k(re.findComponentNodeList(this.container,this.targetCID)),t=e[0];return 0===e.slice(1).length?t:t&&t.parentNode}}},{key:"buildDiffHTML",value:function(e,t,n,i){var r=this,o=this.isCIDPatch(),a=o&&i.getAttribute(j)===this.targetCID.toString();if(!o||a)return t;var u=null,c=document.createElement("template");u=re.cloneNode(i);var s=k(re.findComponentNodeList(u,this.targetCID)),l=s[0],d=s.slice(1);return c.innerHTML=t,d.forEach(function(e){return e.remove()}),Array.from(u.childNodes).forEach(function(e){e.id&&e.nodeType===Node.ELEMENT_NODE&&e.getAttribute(j)!==r.targetCID.toString()&&(e.setAttribute("data-phx-skip",""),e.innerHTML="")}),Array.from(c.content.childNodes).forEach(function(e){return u.insertBefore(e,l)}),l.remove(),u.outerHTML}}]),e}(),ue=function(){function e(t,n,i,r,o){var a=this;A(this,e),this.liveSocket=n,this.flash=o,this.parent=i,this.root=i?i.root:this,this.el=t,this.id=this.el.id,this.view=this.el.getAttribute(O),this.ref=0,this.childJoins=0,this.loaderTimer=null,this.pendingDiffs=[],this.href=r,this.joinCount=this.parent?this.parent.joinCount-1:0,this.joinPending=!0,this.destroyed=!1,this.joinCallback=function(){},this.stopCallback=function(){},this.pendingJoinOps=this.parent?null:[],this.viewHooks={},this.children=this.parent?null:{},this.root.children[this.id]={},this.channel=this.liveSocket.channel("lv:".concat(this.id),function(){return{url:a.href,params:a.connectParams(),session:a.getSession(),static:a.getStatic(),flash:a.flash}}),this.showLoader(this.liveSocket.loaderTimeout),this.bindChannel()}return P(e,[{key:"isMain",value:function(){return this.liveSocket.main===this}},{key:"connectParams",value:function(){var e=this.liveSocket.params(this.view),t=re.all(document,"[".concat(this.binding("track-static"),"]")).map(function(e){return e.src||e.href}).filter(function(e){return"string"==typeof e});return t.length>0&&(e._track_static=t),e._mounts=this.joinCount,e}},{key:"name",value:function(){return this.view}},{key:"isConnected",value:function(){return this.channel.canPush()}},{key:"getSession",value:function(){return this.el.getAttribute("data-phx-session")}},{key:"getStatic",value:function(){var e=this.el.getAttribute(F);return""===e?null:e}},{key:"destroy",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){};this.destroyAllChildren(),this.destroyed=!0,delete this.root.children[this.id],this.parent&&delete this.root.children[this.parent.id][this.id],clearTimeout(this.loaderTimer);var n=function(){for(var n in t(),e.viewHooks)e.viewHooks[n].__trigger__("beforeDestroy"),e.destroyHook(e.viewHooks[n])};this.log("destroyed",function(){return["the child has been removed from the parent"]}),this.channel.leave().receive("ok",n).receive("error",n).receive("timeout",n)}},{key:"setContainerClasses",value:function(){var e;this.el.classList.remove("phx-connected","phx-disconnected","phx-error"),(e=this.el.classList).add.apply(e,arguments)}},{key:"isLoading",value:function(){return this.el.classList.contains("phx-disconnected")}},{key:"showLoader",value:function(e){var t=this;if(clearTimeout(this.loaderTimer),e)this.loaderTimer=setTimeout(function(){return t.showLoader()},e);else{for(var n in this.viewHooks)this.viewHooks[n].__trigger__("disconnected");this.setContainerClasses("phx-disconnected")}}},{key:"hideLoader",value:function(){clearTimeout(this.loaderTimer),this.setContainerClasses("phx-connected")}},{key:"triggerReconnected",value:function(){for(var e in this.viewHooks)this.viewHooks[e].__trigger__("reconnected")}},{key:"log",value:function(e,t){this.liveSocket.log(this,e,t)}},{key:"withinTargets",value:function(e,t){var n=this;if(/^(0|[1-9]\d*)$/.test(e)){var i=re.findComponentNodeList(this.el,e);0===i.length?K("no component found matching phx-target of ".concat(e)):t(this,i[0])}else{var r=Array.from(document.querySelectorAll(e));0===r.length&&K('nothing found matching the phx-target selector "'.concat(e,'"')),r.forEach(function(e){return n.liveSocket.owner(e,function(n){return t(n,e)})})}}},{key:"applyDiff",value:function(e,t,n){this.log(e,function(){return["",z(t)]});var i=te.extract(t),r=i.diff,o=i.reply,a=i.events,u=i.title;return u&&re.putTitle(u),n({diff:r,reply:o,events:a}),o}},{key:"onJoin",value:function(e){var t=this,n=e.rendered;this.joinCount++,this.childJoins=0,this.joinPending=!0,this.flash=null,ie.dropLocal(this.name(),"consecutive-reloads"),this.applyDiff("mount",n,function(n){var i=n.diff,r=n.events;t.rendered=new te(t.id,i);var o=t.renderContainer(null,"join");t.dropPendingRefs();var a=t.formsForRecovery(o);t.joinCount>1&&a.length>0?a.forEach(function(e,n){t.pushFormRecovery(e,function(e){n===a.length-1&&t.onJoinComplete(e,o,r)})}):t.onJoinComplete(e,o,r)})}},{key:"dropPendingRefs",value:function(){re.all(this.el,"[".concat(M,"]"),function(e){return e.removeAttribute(M)})}},{key:"onJoinComplete",value:function(e,t,n){var i=this,r=e.live_patch;if(this.joinCount>1||this.parent&&!this.parent.isJoinPending())return this.applyJoinPatch(r,t,n);0===re.findPhxChildrenInFragment(t,this.id).filter(function(e){var t=e.id&&i.el.querySelector("#".concat(e.id)),n=t&&t.getAttribute(F);return n&&e.setAttribute(F,n),i.joinChild(e)}).length?this.parent?(this.root.pendingJoinOps.push([this,function(){return i.applyJoinPatch(r,t,n)}]),this.parent.ackJoin(this)):(this.onAllChildJoinsComplete(),this.applyJoinPatch(r,t,n)):this.root.pendingJoinOps.push([this,function(){return i.applyJoinPatch(r,t,n)}])}},{key:"attachTrueDocEl",value:function(){this.el=re.byId(this.id),this.el.setAttribute("data-phx-root-id",this.root.id)}},{key:"dispatchEvents",value:function(e){e.forEach(function(e){var t=L(e,2),n=t[0],i=t[1];window.dispatchEvent(new CustomEvent("phx:hook:".concat(n),{detail:i}))})}},{key:"applyJoinPatch",value:function(e,t,n){var i=this;this.attachTrueDocEl();var r=new ae(this,this.el,this.id,t,null);if(r.markPrunableContentForRemoval(),this.performPatch(r,!1),this.joinNewChildren(),re.all(this.el,"[".concat(this.binding("hook"),"]"),function(e){var t=i.addHook(e);t&&t.__trigger__("mounted")}),this.joinPending=!1,this.dispatchEvents(n),this.applyPendingUpdates(),e){var o=e.kind,a=e.to;this.liveSocket.historyPatch(a,o)}this.hideLoader(),this.joinCount>1&&this.triggerReconnected(),this.stopCallback()}},{key:"triggerBeforeUpdateHook",value:function(e,t){this.liveSocket.triggerDOM("onBeforeElUpdated",[e,t]);var n=this.getHook(e),i=n&&"ignore"===e.getAttribute(this.binding("update"));if(n&&!e.isEqualNode(t)&&(!i||!function(e,t){return JSON.stringify(e)===JSON.stringify(t)}(e.dataset,t.dataset)))return n.__trigger__("beforeUpdate"),n}},{key:"triggerUpdatedHook",value:function(e){e.__trigger__("updated")}},{key:"performPatch",value:function(e,t){var n=this,i=[],r=!1,o=new Set;return e.after("added",function(e){var t=n.addHook(e);t&&t.__trigger__("mounted")}),e.after("phxChildAdded",function(e){return r=!0}),e.before("updated",function(e,t){n.triggerBeforeUpdateHook(e,t)&&o.add(e.id)}),e.after("updated",function(e){o.has(e.id)&&n.triggerUpdatedHook(n.getHook(e))}),e.before("discarded",function(e){var t=n.getHook(e);t&&t.__trigger__("beforeDestroy")}),e.after("discarded",function(e){var t=n.componentID(e);"number"==typeof t&&-1===i.indexOf(t)&&i.push(t);var r=n.getHook(e);r&&n.destroyHook(r)}),e.perform(),t&&this.maybePushComponentsDestroyed(i),r}},{key:"joinNewChildren",value:function(){var e=this;re.findPhxChildren(this.el,this.id).forEach(function(t){return e.joinChild(t)})}},{key:"getChildById",value:function(e){return this.root.children[this.id][e]}},{key:"getDescendentByEl",value:function(e){return e.id===this.id?this:this.children[e.getAttribute("data-phx-parent-id")][e.id]}},{key:"destroyDescendent",value:function(e){for(var t in this.root.children)for(var n in this.root.children[t])if(n===e)return this.root.children[t][n].destroy()}},{key:"joinChild",value:function(t){if(!this.getChildById(t.id)){var n=new e(t,this.liveSocket,this);return this.root.children[this.id][n.id]=n,n.join(),this.childJoins++,!0}}},{key:"isJoinPending",value:function(){return this.joinPending}},{key:"ackJoin",value:function(e){this.childJoins--,0===this.childJoins&&(this.parent?this.parent.ackJoin(this):this.onAllChildJoinsComplete())}},{key:"onAllChildJoinsComplete",value:function(){this.joinCallback(),this.pendingJoinOps.forEach(function(e){var t=L(e,2),n=t[0],i=t[1];n.isDestroyed()||i()}),this.pendingJoinOps=[]}},{key:"update",value:function(e,t){var n=this;if(this.isJoinPending()||this.liveSocket.hasPendingLink())return this.pendingDiffs.push({diff:e,events:t});this.rendered.mergeDiff(e);var i=!1;this.rendered.isComponentOnlyDiff(e)?this.liveSocket.time("component patch complete",function(){re.findParentCIDs(n.el,n.rendered.componentCIDs(e)).forEach(function(t){n.componentPatch(n.rendered.getComponent(e,t),t)&&(i=!0)})}):Q(e)||this.liveSocket.time("full patch complete",function(){var t=n.renderContainer(e,"update"),r=new ae(n,n.el,n.id,t,null);i=n.performPatch(r,!0)}),this.dispatchEvents(t),i&&this.joinNewChildren()}},{key:"renderContainer",value:function(e,t){var n=this;return this.liveSocket.time("toString diff (".concat(t,")"),function(){var t=n.el.tagName,i=e?n.rendered.componentCIDs(e):null,r=n.rendered.toString(i);return"<".concat(t,">").concat(r,"</").concat(t,">")})}},{key:"componentPatch",value:function(e,t){if(Q(e))return!1;var n=this.rendered.componentToString(t),i=new ae(this,this.el,this.id,n,t);return this.performPatch(i,!0)}},{key:"getHook",value:function(e){return this.viewHooks[se.elementID(e)]}},{key:"addHook",value:function(e){if(!se.elementID(e)&&e.getAttribute){var t=e.getAttribute(this.binding("hook"));if(!t||this.ownsElement(e)){var n=this.liveSocket.getHookCallbacks(t);if(n){e.id||K('no DOM ID for hook "'.concat(t,'". Hooks require a unique ID on each element.'),e);var i=new se(this,e,n);return this.viewHooks[se.elementID(i.el)]=i,i}null!==t&&K('unknown hook found for "'.concat(t,'"'),e)}}}},{key:"destroyHook",value:function(e){e.__trigger__("destroyed"),e.__cleanup__(),delete this.viewHooks[se.elementID(e.el)]}},{key:"applyPendingUpdates",value:function(){var e=this;this.pendingDiffs.forEach(function(t){var n=t.diff,i=t.events;return e.update(n,i)}),this.pendingDiffs=[]}},{key:"onChannel",value:function(e,t){var n=this;this.liveSocket.onChannel(this.channel,e,function(e){n.isJoinPending()?n.root.pendingJoinOps.push([n,function(){return t(e)}]):t(e)})}},{key:"bindChannel",value:function(){var e=this;this.liveSocket.onChannel(this.channel,"diff",function(t){e.applyDiff("update",t,function(t){var n=t.diff,i=t.events;return e.update(n,i)})}),this.onChannel("redirect",function(t){var n=t.to,i=t.flash;return e.onRedirect({to:n,flash:i})}),this.onChannel("live_patch",function(t){return e.onLivePatch(t)}),this.onChannel("live_redirect",function(t){return e.onLiveRedirect(t)}),this.channel.onError(function(t){return e.onError(t)}),this.channel.onClose(function(){return e.onClose()})}},{key:"destroyAllChildren",value:function(){for(var e in this.root.children[this.id])this.getChildById(e).destroy()}},{key:"onLiveRedirect",value:function(e){var t=e.to,n=e.kind,i=e.flash,r=this.expandURL(t);this.liveSocket.historyRedirect(r,n,i)}},{key:"onLivePatch",value:function(e){var t=e.to,n=e.kind;this.href=this.expandURL(t),this.liveSocket.historyPatch(t,n)}},{key:"expandURL",value:function(e){return e.startsWith("/")?"".concat(window.location.protocol,"//").concat(window.location.host).concat(e):e}},{key:"onRedirect",value:function(e){var t=e.to,n=e.flash;this.liveSocket.redirect(t,n)}},{key:"isDestroyed",value:function(){return this.destroyed}},{key:"join",value:function(e){var t=this;this.parent||(this.stopCallback=this.liveSocket.withPageLoading({to:this.href,kind:"initial"})),this.joinCallback=function(){return e&&e(t,t.joinCount)},this.liveSocket.wrapPush(function(){return t.channel.join().receive("ok",function(e){return t.onJoin(e)}).receive("error",function(e){return t.onJoinError(e)}).receive("timeout",function(){return t.onJoinError({reason:"timeout"})})})}},{key:"onJoinError",value:function(e){return(e.redirect||e.live_redirect)&&(this.joinPending=!1,this.channel.leave()),e.redirect?this.onRedirect(e.redirect):e.live_redirect?this.onLiveRedirect(e.live_redirect):(this.log("error",function(){return["unable to join",e]}),this.liveSocket.reloadWithJitter(this))}},{key:"onClose",value:function(){if(!this.isDestroyed()){if(this.isJoinPending()||this.liveSocket.hasPendingLink())return this.liveSocket.reloadWithJitter(this);this.destroyAllChildren(),this.liveSocket.dropActiveElement(this),document.activeElement&&document.activeElement.blur(),this.liveSocket.isUnloaded()&&this.showLoader(200)}}},{key:"onError",value:function(e){this.onClose(),this.log("error",function(){return["view crashed",e]}),this.liveSocket.isUnloaded()||this.displayError()}},{key:"displayError",value:function(){this.isMain()&&re.dispatchEvent(window,"phx:page-loading-start",{to:this.href,kind:"error"}),this.showLoader(),this.setContainerClasses("phx-disconnected","phx-error")}},{key:"pushWithReply",value:function(e,t,n){var i=this,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},o=L(e?e():[null,[]],2),a=o[0],u=L(o[1],1)[0],c=function(){};return u&&null!==u.getAttribute(this.binding("page-loading"))&&(c=this.liveSocket.withPageLoading({kind:"element",target:u})),"number"!=typeof n.cid&&delete n.cid,this.liveSocket.wrapPush(function(){return i.channel.push(t,n,3e4).receive("ok",function(e){var t=null;null!==a&&i.undoRefs(a),e.diff&&(t=i.applyDiff("update",e.diff,function(e){var t=e.diff,n=e.events;i.update(t,n)})),e.redirect&&i.onRedirect(e.redirect),e.live_patch&&i.onLivePatch(e.live_patch),e.live_redirect&&i.onLiveRedirect(e.live_redirect),c(),r(e,t)})})}},{key:"undoRefs",value:function(e){var t=this;re.all(this.el,"[".concat(M,'="').concat(e,'"]'),function(e){e.removeAttribute(M),null!==e.getAttribute("data-phx-readonly")&&(e.readOnly=!1,e.removeAttribute("data-phx-readonly")),null!==e.getAttribute("data-phx-disabled")&&(e.disabled=!1,e.removeAttribute("data-phx-disabled")),H.forEach(function(t){return re.removeClass(e,t)});var n=e.getAttribute("data-phx-disable-with-restore");null!==n&&(e.innerText=n,e.removeAttribute("data-phx-disable-with-restore"));var i=re.private(e,M);if(i){var r=t.triggerBeforeUpdateHook(e,i);ae.patchEl(e,i,t.liveSocket.getActiveElement()),r&&t.triggerUpdatedHook(r),re.deletePrivate(e,M)}})}},{key:"putRef",value:function(e,t){var n=this.ref++,i=this.binding("disable-with");return e.forEach(function(e){e.classList.add("phx-".concat(t,"-loading")),e.setAttribute(M,n);var r=e.getAttribute(i);null!==r&&(e.getAttribute("data-phx-disable-with-restore")||e.setAttribute("data-phx-disable-with-restore",e.innerText),e.innerText=r)}),[n,e]}},{key:"componentID",value:function(e){var t=e.getAttribute&&e.getAttribute(j);return t?parseInt(t):null}},{key:"targetComponentID",value:function(e,t){return e.getAttribute(this.binding("target"))?this.closestComponentID(t):null}},{key:"closestComponentID",value:function(e){var t=this;return e?Z(e.closest("[".concat(j,"]")),function(e){return t.ownsElement(e)&&t.componentID(e)}):null}},{key:"pushHookEvent",value:function(e,t,n,i){var r=L(this.putRef([],"hook"),2),o=r[0],a=r[1];return this.pushWithReply(function(){return[o,a]},"event",{type:"hook",event:t,value:n,cid:this.closestComponentID(e)},function(e,t){return i(t,o)}),o}},{key:"extractMeta",value:function(e,t){for(var n=this.binding("value-"),i=0;i<e.attributes.length;i++){var r=e.attributes[i].name;r.startsWith(n)&&(t[r.replace(n,"")]=e.getAttribute(r))}return void 0!==e.value&&(t.value=e.value,"INPUT"===e.tagName&&J.indexOf(e.type)>=0&&!e.checked&&delete t.value),t}},{key:"pushEvent",value:function(e,t,n,i,r){var o=this;this.pushWithReply(function(){return o.putRef([t],e)},"event",{type:e,event:i,value:this.extractMeta(t,r),cid:this.targetComponentID(t,n)})}},{key:"pushKey",value:function(e,t,n,i,r){var o=this;this.pushWithReply(function(){return o.putRef([e],n)},"event",{type:n,event:i,value:this.extractMeta(e,r),cid:this.targetComponentID(e,t)})}},{key:"pushInput",value:function(e,t,n,i,r){var o=this;this.pushWithReply(function(){return o.putRef([e,e.form],"change")},"event",{type:"form",event:n,value:ee(e.form,{_target:i.name}),cid:this.targetComponentID(e.form,t)},r)}},{key:"pushFormSubmit",value:function(e,t,n,i){var r=this,o=function(e){return!G(e,"".concat(r.binding("update"),"=ignore"),e.form)};this.pushWithReply(function(){var t=re.all(e,"[".concat(r.binding("disable-with"),"]")),n=re.all(e,"button").filter(o),i=re.all(e,"input,textarea,select").filter(o);return n.forEach(function(e){e.setAttribute("data-phx-disabled",e.disabled),e.disabled=!0}),i.forEach(function(e){e.setAttribute("data-phx-readonly",e.readOnly),e.readOnly=!0}),e.setAttribute(r.binding("page-loading"),""),r.putRef([e].concat(t).concat(n).concat(i),"submit")},"event",{type:"form",event:n,value:ee(e),cid:this.targetComponentID(e,t)},i)}},{key:"pushFormRecovery",value:function(e,t){var n=this;this.liveSocket.withinOwners(e,function(i,r){var o=e.elements[0],a=e.getAttribute(n.binding("auto-recover"))||e.getAttribute(n.binding("change"));i.pushInput(o,r,a,o,t)})}},{key:"pushLinkPatch",value:function(e,t,n){var i=this,r=this.liveSocket.setPendingLink(e),o=t?function(){return i.putRef([t],"click")}:null;this.pushWithReply(o,"link",{url:e},function(t){t.link_redirect?i.liveSocket.replaceMain(e,null,n,r):i.liveSocket.commitPendingLink(r)&&(i.href=e,i.applyPendingUpdates(),n&&n())}).receive("timeout",function(){return i.liveSocket.redirect(window.location.href)})}},{key:"formsForRecovery",value:function(e){var t=this,n=this.binding("change"),i=document.createElement("template");return i.innerHTML=e,re.all(this.el,"form[".concat(n,"]")).filter(function(e){return t.ownsElement(e)}).filter(function(e){return"ignore"!==e.getAttribute(t.binding("auto-recover"))}).filter(function(e){return i.content.querySelector("form[".concat(n,'="').concat(e.getAttribute(n),'"]'))})}},{key:"maybePushComponentsDestroyed",value:function(e){var t=this,n=e.filter(function(e){return 0===re.findComponentNodeList(t.el,e).length});n.length>0&&this.pushWithReply(null,"cids_destroyed",{cids:n},function(){t.rendered.pruneCIDs(n)})}},{key:"ownsElement",value:function(e){return e.getAttribute("data-phx-parent-id")===this.id||Z(e.closest(B),function(e){return e.id})===this.id}},{key:"submitForm",value:function(e,t,n){var i=this;re.putPrivate(e,"phx-has-submitted",!0),this.liveSocket.blurActiveElement(this),this.pushFormSubmit(e,t,n,function(){i.liveSocket.restorePreviouslyActiveFocus()})}},{key:"binding",value:function(e){return this.liveSocket.binding(e)}}]),e}(),ce=1,se=function(){function e(t,n,i){for(var r in A(this,e),this.__view=t,this.__liveSocket=t.liveSocket,this.__callbacks=i,this.__listeners=new Set,this.el=n,this.viewName=t.name(),this.el.phxHookId=this.constructor.makeID(),this.__callbacks)this[r]=this.__callbacks[r]}return P(e,null,[{key:"makeID",value:function(){return ce++}},{key:"elementID",value:function(e){return e.phxHookId}}]),P(e,[{key:"pushEvent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){};return this.__view.pushHookEvent(null,e,t,n)}},{key:"pushEventTo",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){};return this.__view.withinTargets(e,function(e,r){return e.pushHookEvent(r,t,n,i)})}},{key:"handleEvent",value:function(e,t){var n=function(n,i){return i?e:t(n.detail)};return window.addEventListener("phx:hook:".concat(e),n),this.__listeners.add(n),n}},{key:"removeHandleEvent",value:function(e){var t=e(null,!0);window.removeEventListener("phx:hook:".concat(t),e),this.__listeners.delete(e)}},{key:"__cleanup__",value:function(){var e=this;this.__listeners.forEach(function(t){return e.removeHandleEvent(t)})}},{key:"__trigger__",value:function(e){var t=this.__callbacks[e];t&&t.call(this)}}]),e}();t.default=ne},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){(function(t){t.Phoenix||(t.Phoenix={}),e.exports=t.Phoenix.LiveView=n(0)}).call(this,n(1))}])});
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.phoenix_live_view=t():e.phoenix_live_view=t()}(this,function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:i})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";n.r(t);var i,r=11;var o="http://www.w3.org/1999/xhtml",a="undefined"==typeof document?void 0:document,u=!!a&&"content"in a.createElement("template"),s=!!a&&a.createRange&&"createContextualFragment"in a.createRange();function c(e){return e=e.trim(),u?function(e){var t=a.createElement("template");return t.innerHTML=e,t.content.childNodes[0]}(e):s?function(e){return i||(i=a.createRange()).selectNode(a.body),i.createContextualFragment(e).childNodes[0]}(e):function(e){var t=a.createElement("body");return t.innerHTML=e,t.childNodes[0]}(e)}function l(e,t){var n,i,r=e.nodeName,o=t.nodeName;return r===o||(n=r.charCodeAt(0),i=o.charCodeAt(0),n<=90&&i>=97?r===o.toUpperCase():i<=90&&n>=97&&o===r.toUpperCase())}function d(e,t,n){e[n]!==t[n]&&(e[n]=t[n],e[n]?e.setAttribute(n,""):e.removeAttribute(n))}var h={OPTION:function(e,t){var n=e.parentNode;if(n){var i=n.nodeName.toUpperCase();"OPTGROUP"===i&&(i=(n=n.parentNode)&&n.nodeName.toUpperCase()),"SELECT"!==i||n.hasAttribute("multiple")||(e.hasAttribute("selected")&&!t.selected&&(e.setAttribute("selected","selected"),e.removeAttribute("selected")),n.selectedIndex=-1)}d(e,t,"selected")},INPUT:function(e,t){d(e,t,"checked"),d(e,t,"disabled"),e.value!==t.value&&(e.value=t.value),t.hasAttribute("value")||e.removeAttribute("value")},TEXTAREA:function(e,t){var n=t.value;e.value!==n&&(e.value=n);var i=e.firstChild;if(i){var r=i.nodeValue;if(r==n||!n&&r==e.placeholder)return;i.nodeValue=n}},SELECT:function(e,t){if(!t.hasAttribute("multiple")){for(var n,i,r=-1,o=0,a=e.firstChild;a;)if("OPTGROUP"===(i=a.nodeName&&a.nodeName.toUpperCase()))a=(n=a).firstChild;else{if("OPTION"===i){if(a.hasAttribute("selected")){r=o;break}o++}!(a=a.nextSibling)&&n&&(a=n.nextSibling,n=null)}e.selectedIndex=r}}},f=1,v=11,p=3,g=8;function m(){}function y(e){if(e)return e.getAttribute&&e.getAttribute("id")||e.id}var b=function(e){return function(t,n,i){if(i||(i={}),"string"==typeof n)if("#document"===t.nodeName||"HTML"===t.nodeName||"BODY"===t.nodeName){var r=n;(n=a.createElement("html")).innerHTML=r}else n=c(n);var u=i.getNodeKey||y,s=i.onBeforeNodeAdded||m,d=i.onNodeAdded||m,b=i.onBeforeElUpdated||m,k=i.onElUpdated||m,w=i.onBeforeNodeDiscarded||m,A=i.onNodeDiscarded||m,E=i.onBeforeElChildrenUpdated||m,S=!0===i.childrenOnly,x=Object.create(null),C=[];function P(e){C.push(e)}function L(e,t,n){!1!==w(e)&&(t&&t.removeChild(e),A(e),function e(t,n){if(t.nodeType===f)for(var i=t.firstChild;i;){var r=void 0;n&&(r=u(i))?P(r):(A(i),i.firstChild&&e(i,n)),i=i.nextSibling}}(e,n))}function I(e){d(e);for(var t=e.firstChild;t;){var n=t.nextSibling,i=u(t);if(i){var r=x[i];r&&l(t,r)?(t.parentNode.replaceChild(r,t),T(r,t)):I(t)}else I(t);t=n}}function T(t,n,i){var r=u(n);if(r&&delete x[r],!i){if(!1===b(t,n))return;if(e(t,n),k(t),!1===E(t,n))return}"TEXTAREA"!==t.nodeName?function(e,t){var n,i,r,o,c,d=t.firstChild,v=e.firstChild;e:for(;d;){for(o=d.nextSibling,n=u(d);v;){if(r=v.nextSibling,d.isSameNode&&d.isSameNode(v)){d=o,v=r;continue e}i=u(v);var m=v.nodeType,y=void 0;if(m===d.nodeType&&(m===f?(n?n!==i&&((c=x[n])?r===c?y=!1:(e.insertBefore(c,v),i?P(i):L(v,e,!0),v=c):y=!1):i&&(y=!1),(y=!1!==y&&l(v,d))&&T(v,d)):m!==p&&m!=g||(y=!0,v.nodeValue!==d.nodeValue&&(v.nodeValue=d.nodeValue))),y){d=o,v=r;continue e}i?P(i):L(v,e,!0),v=r}if(n&&(c=x[n])&&l(c,d))e.appendChild(c),T(c,d);else{var b=s(d);!1!==b&&(b&&(d=b),d.actualize&&(d=d.actualize(e.ownerDocument||a)),e.appendChild(d),I(d))}d=o,v=r}!function(e,t,n){for(;t;){var i=t.nextSibling;(n=u(t))?P(n):L(t,e,!0),t=i}}(e,v,i);var k=h[e.nodeName];k&&k(e,t)}(t,n):h.TEXTAREA(t,n)}!function e(t){if(t.nodeType===f||t.nodeType===v)for(var n=t.firstChild;n;){var i=u(n);i&&(x[i]=n),e(n),n=n.nextSibling}}(t);var _=t,D=_.nodeType,R=n.nodeType;if(!S)if(D===f)R===f?l(t,n)||(A(t),_=function(e,t){for(var n=e.firstChild;n;){var i=n.nextSibling;t.appendChild(n),n=i}return t}(t,function(e,t){return t&&t!==o?a.createElementNS(t,e):a.createElement(e)}(n.nodeName,n.namespaceURI))):_=n;else if(D===p||D===g){if(R===D)return _.nodeValue!==n.nodeValue&&(_.nodeValue=n.nodeValue),_;_=n}if(_===n)A(t);else{if(n.isSameNode&&n.isSameNode(_))return;if(T(_,n,S),C)for(var N=0,O=C.length;N<O;N++){var H=x[C[N]];H&&L(H,H.parentNode,!1)}}return!S&&_!==t&&t.parentNode&&(_.actualize&&(_=_.actualize(t.ownerDocument||a)),t.parentNode.replaceChild(_,t)),_}}(function(e,t){var n,i,o,a,u=t.attributes;if(t.nodeType!==r&&e.nodeType!==r){for(var s=u.length-1;s>=0;s--)i=(n=u[s]).name,o=n.namespaceURI,a=n.value,o?(i=n.localName||i,e.getAttributeNS(o,i)!==a&&("xmlns"===n.prefix&&(i=n.name),e.setAttributeNS(o,i,a))):e.getAttribute(i)!==a&&e.setAttribute(i,a);for(var c=e.attributes,l=c.length-1;l>=0;l--)i=(n=c[l]).name,(o=n.namespaceURI)?(i=n.localName||i,t.hasAttributeNS(o,i)||e.removeAttributeNS(o,i)):t.hasAttribute(i)||e.removeAttribute(i)}});function k(e){return P(e)||S(e)||L(e)||C()}function w(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,i)}return n}function A(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function E(e){return function(e){if(Array.isArray(e))return I(e)}(e)||S(e)||L(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}function x(e,t){return P(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],i=!0,r=!1,o=void 0;try{for(var a,u=e[Symbol.iterator]();!(i=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);i=!0);}catch(e){r=!0,o=e}finally{try{i||null==u.return||u.return()}finally{if(r)throw o}}return n}(e,t)||L(e,t)||C()}function C(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function P(e){if(Array.isArray(e))return e}function L(e,t){if(e){if("string"==typeof e)return I(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?I(e,t):void 0}}function I(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}function T(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function D(e,t,n){return t&&_(e.prototype,t),n&&_(e,n),e}function R(e){"@babel/helpers - typeof";return(R="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}n.d(t,"debug",function(){return K}),n.d(t,"Rendered",function(){return ue}),n.d(t,"LiveSocket",function(){return se}),n.d(t,"Browser",function(){return ce}),n.d(t,"DOM",function(){return le}),n.d(t,"View",function(){return fe});var N=[1e3,3e3],O="data-phx-view",H=["phx-click-loading","phx-change-loading","phx-submit-loading","phx-keydown-loading","phx-keyup-loading","phx-blur-loading","phx-focus-loading"],j="data-phx-component",F="data-phx-ref",M="[".concat(O,"]"),B=["text","textarea","number","email","password","search","tel","url","date","time"],U=["checkbox","radio"],J="data-phx-static",V=1,W="phx-",q={debounce:300,throttle:300},z=function(e,t){return console.error&&console.error(e,t)};var K=function(e,t,n,i){e.liveSocket.isDebugEnabled()&&console.log("".concat(e.id," ").concat(t,": ").concat(n," - "),i)},$=function(e){return"function"==typeof e?e:function(){return e}},X=function(e){return JSON.parse(JSON.stringify(e))},G=function(e,t,n){do{if(e.matches("[".concat(t,"]")))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType&&!(n&&n.isSameNode(e)||e.matches(M)));return null},Y=function(e){return null!==e&&"object"===R(e)&&!(e instanceof Array)},Q=function(e){for(var t in e)return!1;return!0},Z=function(e,t){return e&&t(e)},ee=function(){function e(t,n,i){T(this,e),this.ref=ie.genFileRef(n),this.fileEl=t,this.file=n,this.view=i,this.meta=null,this._isCancelled=!1,this._isDone=!1,this._progress=0,this._onDone=function(){}}return D(e,null,[{key:"isActive",value:function(e,t){var n=void 0===t._phxRef,i=e.getAttribute("data-phx-active-refs").split(",").indexOf(ie.genFileRef(t))>=0;return t.size>0&&(n||i)}},{key:"isPreflighted",value:function(e,t){var n=e.getAttribute("data-phx-preflighted-refs").split(",").indexOf(ie.genFileRef(t))>=0;return n&&this.isActive(e,t)}}]),D(e,[{key:"metadata",value:function(){return this.meta}},{key:"progress",value:function(e){var t=this;this._progress=Math.floor(e),this._progress>=100?(this._progress=100,this._isDone=!0,this.view.pushFileProgress(this.fileEl,this.ref,100,function(){ie.untrackFile(t.fileEl,t.file),t._onDone()})):this.view.pushFileProgress(this.fileEl,this.ref,this._progress)}},{key:"cancel",value:function(){this._isCancelled=!0,this._isDone=!0,this._onDone()}},{key:"isDone",value:function(){return this._isDone}},{key:"error",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"failed";this.view.pushFileProgress(this.fileEl,this.ref,{error:e})}},{key:"onDone",value:function(e){this._onDone=e}},{key:"toPreflightPayload",value:function(){return{last_modified:this.file.lastModified,name:this.file.name,size:this.file.size,type:this.file.type,ref:this.ref}}},{key:"uploader",value:function(e){if(this.meta.uploader){var t=e[this.meta.uploader]||z("no uploader configured for ".concat(this.meta.uploader));return{name:this.meta.uploader,callback:t}}return{name:"channel",callback:re}}},{key:"zipPostFlight",value:function(e){this.meta=e.entries[this.ref],this.meta||z("no preflight upload response returned with ref ".concat(this.ref),{input:this.fileEl,response:e})}}]),e}(),te={LiveFileUpload:{preflightedRefs:function(){return this.el.getAttribute("data-phx-preflighted-refs")},mounted:function(){this.preflightedWas=this.preflightedRefs()},updated:function(){var e=this.preflightedRefs();this.preflightedWas!==e&&(this.preflightedWas=e,""===e&&this.__view.cancelSubmit(this.el.form))}}};te.LiveImgPreview={mounted:function(){var e=this;this.ref=this.el.getAttribute("data-phx-entry-ref"),this.inputEl=document.getElementById(this.el.getAttribute("data-phx-upload-ref")),ie.getEntryDataURL(this.inputEl,this.ref,function(t){return e.el.src=t})}};var ne=0,ie=function(){function e(t,n,i){T(this,e),this.view=n,this.onComplete=i,this._entries=Array.from(e.filesAwaitingPreflight(t)||[]).map(function(e){return new ee(t,e,n)}),this.numEntriesInProgress=this._entries.length}return D(e,null,[{key:"genFileRef",value:function(e){var t=e._phxRef;return void 0!==t?t:(e._phxRef=(ne++).toString(),e._phxRef)}},{key:"getEntryDataURL",value:function(e,t,n){var i=this,r=this.activeFiles(e).find(function(e){return i.genFileRef(e)===t}),o=new FileReader;o.onload=function(e){return n(e.target.result)},o.readAsDataURL(r)}},{key:"hasUploadsInProgress",value:function(e){var t=0;return le.all(e,'input[type="file"]',function(e){e.getAttribute("data-phx-preflighted-refs")!==e.getAttribute("data-phx-done-refs")&&t++}),t>0}},{key:"serializeUploads",value:function(e){var t=this,n={};return this.activeFiles(e,"serialize").forEach(function(i){var r={path:e.name},o=e.getAttribute("data-phx-upload-ref");n[o]=n[o]||[],r.ref=t.genFileRef(i),r.name=i.name,r.type=i.type,r.size=i.size,n[o].push(r)}),n}},{key:"clearFiles",value:function(e){e.value=null,le.putPrivate(e,"files",[])}},{key:"untrackFile",value:function(e,t){le.putPrivate(e,"files",le.private(e,"files").filter(function(e){return!Object.is(e,t)}))}},{key:"trackFiles",value:function(e,t){var n=this;if(null!==e.getAttribute("multiple")){var i=t.filter(function(t){return!n.activeFiles(e).find(function(e){return Object.is(e,t)})});le.putPrivate(e,"files",this.activeFiles(e).concat(i)),e.value=null}else le.putPrivate(e,"files",t)}},{key:"activeFileInputs",value:function(e){var t=this,n=e.querySelectorAll('input[type="file"]');return Array.from(n).filter(function(e){return e.files&&t.activeFiles(e).length>0})}},{key:"activeFiles",value:function(e){return(le.private(e,"files")||[]).filter(function(t){return ee.isActive(e,t)})}},{key:"inputsAwaitingPreflight",value:function(e){var t=this,n=e.querySelectorAll('input[type="file"]');return Array.from(n).filter(function(e){return t.filesAwaitingPreflight(e).length>0})}},{key:"filesAwaitingPreflight",value:function(e){return this.activeFiles(e).filter(function(t){return!ee.isPreflighted(e,t)})}}]),D(e,[{key:"entries",value:function(){return this._entries}},{key:"initAdapterUpload",value:function(e,t,n){var i=this;this._entries=this._entries.map(function(t){return t.zipPostFlight(e),t.onDone(function(){i.numEntriesInProgress--,0===i.numEntriesInProgress&&i.onComplete()}),t});var r=this._entries.reduce(function(e,t){var i=t.uploader(n.uploaders),r=i.name,o=i.callback;return e[r]=e[r]||{callback:o,entries:[]},e[r].entries.push(t),e},{});for(var o in r){var a=r[o];(0,a.callback)(a.entries,t,e,n)}}}]),e}(),re=function(e,t,n,i){e.forEach(function(e){new oe(e,n.config.chunk_size,i).upload()})},oe=function(){function e(t,n,i){T(this,e),this.liveSocket=i,this.entry=t,this.offset=0,this.chunkSize=n,this.uploadChannel=i.channel("lvu:".concat(t.ref),{token:t.metadata()})}return D(e,[{key:"upload",value:function(){var e=this;this.uploadChannel.join().receive("ok",function(t){return e.readNextChunk()}).receive("error",function(t){e.uploadChannel.leave(),e.entry.error()})}},{key:"isDone",value:function(){return this.offset>=this.entry.file.size}},{key:"readNextChunk",value:function(){var e=this,t=new window.FileReader,n=this.entry.file.slice(this.offset,this.chunkSize+this.offset);t.onload=function(t){if(null!==t.target.error)return z("Read error: "+t.target.error);e.offset+=t.target.result.byteLength,e.pushChunk(t.target.result)},t.readAsArrayBuffer(n)}},{key:"pushChunk",value:function(e){var t=this;this.uploadChannel.isJoined()&&this.uploadChannel.push("chunk",e).receive("ok",function(){t.entry.progress(t.offset/t.entry.file.size*100),t.isDone()||setTimeout(function(){return t.readNextChunk()},t.liveSocket.getLatencySim()||0)})}}]),e}(),ae=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new FormData(e),i=[];n.forEach(function(e,t,n){e instanceof File&&i.push(t)}),i.forEach(function(e){return n.delete(e)});var r,o=new URLSearchParams,a=function(e){if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=L(e))){var t=0,n=function(){};return{s:n,n:function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}},e:function(e){throw e},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,r,o=!0,a=!1;return{s:function(){i=e[Symbol.iterator]()},n:function(){var e=i.next();return o=e.done,e},e:function(e){a=!0,r=e},f:function(){try{o||null==i.return||i.return()}finally{if(a)throw r}}}}(n.entries());try{for(a.s();!(r=a.n()).done;){var u=x(r.value,2),s=u[0],c=u[1];o.append(s,c)}}catch(e){a.e(e)}finally{a.f()}for(var l in t)o.append(l,t[l]);return o.toString()},ue=function(){function e(t,n){T(this,e),this.viewId=t,this.rendered={},this.mergeDiff(n)}return D(e,null,[{key:"extract",value:function(e){var t=e.r,n=e.e,i=e.t;return delete e.r,delete e.e,delete e.t,{diff:e,title:i,reply:t||null,events:n||[]}}}]),D(e,[{key:"parentViewId",value:function(){return this.viewId}},{key:"toString",value:function(e){return this.recursiveToString(this.rendered,this.rendered.c,e)}},{key:"recursiveToString",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.c,n=arguments.length>2?arguments[2]:void 0,i={buffer:"",components:t,onlyCids:n=n?new Set(n):null};return this.toOutputBuffer(e,i),i.buffer}},{key:"componentCIDs",value:function(e){return Object.keys(e.c||{}).map(function(e){return parseInt(e)})}},{key:"isComponentOnlyDiff",value:function(e){return!!e.c&&1===Object.keys(e).length}},{key:"getComponent",value:function(e,t){return e.c[t]}},{key:"mergeDiff",value:function(e){var t=e.c;if(delete e.c,this.rendered=this.recursiveMerge(this.rendered,e),this.rendered.c=this.rendered.c||{},t){var n=this.rendered.c;for(var i in t){var r=t[i],o=r,a=o.s;if("number"==typeof a){for(;"number"==typeof a;)a=(o=a>0?t[a]:n[-a]).s;o=X(o),this.doRecursiveMerge(o,r),o.s=a}else o=n[i]||{},o=this.recursiveMerge(o,r);t[i]=o}for(var u in t)n[u]=t[u];e.c=t}}},{key:"recursiveMerge",value:function(e,t){return void 0!==t.s?t:(this.doRecursiveMerge(e,t),e)}},{key:"doRecursiveMerge",value:function(e,t){for(var n in t){var i=t[n],r=e[n];Y(i)&&void 0===i.s&&Y(r)?this.doRecursiveMerge(r,i):e[n]=i}}},{key:"componentToString",value:function(e){return this.recursiveCIDToString(this.rendered.c,e)}},{key:"pruneCIDs",value:function(e){var t=this;e.forEach(function(e){return delete t.rendered.c[e]})}},{key:"get",value:function(){return this.rendered}},{key:"isNewFingerprint",value:function(){return!!(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).s}},{key:"toOutputBuffer",value:function(e,t){if(e.d)return this.comprehensionToBuffer(e,t);var n=e.s;t.buffer+=n[0];for(var i=1;i<n.length;i++)this.dynamicToBuffer(e[i-1],t),t.buffer+=n[i]}},{key:"comprehensionToBuffer",value:function(e,t){for(var n=e.d,i=e.s,r=0;r<n.length;r++){var o=n[r];t.buffer+=i[0];for(var a=1;a<i.length;a++)this.dynamicToBuffer(o[a-1],t),t.buffer+=i[a]}}},{key:"dynamicToBuffer",value:function(e,t){"number"==typeof e?t.buffer+=this.recursiveCIDToString(t.components,e,t.onlyCids):Y(e)?this.toOutputBuffer(e,t):t.buffer+=e}},{key:"recursiveCIDToString",value:function(e,t,n){var i=this,r=e[t]||z("no component for CID ".concat(t),e),o=document.createElement("template");o.innerHTML=this.recursiveToString(r,e,n);var a=o.content,u=n&&!n.has(t),s=x(Array.from(a.childNodes).reduce(function(e,n,r){var a=x(e,2),s=a[0],c=a[1];return n.nodeType===Node.ELEMENT_NODE?n.getAttribute(j)?[s,!0]:(n.setAttribute(j,t),n.id||(n.id="".concat(i.parentViewId(),"-").concat(t,"-").concat(r)),u&&(n.setAttribute("data-phx-skip",""),n.innerHTML=""),[!0,c]):""!==n.nodeValue.trim()?(z("only HTML element tags are allowed at the root of components.\n\n"+'got: "'.concat(n.nodeValue.trim(),'"\n\n')+"within:\n",o.innerHTML.trim()),n.replaceWith(i.createSpan(n.nodeValue,t)),[!0,c]):(n.remove(),[s,c])},[!1,!1]),2),c=s[0],l=s[1];return c||l?!c&&l?(z("expected at least one HTML element tag directly inside a component, but only subcomponents were found. A component must render at least one HTML tag directly inside itself.",o.innerHTML.trim()),o.innerHTML):o.innerHTML:(z("expected at least one HTML element tag inside a component, but the component is empty:\n",o.innerHTML.trim()),this.createSpan("",t).outerHTML)}},{key:"createSpan",value:function(e,t){var n=document.createElement("span");return n.innerText=e,n.setAttribute(j,t),n}}]),e}(),se=function(){function e(t,n){var i=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(T(this,e),this.unloaded=!1,!n||"Object"===n.constructor.name)throw new Error('\n a phoenix Socket must be provided as the second argument to the LiveSocket constructor. For example:\n\n import {Socket} from "phoenix"\n import {LiveSocket} from "phoenix_live_view"\n let liveSocket = new LiveSocket("/live", Socket, {...})\n ');this.socket=new n(t,r),this.bindingPrefix=r.bindingPrefix||W,this.opts=r,this.params=$(r.params||{}),this.viewLogger=r.viewLogger,this.metadataCallbacks=r.metadata||{},this.defaults=Object.assign(X(q),r.defaults||{}),this.activeElement=null,this.prevActive=null,this.silenced=!1,this.main=null,this.linkRef=0,this.roots={},this.href=window.location.href,this.pendingLink=null,this.currentLocation=X(window.location),this.hooks=r.hooks||{},this.uploaders=r.uploaders||{},this.loaderTimeout=r.loaderTimeout||V,this.boundTopLevelEvents=!1,this.domCallbacks=Object.assign({onNodeAdded:$(),onBeforeElUpdated:$()},r.dom||{}),window.addEventListener("unload",function(e){i.unloaded=!0}),this.socket.onOpen(function(){i.isUnloaded()&&window.location.reload()})}return D(e,[{key:"isProfileEnabled",value:function(){return"true"===sessionStorage.getItem("phx:live-socket:profiling")}},{key:"isDebugEnabled",value:function(){return"true"===sessionStorage.getItem("phx:live-socket:debug")}},{key:"enableDebug",value:function(){sessionStorage.setItem("phx:live-socket:debug","true")}},{key:"enableProfiling",value:function(){sessionStorage.setItem("phx:live-socket:profiling","true")}},{key:"disableDebug",value:function(){sessionStorage.removeItem("phx:live-socket:debug")}},{key:"disableProfiling",value:function(){sessionStorage.removeItem("phx:live-socket:profiling")}},{key:"enableLatencySim",value:function(e){this.enableDebug(),console.log("latency simulator enabled for the duration of this browser session. Call disableLatencySim() to disable"),sessionStorage.setItem("phx:live-socket:latency-sim",e)}},{key:"disableLatencySim",value:function(){sessionStorage.removeItem("phx:live-socket:latency-sim")}},{key:"getLatencySim",value:function(){var e=sessionStorage.getItem("phx:live-socket:latency-sim");return e?parseInt(e):null}},{key:"getSocket",value:function(){return this.socket}},{key:"connect",value:function(){var e=this,t=function(){e.joinRootViews()&&(e.bindTopLevelEvents(),e.socket.connect())};["complete","loaded","interactive"].indexOf(document.readyState)>=0?t():document.addEventListener("DOMContentLoaded",function(){return t()})}},{key:"disconnect",value:function(e){this.socket.disconnect(e)}},{key:"triggerDOM",value:function(e,t){var n;(n=this.domCallbacks)[e].apply(n,E(t))}},{key:"time",value:function(e,t){if(!this.isProfileEnabled()||!console.time)return t();console.time(e);var n=t();return console.timeEnd(e),n}},{key:"log",value:function(e,t,n){if(this.viewLogger){var i=x(n(),2),r=i[0],o=i[1];this.viewLogger(e,t,r,o)}else if(this.isDebugEnabled()){var a=x(n(),2),u=a[0],s=a[1];K(e,t,u,s)}}},{key:"onChannel",value:function(e,t,n){var i=this;e.on(t,function(e){var t=i.getLatencySim();t?(console.log("simulating ".concat(t,"ms of latency from server to client")),setTimeout(function(){return n(e)},t)):n(e)})}},{key:"wrapPush",value:function(e,t,n){var i=this,r=this.getLatencySim();if(!r)return t.timeout?n().receive("timeout",function(){e.isDestroyed()||i.reloadWithJitter(e,function(){i.log(e,"timeout",function(){return["received timeout while communicating with server. Falling back to hard refresh for recovery"]})})}):n();console.log("simulating ".concat(r,"ms of latency from client to server"));var o={receives:[],receive:function(e,t){this.receives.push([e,t])}};return setTimeout(function(){o.receives.reduce(function(e,t){var n=x(t,2),i=n[0],r=n[1];return e.receive(i,r)},n())},r),o}},{key:"reloadWithJitter",value:function(e,t){var n=this;e.destroy(),this.disconnect();var i=N[0],r=N[1],o=Math.floor(Math.random()*(r-i+1))+i,a=ce.updateLocal(e.name(),"consecutive-reloads",0,function(e){return e+1});t?t():this.log(e,"join",function(){return["encountered ".concat(a," consecutive reloads")]}),a>10&&(this.log(e,"join",function(){return["exceeded ".concat(10," consecutive reloads. Entering failsafe mode")]}),o=3e4),setTimeout(function(){n.hasPendingLink()?window.location=n.pendingLink:window.location.reload()},o)}},{key:"getHookCallbacks",value:function(e){return e&&e.startsWith("Phoenix.")?te[e.split(".")[1]]:this.hooks[e]}},{key:"isUnloaded",value:function(){return this.unloaded}},{key:"isConnected",value:function(){return this.socket.isConnected()}},{key:"getBindingPrefix",value:function(){return this.bindingPrefix}},{key:"binding",value:function(e){return"".concat(this.getBindingPrefix()).concat(e)}},{key:"channel",value:function(e,t){return this.socket.channel(e,t)}},{key:"joinRootViews",value:function(){var e=this,t=!1;return le.all(document,"".concat(M,":not([").concat("data-phx-parent-id","])"),function(n){if(!e.getRootById(n.id)){var i=e.joinRootView(n,e.getHref());e.root=e.root||i,n.getAttribute("data-phx-main")&&(e.main=i)}t=!0}),t}},{key:"redirect",value:function(e,t){this.disconnect(),ce.redirect(e,t)}},{key:"replaceMain",value:function(e,t){var n=this,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:this.setPendingLink(e),o=this.main.el;this.main.showLoader(this.loaderTimeout),this.main.destroy(),ce.fetchPage(e,function(a,u){if(200!==a)return n.redirect(e);var s=document.createElement("template");s.innerHTML=u;var c=s.content.childNodes[0];if(!c||!n.isPhxView(c))return n.redirect(e);n.joinRootView(c,e,t,function(e,t){1===t&&(n.commitPendingLink(r)?(o.replaceWith(e.el),n.main=e,i&&i()):e.destroy())})})}},{key:"isPhxView",value:function(e){return e.getAttribute&&null!==e.getAttribute(O)}},{key:"joinRootView",value:function(e,t,n,i){var r=new fe(e,this,null,t,n);return this.roots[r.id]=r,r.join(i),r}},{key:"owner",value:function(e,t){var n=this,i=Z(e.closest(M),function(e){return n.getViewByEl(e)});i&&t(i)}},{key:"withinOwners",value:function(e,t){var n=this;this.owner(e,function(i){var r=e.getAttribute(n.binding("target"));null===r?t(i,e):i.withinTargets(r,t)})}},{key:"getViewByEl",value:function(e){var t=e.getAttribute("data-phx-root-id");return Z(this.getRootById(t),function(t){return t.getDescendentByEl(e)})}},{key:"getRootById",value:function(e){return this.roots[e]}},{key:"destroyAllViews",value:function(){for(var e in this.roots)this.roots[e].destroy(),delete this.roots[e]}},{key:"destroyViewByEl",value:function(e){var t=this.getRootById(e.getAttribute("data-phx-root-id"));t&&t.destroyDescendent(e.id)}},{key:"setActiveElement",value:function(e){var t=this;if(this.activeElement!==e){this.activeElement=e;var n=function(){e===t.activeElement&&(t.activeElement=null),e.removeEventListener("mouseup",t),e.removeEventListener("touchend",t)};e.addEventListener("mouseup",n),e.addEventListener("touchend",n)}}},{key:"getActiveElement",value:function(){return document.activeElement===document.body?this.activeElement||document.activeElement:document.activeElement||document.body}},{key:"dropActiveElement",value:function(e){this.prevActive&&e.ownsElement(this.prevActive)&&(this.prevActive=null)}},{key:"restorePreviouslyActiveFocus",value:function(){this.prevActive&&this.prevActive!==document.body&&this.prevActive.focus()}},{key:"blurActiveElement",value:function(){this.prevActive=this.getActiveElement(),this.prevActive!==document.body&&this.prevActive.blur()}},{key:"bindTopLevelEvents",value:function(){var e=this;this.boundTopLevelEvents||(this.boundTopLevelEvents=!0,window.addEventListener("pageshow",function(t){t.persisted&&(e.withPageLoading({to:window.location.href,kind:"redirect"}),window.location.reload())}),this.bindClicks(),this.bindNav(),this.bindForms(),this.bind({keyup:"keyup",keydown:"keydown"},function(t,n,i,r,o,a,u){var s=r.getAttribute(e.binding("key")),c=t.key&&t.key.toLowerCase();s&&s.toLowerCase()!==c||i.pushKey(r,o,n,a,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?w(Object(n),!0).forEach(function(t){A(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):w(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({key:t.key},e.eventMeta(n,t,r)))}),this.bind({blur:"focusout",focus:"focusin"},function(t,n,i,r,o,a,u){u||i.pushEvent(n,r,o,a,e.eventMeta(n,t,r))}),this.bind({blur:"blur",focus:"focus"},function(t,n,i,r,o,a,u){u&&"window"!==!u&&i.pushEvent(n,r,o,a,e.eventMeta(n,t,r))}),window.addEventListener("dragover",function(e){return e.preventDefault()}),window.addEventListener("drop",function(t){t.preventDefault();var n=Z(G(t.target,e.binding("drop-target")),function(t){return t.getAttribute(e.binding("drop-target"))}),i=n&&document.getElementById(n),r=Array.from(t.dataTransfer.files||[]);i&&!i.disabled&&0!==r.length&&i.files instanceof FileList&&(ie.trackFiles(i,r),i.dispatchEvent(new Event("input",{bubbles:!0})))}))}},{key:"eventMeta",value:function(e,t,n){var i=this.metadataCallbacks[e];return i?i(t,n):{}}},{key:"setPendingLink",value:function(e){return this.linkRef++,this.pendingLink=e,this.linkRef}},{key:"commitPendingLink",value:function(e){return this.linkRef===e&&(this.href=this.pendingLink,this.pendingLink=null,!0)}},{key:"getHref",value:function(){return this.href}},{key:"hasPendingLink",value:function(){return!!this.pendingLink}},{key:"bind",value:function(e,t){var n=this,i=function(i){var r=e[i];n.on(r,function(e){var r=n.binding(i),o=n.binding("window-".concat(i)),a=e.target.getAttribute&&e.target.getAttribute(r);a?n.debounce(e.target,e,function(){n.withinOwners(e.target,function(n,r){t(e,i,n,e.target,r,a,null)})}):le.all(document,"[".concat(o,"]"),function(r){var a=r.getAttribute(o);n.debounce(r,e,function(){n.withinOwners(r,function(n,o){t(e,i,n,r,o,a,"window")})})})})};for(var r in e)i(r)}},{key:"bindClicks",value:function(){var e=this;[!0,!1].forEach(function(t){var n=t?e.binding("capture-click"):e.binding("click");window.addEventListener("click",function(i){var r=null,o=(r=t?i.target.matches("[".concat(n,"]"))?i.target:i.target.querySelector("[".concat(n,"]")):G(i.target,n))&&r.getAttribute(n);o&&("#"===r.getAttribute("href")&&i.preventDefault(),e.debounce(r,i,function(){e.withinOwners(r,function(t,n){t.pushEvent("click",r,n,o,e.eventMeta("click",i,r))})}))},t)})}},{key:"bindNav",value:function(){var e=this;if(ce.canPushState()){history.scrollRestoration&&(history.scrollRestoration="manual");var t=null;window.addEventListener("scroll",function(e){clearTimeout(t),t=setTimeout(function(){ce.updateCurrentState(function(e){return Object.assign(e,{scroll:window.scrollY})})},100)}),window.addEventListener("popstate",function(t){if(e.registerNewLocation(window.location)){var n=t.state||{},i=n.type,r=n.id,o=n.root,a=n.scroll,u=window.location.href;e.main.isConnected()&&"patch"===i&&r===e.main.id?e.main.pushLinkPatch(u,null):e.replaceMain(u,null,function(){o&&e.replaceRootHistory(),"number"==typeof a&&setTimeout(function(){window.scrollTo(0,a)},0)})}},!1),window.addEventListener("click",function(t){var n=G(t.target,"data-phx-link"),i=n&&n.getAttribute("data-phx-link"),r=t.metaKey||t.ctrlKey||1===t.button;if(i&&e.isConnected()&&e.main&&!r){var o=n.href,a=n.getAttribute("data-phx-link-state");if(t.preventDefault(),e.pendingLink!==o)if("patch"===i)e.pushHistoryPatch(o,a,n);else{if("redirect"!==i)throw new Error("expected ".concat("data-phx-link",' to be "patch" or "redirect", got: ').concat(i));e.historyRedirect(o,a)}}},!1)}}},{key:"withPageLoading",value:function(e,t){le.dispatchEvent(window,"phx:page-loading-start",e);var n=function(){return le.dispatchEvent(window,"phx:page-loading-stop",e)};return t?t(n):n}},{key:"pushHistoryPatch",value:function(e,t,n){var i=this;this.withPageLoading({to:e,kind:"patch"},function(r){i.main.pushLinkPatch(e,n,function(){i.historyPatch(e,t),r()})})}},{key:"historyPatch",value:function(e,t){ce.pushState(t,{type:"patch",id:this.main.id},e),this.registerNewLocation(window.location)}},{key:"historyRedirect",value:function(e,t,n){var i=this,r=window.scrollY;this.withPageLoading({to:e,kind:"redirect"},function(o){i.replaceMain(e,n,function(){ce.pushState(t,{type:"redirect",id:i.main.id,scroll:r},e),i.registerNewLocation(window.location),o()})})}},{key:"replaceRootHistory",value:function(){ce.pushState("replace",{root:!0,type:"patch",id:this.main.id})}},{key:"registerNewLocation",value:function(e){var t=this.currentLocation;return t.pathname+t.search!==e.pathname+e.search&&(this.currentLocation=X(e),!0)}},{key:"bindForms",value:function(){var e=this,t=0;this.on("submit",function(t){var n=t.target.getAttribute(e.binding("submit"));n&&(t.preventDefault(),t.target.disabled=!0,e.withinOwners(t.target,function(e,i){return e.submitForm(t.target,i,n)}))},!1);for(var n=function(){var n=r[i];e.on(n,function(i){var r=i.target,o=r.form&&r.form.getAttribute(e.binding("change"));if(o&&("number"!==r.type||!r.validity||!r.validity.badInput)){var a=t;t++;var u=le.private(r,"prev-iteration")||{},s=u.at,c=u.type;s===a-1&&n!==c||(le.putPrivate(r,"prev-iteration",{at:a,type:n}),e.debounce(r,i,function(){e.withinOwners(r.form,function(t,n){le.putPrivate(r,"phx-has-focused",!0),le.isTextualInput(r)||e.setActiveElement(r),t.pushInput(r,n,o,i.target)})}))}},!1)},i=0,r=["change","input"];i<r.length;i++)n()}},{key:"debounce",value:function(e,t,n){var i=this.binding("debounce"),r=this.binding("throttle"),o=this.defaults.debounce.toString(),a=this.defaults.throttle.toString();le.debounce(e,t,i,o,r,a,n)}},{key:"silenceEvents",value:function(e){this.silenced=!0,e(),this.silenced=!1}},{key:"on",value:function(e,t){var n=this;window.addEventListener(e,function(e){n.silenced||t(e)})}}]),e}(),ce={canPushState:function(){return void 0!==history.pushState},dropLocal:function(e,t){return window.localStorage.removeItem(this.localKey(e,t))},updateLocal:function(e,t,n,i){var r=this.getLocal(e,t),o=this.localKey(e,t),a=null===r?n:i(r);return window.localStorage.setItem(o,JSON.stringify(a)),a},getLocal:function(e,t){return JSON.parse(window.localStorage.getItem(this.localKey(e,t)))},fetchPage:function(e,t){var n=new XMLHttpRequest;n.open("GET",e,!0),n.timeout=3e4,n.setRequestHeader("content-type","text/html"),n.setRequestHeader("cache-control","max-age=0, no-cache, no-store, must-revalidate, post-check=0, pre-check=0"),n.setRequestHeader("x-requested-with","live-link"),n.onerror=function(){return t(400)},n.ontimeout=function(){return t(504)},n.onreadystatechange=function(){if(4===n.readyState){var i=new URL(e),r=i.pathname+i.search,o=Z(n.getResponseHeader("x-response-url")||n.responseURL,function(e){return new URL(e)}),a=o?o.pathname+o.search:null;return"live-link"!==n.getResponseHeader("x-requested-with")?t(400):null===o||a!=r?t(302):200!==n.status?t(n.status):void t(200,n.responseText)}},n.send()},updateCurrentState:function(e){this.canPushState()&&history.replaceState(e(history.state||{}),"",window.location.href)},pushState:function(e,t,n){if(this.canPushState()){if(n!==window.location.href){if("redirect"==t.type&&t.scroll){var i=history.state||{};i.scroll=t.scroll,history.replaceState(i,"",window.location.href)}delete t.scroll,history[e+"State"](t,"",n||null);var r=this.getHashTargetEl(window.location.hash);r?r.scrollIntoView():"redirect"===t.type&&window.scroll(0,0)}}else this.redirect(n)},setCookie:function(e,t){document.cookie="".concat(e,"=").concat(t)},getCookie:function(e){return document.cookie.replace(new RegExp("(?:(?:^|.*;s*)".concat(e,"s*=s*([^;]*).*$)|^.*$")),"$1")},redirect:function(e,t){t&&ce.setCookie("__phoenix_flash__",t+"; max-age=60000; path=/"),window.location=e},localKey:function(e,t){return"".concat(e,"-").concat(t)},getHashTargetEl:function(e){var t=e.toString().substring(1);if(""!==t)return document.getElementById(t)||document.querySelector('a[name="'.concat(t,'"]'))}},le={byId:function(e){return document.getElementById(e)||z("no id found for ".concat(e))},removeClass:function(e,t){e.classList.remove(t),0===e.classList.length&&e.removeAttribute("class")},all:function(e,t,n){var i=Array.from(e.querySelectorAll(t));return n?i.forEach(n):i},findComponentNodeList:function(e,t){return this.filterWithinSameLiveView(this.all(e,"[".concat(j,'="').concat(t,'"]')),e)},findPhxChildrenInFragment:function(e,t){var n=document.createElement("template");return n.innerHTML=e,this.findPhxChildren(n.content,t)},isIgnored:function(e,t){return"ignore"===(e.getAttribute(t)||e.getAttribute("data-phx-update"))},isPhxUpdate:function(e,t,n){return e.getAttribute&&n.indexOf(e.getAttribute(t))>=0},findPhxChildren:function(e,t){return this.all(e,"".concat(M,"[").concat("data-phx-parent-id",'="').concat(t,'"]'))},findParentCIDs:function(e,t){var n=this,i=new Set(t);return t.reduce(function(t,i){var r="[".concat(j,'="').concat(i,'"] [').concat(j,"]");return n.filterWithinSameLiveView(n.all(e,r),e).map(function(e){return parseInt(e.getAttribute(j))}).forEach(function(e){return t.delete(e)}),t},i)},filterWithinSameLiveView:function(e,t){var n=this;return t.querySelector(M)?e.filter(function(e){return n.withinSameLiveView(e,t)}):e},withinSameLiveView:function(e,t){for(;e=e.parentNode;){if(e.isSameNode(t))return!0;if(e.getAttribute(O))return!1}},private:function(e,t){return e.phxPrivate&&e.phxPrivate[t]},deletePrivate:function(e,t){e.phxPrivate&&delete e.phxPrivate[t]},putPrivate:function(e,t,n){e.phxPrivate||(e.phxPrivate={}),e.phxPrivate[t]=n},copyPrivates:function(e,t){t.phxPrivate&&(e.phxPrivate=X(t.phxPrivate))},putTitle:function(e){var t=document.querySelector("title").dataset,n=t.prefix,i=t.suffix;document.title="".concat(n||"").concat(e).concat(i||"")},debounce:function(e,t,n,i,r,o,a){var u=this,s=e.getAttribute(n),c=e.getAttribute(r);""===s&&(s=i),""===c&&(c=o);var l=s||c;switch(l){case null:return a();case"blur":return void(this.once(e,"debounce-blur")&&e.addEventListener("blur",function(){return a()}));default:var d=parseInt(l),h=this.incCycle(e,"debounce-trigger",function(){return c?u.deletePrivate(e,"throttled"):a()});if(isNaN(d))return z("invalid throttle/debounce value: ".concat(l));if(c){var f=!1;if("keydown"===t.type){var v=this.private(e,"debounce-prev-key");this.putPrivate(e,"debounce-prev-key",t.key),f=v!==t.key}if(!f&&this.private(e,"throttled"))return!1;a(),this.putPrivate(e,"throttled",!0),setTimeout(function(){return u.triggerCycle(e,"debounce-trigger")},d)}else setTimeout(function(){return u.triggerCycle(e,"debounce-trigger",h)},d);e.form&&this.once(e.form,"bind-debounce")&&e.form.addEventListener("submit",function(t){Array.from(new FormData(e.form).entries(),function(t){var n=x(t,2),i=n[0],r=(n[1],e.form.querySelector('[name="'.concat(i,'"]')));u.incCycle(r,"debounce-trigger"),u.deletePrivate(r,"throttled")})}),this.once(e,"bind-debounce")&&e.addEventListener("blur",function(t){return u.triggerCycle(e,"debounce-trigger")})}},triggerCycle:function(e,t,n){var i=x(this.private(e,t),2),r=i[0],o=i[1];n||(n=r),n===r&&(this.incCycle(e,t),o())},once:function(e,t){return!0!==this.private(e,t)&&(this.putPrivate(e,t,!0),!0)},incCycle:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},i=x(this.private(e,t)||[0,n],2),r=i[0];i[1];return r++,this.putPrivate(e,t,[r,n]),r},discardError:function(e,t,n){var i=t.getAttribute&&t.getAttribute(n),r=i&&e.querySelector("#".concat(i));r&&(this.private(r,"phx-has-focused")||this.private(r.form,"phx-has-submitted")||t.classList.add("phx-no-feedback"))},isPhxChild:function(e){return e.getAttribute&&e.getAttribute("data-phx-parent-id")},dispatchEvent:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n});e.dispatchEvent(i)},cloneNode:function(e,t){if(void 0===t)return e.cloneNode(!0);var n=e.cloneNode(!1);return n.innerHTML=t,n},mergeAttrs:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=n.exclude||[],r=n.isIgnored,o=t.attributes,a=o.length-1;a>=0;a--){var u=o[a].name;i.indexOf(u)<0&&e.setAttribute(u,t.getAttribute(u))}for(var s=e.attributes,c=s.length-1;c>=0;c--){var l=s[c].name;r?l.startsWith("data-")&&!t.hasAttribute(l)&&e.removeAttribute(l):t.hasAttribute(l)||e.removeAttribute(l)}},mergeFocusedInput:function(e,t){e instanceof HTMLSelectElement||le.mergeAttrs(e,t,{except:["value"]}),t.readOnly?e.setAttribute("readonly",!0):e.removeAttribute("readonly")},hasSelectionRange:function(e){return e.setSelectionRange&&("text"===e.type||"textarea"===e.type)},restoreFocus:function(e,t,n){if(le.isTextualInput(e)){var i=e.matches(":focus");e.readOnly&&e.blur(),i||e.focus(),this.hasSelectionRange(e)&&e.setSelectionRange(t,n)}},isFormInput:function(e){return/^(?:input|select|textarea)$/i.test(e.tagName)&&"button"!==e.type},syncAttrsToProps:function(e){e instanceof HTMLInputElement&&U.indexOf(e.type.toLocaleLowerCase())>=0&&(e.checked=null!==e.getAttribute("checked"))},isTextualInput:function(e){return B.indexOf(e.type)>=0},isNowTriggerFormExternal:function(e,t){return e.getAttribute&&null!==e.getAttribute(t)},syncPendingRef:function(e,t,n){var i=e.getAttribute(F);return null===i||(le.isFormInput(e)||null!==e.getAttribute(n)?("file"===e.type&&le.mergeAttrs(e,t,{isIgnored:!0}),le.putPrivate(e,F,t),!1):(H.forEach(function(n){e.classList.contains(n)&&t.classList.add(n)}),t.setAttribute(F,i),!0))},cleanChildNodes:function(e,t){if(le.isPhxUpdate(e,t,["append","prepend"])){var n=[];e.childNodes.forEach(function(e){e.id||(e.nodeType===Node.TEXT_NODE&&""===e.nodeValue.trim()||z("only HTML element tags with an id are allowed inside containers with phx-update.\n\n"+'removing illegal node: "'.concat((e.outerHTML||e.nodeValue).trim(),'"\n\n')),n.push(e))}),n.forEach(function(e){return e.remove()})}}},de=function(){function e(t,n,i){T(this,e);var r=new Set,o=new Set(E(n.children).map(function(e){return e.id})),a=[];Array.from(t.children).forEach(function(e){if(e.id&&(r.add(e.id),o.has(e.id))){var t=e.previousElementSibling&&e.previousElementSibling.id;a.push({elementId:e.id,previousElementId:t})}}),this.containerId=n.id,this.updateType=i,this.elementsToModify=a,this.elementIdsToAdd=E(o).filter(function(e){return!r.has(e)})}return D(e,[{key:"perform",value:function(){var e=le.byId(this.containerId);this.elementsToModify.forEach(function(t){t.previousElementId?Z(document.getElementById(t.previousElementId),function(e){Z(document.getElementById(t.elementId),function(t){t.previousElementSibling&&t.previousElementSibling.id==e.id||e.insertAdjacentElement("afterend",t)})}):Z(document.getElementById(t.elementId),function(t){null==t.previousElementSibling||e.insertAdjacentElement("afterbegin",t)})}),"prepend"==this.updateType&&this.elementIdsToAdd.reverse().forEach(function(t){Z(document.getElementById(t),function(t){return e.insertAdjacentElement("afterbegin",t)})})}}]),e}(),he=function(){function e(t,n,i,r,o){T(this,e),this.view=t,this.liveSocket=t.liveSocket,this.container=n,this.id=i,this.rootID=t.root.id,this.html=r,this.targetCID=o,this.cidPatch="number"==typeof this.targetCID,this.callbacks={beforeadded:[],beforeupdated:[],beforediscarded:[],beforephxChildAdded:[],afteradded:[],afterupdated:[],afterdiscarded:[],afterphxChildAdded:[]}}return D(e,null,[{key:"patchEl",value:function(e,t,n){b(e,t,{childrenOnly:!1,onBeforeElUpdated:function(e,t){if(n&&n.isSameNode(e)&&le.isFormInput(e))return le.mergeFocusedInput(e,t),!1}})}}]),D(e,[{key:"before",value:function(e,t){this.callbacks["before".concat(e)].push(t)}},{key:"after",value:function(e,t){this.callbacks["after".concat(e)].push(t)}},{key:"trackBefore",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];this.callbacks["before".concat(e)].forEach(function(e){return e.apply(void 0,n)})}},{key:"trackAfter",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];this.callbacks["after".concat(e)].forEach(function(e){return e.apply(void 0,n)})}},{key:"markPrunableContentForRemoval",value:function(){le.all(this.container,"[phx-update=append] > *, [phx-update=prepend] > *",function(e){e.setAttribute("data-phx-remove","")})}},{key:"perform",value:function(){var e=this,t=this.view,n=this.liveSocket,i=this.container,r=this.html,o=this.isCIDPatch()?this.targetCIDContainer():i;if(!this.isCIDPatch()||o){var a=n.getActiveElement(),u=a&&le.hasSelectionRange(a)?a:{},s=u.selectionStart,c=u.selectionEnd,l=n.binding("update"),d=n.binding("feedback-for"),h=n.binding("disable-with"),f=n.binding("trigger-action"),v=[],p=[],g=[],m=null,y=n.time("premorph container prep",function(){return e.buildDiffHTML(i,r,l,o)});return this.trackBefore("added",i),this.trackBefore("updated",i,i),n.time("morphdom",function(){b(o,y,{childrenOnly:null===o.getAttribute(j),onBeforeNodeAdded:function(t){return le.discardError(o,t,d),e.trackBefore("added",t),t},onNodeAdded:function(n){le.isNowTriggerFormExternal(n,f)&&(m=n),le.isPhxChild(n)&&t.ownsElement(n)&&e.trackAfter("phxChildAdded",n),v.push(n)},onNodeDiscarded:function(t){le.isPhxChild(t)&&n.destroyViewByEl(t),e.trackAfter("discarded",t)},onBeforeNodeDiscarded:function(t){return!(!t.getAttribute||null===t.getAttribute("data-phx-remove"))||(null===t.parentNode||!le.isPhxUpdate(t.parentNode,l,["append","prepend"])||!t.id)&&(!e.skipCIDSibling(t)&&(e.trackBefore("discarded",t),!0))},onElUpdated:function(e){le.isNowTriggerFormExternal(e,f)&&(m=e),p.push(e)},onBeforeElUpdated:function(t,n){if(le.cleanChildNodes(n,l),e.skipCIDSibling(n))return!1;if(le.isIgnored(t,l))return e.trackBefore("updated",t,n),le.mergeAttrs(t,n,{isIgnored:!0}),p.push(t),!1;if("number"===t.type&&t.validity&&t.validity.badInput)return!1;if(!le.syncPendingRef(t,n,h))return"file"===t.type&&(e.trackBefore("updated",t,n),p.push(t)),!1;if(le.isPhxChild(n)){var i=t.getAttribute(J);return le.mergeAttrs(t,n),t.setAttribute(J,i),t.setAttribute("data-phx-root-id",e.rootID),!1}return le.copyPrivates(n,t),le.discardError(o,n,d),a&&t.isSameNode(a)&&le.isFormInput(t)&&!e.forceFocusedSelectUpdate(t,n)?(e.trackBefore("updated",t,n),le.mergeFocusedInput(t,n),le.syncAttrsToProps(t),p.push(t),!1):(le.isPhxUpdate(n,l,["append","prepend"])&&g.push(new de(t,n,n.getAttribute(l))),le.syncAttrsToProps(n),e.trackBefore("updated",t,n),!0)}})}),n.isDebugEnabled()&&function(){for(var e=new Set,t=document.querySelectorAll("*[id]"),n=0,i=t.length;n<i;n++)e.has(t[n].id)?console.error("Multiple IDs detected: ".concat(t[n].id,". Ensure unique element ids.")):e.add(t[n].id)}(),g.length>0&&n.time("post-morph append/prepend restoration",function(){g.forEach(function(e){return e.perform()})}),n.silenceEvents(function(){return le.restoreFocus(a,s,c)}),le.dispatchEvent(document,"phx:update"),v.forEach(function(t){return e.trackAfter("added",t)}),p.forEach(function(t){return e.trackAfter("updated",t)}),m&&(n.disconnect(),m.submit()),!0}}},{key:"forceFocusedSelectUpdate",value:function(e,t){return!0===e.multiple||e.innerHTML!=t.innerHTML}},{key:"isCIDPatch",value:function(){return this.cidPatch}},{key:"skipCIDSibling",value:function(e){return e.nodeType===Node.ELEMENT_NODE&&null!==e.getAttribute("data-phx-skip")}},{key:"targetCIDContainer",value:function(){if(this.isCIDPatch()){var e=k(le.findComponentNodeList(this.container,this.targetCID)),t=e[0];return 0===e.slice(1).length?t:t&&t.parentNode}}},{key:"buildDiffHTML",value:function(e,t,n,i){var r=this,o=this.isCIDPatch(),a=o&&i.getAttribute(j)===this.targetCID.toString();if(!o||a)return t;var u=null,s=document.createElement("template");u=le.cloneNode(i);var c=k(le.findComponentNodeList(u,this.targetCID)),l=c[0],d=c.slice(1);return s.innerHTML=t,d.forEach(function(e){return e.remove()}),Array.from(u.childNodes).forEach(function(e){e.id&&e.nodeType===Node.ELEMENT_NODE&&e.getAttribute(j)!==r.targetCID.toString()&&(e.setAttribute("data-phx-skip",""),e.innerHTML="")}),Array.from(s.content.childNodes).forEach(function(e){return u.insertBefore(e,l)}),l.remove(),u.outerHTML}}]),e}(),fe=function(){function e(t,n,i,r,o){var a=this;T(this,e),this.liveSocket=n,this.flash=o,this.parent=i,this.root=i?i.root:this,this.el=t,this.id=this.el.id,this.view=this.el.getAttribute(O),this.ref=0,this.childJoins=0,this.loaderTimer=null,this.pendingDiffs=[],this.pruningCIDs=[],this.href=r,this.joinCount=this.parent?this.parent.joinCount-1:0,this.joinPending=!0,this.destroyed=!1,this.joinCallback=function(){},this.stopCallback=function(){},this.pendingJoinOps=this.parent?null:[],this.viewHooks={},this.uploaders={},this.formSubmits=[],this.children=this.parent?null:{},this.root.children[this.id]={},this.channel=this.liveSocket.channel("lv:".concat(this.id),function(){return{url:a.href,params:a.connectParams(),session:a.getSession(),static:a.getStatic(),flash:a.flash}}),this.showLoader(this.liveSocket.loaderTimeout),this.bindChannel()}return D(e,[{key:"isMain",value:function(){return this.liveSocket.main===this}},{key:"connectParams",value:function(){var e=this.liveSocket.params(this.view),t=le.all(document,"[".concat(this.binding("track-static"),"]")).map(function(e){return e.src||e.href}).filter(function(e){return"string"==typeof e});return t.length>0&&(e._track_static=t),e._mounts=this.joinCount,e}},{key:"name",value:function(){return this.view}},{key:"isConnected",value:function(){return this.channel.canPush()}},{key:"getSession",value:function(){return this.el.getAttribute("data-phx-session")}},{key:"getStatic",value:function(){var e=this.el.getAttribute(J);return""===e?null:e}},{key:"destroy",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){};this.destroyAllChildren(),this.destroyed=!0,delete this.root.children[this.id],this.parent&&delete this.root.children[this.parent.id][this.id],clearTimeout(this.loaderTimer);var n=function(){for(var n in t(),e.viewHooks)e.viewHooks[n].__trigger__("beforeDestroy"),e.destroyHook(e.viewHooks[n])};this.log("destroyed",function(){return["the child has been removed from the parent"]}),this.channel.leave().receive("ok",n).receive("error",n).receive("timeout",n)}},{key:"setContainerClasses",value:function(){var e;this.el.classList.remove("phx-connected","phx-disconnected","phx-error"),(e=this.el.classList).add.apply(e,arguments)}},{key:"isLoading",value:function(){return this.el.classList.contains("phx-disconnected")}},{key:"showLoader",value:function(e){var t=this;if(clearTimeout(this.loaderTimer),e)this.loaderTimer=setTimeout(function(){return t.showLoader()},e);else{for(var n in this.viewHooks)this.viewHooks[n].__trigger__("disconnected");this.setContainerClasses("phx-disconnected")}}},{key:"hideLoader",value:function(){clearTimeout(this.loaderTimer),this.setContainerClasses("phx-connected")}},{key:"triggerReconnected",value:function(){for(var e in this.viewHooks)this.viewHooks[e].__trigger__("reconnected")}},{key:"log",value:function(e,t){this.liveSocket.log(this,e,t)}},{key:"withinTargets",value:function(e,t){var n=this;if(/^(0|[1-9]\d*)$/.test(e)){var i=le.findComponentNodeList(this.el,e);0===i.length?z("no component found matching phx-target of ".concat(e)):t(this,i[0])}else{var r=Array.from(document.querySelectorAll(e));0===r.length&&z('nothing found matching the phx-target selector "'.concat(e,'"')),r.forEach(function(e){return n.liveSocket.owner(e,function(n){return t(n,e)})})}}},{key:"applyDiff",value:function(e,t,n){this.log(e,function(){return["",X(t)]});var i=ue.extract(t),r=i.diff,o=i.reply,a=i.events,u=i.title;return u&&le.putTitle(u),n({diff:r,reply:o,events:a}),o}},{key:"onJoin",value:function(e){var t=this,n=e.rendered;this.childJoins=0,this.joinPending=!0,this.flash=null,ce.dropLocal(this.name(),"consecutive-reloads"),this.applyDiff("mount",n,function(n){var i=n.diff,r=n.events;t.rendered=new ue(t.id,i);var o=t.renderContainer(null,"join");t.dropPendingRefs();var a=t.formsForRecovery(o);t.joinCount++,a.length>0?a.forEach(function(e,n){t.pushFormRecovery(e,function(e){n===a.length-1&&t.onJoinComplete(e,o,r)})}):t.onJoinComplete(e,o,r)})}},{key:"dropPendingRefs",value:function(){le.all(this.el,"[".concat(F,"]"),function(e){return e.removeAttribute(F)})}},{key:"onJoinComplete",value:function(e,t,n){var i=this,r=e.live_patch;if(this.joinCount>1||this.parent&&!this.parent.isJoinPending())return this.applyJoinPatch(r,t,n);0===le.findPhxChildrenInFragment(t,this.id).filter(function(e){var t=e.id&&i.el.querySelector("#".concat(e.id)),n=t&&t.getAttribute(J);return n&&e.setAttribute(J,n),i.joinChild(e)}).length?this.parent?(this.root.pendingJoinOps.push([this,function(){return i.applyJoinPatch(r,t,n)}]),this.parent.ackJoin(this)):(this.onAllChildJoinsComplete(),this.applyJoinPatch(r,t,n)):this.root.pendingJoinOps.push([this,function(){return i.applyJoinPatch(r,t,n)}])}},{key:"attachTrueDocEl",value:function(){this.el=le.byId(this.id),this.el.setAttribute("data-phx-root-id",this.root.id)}},{key:"dispatchEvents",value:function(e){e.forEach(function(e){var t=x(e,2),n=t[0],i=t[1];window.dispatchEvent(new CustomEvent("phx:hook:".concat(n),{detail:i}))})}},{key:"applyJoinPatch",value:function(e,t,n){var i=this;this.attachTrueDocEl();var r=new he(this,this.el,this.id,t,null);if(r.markPrunableContentForRemoval(),this.performPatch(r,!1),this.joinNewChildren(),le.all(this.el,"[".concat(this.binding("hook"),"], [data-phx-").concat("hook","]"),function(e){var t=i.addHook(e);t&&t.__trigger__("mounted")}),this.joinPending=!1,this.dispatchEvents(n),this.applyPendingUpdates(),e){var o=e.kind,a=e.to;this.liveSocket.historyPatch(a,o)}this.hideLoader(),this.joinCount>1&&this.triggerReconnected(),this.stopCallback()}},{key:"triggerBeforeUpdateHook",value:function(e,t){this.liveSocket.triggerDOM("onBeforeElUpdated",[e,t]);var n=this.getHook(e),i=n&&le.isIgnored(e,this.binding("update"));if(n&&!e.isEqualNode(t)&&(!i||!function(e,t){return JSON.stringify(e)===JSON.stringify(t)}(e.dataset,t.dataset)))return n.__trigger__("beforeUpdate"),n}},{key:"triggerUpdatedHook",value:function(e){e.__trigger__("updated")}},{key:"performPatch",value:function(e,t){var n=this,i=[],r=!1,o=new Set;return e.after("added",function(e){n.liveSocket.triggerDOM("onNodeAdded",[e]);var t=n.addHook(e);t&&t.__trigger__("mounted")}),e.after("phxChildAdded",function(e){return r=!0}),e.before("updated",function(e,t){n.triggerBeforeUpdateHook(e,t)&&o.add(e.id)}),e.after("updated",function(e){o.has(e.id)&&n.triggerUpdatedHook(n.getHook(e))}),e.before("discarded",function(e){var t=n.getHook(e);t&&t.__trigger__("beforeDestroy")}),e.after("discarded",function(e){var t=n.componentID(e);"number"==typeof t&&-1===i.indexOf(t)&&i.push(t);var r=n.getHook(e);r&&n.destroyHook(r)}),e.perform(),t&&this.maybePushComponentsDestroyed(i),r}},{key:"joinNewChildren",value:function(){var e=this;le.findPhxChildren(this.el,this.id).forEach(function(t){return e.joinChild(t)})}},{key:"getChildById",value:function(e){return this.root.children[this.id][e]}},{key:"getDescendentByEl",value:function(e){return e.id===this.id?this:this.children[e.getAttribute("data-phx-parent-id")][e.id]}},{key:"destroyDescendent",value:function(e){for(var t in this.root.children)for(var n in this.root.children[t])if(n===e)return this.root.children[t][n].destroy()}},{key:"joinChild",value:function(t){if(!this.getChildById(t.id)){var n=new e(t,this.liveSocket,this);return this.root.children[this.id][n.id]=n,n.join(),this.childJoins++,!0}}},{key:"isJoinPending",value:function(){return this.joinPending}},{key:"ackJoin",value:function(e){this.childJoins--,0===this.childJoins&&(this.parent?this.parent.ackJoin(this):this.onAllChildJoinsComplete())}},{key:"onAllChildJoinsComplete",value:function(){this.joinCallback(),this.pendingJoinOps.forEach(function(e){var t=x(e,2),n=t[0],i=t[1];n.isDestroyed()||i()}),this.pendingJoinOps=[]}},{key:"update",value:function(e,t){var n=this;if(this.isJoinPending()||this.liveSocket.hasPendingLink())return this.pendingDiffs.push({diff:e,events:t});this.rendered.mergeDiff(e);var i=!1;this.rendered.isComponentOnlyDiff(e)?this.liveSocket.time("component patch complete",function(){le.findParentCIDs(n.el,n.rendered.componentCIDs(e)).forEach(function(t){n.componentPatch(n.rendered.getComponent(e,t),t)&&(i=!0)})}):Q(e)||this.liveSocket.time("full patch complete",function(){var t=n.renderContainer(e,"update"),r=new he(n,n.el,n.id,t,null);i=n.performPatch(r,!0)}),this.dispatchEvents(t),i&&this.joinNewChildren()}},{key:"renderContainer",value:function(e,t){var n=this;return this.liveSocket.time("toString diff (".concat(t,")"),function(){var t=n.el.tagName,i=e?n.rendered.componentCIDs(e).concat(n.pruningCIDs):null,r=n.rendered.toString(i);return"<".concat(t,">").concat(r,"</").concat(t,">")})}},{key:"componentPatch",value:function(e,t){if(Q(e))return!1;var n=this.rendered.componentToString(t),i=new he(this,this.el,this.id,n,t);return this.performPatch(i,!0)}},{key:"getHook",value:function(e){return this.viewHooks[pe.elementID(e)]}},{key:"addHook",value:function(e){if(!pe.elementID(e)&&e.getAttribute){var t=e.getAttribute("data-phx-".concat("hook"))||e.getAttribute(this.binding("hook"));if(!t||this.ownsElement(e)){var n=this.liveSocket.getHookCallbacks(t);if(n){e.id||z('no DOM ID for hook "'.concat(t,'". Hooks require a unique ID on each element.'),e);var i=new pe(this,e,n);return this.viewHooks[pe.elementID(i.el)]=i,i}null!==t&&z('unknown hook found for "'.concat(t,'"'),e)}}}},{key:"destroyHook",value:function(e){e.__trigger__("destroyed"),e.__cleanup__(),delete this.viewHooks[pe.elementID(e.el)]}},{key:"applyPendingUpdates",value:function(){var e=this;this.pendingDiffs.forEach(function(t){var n=t.diff,i=t.events;return e.update(n,i)}),this.pendingDiffs=[]}},{key:"onChannel",value:function(e,t){var n=this;this.liveSocket.onChannel(this.channel,e,function(e){n.isJoinPending()?n.root.pendingJoinOps.push([n,function(){return t(e)}]):t(e)})}},{key:"bindChannel",value:function(){var e=this;this.liveSocket.onChannel(this.channel,"diff",function(t){e.applyDiff("update",t,function(t){var n=t.diff,i=t.events;return e.update(n,i)})}),this.onChannel("redirect",function(t){var n=t.to,i=t.flash;return e.onRedirect({to:n,flash:i})}),this.onChannel("live_patch",function(t){return e.onLivePatch(t)}),this.onChannel("live_redirect",function(t){return e.onLiveRedirect(t)}),this.channel.onError(function(t){return e.onError(t)}),this.channel.onClose(function(t){return e.onClose(t)})}},{key:"destroyAllChildren",value:function(){for(var e in this.root.children[this.id])this.getChildById(e).destroy()}},{key:"onLiveRedirect",value:function(e){var t=e.to,n=e.kind,i=e.flash,r=this.expandURL(t);this.liveSocket.historyRedirect(r,n,i)}},{key:"onLivePatch",value:function(e){var t=e.to,n=e.kind;this.href=this.expandURL(t),this.liveSocket.historyPatch(t,n)}},{key:"expandURL",value:function(e){return e.startsWith("/")?"".concat(window.location.protocol,"//").concat(window.location.host).concat(e):e}},{key:"onRedirect",value:function(e){var t=e.to,n=e.flash;this.liveSocket.redirect(t,n)}},{key:"isDestroyed",value:function(){return this.destroyed}},{key:"join",value:function(e){var t=this;this.parent||(this.stopCallback=this.liveSocket.withPageLoading({to:this.href,kind:"initial"})),this.joinCallback=function(){return e&&e(t,t.joinCount)},this.liveSocket.wrapPush(this,{timeout:!1},function(){return t.channel.join().receive("ok",function(e){return t.onJoin(e)}).receive("error",function(e){return t.onJoinError(e)}).receive("timeout",function(){return t.onJoinError({reason:"timeout"})})})}},{key:"onJoinError",value:function(e){return(e.redirect||e.live_redirect)&&(this.joinPending=!1,this.channel.leave()),e.redirect?this.onRedirect(e.redirect):e.live_redirect?this.onLiveRedirect(e.live_redirect):(this.log("error",function(){return["unable to join",e]}),this.liveSocket.reloadWithJitter(this))}},{key:"onClose",value:function(e){if(!this.isDestroyed()){if(this.isJoinPending()||this.liveSocket.hasPendingLink()&&"leave"!==e)return this.liveSocket.reloadWithJitter(this);this.destroyAllChildren(),this.liveSocket.dropActiveElement(this),document.activeElement&&document.activeElement.blur(),this.liveSocket.isUnloaded()&&this.showLoader(200)}}},{key:"onError",value:function(e){this.onClose(e),this.log("error",function(){return["view crashed",e]}),this.liveSocket.isUnloaded()||this.displayError()}},{key:"displayError",value:function(){this.isMain()&&le.dispatchEvent(window,"phx:page-loading-start",{to:this.href,kind:"error"}),this.showLoader(),this.setContainerClasses("phx-disconnected","phx-error")}},{key:"pushWithReply",value:function(e,t,n){var i=this,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},o=x(e?e():[null,[]],2),a=o[0],u=x(o[1],1)[0],s=function(){};return u&&null!==u.getAttribute(this.binding("page-loading"))&&(s=this.liveSocket.withPageLoading({kind:"element",target:u})),"number"!=typeof n.cid&&delete n.cid,this.liveSocket.wrapPush(this,{timeout:!0},function(){return i.channel.push(t,n,3e4).receive("ok",function(e){var t=null;null!==a&&i.undoRefs(a),e.diff&&(t=i.applyDiff("update",e.diff,function(e){var t=e.diff,n=e.events;i.update(t,n)})),e.redirect&&i.onRedirect(e.redirect),e.live_patch&&i.onLivePatch(e.live_patch),e.live_redirect&&i.onLiveRedirect(e.live_redirect),s(),r(e,t)})})}},{key:"undoRefs",value:function(e){var t=this;le.all(this.el,"[".concat(F,'="').concat(e,'"]'),function(e){e.removeAttribute(F),null!==e.getAttribute("data-phx-readonly")&&(e.readOnly=!1,e.removeAttribute("data-phx-readonly")),null!==e.getAttribute("data-phx-disabled")&&(e.disabled=!1,e.removeAttribute("data-phx-disabled")),H.forEach(function(t){return le.removeClass(e,t)});var n=e.getAttribute("data-phx-disable-with-restore");null!==n&&(e.innerText=n,e.removeAttribute("data-phx-disable-with-restore"));var i=le.private(e,F);if(i){var r=t.triggerBeforeUpdateHook(e,i);he.patchEl(e,i,t.liveSocket.getActiveElement()),r&&t.triggerUpdatedHook(r),le.deletePrivate(e,F)}})}},{key:"putRef",value:function(e,t){var n=this.ref++,i=this.binding("disable-with");return e.forEach(function(e){e.classList.add("phx-".concat(t,"-loading")),e.setAttribute(F,n);var r=e.getAttribute(i);null!==r&&(e.getAttribute("data-phx-disable-with-restore")||e.setAttribute("data-phx-disable-with-restore",e.innerText),e.innerText=r)}),[n,e]}},{key:"componentID",value:function(e){var t=e.getAttribute&&e.getAttribute(j);return t?parseInt(t):null}},{key:"targetComponentID",value:function(e,t){return e.getAttribute(this.binding("target"))?this.closestComponentID(t):null}},{key:"closestComponentID",value:function(e){var t=this;return e?Z(e.closest("[".concat(j,"]")),function(e){return t.ownsElement(e)&&t.componentID(e)}):null}},{key:"pushHookEvent",value:function(e,t,n,i){var r=x(this.putRef([],"hook"),2),o=r[0],a=r[1];return this.pushWithReply(function(){return[o,a]},"event",{type:"hook",event:t,value:n,cid:this.closestComponentID(e)},function(e,t){return i(t,o)}),o}},{key:"extractMeta",value:function(e,t){for(var n=this.binding("value-"),i=0;i<e.attributes.length;i++){var r=e.attributes[i].name;r.startsWith(n)&&(t[r.replace(n,"")]=e.getAttribute(r))}return void 0!==e.value&&(t.value=e.value,"INPUT"===e.tagName&&U.indexOf(e.type)>=0&&!e.checked&&delete t.value),t}},{key:"pushEvent",value:function(e,t,n,i,r){var o=this;this.pushWithReply(function(){return o.putRef([t],e)},"event",{type:e,event:i,value:this.extractMeta(t,r),cid:this.targetComponentID(t,n)})}},{key:"pushKey",value:function(e,t,n,i,r){var o=this;this.pushWithReply(function(){return o.putRef([e],n)},"event",{type:n,event:i,value:this.extractMeta(e,r),cid:this.targetComponentID(e,t)})}},{key:"pushFileProgress",value:function(e,t,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){};this.liveSocket.withinOwners(e.form,function(r,o){r.pushWithReply(null,"progress",{event:e.getAttribute(r.binding("progress")),ref:e.getAttribute("data-phx-upload-ref"),entry_ref:t,progress:n,cid:r.targetComponentID(e.form,o)},i)})}},{key:"pushInput",value:function(e,t,n,i,r){var o=this,a=this.targetComponentID(e.form,t),u=function(){return o.putRef([e,e.form],"change")},s=ae(e.form,{_target:i.name});e.files&&e.files.length>0&&ie.trackFiles(e,Array.from(e.files));var c={type:"form",event:n,value:s,uploads:ie.serializeUploads(e),cid:a};this.pushWithReply(u,"event",c,function(n){if("file"===e.type&&null!==e.getAttribute("data-phx-auto-upload")){if(ie.filesAwaitingPreflight(e).length>0){var i=x(u(),2),s=i[0];i[1];o.uploadFiles(e.form,t,s,a,function(t){r&&r(n),o.triggerAwaitingSubmit(e.form)})}}else r&&r(n)})}},{key:"triggerAwaitingSubmit",value:function(e){var t=this.getScheduledSubmit(e);if(t){var n=x(t,3),i=(n[0],n[1],n[2]);this.cancelSubmit(e),i()}}},{key:"getScheduledSubmit",value:function(e){return this.formSubmits.find(function(t){var n=x(t,2),i=n[0];n[1];return i.isSameNode(e)})}},{key:"scheduleSubmit",value:function(e,t,n){if(this.getScheduledSubmit(e))return!0;this.formSubmits.push([e,t,n])}},{key:"cancelSubmit",value:function(e){var t=this;this.formSubmits=this.formSubmits.filter(function(n){var i=x(n,3),r=i[0],o=i[1];i[2];return!r.isSameNode(e)||(t.undoRefs(o),!1)})}},{key:"pushFormSubmit",value:function(e,t,n,i){var r=this,o=function(e){return!(G(e,"".concat(r.binding("update"),"=ignore"),e.form)||G(e,"data-phx-update=ignore",e.form))},a=function(){var t=le.all(e,"[".concat(r.binding("disable-with"),"]")),n=le.all(e,"button").filter(o),i=le.all(e,"input,textarea,select").filter(o);return n.forEach(function(e){e.setAttribute("data-phx-disabled",e.disabled),e.disabled=!0}),i.forEach(function(e){e.setAttribute("data-phx-readonly",e.readOnly),e.readOnly=!0,e.files&&(e.setAttribute("data-phx-disabled",e.disabled),e.disabled=!0)}),e.setAttribute(r.binding("page-loading"),""),r.putRef([e].concat(t).concat(n).concat(i),"submit")},u=this.targetComponentID(e,t);if(ie.hasUploadsInProgress(e)){var s=x(a(),2),c=s[0];s[1];return this.scheduleSubmit(e,c,function(){return r.pushFormSubmit(e,t,n,i)})}if(ie.inputsAwaitingPreflight(e).length>0){var l=x(a(),2),d=l[0],h=l[1],f=function(){return[d,h]};this.uploadFiles(e,t,d,u,function(t){var o=ae(e,{});r.pushWithReply(f,"event",{type:"form",event:n,value:o,cid:u},i)})}else{var v=ae(e);this.pushWithReply(a,"event",{type:"form",event:n,value:v,cid:u},i)}}},{key:"uploadFiles",value:function(e,t,n,i,r){var o=this,a=this.joinCount;ie.activeFileInputs(e).forEach(function(e){var i=new ie(e,o,r);o.uploaders[e]=i;var u=i.entries().map(function(e){return e.toPreflightPayload()}),s={ref:e.getAttribute("data-phx-upload-ref"),entries:u,cid:o.targetComponentID(e.form,t)};o.log("upload",function(){return["sending preflight request",s]}),o.pushWithReply(null,"allow_upload",s,function(e){if(o.log("upload",function(){return["got preflight response",e]}),e.error){o.undoRefs(n);var t=x(e.error,2),r=t[0],u=t[1];o.log("upload",function(){return["error for entry ".concat(r),u]})}else{i.initAdapterUpload(e,function(e){o.channel.onError(function(){o.joinCount===a&&e()})},o.liveSocket)}})})}},{key:"pushFormRecovery",value:function(e,t){var n=this;this.liveSocket.withinOwners(e,function(i,r){var o=e.elements[0],a=e.getAttribute(n.binding("auto-recover"))||e.getAttribute(n.binding("change"));i.pushInput(o,r,a,o,t)})}},{key:"pushLinkPatch",value:function(e,t,n){var i=this,r=this.liveSocket.setPendingLink(e),o=t?function(){return i.putRef([t],"click")}:null;this.pushWithReply(o,"link",{url:e},function(t){t.link_redirect?i.liveSocket.replaceMain(e,null,n,r):i.liveSocket.commitPendingLink(r)&&(i.href=e,i.applyPendingUpdates(),n&&n())}).receive("timeout",function(){return i.liveSocket.redirect(window.location.href)})}},{key:"formsForRecovery",value:function(e){var t=this;if(this.joinCount<=1)return[];var n=this.binding("change"),i=document.createElement("template");return i.innerHTML=e,le.all(this.el,"form[".concat(n,"]")).filter(function(e){return t.ownsElement(e)}).filter(function(e){return e.elements.length>0}).filter(function(e){return"ignore"!==e.getAttribute(t.binding("auto-recover"))}).filter(function(e){return i.content.querySelector("form[".concat(n,'="').concat(e.getAttribute(n),'"]'))})}},{key:"maybePushComponentsDestroyed",value:function(e){var t,n=this,i=e.filter(function(e){return 0===le.findComponentNodeList(n.el,e).length});i.length>0&&((t=this.pruningCIDs).push.apply(t,E(i)),this.pushWithReply(null,"cids_will_destroy",{cids:i},function(){n.pruningCIDs=n.pruningCIDs.filter(function(e){return-1!==i.indexOf(e)});var e=i.filter(function(e){return 0===le.findComponentNodeList(n.el,e).length});e.length>0&&n.pushWithReply(null,"cids_destroyed",{cids:e},function(e){n.rendered.pruneCIDs(e.cids)})}))}},{key:"ownsElement",value:function(e){return e.getAttribute("data-phx-parent-id")===this.id||Z(e.closest(M),function(e){return e.id})===this.id}},{key:"submitForm",value:function(e,t,n){var i=this;le.putPrivate(e,"phx-has-submitted",!0),this.liveSocket.blurActiveElement(this),this.pushFormSubmit(e,t,n,function(){i.liveSocket.restorePreviouslyActiveFocus()})}},{key:"binding",value:function(e){return this.liveSocket.binding(e)}}]),e}(),ve=1,pe=function(){function e(t,n,i){for(var r in T(this,e),this.__view=t,this.__liveSocket=t.liveSocket,this.__callbacks=i,this.__listeners=new Set,this.el=n,this.viewName=t.name(),this.el.phxHookId=this.constructor.makeID(),this.__callbacks)this[r]=this.__callbacks[r]}return D(e,null,[{key:"makeID",value:function(){return ve++}},{key:"elementID",value:function(e){return e.phxHookId}}]),D(e,[{key:"pushEvent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){};return this.__view.pushHookEvent(null,e,t,n)}},{key:"pushEventTo",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){};return this.__view.withinTargets(e,function(e,r){return e.pushHookEvent(r,t,n,i)})}},{key:"handleEvent",value:function(e,t){var n=function(n,i){return i?e:t(n.detail)};return window.addEventListener("phx:hook:".concat(e),n),this.__listeners.add(n),n}},{key:"removeHandleEvent",value:function(e){var t=e(null,!0);window.removeEventListener("phx:hook:".concat(t),e),this.__listeners.delete(e)}},{key:"__cleanup__",value:function(){var e=this;this.__listeners.forEach(function(t){return e.removeHandleEvent(t)})}},{key:"__trigger__",value:function(e){var t=this.__callbacks[e];t&&t.call(this)}}]),e}();t.default=se},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){(function(t){t.Phoenix||(t.Phoenix={}),e.exports=t.Phoenix.LiveView=n(0)}).call(this,n(1))}])});
@@ -1,35 +0,0 @@
1
- {
2
- "name": "phoenix_live_view",
3
- "version": "0.14.8",
4
- "description": "The Phoenix LiveView JavaScript client.",
5
- "license": "MIT",
6
- "repository": {},
7
- "scripts": {
8
- "build": "webpack --mode production",
9
- "watch": "webpack --mode development --watch",
10
- "test": "jest",
11
- "test.coverage": "jest --coverage",
12
- "test.watch": "jest --watch"
13
- },
14
- "dependencies": {
15
- "morphdom": "2.6.1"
16
- },
17
- "devDependencies": {
18
- "@babel/core": "^7.3.4",
19
- "@babel/preset-env": "^7.4.1",
20
- "babel-loader": "^8.0.5",
21
- "copy-webpack-plugin": "^4.5.0",
22
- "css-loader": "^0.28.10",
23
- "expose-loader": "^0.7.5",
24
- "extract-text-webpack-plugin": "^4.0.0-beta.0",
25
- "jest": "^26.0.1",
26
- "phoenix": "file:../deps/phoenix",
27
- "style-loader": "^0.20.2",
28
- "wait-for-expect": "^1.1.0",
29
- "webpack": "4.0.0",
30
- "webpack-cli": "^2.0.10"
31
- },
32
- "jest": {
33
- "testRegex": "/test/.*_test\\.js$"
34
- }
35
- }