phoenix_live_view 0.1.1 → 0.3.1

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,7 +1,70 @@
1
- ## 0.1.0 (2019-08-27)
1
+ ## 0.3.1 (2019-09-23)
2
+
3
+ ### Backwards incompatible changes
4
+ - `live_isolated` in tests no longer requires a router and a pipeline (it now expects only 3 arguments)
5
+ - Raise if `handle_params` is used on a non-router LiveView
6
+
7
+ ### Bug Fixes
8
+ - [LiveViewTest] Fix function clause errors caused by HTML comments
9
+ - Fix `live_redirect` failing to detect back button URL changes
10
+
11
+ ## 0.3.0 (2019-09-19)
12
+
13
+ ### Enhancements
14
+ - Add `phx-debounce` and `phx-throttle` bindings to rate limit events
15
+
16
+ ### Backwards incompatible changes
17
+ - IE11 support now requires two additional polyfills, `mdn-polyfills/CustomEvent` and `mdn-polyfills/String.prototype.startsWith`
18
+
19
+ ### Bug Fixes
20
+ - Fix IE11 support caused by unsupported `getAttributeNames` lookup
21
+ - Fix Floki dependency compilation warnings
22
+
23
+ ## 0.2.1 (2019-09-17)
24
+
25
+ ### Bug Fixes
26
+ - [LiveView.Router] Fix module concat failing to build correct layout module when using custom namespace
27
+ - [LiveViewTest] Fix phx-update append/prepend containers not building proper DOM content
28
+ - [LiveViewTest] Fix phx-update append/prepend containers not updating existing child containers with matching IDs
29
+
30
+ ## 0.2.0 (2019-09-12)
31
+
32
+ ### Enhancements
33
+ - [LiveView] Add new `:container` option to `use Phoenix.LiveView`
34
+ - [LiveViewTest] Add `live_isolated` test helper for testing LiveViews which are not routable
35
+
36
+ ### Backwards incompatible changes
37
+ - Replace `configure_temporary_assigns/2` with 3-tuple mount return, supporting a `:temporary_assigns` key
38
+ - Do not allow `redirect`/`live_redirect` on mount nor in child live views
39
+ - All `phx-update` containers now require a unique ID
40
+ - `LiveSocket` JavaScript constructor now requires explicit dependency injection of Phoenix Socket constructor. For example:
41
+
42
+ ```javascript
43
+ import {Socket} from "phoenix"
44
+ import LiveSocket from "phoenix_live_view"
45
+
46
+ let liveSocket = new LiveSocket("/live", Socket, {...})
47
+ ````
48
+
49
+ ### Bug Fixes
50
+ - Fix phx-update=append/prepend failing to join new nested live views or wire up new phx-hooks
51
+ - Fix number input handling causing some browsers to reset form fields on invalid inputs
52
+ - Fix multi-select decoding causing server error
53
+ - Fix multi-select change tracking failing to submit an event when a value is deselected
54
+ - Fix live redirect loop triggered under certain scenarios
55
+ - Fix params failing to update on re-mounts after live_redirect
56
+ - Fix blur event metadata being sent with type of "focus"
57
+
58
+ ## 0.1.2
59
+
60
+ ### Backwards incompatible changes
61
+ - `phx-value` has no effect, use `phx-value-*` instead
62
+ - The `:path_params` key in session has no effect (use `handle_params` in `LiveView` instead)
63
+
64
+ ## 0.1.1 (2019-08-27)
2
65
 
3
66
  ### Enhancements
4
- - Use optimized insertAdjacentHTML for faster append/prepend and proper css animation handling
67
+ - Use optimized `insertAdjacentHTML` for faster append/prepend and proper css animation handling
5
68
  - Allow for replacing previously appended/prepended elements by replacing duplicate IDs during append/prepend instead of adding new DOM nodes
6
69
 
7
70
  ### Bug Fixes
@@ -12,7 +75,9 @@
12
75
 
13
76
  ### Enhancements
14
77
  - The LiveView `handle_in/3` callback now receives a map of metadata about the client event
15
- - For `phx-change` events, `handle_in/3` now receives a `"_target"` param representing the keyspace
16
- of the form input name which triggered the change
17
- - Multiple values may be provided for any phx binding, using the `phx-value-` prefix, such as `phx-value-myval1`, `phx-value-myval2`, etc
78
+ - For `phx-change` events, `handle_in/3` now receives a `"_target"` param representing the keyspace of the form input name which triggered the change
79
+ - Multiple values may be provided for any phx binding by using the `phx-value-` prefix, such as `phx-value-myval1`, `phx-value-myval2`, etc
80
+ - Add control over the DOM patching via `phx-update`, which can be set to "replace", "append", "prepend" or "ignore"
18
81
 
82
+ ### Backwards incompatible changes
83
+ - `phx-ignore` was renamed to `phx-update="ignore"`
package/README.md CHANGED
@@ -22,7 +22,8 @@ To use LiveView, add to your `mix.exs` and run `mix deps.get`:
22
22
  ```elixir
23
23
  def deps do
24
24
  [
25
- {:phoenix_live_view, "~> 0.1.0"}
25
+ {:phoenix_live_view, "~> 0.3.0"},
26
+ {:floki, ">= 0.0.0", only: :test}
26
27
  ]
27
28
  end
28
29
  ```
@@ -58,14 +59,15 @@ Then add the following imports to your web file in `lib/my_app_web.ex`:
58
59
  def controller do
59
60
  quote do
60
61
  ...
61
- import Phoenix.LiveView.Controller, only: [live_render: 3]
62
+ import Phoenix.LiveView.Controller
62
63
  end
63
64
  end
64
65
 
65
66
  def view do
66
67
  quote do
67
68
  ...
68
- import Phoenix.LiveView, only: [live_render: 2, live_render: 3, live_link: 1, live_link: 2]
69
+ import Phoenix.LiveView,
70
+ only: [live_render: 2, live_render: 3, live_link: 1, live_link: 2]
69
71
  end
70
72
  end
71
73
 
@@ -120,27 +122,13 @@ Enable connecting to a LiveView socket in your `app.js` file.
120
122
 
121
123
  ```javascript
122
124
  // assets/js/app.js
125
+ import {Socket} from "phoenix"
123
126
  import LiveSocket from "phoenix_live_view"
124
127
 
125
- let liveSocket = new LiveSocket("/live")
128
+ let liveSocket = new LiveSocket("/live", Socket)
126
129
  liveSocket.connect()
127
130
  ```
128
131
 
129
- Finally, by convention live views are saved in a `lib/my_app_web/live/`
130
- directory. For live page reload support, add the following pattern to
131
- your `config/dev.exs`:
132
-
133
- ```elixir
134
- # config/dev.exs
135
- config :demo, MyAppWeb.Endpoint,
136
- live_reload: [
137
- patterns: [
138
- ...,
139
- ~r{lib/my_app_web/live/.*(ex)$}
140
- ]
141
- ]
142
- ```
143
-
144
132
  You can also optionally import the style for the default CSS classes in your `app.css` file.
145
133
 
146
134
  ```css
@@ -159,6 +147,9 @@ $ npm install --save --prefix assets mdn-polyfills url-search-params-polyfill fo
159
147
 
160
148
  ```javascript
161
149
  // assets/js/app.js
150
+ import "mdn-polyfills/CustomEvent"
151
+ import "mdn-polyfills/String.prototype.startsWith"
152
+ import "mdn-polyfills/Array.from"
162
153
  import "mdn-polyfills/NodeList.prototype.forEach"
163
154
  import "mdn-polyfills/Element.prototype.closest"
164
155
  import "mdn-polyfills/Element.prototype.matches"
@@ -167,6 +158,7 @@ import "url-search-params-polyfill"
167
158
  import "formdata-polyfill"
168
159
  import "classlist-polyfill"
169
160
 
161
+ import {Socket} from "phoenix"
170
162
  import LiveSocket from "phoenix_live_view"
171
163
  ...
172
164
  ```
@@ -8,9 +8,9 @@ See the hexdocs at `https://hexdocs.pm/phoenix_live_view` for documentation.
8
8
  */
9
9
 
10
10
  import morphdom from "morphdom"
11
- import {Socket} from "phoenix"
12
11
 
13
12
  const PHX_VIEW = "data-phx-view"
13
+ const PHX_COMPONENT = "data-phx-component"
14
14
  const PHX_LIVE_LINK = "data-phx-live-link"
15
15
  const PHX_CONNECTED_CLASS = "phx-connected"
16
16
  const PHX_LOADING_CLASS = "phx-loading"
@@ -20,7 +20,6 @@ const PHX_PARENT_ID = "data-phx-parent-id"
20
20
  const PHX_VIEW_SELECTOR = `[${PHX_VIEW}]`
21
21
  const PHX_ERROR_FOR = "data-phx-error-for"
22
22
  const PHX_HAS_FOCUSED = "phx-has-focused"
23
- const PHX_BOUND = "data-phx-bound"
24
23
  const FOCUSABLE_INPUTS = ["text", "textarea", "number", "email", "password", "search", "tel", "url"]
25
24
  const PHX_HAS_SUBMITTED = "phx-has-submitted"
26
25
  const PHX_SESSION = "data-phx-session"
@@ -29,19 +28,26 @@ const PHX_READONLY = "data-phx-readonly"
29
28
  const PHX_DISABLED = "data-phx-disabled"
30
29
  const PHX_DISABLE_WITH = "disable-with"
31
30
  const PHX_HOOK = "hook"
31
+ const PHX_DEBOUNCE = "debounce"
32
+ const PHX_THROTTLE = "throttle"
33
+ const PHX_CHANGE = "phx-change"
32
34
  const PHX_UPDATE = "update"
35
+ const PHX_PRIVATE = "phxPrivate"
33
36
  const LOADER_TIMEOUT = 1
34
37
  const BEFORE_UNLOAD_LOADER_TIMEOUT = 200
35
38
  const BINDING_PREFIX = "phx-"
36
39
  const PUSH_TIMEOUT = 30000
37
40
  const LINK_HEADER = "x-requested-with"
38
- const PHX_PREV_APPEND = "phxPrevAppend"
41
+ const DEBOUNCE_BLUR = "debounce-blur"
42
+ const DEBOUNCE_TIMER = "debounce-timer"
43
+ const DEBOUNCE_PREV_KEY = "debounce-prev-key"
44
+
45
+ let logError = (msg, obj) => console.error && console.error(msg, obj)
39
46
 
40
47
  export let debug = (view, kind, msg, obj) => {
41
48
  console.log(`${view.id} ${kind}: ${msg} - `, obj)
42
49
  }
43
50
 
44
-
45
51
  // wraps value in closure or returns closure
46
52
  let closure = (val) => typeof val === "function" ? val : function(){ return val }
47
53
 
@@ -64,13 +70,7 @@ let isEmpty = (obj) => {
64
70
  return true
65
71
  }
66
72
 
67
- let maybe = (el, key) => {
68
- if(el){
69
- return el[key]
70
- } else {
71
- return null
72
- }
73
- }
73
+ let maybe = (el, callback) => el && callback(el)
74
74
 
75
75
  let serializeForm = (form, meta = {}) => {
76
76
  let formData = new FormData(form)
@@ -94,13 +94,6 @@ let recursiveMerge = (target, source) => {
94
94
  }
95
95
  }
96
96
 
97
- let Session = {
98
- get(el){ return el.getAttribute(PHX_SESSION) },
99
-
100
- isEqual(el1, el2){ return this.get(el1) === this.get(el2) }
101
- }
102
-
103
-
104
97
  export let Rendered = {
105
98
  mergeDiff(source, diff){
106
99
  if(this.isNewFingerprint(diff)){
@@ -152,11 +145,44 @@ export let Rendered = {
152
145
  }
153
146
  }
154
147
 
155
- // todo document LiveSocket specific options like viewLogger
148
+ /** Initializes the LiveSocket
149
+ *
150
+ *
151
+ * @param {string} endPoint - The string WebSocket endpoint, ie, `"wss://example.com/live"`,
152
+ * `"/live"` (inherited host & protocol)
153
+ * @param {Phoenix.Socket} socket - the required Phoenix Socket class imported from "phoenix". For example:
154
+ *
155
+ * import {Socket} from "phoenix"
156
+ * import {LiveSocket} from "phoenix_live_view"
157
+ * let liveSocket = new LiveSocket("/live", Socket, {...})
158
+ *
159
+ * @param {Object} [opts] - Optional configuration. Outside of keys listed below, all
160
+ * configuration is passed directly to the Phoenix Socket constructor.
161
+ * @param {Function} [opts.params] - The optional function for passing connect params.
162
+ * The function receives the viewName associated with a given LiveView. For example:
163
+ *
164
+ * (viewName) => {view: viewName, token: window.myToken}
165
+ *
166
+ * @param {string} [opts.bindingPrefix] - The optional prefix to use for all phx DOM annotations.
167
+ * Defaults to "phx-".
168
+ * @param {string} [opts.hooks] - The optional object for referencing LiveView hook callbacks.
169
+ * @param {Function} [opts.viewLogger] - The optional function to log debug information. For example:
170
+ *
171
+ * (view, kind, msg, obj) => console.log(`${view.id} ${kind}: ${msg} - `, obj)
172
+ */
156
173
  export class LiveSocket {
157
- constructor(url, opts = {}){
174
+ constructor(url, phxSocket, opts = {}){
158
175
  this.unloaded = false
159
- this.socket = new Socket(url, opts)
176
+ if(!phxSocket || phxSocket.constructor.name === "Object"){
177
+ throw new Error(`
178
+ a phoenix Socket must be provided as the second argument to the LiveSocket constructor. For example:
179
+
180
+ import {Socket} from "phoenix"
181
+ import {LiveSocket} from "phoenix_live_view"
182
+ let liveSocket = new LiveSocket("/live", Socket, {...})
183
+ `)
184
+ }
185
+ this.socket = new phxSocket(url, opts)
160
186
  this.bindingPrefix = opts.bindingPrefix || BINDING_PREFIX
161
187
  this.opts = opts
162
188
  this.views = {}
@@ -222,7 +248,7 @@ export class LiveSocket {
222
248
  channel(topic, params){ return this.socket.channel(topic, params) }
223
249
 
224
250
  joinRootViews(){
225
- Browser.all(document, `${PHX_VIEW_SELECTOR}:not([${PHX_PARENT_ID}])`, rootEl => {
251
+ DOM.all(document, `${PHX_VIEW_SELECTOR}:not([${PHX_PARENT_ID}])`, rootEl => {
226
252
  let view = this.joinView(rootEl, null, this.getHref())
227
253
  this.root = this.root || view
228
254
  })
@@ -254,7 +280,7 @@ export class LiveSocket {
254
280
  }
255
281
 
256
282
  joinView(el, parentView, href, callback){
257
- if(this.getViewById(el.id)){ return }
283
+ if(this.getViewByEl(el)){ return }
258
284
 
259
285
  let view = new View(el, this, parentView, href)
260
286
  this.views[view.id] = view
@@ -263,11 +289,11 @@ export class LiveSocket {
263
289
  }
264
290
 
265
291
  owner(childEl, callback){
266
- let view = this.getViewById(maybe(childEl.closest(PHX_VIEW_SELECTOR), "id"))
292
+ let view = maybe(childEl.closest(PHX_VIEW_SELECTOR), el => this.getViewByEl(el))
267
293
  if(view){ callback(view) }
268
294
  }
269
295
 
270
- getViewById(id){ return this.views[id] }
296
+ getViewByEl(el){ return this.views[el.id] }
271
297
 
272
298
  onViewError(view){
273
299
  this.dropActiveElement(view)
@@ -277,6 +303,8 @@ export class LiveSocket {
277
303
  for(let id in this.views){ this.destroyViewById(id) }
278
304
  }
279
305
 
306
+ destroyViewByEl(el){ return this.destroyViewById(el.id) }
307
+
280
308
  destroyViewById(id){
281
309
  let view = this.views[id]
282
310
  if(view){
@@ -347,7 +375,7 @@ export class LiveSocket {
347
375
  })
348
376
  this.bindTargetable({blur: "focusout", focus: "focusin"}, (e, type, view, targetEl, phxEvent, phxTarget) => {
349
377
  if(!phxTarget){
350
- view.pushEvent(type, targetEl, phxEvent, {type: "focus"})
378
+ view.pushEvent(type, targetEl, phxEvent, {type: type})
351
379
  }
352
380
  })
353
381
  this.bindTargetable({blur: "blur", focus: "focus"}, (e, type, view, targetEl, phxEvent, phxTarget) => {
@@ -389,11 +417,15 @@ export class LiveSocket {
389
417
  let bindTarget = this.binding("target")
390
418
  let targetPhxEvent = e.target.getAttribute && e.target.getAttribute(binding)
391
419
  if(targetPhxEvent && !e.target.getAttribute(bindTarget)){
392
- this.owner(e.target, view => callback(e, event, view, e.target, targetPhxEvent, null))
420
+ this.owner(e.target, view => {
421
+ this.debounce(e.target, e, () => callback(e, event, view, e.target, targetPhxEvent, null))
422
+ })
393
423
  } else {
394
- Browser.all(document, `[${binding}][${bindTarget}=window]`, el => {
424
+ DOM.all(document, `[${binding}][${bindTarget}=window]`, el => {
395
425
  let phxEvent = el.getAttribute(binding)
396
- this.owner(el, view => callback(e, event, view, el, phxEvent, "window"))
426
+ this.owner(el, view => {
427
+ this.debounce(el, e, () => callback(e, event, view, el, phxEvent, "window"))
428
+ })
397
429
  })
398
430
  }
399
431
  })
@@ -406,10 +438,10 @@ export class LiveSocket {
406
438
  let target = closestPhxBinding(e.target, click)
407
439
  let phxEvent = target && target.getAttribute(click)
408
440
  if(!phxEvent){ return }
409
- e.preventDefault()
410
-
441
+ e.stopPropagation()
442
+
411
443
  let meta = {
412
- altKey: e.altKey,
444
+ altKey: e.altKey,
413
445
  shiftKey: e.shiftKey,
414
446
  ctrlKey: e.ctrlKey,
415
447
  metaKey: e.metaKey,
@@ -421,7 +453,9 @@ export class LiveSocket {
421
453
  screenY: e.screenY,
422
454
  }
423
455
 
424
- this.owner(target, view => view.pushEvent("click", target, phxEvent, meta))
456
+ this.owner(target, view => {
457
+ this.debounce(target, e, () => view.pushEvent("click", target, phxEvent, meta))
458
+ })
425
459
  }, false)
426
460
  }
427
461
 
@@ -473,25 +507,31 @@ export class LiveSocket {
473
507
  for(let type of ["change", "input"]){
474
508
  this.on(type, e => {
475
509
  let input = e.target
476
- let key = input.type === "checkbox" ? "checked" : "value"
477
- if(this.prevInput === input && this.prevValue === input[key]){ return }
478
-
479
- this.prevInput = input
480
- this.prevValue = input[key]
481
510
  let phxEvent = input.form && input.form.getAttribute(this.binding("change"))
482
511
  if(!phxEvent){ return }
512
+
513
+ let value = JSON.stringify((new FormData(input.form)).getAll(input.name))
514
+ if(this.prevInput === input && this.prevValue === value){ return }
515
+ if(input.type === "number" && input.validity && input.validity.badInput){ return }
516
+
517
+ this.prevInput = input
518
+ this.prevValue = value
483
519
  this.owner(input, view => {
484
520
  if(DOM.isTextualInput(input)){
485
- input[PHX_HAS_FOCUSED] = true
521
+ DOM.putPrivate(input, PHX_HAS_FOCUSED, true)
486
522
  } else {
487
523
  this.setActiveElement(input)
488
524
  }
489
- view.pushInput(input, phxEvent, e)
525
+ this.debounce(input, e, () => view.pushInput(input, phxEvent, e))
490
526
  })
491
527
  }, false)
492
528
  }
493
529
  }
494
530
 
531
+ debounce(el, event, callback){
532
+ DOM.debounce(el, event, this.binding(PHX_DEBOUNCE), this.binding(PHX_THROTTLE), callback)
533
+ }
534
+
495
535
  silenceEvents(callback){
496
536
  this.silenced = true
497
537
  callback()
@@ -506,10 +546,6 @@ export class LiveSocket {
506
546
  }
507
547
 
508
548
  export let Browser = {
509
- all(node, query, callback){
510
- node.querySelectorAll(query).forEach(callback)
511
- },
512
-
513
549
  canPushState(){ return (typeof(history.pushState) !== "undefined") },
514
550
 
515
551
  fetchPage(href, callback){
@@ -538,17 +574,6 @@ export let Browser = {
538
574
  }
539
575
  },
540
576
 
541
- dispatchEvent(target, eventString){
542
- let event = null
543
- if(typeof(Event) === "function"){
544
- event = new Event(eventString)
545
- } else {
546
- event = document.createEvent("Event")
547
- event.initEvent(eventString, true, true)
548
- }
549
- target.dispatchEvent(event)
550
- },
551
-
552
577
  setCookie(name, value){
553
578
  document.cookie = `${name}=${value}`
554
579
  },
@@ -563,21 +588,83 @@ export let Browser = {
563
588
  }
564
589
  }
565
590
 
566
- let DOM = {
591
+ export let DOM = {
592
+ all(node, query, callback){
593
+ return Array.from(node.querySelectorAll(query)).forEach(callback)
594
+ },
595
+
596
+ private(el, key){ return el[PHX_PRIVATE] && el[PHX_PRIVATE][key] },
597
+
598
+ deletePrivate(el, key){ el[PHX_PRIVATE] && delete(el[PHX_PRIVATE][key]) },
599
+
600
+ putPrivate(el, key, value){
601
+ if(!el[PHX_PRIVATE]){ el[PHX_PRIVATE] = {} }
602
+ el[PHX_PRIVATE][key] = value
603
+ },
604
+
605
+ copyPrivates(target, source){
606
+ if(source[PHX_PRIVATE]){
607
+ target[PHX_PRIVATE] = clone(source[PHX_PRIVATE])
608
+ }
609
+ },
610
+
611
+ debounce(el, event, phxDebounce, phxThrottle, callback){
612
+ let debounce = el.getAttribute(phxDebounce)
613
+ let throttle = el.getAttribute(phxThrottle)
614
+ let value = debounce || throttle
615
+ switch(value){
616
+ case null: return callback()
617
+
618
+ case "blur":
619
+ if(this.private(el, DEBOUNCE_BLUR)){ return }
620
+ el.addEventListener("blur", () => callback())
621
+ this.putPrivate(el, DEBOUNCE_BLUR, value)
622
+ return
623
+
624
+ default:
625
+ let timeout = parseInt(value)
626
+ if(isNaN(timeout)){ return logError(`invalid throttle/debounce value: ${value}`) }
627
+ if(throttle && event.type === "keydown"){
628
+ let prevKey = this.private(el, DEBOUNCE_PREV_KEY)
629
+ this.putPrivate(el, DEBOUNCE_PREV_KEY, event.which)
630
+ if(prevKey !== event.which){ return callback() }
631
+ }
632
+ if(this.private(el, DEBOUNCE_TIMER)){ return }
633
+
634
+ let clearTimer = (e) => {
635
+ if(throttle && e.type === PHX_CHANGE && e.detail.triggeredBy.name === el.name){ return }
636
+ clearTimeout(this.private(el, DEBOUNCE_TIMER))
637
+ this.deletePrivate(el, DEBOUNCE_TIMER)
638
+ }
639
+ this.putPrivate(el, DEBOUNCE_TIMER, setTimeout(() => {
640
+ if(el.form){
641
+ el.form.removeEventListener(PHX_CHANGE, clearTimer)
642
+ el.form.removeEventListener("submit", clearTimer)
643
+ }
644
+ this.deletePrivate(el, DEBOUNCE_TIMER)
645
+ if(!throttle){ callback() }
646
+ }, timeout))
647
+ if(el.form){
648
+ el.form.addEventListener(PHX_CHANGE, clearTimer)
649
+ el.form.addEventListener("submit", clearTimer)
650
+ }
651
+ if(throttle){ callback() }
652
+ }
653
+ },
567
654
 
568
655
  disableForm(form, prefix){
569
656
  let disableWith = `${prefix}${PHX_DISABLE_WITH}`
570
657
  form.classList.add(PHX_LOADING_CLASS)
571
- Browser.all(form, `[${disableWith}]`, el => {
658
+ DOM.all(form, `[${disableWith}]`, el => {
572
659
  let value = el.getAttribute(disableWith)
573
660
  el.setAttribute(`${disableWith}-restore`, el.innerText)
574
661
  el.innerText = value
575
662
  })
576
- Browser.all(form, "button", button => {
663
+ DOM.all(form, "button", button => {
577
664
  button.setAttribute(PHX_DISABLED, button.disabled)
578
665
  button.disabled = true
579
666
  })
580
- Browser.all(form, "input", input => {
667
+ DOM.all(form, "input", input => {
581
668
  input.setAttribute(PHX_READONLY, input.readOnly)
582
669
  input.readOnly = true
583
670
  })
@@ -587,7 +674,7 @@ let DOM = {
587
674
  let disableWith = `${prefix}${PHX_DISABLE_WITH}`
588
675
  form.classList.remove(PHX_LOADING_CLASS)
589
676
 
590
- Browser.all(form, `[${disableWith}]`, el => {
677
+ DOM.all(form, `[${disableWith}]`, el => {
591
678
  let value = el.getAttribute(`${disableWith}-restore`)
592
679
  if(value){
593
680
  if(el.nodeName === "INPUT") {
@@ -598,14 +685,14 @@ let DOM = {
598
685
  el.removeAttribute(`${disableWith}-restore`)
599
686
  }
600
687
  })
601
- Browser.all(form, "button", button => {
688
+ DOM.all(form, "button", button => {
602
689
  let prev = button.getAttribute(PHX_DISABLED)
603
690
  if(prev){
604
691
  button.disabled = prev === "true"
605
692
  button.removeAttribute(PHX_DISABLED)
606
693
  }
607
694
  })
608
- Browser.all(form, "input", input => {
695
+ DOM.all(form, "input", input => {
609
696
  let prev = input.getAttribute(PHX_READONLY)
610
697
  if(prev){
611
698
  input.readOnly = prev === "true"
@@ -614,12 +701,12 @@ let DOM = {
614
701
  })
615
702
  },
616
703
 
617
- discardError(el){
704
+ discardError(container, el){
618
705
  let field = el.getAttribute && el.getAttribute(PHX_ERROR_FOR)
619
706
  if(!field) { return }
620
- let input = document.getElementById(field)
707
+ let input = container.querySelector(`#${field}`)
621
708
 
622
- if(field && !(input[PHX_HAS_FOCUSED] || input.form[PHX_HAS_SUBMITTED])){
709
+ if(field && !(this.private(input, PHX_HAS_FOCUSED) || this.private(input.form, PHX_HAS_SUBMITTED))){
623
710
  el.style.display = "none"
624
711
  }
625
712
  },
@@ -628,107 +715,51 @@ let DOM = {
628
715
  return node.getAttribute && node.getAttribute(PHX_PARENT_ID)
629
716
  },
630
717
 
631
- applyPhxUpdate(fromEl, toEl, phxUpdate, phxHook, changes){
632
- let type = toEl.getAttribute && toEl.getAttribute(phxUpdate)
633
- if(!type || type === "replace"){
634
- return false
635
- } else {
636
- DOM.mergeAttrs(fromEl, toEl)
637
- }
638
-
639
- switch(type){
640
- case "ignore": break
641
- case "append":
642
- case "prepend":
643
- let newHTML = toEl.innerHTML
644
- if(fromEl[PHX_PREV_APPEND] === newHTML){ break }
645
-
646
- fromEl[PHX_PREV_APPEND] = newHTML
647
- toEl.querySelectorAll("[id]").forEach(el => {
648
- let existing = fromEl.querySelector(`[id="${el.id}"]`)
649
- if(existing){
650
- changes.discarded.push(existing)
651
- el.remove()
652
- existing.replaceWith(el)
653
- }
654
- })
655
- let operation = type === "append" ? "beforeend" : "afterbegin"
656
- fromEl.insertAdjacentHTML(operation, toEl.innerHTML)
657
- fromEl.querySelectorAll(`[${phxHook}]`).forEach(el => changes.added.push(el))
658
- break
659
- default: throw new Error(`unsupported phx-update "${type}"`)
660
- }
661
- changes.updated.push({fromEl, toEl: fromEl})
662
- return true
663
- },
664
-
665
718
  patch(view, container, id, html){
666
- let changes = {added: [], updated: [], discarded: []}
719
+ let changes = {added: [], updated: [], discarded: [], phxChildrenAdded: []}
667
720
  let focused = view.liveSocket.getActiveElement()
668
- let selectionStart = null
669
- let selectionEnd = null
721
+ let {selectionStart, selectionEnd} = focused && DOM.isTextualInput(focused) ? focused : {}
670
722
  let phxUpdate = view.liveSocket.binding(PHX_UPDATE)
671
- let phxHook = view.liveSocket.binding(PHX_HOOK)
672
- let diffContainer = container.cloneNode()
673
- diffContainer.innerHTML = html
723
+ let diffContainer = this.buildDiffContainer(container, html, phxUpdate)
674
724
 
675
- if(DOM.isTextualInput(focused)){
676
- selectionStart = focused.selectionStart
677
- selectionEnd = focused.selectionEnd
678
- }
679
-
680
- morphdom(container, diffContainer, {
725
+ morphdom(container, diffContainer.outerHTML, {
681
726
  childrenOnly: true,
682
727
  onBeforeNodeAdded: function(el){
683
728
  //input handling
684
- DOM.discardError(el)
729
+ DOM.discardError(container, el)
685
730
  return el
686
731
  },
687
732
  onNodeAdded: function(el){
688
733
  // nested view handling
689
734
  if(DOM.isPhxChild(el) && view.ownsElement(el)){
690
- view.onNewChildAdded()
691
- return true
692
- } else {
693
- changes.added.push(el)
735
+ changes.phxChildrenAdded.push(el)
694
736
  }
737
+ changes.added.push(el)
695
738
  },
696
739
  onBeforeNodeDiscarded: function(el){
697
740
  // nested view handling
698
741
  if(DOM.isPhxChild(el)){
699
- view.liveSocket.destroyViewById(el.id)
742
+ view.liveSocket.destroyViewByEl(el)
700
743
  return true
701
744
  }
702
745
  changes.discarded.push(el)
703
746
  },
704
747
  onBeforeElUpdated: function(fromEl, toEl) {
705
748
  if(fromEl.isEqualNode(toEl)){ return false } // Skip subtree if both elems and children are equal
706
-
707
- if(DOM.applyPhxUpdate(fromEl, toEl, phxUpdate, phxHook, changes)){
708
- return false
709
- }
749
+ if(fromEl.getAttribute(phxUpdate) === "ignore"){ return false }
750
+ if(fromEl.type === "number" && (fromEl.validity && fromEl.validity.badInput)){ return false }
710
751
 
711
752
  // nested view handling
712
753
  if(DOM.isPhxChild(toEl)){
713
754
  let prevStatic = fromEl.getAttribute(PHX_STATIC)
714
-
715
- if(!Session.isEqual(toEl, fromEl)){
716
- view.liveSocket.destroyViewById(fromEl.id)
717
- view.onNewChildAdded()
718
- }
719
755
  DOM.mergeAttrs(fromEl, toEl)
720
756
  fromEl.setAttribute(PHX_STATIC, prevStatic)
721
757
  return false
722
758
  }
723
759
 
724
760
  // input handling
725
- if(fromEl.getAttribute && fromEl[PHX_HAS_SUBMITTED]){
726
- toEl[PHX_HAS_SUBMITTED] = true
727
- }
728
- if(fromEl[PHX_HAS_FOCUSED]){
729
- toEl[PHX_HAS_FOCUSED] = true
730
- }
731
- DOM.discardError(toEl)
761
+ DOM.copyPrivates(toEl, fromEl)
762
+ DOM.discardError(container, toEl)
732
763
 
733
764
  if(DOM.isTextualInput(fromEl) && fromEl === focused){
734
765
  DOM.mergeInputs(fromEl, toEl)
@@ -741,24 +772,64 @@ let DOM = {
741
772
  }
742
773
  })
743
774
 
744
- view.liveSocket.silenceEvents(() => {
745
- DOM.restoreFocus(focused, selectionStart, selectionEnd)
746
- })
747
- Browser.dispatchEvent(document, "phx:update")
775
+ view.liveSocket.silenceEvents(() => DOM.restoreFocus(focused, selectionStart, selectionEnd))
776
+ DOM.dispatchEvent(document, "phx:update")
748
777
  return changes
749
778
  },
750
779
 
751
- mergeAttrs(target, source){
780
+ dispatchEvent(target, eventString, detail = {}){
781
+ let event = new CustomEvent(eventString, {bubbles: true, cancelable: true, detail: detail})
782
+ target.dispatchEvent(event)
783
+ },
784
+
785
+ cloneNode(node, html){
786
+ let cloned = node.cloneNode()
787
+ cloned.innerHTML = html || node.innerHTML
788
+ return cloned
789
+ },
790
+
791
+ // builds container for morphdom patch
792
+ // - precomputes append/prepend content in diff node to make it appear as if
793
+ // the contents had been appended/prepended on full child node list
794
+ // - precomputes updates on existing child ids within a prepend/append child list
795
+ // to allow existing nodes to be updated in place rather than reordered
796
+ buildDiffContainer(container, html, phxUpdate){
797
+ let diffContainer = this.cloneNode(container, html)
798
+ let elementsOnly = child => child.nodeType === Node.ELEMENT_NODE
799
+ let idsOnly = child => child.id || logError("append/prepend children require IDs, got: ", child)
800
+
801
+ DOM.all(diffContainer, `[${phxUpdate}=append],[${phxUpdate}=prepend]`, el => {
802
+ let id = el.id || logError("append/prepend requires an ID, got: ", el)
803
+ let existingInContainer = container.querySelector(`#${id}`)
804
+ if(!existingInContainer){ return }
805
+ let existing = this.cloneNode(existingInContainer)
806
+ let updateType = el.getAttribute(phxUpdate)
807
+ let newIds = Array.from(el.childNodes).filter(elementsOnly).map(idsOnly)
808
+ let existingIds = Array.from(existing.childNodes).filter(elementsOnly).map(idsOnly)
809
+
810
+ if(newIds.toString() !== existingIds.toString()){
811
+ let dupIds = newIds.filter(id => existingIds.indexOf(id) >= 0)
812
+ dupIds.forEach(id => {
813
+ let updatedEl = el.querySelector(`#${id}`)
814
+ existing.querySelector(`#${id}`).replaceWith(updatedEl)
815
+ })
816
+ el.insertAdjacentHTML(updateType === "append" ? "afterbegin" : "beforeend", existing.innerHTML)
817
+ }
818
+ })
819
+
820
+ return diffContainer
821
+ },
822
+
823
+ mergeAttrs(target, source, exclude = []){
752
824
  var attrs = source.attributes
753
825
  for (let i = 0, length = attrs.length; i < length; i++){
754
826
  let name = attrs[i].name
755
- let value = source.getAttribute(name)
756
- target.setAttribute(name, value)
827
+ if(exclude.indexOf(name) < 0){ target.setAttribute(name, source.getAttribute(name)) }
757
828
  }
758
829
  },
759
830
 
760
831
  mergeInputs(target, source){
761
- DOM.mergeAttrs(target, source)
832
+ DOM.mergeAttrs(target, source, ["value"])
762
833
  target.readOnly = source.readOnly
763
834
  },
764
835
 
@@ -780,7 +851,6 @@ export class View {
780
851
  constructor(el, liveSocket, parentView, href){
781
852
  this.liveSocket = liveSocket
782
853
  this.parent = parentView
783
- this.newChildrenAdded = false
784
854
  this.gracefullyClosed = false
785
855
  this.el = el
786
856
  this.id = this.el.id
@@ -804,7 +874,7 @@ export class View {
804
874
 
805
875
  isConnected(){ return this.channel.canPush() }
806
876
 
807
- getSession(){ return Session.get(this.el) }
877
+ getSession(){ return this.el.getAttribute(PHX_SESSION) }
808
878
 
809
879
  getStatic(){
810
880
  let val = this.el.getAttribute(PHX_STATIC)
@@ -866,7 +936,7 @@ export class View {
866
936
  this.hideLoader()
867
937
  let changes = DOM.patch(this, this.el, this.id, Rendered.toString(this.rendered))
868
938
  changes.added.push(this.el)
869
- Browser.all(this.el, `[${this.binding(PHX_HOOK)}]`, hookEl => changes.added.push(hookEl))
939
+ DOM.all(this.el, `[${this.binding(PHX_HOOK)}]`, hookEl => changes.added.push(hookEl))
870
940
  this.triggerHooks(changes)
871
941
  this.joinNewChildren()
872
942
  if(live_redirect){
@@ -876,8 +946,8 @@ export class View {
876
946
  }
877
947
 
878
948
  joinNewChildren(){
879
- Browser.all(document, `${PHX_VIEW_SELECTOR}[${PHX_PARENT_ID}="${this.id}"]`, el => {
880
- let child = this.liveSocket.getViewById(el.id)
949
+ DOM.all(document, `${PHX_VIEW_SELECTOR}[${PHX_PARENT_ID}="${this.id}"]`, el => {
950
+ let child = this.liveSocket.getViewByEl(el)
881
951
  if(!child){
882
952
  this.liveSocket.joinView(el, this)
883
953
  }
@@ -891,9 +961,11 @@ export class View {
891
961
  this.log("update", () => ["", JSON.stringify(diff)])
892
962
  this.rendered = Rendered.mergeDiff(this.rendered, diff)
893
963
  let html = Rendered.toString(this.rendered)
894
- this.newChildrenAdded = false
895
- this.triggerHooks(DOM.patch(this, this.el, this.id, html))
896
- if(this.newChildrenAdded){ this.joinNewChildren() }
964
+ let changes = DOM.patch(this, this.el, this.id, html)
965
+ if(changes.phxChildrenAdded.length > 0){
966
+ this.joinNewChildren()
967
+ }
968
+ this.triggerHooks(changes)
897
969
  }
898
970
 
899
971
  getHook(el){ return this.viewHooks[ViewHook.elementID(el)] }
@@ -913,6 +985,7 @@ export class View {
913
985
  }
914
986
 
915
987
  triggerHooks(changes){
988
+ let destroyedCIDs = []
916
989
  changes.updated.push({fromEl: this.el, toEl: this.el})
917
990
  changes.added.forEach(el => this.addHook(el))
918
991
  changes.updated.forEach(({fromEl, toEl}) => {
@@ -926,9 +999,12 @@ export class View {
926
999
  }
927
1000
  })
928
1001
  changes.discarded.forEach(el => {
1002
+ let cid = this.componentID(el)
1003
+ if(cid){ destroyedCIDs.push(cid) }
929
1004
  let hook = this.getHook(el)
930
1005
  hook && this.destroyHook(hook)
931
1006
  })
1007
+ if(destroyedCIDs.length > 0){ this.pushComponentsDestroyed(destroyedCIDs) }
932
1008
  }
933
1009
 
934
1010
  applyPendingUpdates(){
@@ -936,10 +1012,6 @@ export class View {
936
1012
  this.pendingDiffs = []
937
1013
  }
938
1014
 
939
- onNewChildAdded(){
940
- this.newChildrenAdded = true
941
- }
942
-
943
1015
  bindChannel(){
944
1016
  this.channel.on("diff", (diff) => this.update(diff))
945
1017
  this.channel.on("redirect", ({to, flash}) => this.onRedirect({to, flash}))
@@ -956,10 +1028,14 @@ export class View {
956
1028
  }
957
1029
 
958
1030
  onExternalLiveRedirect({to, kind}){
959
- this.liveSocket.replaceRoot(to, () => Browser.pushState(kind, {}, to))
1031
+ this.liveSocket.replaceRoot(to, () => {
1032
+ Browser.pushState(kind, {}, to)
1033
+ this.liveSocket.registerNewLocation(window.location)
1034
+ })
960
1035
  }
961
1036
 
962
1037
  onLiveRedirect({to, kind}){
1038
+ this.href = to
963
1039
  Browser.pushState(kind, {}, to)
964
1040
  }
965
1041
 
@@ -983,6 +1059,7 @@ export class View {
983
1059
  }
984
1060
 
985
1061
  onJoinError(resp){
1062
+ if(resp.redirect || resp.external_live_redirect){ this.channel.leave() }
986
1063
  if(resp.redirect){ return this.onRedirect(resp.redirect) }
987
1064
  if(resp.external_live_redirect){ return this.onExternalLiveRedirect(resp.external_live_redirect) }
988
1065
  this.displayError()
@@ -1017,42 +1094,46 @@ export class View {
1017
1094
  )
1018
1095
  }
1019
1096
 
1097
+ componentID(el){ return el.getAttribute && el.getAttribute(PHX_COMPONENT) && el.id }
1098
+
1099
+ targetComponentID(target){
1100
+ return maybe(target.closest(`[${PHX_COMPONENT}]`), el => this.ownsElement(el) && this.componentID(el))
1101
+ }
1102
+
1020
1103
  pushEvent(type, el, phxEvent, meta){
1021
- let value = el.getAttribute(this.binding("value"))
1022
- if(value === null){
1023
- value = meta
1024
- let prefix = this.binding("value-")
1025
- for(let key of el.getAttributeNames()){ if(!key.startsWith(prefix)){ continue }
1026
- value[key.replace(prefix, "")] = el.getAttribute(key)
1027
- }
1028
- if(el.value !== undefined){ value.value = el.value }
1104
+ let prefix = this.binding("value-")
1105
+ for (let i = 0; i < el.attributes.length; i++){
1106
+ let name = el.attributes[i].name
1107
+ if(name.startsWith(prefix)){ meta[name.replace(prefix, "")] = el.getAttribute(name) }
1029
1108
  }
1030
-
1109
+ if(el.value !== undefined){ meta.value = el.value }
1110
+
1031
1111
  this.pushWithReply("event", {
1032
1112
  type: type,
1033
1113
  event: phxEvent,
1034
- value: value
1114
+ value: meta,
1115
+ cid: this.targetComponentID(el) || undefined
1035
1116
  })
1036
1117
  }
1037
1118
 
1038
1119
  pushKey(keyElement, kind, phxEvent, meta){
1039
- let value = keyElement.getAttribute(this.binding("value"))
1040
- if(value === null){
1041
- value = meta
1042
- if(keyElement.value !== undefined){ value.value = keyElement.value }
1043
- }
1120
+ if(keyElement.value !== undefined){ meta.value = keyElement.value }
1121
+
1044
1122
  this.pushWithReply("event", {
1045
1123
  type: kind,
1046
1124
  event: phxEvent,
1047
- value: value
1125
+ value: meta,
1126
+ cid: this.targetComponentID(keyElement) || undefined
1048
1127
  })
1049
1128
  }
1050
1129
 
1051
1130
  pushInput(inputEl, phxEvent, e){
1131
+ DOM.dispatchEvent(inputEl.form, PHX_CHANGE, {triggeredBy: inputEl})
1052
1132
  this.pushWithReply("event", {
1053
1133
  type: "form",
1054
1134
  event: phxEvent,
1055
- value: serializeForm(inputEl.form, {_target: e.target.name})
1135
+ value: serializeForm(inputEl.form, {_target: e.target.name}),
1136
+ cid: this.targetComponentID(inputEl) || undefined
1056
1137
  })
1057
1138
  }
1058
1139
 
@@ -1060,7 +1141,8 @@ export class View {
1060
1141
  this.pushWithReply("event", {
1061
1142
  type: "form",
1062
1143
  event: phxEvent,
1063
- value: serializeForm(formEl)
1144
+ value: serializeForm(formEl),
1145
+ cid: this.targetComponentID(formEl) || undefined
1064
1146
  }, onReply)
1065
1147
  }
1066
1148
 
@@ -1079,14 +1161,18 @@ export class View {
1079
1161
  }).receive("timeout", () => Browser.redirect(window.location.href))
1080
1162
  }
1081
1163
 
1082
- ownsElement(element){
1083
- return element.getAttribute(PHX_PARENT_ID) === this.id ||
1084
- maybe(element.closest(PHX_VIEW_SELECTOR), "id") === this.id
1164
+ pushComponentsDestroyed(cids){
1165
+ this.pushWithReply("cids_destroyed", {cids: cids})
1166
+ }
1167
+
1168
+ ownsElement(el){
1169
+ return el.getAttribute(PHX_PARENT_ID) === this.id ||
1170
+ maybe(el.closest(PHX_VIEW_SELECTOR), node => node.id) === this.id
1085
1171
  }
1086
1172
 
1087
1173
  submitForm(form, phxEvent){
1088
1174
  let prefix = this.liveSocket.getBindingPrefix()
1089
- form[PHX_HAS_SUBMITTED] = "true"
1175
+ DOM.putPrivate(form, PHX_HAS_SUBMITTED, true)
1090
1176
  DOM.disableForm(form, prefix)
1091
1177
  this.liveSocket.blurActiveElement(this)
1092
1178
  this.pushFormSubmit(form, phxEvent, () => {
@@ -1121,4 +1207,4 @@ class ViewHook {
1121
1207
  }
1122
1208
  }
1123
1209
 
1124
- export default LiveSocket
1210
+ export default LiveSocket
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phoenix_live_view",
3
- "version": "0.1.1",
3
+ "version": "0.3.1",
4
4
  "description": "The Phoenix LiveView JavaScript client.",
5
5
  "license": "MIT",
6
6
  "main": "./priv/static/_live_view.js",
@@ -14,7 +14,6 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "morphdom": "2.5.5",
17
- "phoenix": "file:../deps/phoenix",
18
17
  "phoenix_html": "file:../deps/phoenix_html"
19
18
  },
20
19
  "devDependencies": {
@@ -26,6 +25,7 @@
26
25
  "expose-loader": "^0.7.5",
27
26
  "extract-text-webpack-plugin": "^4.0.0-beta.0",
28
27
  "jest": "^24.5.0",
28
+ "phoenix": "file:../deps/phoenix",
29
29
  "style-loader": "^0.20.2",
30
30
  "wait-for-expect": "^1.1.0",
31
31
  "webpack": "4.0.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phoenix_live_view",
3
- "version": "0.1.1",
3
+ "version": "0.3.1",
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 o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.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=4)}([function(e,t,n){(function(e){var n,i,o;function r(e){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)}!function(s,a){"object"==r(t)&&"object"==r(e)?e.exports=a():(i=[],void 0===(o="function"==typeof(n=a)?n.apply(t,i):n)||(e.exports=o))}(0,function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==r(e)&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},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=0)}([function(e,t,n){(function(t){e.exports=t.Phoenix=n(2)}).call(this,n(1))},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==("undefined"==typeof window?"undefined":r(window))&&(n=window)}e.exports=n},function(e,t,n){"use strict";function i(e){return(i="function"==typeof Symbol&&"symbol"==r(Symbol.iterator)?function(e){return r(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":r(e)})(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(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 a(e,t,n){return t&&s(e.prototype,t),n&&s(e,n),e}n.r(t),n.d(t,"Channel",function(){return k}),n.d(t,"Serializer",function(){return b}),n.d(t,"Socket",function(){return w}),n.d(t,"LongPoll",function(){return E}),n.d(t,"Ajax",function(){return x}),n.d(t,"Presence",function(){return S});var u="undefined"!=typeof self?self:null,c="undefined"!=typeof window?window:null,l=u||c||void 0,h={connecting:0,open:1,closing:2,closed:3},f=1e4,d={closed:"closed",errored:"errored",joined:"joined",joining:"joining",leaving:"leaving"},v={close:"phx_close",error:"phx_error",join:"phx_join",reply:"phx_reply",leave:"phx_leave"},p=[v.close,v.error,v.join,v.reply,v.leave],y={longpoll:"longpoll",websocket:"websocket"},g=function(e){return"function"==typeof e?e:function(){return e}},m=function(){function e(t,n,i,r){o(this,e),this.channel=t,this.event=n,this.payload=i||function(){return{}},this.receivedResp=null,this.timeout=r,this.timeoutTimer=null,this.recHooks=[],this.sent=!1}return a(e,[{key:"resend",value:function(e){this.timeout=e,this.reset(),this.send()}},{key:"send",value:function(){this.hasReceived("timeout")||(this.startTimeout(),this.sent=!0,this.channel.socket.push({topic:this.channel.topic,event:this.event,payload:this.payload(),ref:this.ref,join_ref:this.channel.joinRef()}))}},{key:"receive",value:function(e,t){return this.hasReceived(e)&&t(this.receivedResp.response),this.recHooks.push({status:e,callback:t}),this}},{key:"reset",value:function(){this.cancelRefEvent(),this.ref=null,this.refEvent=null,this.receivedResp=null,this.sent=!1}},{key:"matchReceive",value:function(e){var t=e.status,n=e.response;e.ref,this.recHooks.filter(function(e){return e.status===t}).forEach(function(e){return e.callback(n)})}},{key:"cancelRefEvent",value:function(){this.refEvent&&this.channel.off(this.refEvent)}},{key:"cancelTimeout",value:function(){clearTimeout(this.timeoutTimer),this.timeoutTimer=null}},{key:"startTimeout",value:function(){var e=this;this.timeoutTimer&&this.cancelTimeout(),this.ref=this.channel.socket.makeRef(),this.refEvent=this.channel.replyEventName(this.ref),this.channel.on(this.refEvent,function(t){e.cancelRefEvent(),e.cancelTimeout(),e.receivedResp=t,e.matchReceive(t)}),this.timeoutTimer=setTimeout(function(){e.trigger("timeout",{})},this.timeout)}},{key:"hasReceived",value:function(e){return this.receivedResp&&this.receivedResp.status===e}},{key:"trigger",value:function(e,t){this.channel.trigger(this.refEvent,{status:e,response:t})}}]),e}(),k=function(){function e(t,n,i){var r=this;o(this,e),this.state=d.closed,this.topic=t,this.params=g(n||{}),this.socket=i,this.bindings=[],this.bindingRef=0,this.timeout=this.socket.timeout,this.joinedOnce=!1,this.joinPush=new m(this,v.join,this.params,this.timeout),this.pushBuffer=[],this.rejoinTimer=new A(function(){r.socket.isConnected()&&r.rejoin()},this.socket.rejoinAfterMs),this.socket.onError(function(){return r.rejoinTimer.reset()}),this.socket.onOpen(function(){r.rejoinTimer.reset(),r.isErrored()&&r.rejoin()}),this.joinPush.receive("ok",function(){r.state=d.joined,r.rejoinTimer.reset(),r.pushBuffer.forEach(function(e){return e.send()}),r.pushBuffer=[]}),this.joinPush.receive("error",function(){r.state=d.errored,r.socket.isConnected()&&r.rejoinTimer.scheduleTimeout()}),this.onClose(function(){r.rejoinTimer.reset(),r.socket.hasLogger()&&r.socket.log("channel","close ".concat(r.topic," ").concat(r.joinRef())),r.state=d.closed,r.socket.remove(r)}),this.onError(function(e){r.socket.hasLogger()&&r.socket.log("channel","error ".concat(r.topic),e),r.isJoining()&&r.joinPush.reset(),r.state=d.errored,r.socket.isConnected()&&r.rejoinTimer.scheduleTimeout()}),this.joinPush.receive("timeout",function(){r.socket.hasLogger()&&r.socket.log("channel","timeout ".concat(r.topic," (").concat(r.joinRef(),")"),r.joinPush.timeout),new m(r,v.leave,g({}),r.timeout).send(),r.state=d.errored,r.joinPush.reset(),r.socket.isConnected()&&r.rejoinTimer.scheduleTimeout()}),this.on(v.reply,function(e,t){r.trigger(r.replyEventName(t),e)})}return a(e,[{key:"join",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.timeout;if(this.joinedOnce)throw new Error("tried to join multiple times. 'join' can only be called a single time per channel instance");return this.timeout=e,this.joinedOnce=!0,this.rejoin(),this.joinPush}},{key:"onClose",value:function(e){this.on(v.close,e)}},{key:"onError",value:function(e){return this.on(v.error,function(t){return e(t)})}},{key:"on",value:function(e,t){var n=this.bindingRef++;return this.bindings.push({event:e,ref:n,callback:t}),n}},{key:"off",value:function(e,t){this.bindings=this.bindings.filter(function(n){return!(n.event===e&&(void 0===t||t===n.ref))})}},{key:"canPush",value:function(){return this.socket.isConnected()&&this.isJoined()}},{key:"push",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.timeout;if(!this.joinedOnce)throw new Error("tried to push '".concat(e,"' to '").concat(this.topic,"' before joining. Use channel.join() before pushing events"));var i=new m(this,e,function(){return t},n);return this.canPush()?i.send():(i.startTimeout(),this.pushBuffer.push(i)),i}},{key:"leave",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.timeout;this.rejoinTimer.reset(),this.joinPush.cancelTimeout(),this.state=d.leaving;var n=function(){e.socket.hasLogger()&&e.socket.log("channel","leave ".concat(e.topic)),e.trigger(v.close,"leave")},i=new m(this,v.leave,g({}),t);return i.receive("ok",function(){return n()}).receive("timeout",function(){return n()}),i.send(),this.canPush()||i.trigger("ok",{}),i}},{key:"onMessage",value:function(e,t,n){return t}},{key:"isLifecycleEvent",value:function(e){return p.indexOf(e)>=0}},{key:"isMember",value:function(e,t,n,i){return!(this.topic!==e||i&&i!==this.joinRef()&&this.isLifecycleEvent(t)&&(this.socket.hasLogger()&&this.socket.log("channel","dropping outdated message",{topic:e,event:t,payload:n,joinRef:i}),1))}},{key:"joinRef",value:function(){return this.joinPush.ref}},{key:"sendJoin",value:function(e){this.state=d.joining,this.joinPush.resend(e)}},{key:"rejoin",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.timeout;this.isLeaving()||this.sendJoin(e)}},{key:"trigger",value:function(e,t,n,i){var o=this.onMessage(e,t,n,i);if(t&&!o)throw new Error("channel onMessage callbacks must return the payload, modified or unmodified");for(var r=0;r<this.bindings.length;r++){var s=this.bindings[r];s.event===e&&s.callback(o,n,i||this.joinRef())}}},{key:"replyEventName",value:function(e){return"chan_reply_".concat(e)}},{key:"isClosed",value:function(){return this.state===d.closed}},{key:"isErrored",value:function(){return this.state===d.errored}},{key:"isJoined",value:function(){return this.state===d.joined}},{key:"isJoining",value:function(){return this.state===d.joining}},{key:"isLeaving",value:function(){return this.state===d.leaving}}]),e}(),b={encode:function(e,t){var n=[e.join_ref,e.ref,e.topic,e.event,e.payload];return t(JSON.stringify(n))},decode:function(e,t){var n=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],i=!0,o=!1,r=void 0;try{for(var s,a=e[Symbol.iterator]();!(i=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);i=!0);}catch(e){o=!0,r=e}finally{try{i||null==a.return||a.return()}finally{if(o)throw r}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}(JSON.parse(e),5);return t({join_ref:n[0],ref:n[1],topic:n[2],event:n[3],payload:n[4]})}},w=function(){function e(t){var n=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,e),this.stateChangeCallbacks={open:[],close:[],error:[],message:[]},this.channels=[],this.sendBuffer=[],this.ref=0,this.timeout=i.timeout||f,this.transport=i.transport||l.WebSocket||E,this.defaultEncoder=b.encode,this.defaultDecoder=b.decode,this.closeWasClean=!1,this.unloaded=!1,this.binaryType=i.binaryType||"arraybuffer",this.transport!==E?(this.encode=i.encode||this.defaultEncoder,this.decode=i.decode||this.defaultDecoder):(this.encode=this.defaultEncoder,this.decode=this.defaultDecoder),c&&c.addEventListener&&c.addEventListener("beforeunload",function(e){n.conn&&(n.unloaded=!0,n.abnormalClose("unloaded"))}),this.heartbeatIntervalMs=i.heartbeatIntervalMs||3e4,this.rejoinAfterMs=function(e){return i.rejoinAfterMs?i.rejoinAfterMs(e):[1e3,2e3,5e3][e-1]||1e4},this.reconnectAfterMs=function(e){return n.unloaded?100:i.reconnectAfterMs?i.reconnectAfterMs(e):[10,50,100,150,200,250,500,1e3,2e3][e-1]||5e3},this.logger=i.logger||null,this.longpollerTimeout=i.longpollerTimeout||2e4,this.params=g(i.params||{}),this.endPoint="".concat(t,"/").concat(y.websocket),this.heartbeatTimer=null,this.pendingHeartbeatRef=null,this.reconnectTimer=new A(function(){n.teardown(function(){return n.connect()})},this.reconnectAfterMs)}return a(e,[{key:"protocol",value:function(){return location.protocol.match(/^https/)?"wss":"ws"}},{key:"endPointURL",value:function(){var e=x.appendParams(x.appendParams(this.endPoint,this.params()),{vsn:"2.0.0"});return"/"!==e.charAt(0)?e:"/"===e.charAt(1)?"".concat(this.protocol(),":").concat(e):"".concat(this.protocol(),"://").concat(location.host).concat(e)}},{key:"disconnect",value:function(e,t,n){this.closeWasClean=!0,this.reconnectTimer.reset(),this.teardown(e,t,n)}},{key:"connect",value:function(e){var t=this;e&&(console&&console.log("passing params to connect is deprecated. Instead pass :params to the Socket constructor"),this.params=g(e)),this.conn||(this.closeWasClean=!1,this.conn=new this.transport(this.endPointURL()),this.conn.binaryType=this.binaryType,this.conn.timeout=this.longpollerTimeout,this.conn.onopen=function(){return t.onConnOpen()},this.conn.onerror=function(e){return t.onConnError(e)},this.conn.onmessage=function(e){return t.onConnMessage(e)},this.conn.onclose=function(e){return t.onConnClose(e)})}},{key:"log",value:function(e,t,n){this.logger(e,t,n)}},{key:"hasLogger",value:function(){return null!==this.logger}},{key:"onOpen",value:function(e){this.stateChangeCallbacks.open.push(e)}},{key:"onClose",value:function(e){this.stateChangeCallbacks.close.push(e)}},{key:"onError",value:function(e){this.stateChangeCallbacks.error.push(e)}},{key:"onMessage",value:function(e){this.stateChangeCallbacks.message.push(e)}},{key:"onConnOpen",value:function(){this.hasLogger()&&this.log("transport","connected to ".concat(this.endPointURL())),this.unloaded=!1,this.closeWasClean=!1,this.flushSendBuffer(),this.reconnectTimer.reset(),this.resetHeartbeat(),this.stateChangeCallbacks.open.forEach(function(e){return e()})}},{key:"resetHeartbeat",value:function(){var e=this;this.conn&&this.conn.skipHeartbeat||(this.pendingHeartbeatRef=null,clearInterval(this.heartbeatTimer),this.heartbeatTimer=setInterval(function(){return e.sendHeartbeat()},this.heartbeatIntervalMs))}},{key:"teardown",value:function(e,t,n){this.conn&&(this.conn.onclose=function(){},t?this.conn.close(t,n||""):this.conn.close(),this.conn=null),e&&e()}},{key:"onConnClose",value:function(e){this.hasLogger()&&this.log("transport","close",e),this.triggerChanError(),clearInterval(this.heartbeatTimer),this.closeWasClean||this.reconnectTimer.scheduleTimeout(),this.stateChangeCallbacks.close.forEach(function(t){return t(e)})}},{key:"onConnError",value:function(e){this.hasLogger()&&this.log("transport",e),this.triggerChanError(),this.stateChangeCallbacks.error.forEach(function(t){return t(e)})}},{key:"triggerChanError",value:function(){this.channels.forEach(function(e){e.isErrored()||e.isLeaving()||e.isClosed()||e.trigger(v.error)})}},{key:"connectionState",value:function(){switch(this.conn&&this.conn.readyState){case h.connecting:return"connecting";case h.open:return"open";case h.closing:return"closing";default:return"closed"}}},{key:"isConnected",value:function(){return"open"===this.connectionState()}},{key:"remove",value:function(e){this.channels=this.channels.filter(function(t){return t.joinRef()!==e.joinRef()})}},{key:"channel",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new k(e,t,this);return this.channels.push(n),n}},{key:"push",value:function(e){var t=this;if(this.hasLogger()){var n=e.topic,i=e.event,o=e.payload,r=e.ref,s=e.join_ref;this.log("push","".concat(n," ").concat(i," (").concat(s,", ").concat(r,")"),o)}this.isConnected()?this.encode(e,function(e){return t.conn.send(e)}):this.sendBuffer.push(function(){return t.encode(e,function(e){return t.conn.send(e)})})}},{key:"makeRef",value:function(){var e=this.ref+1;return e===this.ref?this.ref=0:this.ref=e,this.ref.toString()}},{key:"sendHeartbeat",value:function(){if(this.isConnected()){if(this.pendingHeartbeatRef)return this.pendingHeartbeatRef=null,this.hasLogger()&&this.log("transport","heartbeat timeout. Attempting to re-establish connection"),void this.abnormalClose("heartbeat timeout");this.pendingHeartbeatRef=this.makeRef(),this.push({topic:"phoenix",event:"heartbeat",payload:{},ref:this.pendingHeartbeatRef})}}},{key:"abnormalClose",value:function(e){this.closeWasClean=!1,this.conn.close(1e3,e)}},{key:"flushSendBuffer",value:function(){this.isConnected()&&this.sendBuffer.length>0&&(this.sendBuffer.forEach(function(e){return e()}),this.sendBuffer=[])}},{key:"onConnMessage",value:function(e){var t=this;this.decode(e.data,function(e){var n=e.topic,i=e.event,o=e.payload,r=e.ref,s=e.join_ref;r&&r===t.pendingHeartbeatRef&&(t.pendingHeartbeatRef=null),t.hasLogger()&&t.log("receive","".concat(o.status||""," ").concat(n," ").concat(i," ").concat(r&&"("+r+")"||""),o);for(var a=0;a<t.channels.length;a++){var u=t.channels[a];u.isMember(n,i,o,s)&&u.trigger(i,o,r,s)}for(var c=0;c<t.stateChangeCallbacks.message.length;c++)t.stateChangeCallbacks.message[c](e)})}}]),e}(),E=function(){function e(t){o(this,e),this.endPoint=null,this.token=null,this.skipHeartbeat=!0,this.onopen=function(){},this.onerror=function(){},this.onmessage=function(){},this.onclose=function(){},this.pollEndpoint=this.normalizeEndpoint(t),this.readyState=h.connecting,this.poll()}return a(e,[{key:"normalizeEndpoint",value:function(e){return e.replace("ws://","http://").replace("wss://","https://").replace(new RegExp("(.*)/"+y.websocket),"$1/"+y.longpoll)}},{key:"endpointURL",value:function(){return x.appendParams(this.pollEndpoint,{token:this.token})}},{key:"closeAndRetry",value:function(){this.close(),this.readyState=h.connecting}},{key:"ontimeout",value:function(){this.onerror("timeout"),this.closeAndRetry()}},{key:"poll",value:function(){var e=this;this.readyState!==h.open&&this.readyState!==h.connecting||x.request("GET",this.endpointURL(),"application/json",null,this.timeout,this.ontimeout.bind(this),function(t){if(t){var n=t.status,i=t.token,o=t.messages;e.token=i}else n=0;switch(n){case 200:o.forEach(function(t){return e.onmessage({data:t})}),e.poll();break;case 204:e.poll();break;case 410:e.readyState=h.open,e.onopen(),e.poll();break;case 0:case 500:e.onerror(),e.closeAndRetry();break;default:throw new Error("unhandled poll status ".concat(n))}})}},{key:"send",value:function(e){var t=this;x.request("POST",this.endpointURL(),"application/json",e,this.timeout,this.onerror.bind(this,"timeout"),function(e){e&&200===e.status||(t.onerror(e&&e.status),t.closeAndRetry())})}},{key:"close",value:function(e,t){this.readyState=h.closed,this.onclose()}}]),e}(),x=function(){function e(){o(this,e)}return a(e,null,[{key:"request",value:function(e,t,n,i,o,r,s){if(l.XDomainRequest){var a=new XDomainRequest;this.xdomainRequest(a,e,t,i,o,r,s)}else{var u=l.XMLHttpRequest?new l.XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");this.xhrRequest(u,e,t,n,i,o,r,s)}}},{key:"xdomainRequest",value:function(e,t,n,i,o,r,s){var a=this;e.timeout=o,e.open(t,n),e.onload=function(){var t=a.parseJSON(e.responseText);s&&s(t)},r&&(e.ontimeout=r),e.onprogress=function(){},e.send(i)}},{key:"xhrRequest",value:function(e,t,n,i,o,r,s,a){var u=this;e.open(t,n,!0),e.timeout=r,e.setRequestHeader("Content-Type",i),e.onerror=function(){a&&a(null)},e.onreadystatechange=function(){if(e.readyState===u.states.complete&&a){var t=u.parseJSON(e.responseText);a(t)}},s&&(e.ontimeout=s),e.send(o)}},{key:"parseJSON",value:function(e){if(!e||""===e)return null;try{return JSON.parse(e)}catch(t){return console&&console.log("failed to parse JSON response",e),null}}},{key:"serialize",value:function(e,t){var n=[];for(var o in e)if(e.hasOwnProperty(o)){var r=t?"".concat(t,"[").concat(o,"]"):o,s=e[o];"object"===i(s)?n.push(this.serialize(s,r)):n.push(encodeURIComponent(r)+"="+encodeURIComponent(s))}return n.join("&")}},{key:"appendParams",value:function(e,t){if(0===Object.keys(t).length)return e;var n=e.match(/\?/)?"&":"?";return"".concat(e).concat(n).concat(this.serialize(t))}}]),e}();x.states={complete:4};var S=function(){function e(t){var n=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,e);var r=i.events||{state:"presence_state",diff:"presence_diff"};this.state={},this.pendingDiffs=[],this.channel=t,this.joinRef=null,this.caller={onJoin:function(){},onLeave:function(){},onSync:function(){}},this.channel.on(r.state,function(t){var i=n.caller,o=i.onJoin,r=i.onLeave,s=i.onSync;n.joinRef=n.channel.joinRef(),n.state=e.syncState(n.state,t,o,r),n.pendingDiffs.forEach(function(t){n.state=e.syncDiff(n.state,t,o,r)}),n.pendingDiffs=[],s()}),this.channel.on(r.diff,function(t){var i=n.caller,o=i.onJoin,r=i.onLeave,s=i.onSync;n.inPendingSyncState()?n.pendingDiffs.push(t):(n.state=e.syncDiff(n.state,t,o,r),s())})}return a(e,[{key:"onJoin",value:function(e){this.caller.onJoin=e}},{key:"onLeave",value:function(e){this.caller.onLeave=e}},{key:"onSync",value:function(e){this.caller.onSync=e}},{key:"list",value:function(t){return e.list(this.state,t)}},{key:"inPendingSyncState",value:function(){return!this.joinRef||this.joinRef!==this.channel.joinRef()}}],[{key:"syncState",value:function(e,t,n,i){var o=this,r=this.clone(e),s={},a={};return this.map(r,function(e,n){t[e]||(a[e]=n)}),this.map(t,function(e,t){var n=r[e];if(n){var i=t.metas.map(function(e){return e.phx_ref}),u=n.metas.map(function(e){return e.phx_ref}),c=t.metas.filter(function(e){return u.indexOf(e.phx_ref)<0}),l=n.metas.filter(function(e){return i.indexOf(e.phx_ref)<0});c.length>0&&(s[e]=t,s[e].metas=c),l.length>0&&(a[e]=o.clone(n),a[e].metas=l)}else s[e]=t}),this.syncDiff(r,{joins:s,leaves:a},n,i)}},{key:"syncDiff",value:function(e,t,n,i){var o=t.joins,r=t.leaves,s=this.clone(e);return n||(n=function(){}),i||(i=function(){}),this.map(o,function(e,t){var i=s[e];if(s[e]=t,i){var o,r=s[e].metas.map(function(e){return e.phx_ref}),a=i.metas.filter(function(e){return r.indexOf(e.phx_ref)<0});(o=s[e].metas).unshift.apply(o,function(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}(a))}n(e,i,t)}),this.map(r,function(e,t){var n=s[e];if(n){var o=t.metas.map(function(e){return e.phx_ref});n.metas=n.metas.filter(function(e){return o.indexOf(e.phx_ref)<0}),i(e,n,t),0===n.metas.length&&delete s[e]}}),s}},{key:"list",value:function(e,t){return t||(t=function(e,t){return t}),this.map(e,function(e,n){return t(e,n)})}},{key:"map",value:function(e,t){return Object.getOwnPropertyNames(e).map(function(n){return t(n,e[n])})}},{key:"clone",value:function(e){return JSON.parse(JSON.stringify(e))}}]),e}(),A=function(){function e(t,n){o(this,e),this.callback=t,this.timerCalc=n,this.timer=null,this.tries=0}return a(e,[{key:"reset",value:function(){this.tries=0,clearTimeout(this.timer)}},{key:"scheduleTimeout",value:function(){var e=this;clearTimeout(this.timer),this.timer=setTimeout(function(){e.tries=e.tries+1,e.callback()},this.timerCalc(this.tries+1))}}]),e}()}])})}).call(this,n(2)(e))},function(e,t,n){"use strict";var i;n.r(t);var o="http://www.w3.org/1999/xhtml",r="undefined"==typeof document?void 0:document,s=!!r&&"content"in r.createElement("template"),a=!!r&&r.createRange&&"createContextualFragment"in r.createRange();function u(e){return s?function(e){var t=r.createElement("template");return t.innerHTML=e,t.content.childNodes[0]}(e):a?function(e){return i||(i=r.createRange()).selectNode(r.body),i.createContextualFragment(e).childNodes[0]}(e):function(e){var t=r.createElement("body");return t.innerHTML=e,t.childNodes[0]}(e)}function c(e,t){var n=e.nodeName,i=t.nodeName;return n===i||!!(t.actualize&&n.charCodeAt(0)<91&&i.charCodeAt(0)>90)&&n===i.toUpperCase()}function l(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)}l(e,t,"selected")},INPUT:function(e,t){l(e,t,"checked"),l(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 o=i.nodeValue;if(o==n||!n&&o==e.placeholder)return;i.nodeValue=n}},SELECT:function(e,t){if(!t.hasAttribute("multiple")){for(var n,i,o=-1,r=0,s=e.firstChild;s;)if("OPTGROUP"===(i=s.nodeName&&s.nodeName.toUpperCase()))s=(n=s).firstChild;else{if("OPTION"===i){if(s.hasAttribute("selected")){o=r;break}r++}!(s=s.nextSibling)&&n&&(s=n.nextSibling,n=null)}e.selectedIndex=o}}},f=1,d=11,v=3,p=8;function y(){}function g(e){return e.id}var m=function(e){return function(t,n,i){if(i||(i={}),"string"==typeof n)if("#document"===t.nodeName||"HTML"===t.nodeName){var s=n;(n=r.createElement("html")).innerHTML=s}else n=u(n);var a,l=i.getNodeKey||g,m=i.onBeforeNodeAdded||y,k=i.onNodeAdded||y,b=i.onBeforeElUpdated||y,w=i.onElUpdated||y,E=i.onBeforeNodeDiscarded||y,x=i.onNodeDiscarded||y,S=i.onBeforeElChildrenUpdated||y,A=!0===i.childrenOnly,C={};function j(e){a?a.push(e):a=[e]}function T(e,t,n){!1!==E(e)&&(t&&t.removeChild(e),x(e),function e(t,n){if(t.nodeType===f)for(var i=t.firstChild;i;){var o=void 0;n&&(o=l(i))?j(o):(x(i),i.firstChild&&e(i,n)),i=i.nextSibling}}(e,n))}function R(e){k(e);for(var t=e.firstChild;t;){var n=t.nextSibling,i=l(t);if(i){var o=C[i];o&&c(t,o)&&(t.parentNode.replaceChild(o,t),L(o,t))}R(t),t=n}}function L(i,o,s){var a=l(o);if(a&&delete C[a],!n.isSameNode||!n.isSameNode(t)){if(!s){if(!1===b(i,o))return;if(e(i,o),w(i),!1===S(i,o))return}"TEXTAREA"!==i.nodeName?function(e,t){var n,i,o,s,a,u=t.firstChild,d=e.firstChild;e:for(;u;){for(s=u.nextSibling,n=l(u);d;){if(o=d.nextSibling,u.isSameNode&&u.isSameNode(d)){u=s,d=o;continue e}i=l(d);var y=d.nodeType,g=void 0;if(y===u.nodeType&&(y===f?(n?n!==i&&((a=C[n])?o===a?g=!1:(e.insertBefore(a,d),i?j(i):T(d,e,!0),d=a):g=!1):i&&(g=!1),(g=!1!==g&&c(d,u))&&L(d,u)):y!==v&&y!=p||(g=!0,d.nodeValue!==u.nodeValue&&(d.nodeValue=u.nodeValue))),g){u=s,d=o;continue e}i?j(i):T(d,e,!0),d=o}if(n&&(a=C[n])&&c(a,u))e.appendChild(a),L(a,u);else{var k=m(u);!1!==k&&(k&&(u=k),u.actualize&&(u=u.actualize(e.ownerDocument||r)),e.appendChild(u),R(u))}u=s,d=o}!function(e,t,n){for(;t;){var i=t.nextSibling;(n=l(t))?j(n):T(t,e,!0),t=i}}(e,d,i);var b=h[e.nodeName];b&&b(e,t)}(i,o):h.TEXTAREA(i,o)}}!function e(t){if(t.nodeType===f||t.nodeType===d)for(var n=t.firstChild;n;){var i=l(n);i&&(C[i]=n),e(n),n=n.nextSibling}}(t);var _=t,P=_.nodeType,N=n.nodeType;if(!A)if(P===f)N===f?c(t,n)||(x(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?r.createElementNS(t,e):r.createElement(e)}(n.nodeName,n.namespaceURI))):_=n;else if(P===v||P===p){if(N===P)return _.nodeValue!==n.nodeValue&&(_.nodeValue=n.nodeValue),_;_=n}if(_===n)x(t);else if(L(_,n,A),a)for(var O=0,H=a.length;O<H;O++){var I=C[a[O]];I&&T(I,I.parentNode,!1)}return!A&&_!==t&&t.parentNode&&(_.actualize&&(_=_.actualize(t.ownerDocument||r)),t.parentNode.replaceChild(_,t)),_}}(function(e,t){var n,i,o,r,s,a=t.attributes;for(n=a.length-1;n>=0;--n)o=(i=a[n]).name,r=i.namespaceURI,s=i.value,r?(o=i.localName||o,e.getAttributeNS(r,o)!==s&&e.setAttributeNS(r,o,s)):e.getAttribute(o)!==s&&e.setAttribute(o,s);for(n=(a=e.attributes).length-1;n>=0;--n)!1!==(i=a[n]).specified&&(o=i.name,(r=i.namespaceURI)?(o=i.localName||o,t.hasAttributeNS(r,o)||e.removeAttributeNS(r,o)):t.hasAttribute(o)||e.removeAttribute(o))}),k=n(0);function b(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function w(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 E(e,t,n){return t&&w(e.prototype,t),n&&w(e,n),e}function x(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],i=!0,o=!1,r=void 0;try{for(var s,a=e[Symbol.iterator]();!(i=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);i=!0);}catch(e){o=!0,r=e}finally{try{i||null==a.return||a.return()}finally{if(o)throw r}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function S(e){return(S="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 L}),n.d(t,"Rendered",function(){return M}),n.d(t,"LiveSocket",function(){return D}),n.d(t,"Browser",function(){return V}),n.d(t,"View",function(){return J});var A="data-phx-view",C="[".concat(A,"]"),j=["text","textarea","number","email","password","search","tel","url"],T=1,R="phx-",L=function(e,t,n,i){console.log("".concat(e.id," ").concat(t,": ").concat(n," - "),i)},_=function(e){return"function"==typeof e?e:function(){return e}},P=function(e){return JSON.parse(JSON.stringify(e))},N=function(e,t){do{if(e.matches("[".concat(t,"]")))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType&&!e.matches(C));return null},O=function(e){return null!==e&&"object"===S(e)&&!(e instanceof Array)},H=function(e,t){return e?e[t]:null},I=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new FormData(e),i=new URLSearchParams,o=!0,r=!1,s=void 0;try{for(var a,u=n.entries()[Symbol.iterator]();!(o=(a=u.next()).done);o=!0){var c=x(a.value,2),l=c[0],h=c[1];i.append(l,h)}}catch(e){r=!0,s=e}finally{try{o||null==u.return||u.return()}finally{if(r)throw s}}for(var f in t)i.append(f,t[f]);return i.toString()},B={get:function(e){return e.getAttribute("data-phx-session")},isEqual:function(e,t){return this.get(e)===this.get(t)}},M={mergeDiff:function(e,t){return this.isNewFingerprint(t)?t:(function e(t,n){for(var i in n){var o=n[i],r=t[i];O(o)&&O(r)?(r.dynamics&&!o.dynamics&&delete r.dynamics,e(r,o)):t[i]=o}}(e,t),e)},isNewFingerprint:function(){return!!(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).static},toString:function(e){var t={buffer:""};return this.toOutputBuffer(e,t),t.buffer},toOutputBuffer:function(e,t){if(e.dynamics)return this.comprehensionToBuffer(e,t);var n=e.static;t.buffer+=n[0];for(var i=1;i<n.length;i++)this.dynamicToBuffer(e[i-1],t),t.buffer+=n[i]},comprehensionToBuffer:function(e,t){for(var n=e.dynamics,i=e.static,o=0;o<n.length;o++){var r=n[o];t.buffer+=i[0];for(var s=1;s<i.length;s++)this.dynamicToBuffer(r[s-1],t),t.buffer+=i[s]}},dynamicToBuffer:function(e,t){O(e)?this.toOutputBuffer(e,t):t.buffer+=e}},D=function(){function e(t){var n=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this.unloaded=!1,this.socket=new k.Socket(t,i),this.bindingPrefix=i.bindingPrefix||R,this.opts=i,this.views={},this.params=_(i.params||{}),this.viewLogger=i.viewLogger,this.activeElement=null,this.prevActive=null,this.prevInput=null,this.prevValue=null,this.silenced=!1,this.root=null,this.linkRef=0,this.href=window.location.href,this.pendingLink=null,this.currentLocation=P(window.location),this.hooks=i.hooks||{},this.socket.onOpen(function(){n.isUnloaded()&&(n.destroyAllViews(),n.joinRootViews()),n.unloaded=!1}),window.addEventListener("beforeunload",function(e){n.unloaded=!0}),this.bindTopLevelEvents()}return E(e,[{key:"getSocket",value:function(){return this.socket}},{key:"log",value:function(e,t,n){if(this.viewLogger){var i=x(n(),2),o=i[0],r=i[1];this.viewLogger(e,t,o,r)}}},{key:"connect",value:function(){var e=this;return["complete","loaded","interactive"].indexOf(document.readyState)>=0?this.joinRootViews():document.addEventListener("DOMContentLoaded",function(){e.joinRootViews()}),this.socket.connect()}},{key:"disconnect",value:function(){this.socket.disconnect()}},{key:"getHookCallbacks",value:function(e){return this.hooks[e]}},{key:"isUnloaded",value:function(){return this.unloaded}},{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;V.all(document,"".concat(C,":not([").concat("data-phx-parent-id","])"),function(t){var n=e.joinView(t,null,e.getHref());e.root=e.root||n})}},{key:"replaceRoot",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.setPendingLink(e);this.root.showLoader(T);var o=this.root.el,r=this.root.id,s=this.root.isLoading();V.fetchPage(e,function(a,u){if(200!==a)return V.redirect(e);var c=document.createElement("div");c.innerHTML=u,t.joinView(c.firstChild,null,e,function(e){t.commitPendingLink(i)?(n&&n(),t.destroyViewById(r),o.replaceWith(e.el),t.root=e,s&&t.root.showLoader()):e.destroy()})})}},{key:"joinView",value:function(e,t,n,i){if(!this.getViewById(e.id)){var o=new J(e,this,t,n);return this.views[o.id]=o,o.join(i),o}}},{key:"owner",value:function(e,t){var n=this.getViewById(H(e.closest(C),"id"));n&&t(n)}},{key:"getViewById",value:function(e){return this.views[e]}},{key:"onViewError",value:function(e){this.dropActiveElement(e)}},{key:"destroyAllViews",value:function(){for(var e in this.views)this.destroyViewById(e)}},{key:"destroyViewById",value:function(e){var t=this.views[e];t&&(delete this.views[t.id],this.root&&t.id===this.root.id&&(this.root=null),t.destroy())}},{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}},{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(){this.bindClicks(),this.bindNav(),this.bindForms(),this.bindTargetable({keyup:"keyup",keydown:"keydown"},function(e,t,n,i,o,r){n.pushKey(i,t,o,{altGraphKey:e.altGraphKey,altKey:e.altKey,charCode:e.charCode,code:e.code,ctrlKey:e.ctrlKey,key:e.key,keyCode:e.keyCode,keyIdentifier:e.keyIdentifier,keyLocation:e.keyLocation,location:e.location,metaKey:e.metaKey,repeat:e.repeat,shiftKey:e.shiftKey,which:e.which})}),this.bindTargetable({blur:"focusout",focus:"focusin"},function(e,t,n,i,o,r){r||n.pushEvent(t,i,o,{type:"focus"})}),this.bindTargetable({blur:"blur",focus:"focus"},function(e,t,n,i,o,r){r&&"window"!==!r&&n.pushEvent(t,i,o,{type:e.type})})}},{key:"setPendingLink",value:function(e){this.linkRef++;this.linkRef;return 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:"bindTargetable",value:function(e,t){var n=this,i=function(i){var o=e[i];n.on(o,function(e){var o=n.binding(i),r=n.binding("target"),s=e.target.getAttribute&&e.target.getAttribute(o);s&&!e.target.getAttribute(r)?n.owner(e.target,function(n){return t(e,i,n,e.target,s,null)}):V.all(document,"[".concat(o,"][").concat(r,"=window]"),function(r){var s=r.getAttribute(o);n.owner(r,function(n){return t(e,i,n,r,s,"window")})})})};for(var o in e)i(o)}},{key:"bindClicks",value:function(){var e=this;window.addEventListener("click",function(t){var n=e.binding("click"),i=N(t.target,n),o=i&&i.getAttribute(n);if(o){t.preventDefault();var r={altKey:t.altKey,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,x:t.x||t.clientX,y:t.y||t.clientY,pageX:t.pageX,pageY:t.pageY,screenX:t.screenX,screenY:t.screenY};e.owner(i,function(e){return e.pushEvent("click",i,o,r)})}},!1)}},{key:"bindNav",value:function(){var e=this;V.canPushState()&&(window.onpopstate=function(t){if(e.registerNewLocation(window.location)){var n=window.location.href;e.root.isConnected()?e.root.pushInternalLink(n):e.replaceRoot(n)}},window.addEventListener("click",function(t){var n=N(t.target,"data-phx-live-link"),i=n&&n.getAttribute("data-phx-live-link");if(i){var o=n.href;t.preventDefault(),e.root.pushInternalLink(o,function(){V.pushState(i,{},o),e.registerNewLocation(window.location)})}},!1))}},{key:"registerNewLocation",value:function(e){var t=this.currentLocation;return t.pathname+t.search!==e.pathname+e.search&&(this.currentLocation=P(e),!0)}},{key:"bindForms",value:function(){var e=this;this.on("submit",function(t){var n=t.target.getAttribute(e.binding("submit"));n&&(t.preventDefault(),t.target.disabled=!0,e.owner(t.target,function(e){return e.submitForm(t.target,n)}))},!1);for(var t=["change","input"],n=0;n<t.length;n++){var i=t[n];this.on(i,function(t){var n=t.target,i="checkbox"===n.type?"checked":"value";if(e.prevInput!==n||e.prevValue!==n[i]){e.prevInput=n,e.prevValue=n[i];var o=n.form&&n.form.getAttribute(e.binding("change"));o&&e.owner(n,function(i){U.isTextualInput(n)?n["phx-has-focused"]=!0:e.setActiveElement(n),i.pushInput(n,o,t)})}},!1)}}},{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}(),V={all:function(e,t,n){e.querySelectorAll(t).forEach(n)},canPushState:function(){return void 0!==history.pushState},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)return"live-link"!==n.getResponseHeader("x-requested-with")?t(400):200!==n.status?t(n.status):void t(200,n.responseText)},n.send()},pushState:function(e,t,n){this.canPushState()?n!==window.location.href&&history[e+"State"](t,"",n):this.redirect(n)},dispatchEvent:function(e,t){var n=null;"function"==typeof Event?n=new Event(t):(n=document.createEvent("Event")).initEvent(t,!0,!0),e.dispatchEvent(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&&V.setCookie("__phoenix_flash__",t+"; max-age=60000; path=/"),window.location=e}},U={disableForm:function(e,t){var n="".concat(t).concat("disable-with");e.classList.add("phx-loading"),V.all(e,"[".concat(n,"]"),function(e){var t=e.getAttribute(n);e.setAttribute("".concat(n,"-restore"),e.innerText),e.innerText=t}),V.all(e,"button",function(e){e.setAttribute("data-phx-disabled",e.disabled),e.disabled=!0}),V.all(e,"input",function(e){e.setAttribute("data-phx-readonly",e.readOnly),e.readOnly=!0})},restoreDisabledForm:function(e,t){var n="".concat(t).concat("disable-with");e.classList.remove("phx-loading"),V.all(e,"[".concat(n,"]"),function(e){var t=e.getAttribute("".concat(n,"-restore"));t&&("INPUT"===e.nodeName?e.value=t:e.innerText=t,e.removeAttribute("".concat(n,"-restore")))}),V.all(e,"button",function(e){var t=e.getAttribute("data-phx-disabled");t&&(e.disabled="true"===t,e.removeAttribute("data-phx-disabled"))}),V.all(e,"input",function(e){var t=e.getAttribute("data-phx-readonly");t&&(e.readOnly="true"===t,e.removeAttribute("data-phx-readonly"))})},discardError:function(e){var t=e.getAttribute&&e.getAttribute("data-phx-error-for");if(t){var n=document.getElementById(t);!t||n["phx-has-focused"]||n.form["phx-has-submitted"]||(e.style.display="none")}},isPhxChild:function(e){return e.getAttribute&&e.getAttribute("data-phx-parent-id")},applyPhxUpdate:function(e,t,n,i,o){var r=t.getAttribute&&t.getAttribute(n);if(!r||"replace"===r)return!1;switch(U.mergeAttrs(e,t),r){case"ignore":break;case"append":case"prepend":var s=t.innerHTML;if(e.phxPrevAppend===s)break;e.phxPrevAppend=s,t.querySelectorAll("[id]").forEach(function(t){var n=e.querySelector('[id="'.concat(t.id,'"]'));n&&(o.discarded.push(n),t.remove(),n.replaceWith(t))});var a="append"===r?"beforeend":"afterbegin";e.insertAdjacentHTML(a,t.innerHTML),e.querySelectorAll("[".concat(i,"]")).forEach(function(e){return o.added.push(e)});break;default:throw new Error('unsupported phx-update "'.concat(r,'"'))}return o.updated.push({fromEl:e,toEl:e}),!0},patch:function(e,t,n,i){var o={added:[],updated:[],discarded:[]},r=e.liveSocket.getActiveElement(),s=null,a=null,u=e.liveSocket.binding("update"),c=e.liveSocket.binding("hook"),l=t.cloneNode();return l.innerHTML=i,U.isTextualInput(r)&&(s=r.selectionStart,a=r.selectionEnd),m(t,l,{childrenOnly:!0,onBeforeNodeAdded:function(e){return U.discardError(e),e},onNodeAdded:function(t){if(U.isPhxChild(t)&&e.ownsElement(t))return e.onNewChildAdded(),!0;o.added.push(t)},onBeforeNodeDiscarded:function(t){if(U.isPhxChild(t))return e.liveSocket.destroyViewById(t.id),!0;o.discarded.push(t)},onBeforeElUpdated:function(t,n){if(t.isEqualNode(n))return!1;if(U.applyPhxUpdate(t,n,u,c,o))return!1;if(U.isPhxChild(n)){var i=t.getAttribute("data-phx-static");return B.isEqual(n,t)||(e.liveSocket.destroyViewById(t.id),e.onNewChildAdded()),U.mergeAttrs(t,n),t.setAttribute("data-phx-static",i),!1}return t.getAttribute&&t["phx-has-submitted"]&&(n["phx-has-submitted"]=!0),t["phx-has-focused"]&&(n["phx-has-focused"]=!0),U.discardError(n),U.isTextualInput(t)&&t===r?(U.mergeInputs(t,n),o.updated.push({fromEl:t,toEl:t}),!1):(o.updated.push({fromEl:t,toEl:n}),!0)}}),e.liveSocket.silenceEvents(function(){U.restoreFocus(r,s,a)}),V.dispatchEvent(document,"phx:update"),o},mergeAttrs:function(e,t){for(var n=t.attributes,i=0,o=n.length;i<o;i++){var r=n[i].name,s=t.getAttribute(r);e.setAttribute(r,s)}},mergeInputs:function(e,t){U.mergeAttrs(e,t),e.readOnly=t.readOnly},restoreFocus:function(e,t,n){U.isTextualInput(e)&&((""===e.value||e.readOnly)&&e.blur(),e.focus(),(e.setSelectionRange&&"text"===e.type||"textarea"===e.type)&&e.setSelectionRange(t,n))},isTextualInput:function(e){return j.indexOf(e.type)>=0}},J=function(){function e(t,n,i,o){var r=this;b(this,e),this.liveSocket=n,this.parent=i,this.newChildrenAdded=!1,this.gracefullyClosed=!1,this.el=t,this.id=this.el.id,this.view=this.el.getAttribute(A),this.loaderTimer=null,this.pendingDiffs=[],this.href=o,this.joinedOnce=!1,this.viewHooks={},this.channel=this.liveSocket.channel("lv:".concat(this.id),function(){return{url:r.href||r.liveSocket.root.href,params:r.liveSocket.params(r.view),session:r.getSession(),static:r.getStatic()}}),this.showLoader(T),this.bindChannel()}return E(e,[{key:"isConnected",value:function(){return this.channel.canPush()}},{key:"getSession",value:function(){return B.get(this.el)}},{key:"getStatic",value:function(){var e=this.el.getAttribute("data-phx-static");return""===e?null:e}},{key:"destroy",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){};clearTimeout(this.loaderTimer);var n=function(){for(var n in t(),e.viewHooks)e.destroyHook(e.viewHooks[n])};this.hasGracefullyClosed()?(this.log("destroyed",function(){return["the server view has gracefully closed"]}),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(){for(var e in clearTimeout(this.loaderTimer),this.viewHooks)this.viewHooks[e].__trigger__("reconnected");this.setContainerClasses("phx-connected")}},{key:"log",value:function(e,t){this.liveSocket.log(this,e,t)}},{key:"onJoin",value:function(e){var t=e.rendered,n=e.live_redirect;this.log("join",function(){return["",JSON.stringify(t)]}),this.rendered=t,this.hideLoader();var i=U.patch(this,this.el,this.id,M.toString(this.rendered));if(i.added.push(this.el),V.all(this.el,"[".concat(this.binding("hook"),"]"),function(e){return i.added.push(e)}),this.triggerHooks(i),this.joinNewChildren(),n){var o=n.kind,r=n.to;V.pushState(o,{},r)}}},{key:"joinNewChildren",value:function(){var e=this;V.all(document,"".concat(C,"[").concat("data-phx-parent-id",'="').concat(this.id,'"]'),function(t){e.liveSocket.getViewById(t.id)||e.liveSocket.joinView(t,e)})}},{key:"update",value:function(e){if(!function(e){for(var t in e)return!1;return!0}(e)){if(this.liveSocket.hasPendingLink())return this.pendingDiffs.push(e);this.log("update",function(){return["",JSON.stringify(e)]}),this.rendered=M.mergeDiff(this.rendered,e);var t=M.toString(this.rendered);this.newChildrenAdded=!1,this.triggerHooks(U.patch(this,this.el,this.id,t)),this.newChildrenAdded&&this.joinNewChildren()}}},{key:"getHook",value:function(e){return this.viewHooks[F.elementID(e)]}},{key:"addHook",value:function(e){if(!F.elementID(e)&&e.getAttribute){var t=this.liveSocket.getHookCallbacks(e.getAttribute(this.binding("hook")));if(t&&this.ownsElement(e)){var n=new F(this,e,t);this.viewHooks[F.elementID(n.el)]=n,n.__trigger__("mounted")}}}},{key:"destroyHook",value:function(e){e.__trigger__("destroyed"),delete this.viewHooks[F.elementID(e.el)]}},{key:"triggerHooks",value:function(e){var t=this;e.updated.push({fromEl:this.el,toEl:this.el}),e.added.forEach(function(e){return t.addHook(e)}),e.updated.forEach(function(e){var n=e.fromEl,i=e.toEl,o=t.getHook(n),r=t.binding("hook");o&&i.getAttribute&&n.getAttribute(r)===i.getAttribute(r)?o.__trigger__("updated"):o&&(t.destroyHook(o),t.addHook(n))}),e.discarded.forEach(function(e){var n=t.getHook(e);n&&t.destroyHook(n)})}},{key:"applyPendingUpdates",value:function(){var e=this;this.pendingDiffs.forEach(function(t){return e.update(t)}),this.pendingDiffs=[]}},{key:"onNewChildAdded",value:function(){this.newChildrenAdded=!0}},{key:"bindChannel",value:function(){var e=this;this.channel.on("diff",function(t){return e.update(t)}),this.channel.on("redirect",function(t){var n=t.to,i=t.flash;return e.onRedirect({to:n,flash:i})}),this.channel.on("live_redirect",function(t){var n=t.to,i=t.kind;return e.onLiveRedirect({to:n,kind:i})}),this.channel.on("external_live_redirect",function(t){var n=t.to,i=t.kind;return e.onExternalLiveRedirect({to:n,kind:i})}),this.channel.on("session",function(t){var n=t.token;return e.el.setAttribute("data-phx-session",n)}),this.channel.onError(function(t){return e.onError(t)}),this.channel.onClose(function(){return e.onGracefulClose()})}},{key:"onGracefulClose",value:function(){this.gracefullyClosed=!0,this.liveSocket.destroyViewById(this.id)}},{key:"onExternalLiveRedirect",value:function(e){var t=e.to,n=e.kind;this.liveSocket.replaceRoot(t,function(){return V.pushState(n,{},t)})}},{key:"onLiveRedirect",value:function(e){var t=e.to,n=e.kind;V.pushState(n,{},t)}},{key:"onRedirect",value:function(e){var t=e.to,n=e.flash;V.redirect(t,n)}},{key:"hasGracefullyClosed",value:function(){return this.gracefullyClosed}},{key:"join",value:function(e){var t=this;this.parent&&(this.parent.channel.onClose(function(){return t.onGracefulClose()}),this.parent.channel.onError(function(){return t.liveSocket.destroyViewById(t.id)})),this.channel.join().receive("ok",function(n){t.joinedOnce||e&&e(t),t.joinedOnce=!0,t.onJoin(n)}).receive("error",function(e){return t.onJoinError(e)}).receive("timeout",function(){return t.onJoinError("timeout")})}},{key:"onJoinError",value:function(e){return e.redirect?this.onRedirect(e.redirect):e.external_live_redirect?this.onExternalLiveRedirect(e.external_live_redirect):(this.displayError(),void this.log("error",function(){return["unable to join",e]}))}},{key:"onError",value:function(e){this.log("error",function(){return["view crashed",e]}),this.liveSocket.onViewError(this),document.activeElement.blur(),this.liveSocket.isUnloaded()?this.showLoader(200):this.displayError()}},{key:"displayError",value:function(){this.showLoader(),this.setContainerClasses("phx-disconnected","phx-error")}},{key:"pushWithReply",value:function(e,t){var n=this,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){};return this.channel.push(e,t,3e4).receive("ok",function(e){e.diff&&n.update(e.diff),e.redirect&&n.onRedirect(e.redirect),e.live_redirect&&n.onLiveRedirect(e.live_redirect),e.external_live_redirect&&n.onExternalLiveRedirect(e.external_live_redirect),i(e)})}},{key:"pushEvent",value:function(e,t,n,i){var o=t.getAttribute(this.binding("value"));if(null===o){o=i;var r=this.binding("value-"),s=!0,a=!1,u=void 0;try{for(var c,l=t.getAttributeNames()[Symbol.iterator]();!(s=(c=l.next()).done);s=!0){var h=c.value;h.startsWith(r)&&(o[h.replace(r,"")]=t.getAttribute(h))}}catch(e){a=!0,u=e}finally{try{s||null==l.return||l.return()}finally{if(a)throw u}}void 0!==t.value&&(o.value=t.value)}this.pushWithReply("event",{type:e,event:n,value:o})}},{key:"pushKey",value:function(e,t,n,i){var o=e.getAttribute(this.binding("value"));null===o&&(o=i,void 0!==e.value&&(o.value=e.value)),this.pushWithReply("event",{type:t,event:n,value:o})}},{key:"pushInput",value:function(e,t,n){this.pushWithReply("event",{type:"form",event:t,value:I(e.form,{_target:n.target.name})})}},{key:"pushFormSubmit",value:function(e,t,n){this.pushWithReply("event",{type:"form",event:t,value:I(e)},n)}},{key:"pushInternalLink",value:function(e,t){var n=this;this.isLoading()||this.showLoader(T);var i=this.liveSocket.setPendingLink(e);this.pushWithReply("link",{url:e},function(o){o.link_redirect?n.liveSocket.replaceRoot(e,t,i):n.liveSocket.commitPendingLink(i)&&(n.href=e,n.applyPendingUpdates(),n.hideLoader(),t&&t())}).receive("timeout",function(){return V.redirect(window.location.href)})}},{key:"ownsElement",value:function(e){return e.getAttribute("data-phx-parent-id")===this.id||H(e.closest(C),"id")===this.id}},{key:"submitForm",value:function(e,t){var n=this,i=this.liveSocket.getBindingPrefix();e["phx-has-submitted"]="true",U.disableForm(e,i),this.liveSocket.blurActiveElement(this),this.pushFormSubmit(e,t,function(){U.restoreDisabledForm(e,i),n.liveSocket.restorePreviouslyActiveFocus()})}},{key:"binding",value:function(e){return this.liveSocket.binding(e)}}]),e}(),q=1,F=function(){function e(t,n,i){for(var o in b(this,e),this.__view=t,this.__callbacks=i,this.el=n,this.viewName=t.view,this.el.phxHookId=this.constructor.makeID(),this.__callbacks)this[o]=this.__callbacks[o]}return E(e,null,[{key:"makeID",value:function(){return q++}},{key:"elementID",value:function(e){return e.phxHookId}}]),E(e,[{key:"pushEvent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.__view.pushWithReply("event",{type:"hook",event:e,value:t})}},{key:"__trigger__",value:function(e){var t=this.__callbacks[e];t&&t.call(this)}}]),e}();t.default=D},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},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(1)}).call(this,n(3))}])});
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";var i;n.r(t);var r="http://www.w3.org/1999/xhtml",o="undefined"==typeof document?void 0:document,a=!!o&&"content"in o.createElement("template"),u=!!o&&o.createRange&&"createContextualFragment"in o.createRange();function c(e){return a?function(e){var t=o.createElement("template");return t.innerHTML=e,t.content.childNodes[0]}(e):u?function(e){return i||(i=o.createRange()).selectNode(o.body),i.createContextualFragment(e).childNodes[0]}(e):function(e){var t=o.createElement("body");return t.innerHTML=e,t.childNodes[0]}(e)}function s(e,t){var n=e.nodeName,i=t.nodeName;return n===i||!!(t.actualize&&n.charCodeAt(0)<91&&i.charCodeAt(0)>90)&&n===i.toUpperCase()}function l(e,t,n){e[n]!==t[n]&&(e[n]=t[n],e[n]?e.setAttribute(n,""):e.removeAttribute(n))}var d={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)}l(e,t,"selected")},INPUT:function(e,t){l(e,t,"checked"),l(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}}},h=1,f=11,v=3,p=8;function y(){}function g(e){return e.id}var m=function(e){return function(t,n,i){if(i||(i={}),"string"==typeof n)if("#document"===t.nodeName||"HTML"===t.nodeName){var a=n;(n=o.createElement("html")).innerHTML=a}else n=c(n);var u,l=i.getNodeKey||g,m=i.onBeforeNodeAdded||y,k=i.onNodeAdded||y,b=i.onBeforeElUpdated||y,w=i.onElUpdated||y,x=i.onBeforeNodeDiscarded||y,E=i.onNodeDiscarded||y,A=i.onBeforeElChildrenUpdated||y,S=!0===i.childrenOnly,L={};function C(e){u?u.push(e):u=[e]}function N(e,t,n){!1!==x(e)&&(t&&t.removeChild(e),E(e),function e(t,n){if(t.nodeType===h)for(var i=t.firstChild;i;){var r=void 0;n&&(r=l(i))?C(r):(E(i),i.firstChild&&e(i,n)),i=i.nextSibling}}(e,n))}function _(e){k(e);for(var t=e.firstChild;t;){var n=t.nextSibling,i=l(t);if(i){var r=L[i];r&&s(t,r)&&(t.parentNode.replaceChild(r,t),T(r,t))}_(t),t=n}}function T(i,r,a){var u=l(r);if(u&&delete L[u],!n.isSameNode||!n.isSameNode(t)){if(!a){if(!1===b(i,r))return;if(e(i,r),w(i),!1===A(i,r))return}"TEXTAREA"!==i.nodeName?function(e,t){var n,i,r,a,u,c=t.firstChild,f=e.firstChild;e:for(;c;){for(a=c.nextSibling,n=l(c);f;){if(r=f.nextSibling,c.isSameNode&&c.isSameNode(f)){c=a,f=r;continue e}i=l(f);var y=f.nodeType,g=void 0;if(y===c.nodeType&&(y===h?(n?n!==i&&((u=L[n])?r===u?g=!1:(e.insertBefore(u,f),i?C(i):N(f,e,!0),f=u):g=!1):i&&(g=!1),(g=!1!==g&&s(f,c))&&T(f,c)):y!==v&&y!=p||(g=!0,f.nodeValue!==c.nodeValue&&(f.nodeValue=c.nodeValue))),g){c=a,f=r;continue e}i?C(i):N(f,e,!0),f=r}if(n&&(u=L[n])&&s(u,c))e.appendChild(u),T(u,c);else{var k=m(c);!1!==k&&(k&&(c=k),c.actualize&&(c=c.actualize(e.ownerDocument||o)),e.appendChild(c),_(c))}c=a,f=r}!function(e,t,n){for(;t;){var i=t.nextSibling;(n=l(t))?C(n):N(t,e,!0),t=i}}(e,f,i);var b=d[e.nodeName];b&&b(e,t)}(i,r):d.TEXTAREA(i,r)}}!function e(t){if(t.nodeType===h||t.nodeType===f)for(var n=t.firstChild;n;){var i=l(n);i&&(L[i]=n),e(n),n=n.nextSibling}}(t);var P=t,I=P.nodeType,R=n.nodeType;if(!S)if(I===h)R===h?s(t,n)||(E(t),P=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!==r?o.createElementNS(t,e):o.createElement(e)}(n.nodeName,n.namespaceURI))):P=n;else if(I===v||I===p){if(R===I)return P.nodeValue!==n.nodeValue&&(P.nodeValue=n.nodeValue),P;P=n}if(P===n)E(t);else if(T(P,n,S),u)for(var H=0,D=u.length;H<D;H++){var O=L[u[H]];O&&N(O,O.parentNode,!1)}return!S&&P!==t&&t.parentNode&&(P.actualize&&(P=P.actualize(t.ownerDocument||o)),t.parentNode.replaceChild(P,t)),P}}(function(e,t){var n,i,r,o,a,u=t.attributes;for(n=u.length-1;n>=0;--n)r=(i=u[n]).name,o=i.namespaceURI,a=i.value,o?(r=i.localName||r,e.getAttributeNS(o,r)!==a&&e.setAttributeNS(o,r,a)):e.getAttribute(r)!==a&&e.setAttribute(r,a);for(n=(u=e.attributes).length-1;n>=0;--n)!1!==(i=u[n]).specified&&(r=i.name,(o=i.namespaceURI)?(r=i.localName||r,t.hasAttributeNS(o,r)||e.removeAttributeNS(o,r)):t.hasAttribute(r)||e.removeAttribute(r))});function k(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function b(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 w(e,t,n){return t&&b(e.prototype,t),n&&b(e,n),e}function x(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){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)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function E(e){return(E="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 T}),n.d(t,"Rendered",function(){return V}),n.d(t,"LiveSocket",function(){return B}),n.d(t,"Browser",function(){return j}),n.d(t,"DOM",function(){return F}),n.d(t,"View",function(){return K});var A="data-phx-view",S="[".concat(A,"]"),L=["text","textarea","number","email","password","search","tel","url"],C=1,N="phx-",_=function(e,t){return console.error&&console.error(e,t)},T=function(e,t,n,i){console.log("".concat(e.id," ").concat(t,": ").concat(n," - "),i)},P=function(e){return"function"==typeof e?e:function(){return e}},I=function(e){return JSON.parse(JSON.stringify(e))},R=function(e,t){do{if(e.matches("[".concat(t,"]")))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType&&!e.matches(S));return null},H=function(e){return null!==e&&"object"===E(e)&&!(e instanceof Array)},D=function(e,t){return e&&t(e)},O=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new FormData(e),i=new URLSearchParams,r=!0,o=!1,a=void 0;try{for(var u,c=n.entries()[Symbol.iterator]();!(r=(u=c.next()).done);r=!0){var s=x(u.value,2),l=s[0],d=s[1];i.append(l,d)}}catch(e){o=!0,a=e}finally{try{r||null==c.return||c.return()}finally{if(o)throw a}}for(var h in t)i.append(h,t[h]);return i.toString()},V={mergeDiff:function(e,t){return this.isNewFingerprint(t)?t:(function e(t,n){for(var i in n){var r=n[i],o=t[i];H(r)&&H(o)?(o.dynamics&&!r.dynamics&&delete o.dynamics,e(o,r)):t[i]=r}}(e,t),e)},isNewFingerprint:function(){return!!(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).static},toString:function(e){var t={buffer:""};return this.toOutputBuffer(e,t),t.buffer},toOutputBuffer:function(e,t){if(e.dynamics)return this.comprehensionToBuffer(e,t);var n=e.static;t.buffer+=n[0];for(var i=1;i<n.length;i++)this.dynamicToBuffer(e[i-1],t),t.buffer+=n[i]},comprehensionToBuffer:function(e,t){for(var n=e.dynamics,i=e.static,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]}},dynamicToBuffer:function(e,t){H(e)?this.toOutputBuffer(e,t):t.buffer+=e}},B=function(){function e(t,n){var i=this,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(k(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||N,this.opts=r,this.views={},this.params=P(r.params||{}),this.viewLogger=r.viewLogger,this.activeElement=null,this.prevActive=null,this.prevInput=null,this.prevValue=null,this.silenced=!1,this.root=null,this.linkRef=0,this.href=window.location.href,this.pendingLink=null,this.currentLocation=I(window.location),this.hooks=r.hooks||{},this.socket.onOpen(function(){i.isUnloaded()&&(i.destroyAllViews(),i.joinRootViews()),i.unloaded=!1}),window.addEventListener("beforeunload",function(e){i.unloaded=!0}),this.bindTopLevelEvents()}return w(e,[{key:"getSocket",value:function(){return this.socket}},{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)}}},{key:"connect",value:function(){var e=this;return["complete","loaded","interactive"].indexOf(document.readyState)>=0?this.joinRootViews():document.addEventListener("DOMContentLoaded",function(){e.joinRootViews()}),this.socket.connect()}},{key:"disconnect",value:function(){this.socket.disconnect()}},{key:"getHookCallbacks",value:function(e){return this.hooks[e]}},{key:"isUnloaded",value:function(){return this.unloaded}},{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;F.all(document,"".concat(S,":not([").concat("data-phx-parent-id","])"),function(t){var n=e.joinView(t,null,e.getHref());e.root=e.root||n})}},{key:"replaceRoot",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.setPendingLink(e);this.root.showLoader(C);var r=this.root.el,o=this.root.id,a=this.root.isLoading();j.fetchPage(e,function(u,c){if(200!==u)return j.redirect(e);var s=document.createElement("div");s.innerHTML=c,t.joinView(s.firstChild,null,e,function(e){t.commitPendingLink(i)?(n&&n(),t.destroyViewById(o),r.replaceWith(e.el),t.root=e,a&&t.root.showLoader()):e.destroy()})})}},{key:"joinView",value:function(e,t,n,i){if(!this.getViewByEl(e)){var r=new K(e,this,t,n);return this.views[r.id]=r,r.join(i),r}}},{key:"owner",value:function(e,t){var n=this,i=D(e.closest(S),function(e){return n.getViewByEl(e)});i&&t(i)}},{key:"getViewByEl",value:function(e){return this.views[e.id]}},{key:"onViewError",value:function(e){this.dropActiveElement(e)}},{key:"destroyAllViews",value:function(){for(var e in this.views)this.destroyViewById(e)}},{key:"destroyViewByEl",value:function(e){return this.destroyViewById(e.id)}},{key:"destroyViewById",value:function(e){var t=this.views[e];t&&(delete this.views[t.id],this.root&&t.id===this.root.id&&(this.root=null),t.destroy())}},{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}},{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(){this.bindClicks(),this.bindNav(),this.bindForms(),this.bindTargetable({keyup:"keyup",keydown:"keydown"},function(e,t,n,i,r,o){n.pushKey(i,t,r,{altGraphKey:e.altGraphKey,altKey:e.altKey,charCode:e.charCode,code:e.code,ctrlKey:e.ctrlKey,key:e.key,keyCode:e.keyCode,keyIdentifier:e.keyIdentifier,keyLocation:e.keyLocation,location:e.location,metaKey:e.metaKey,repeat:e.repeat,shiftKey:e.shiftKey,which:e.which})}),this.bindTargetable({blur:"focusout",focus:"focusin"},function(e,t,n,i,r,o){o||n.pushEvent(t,i,r,{type:t})}),this.bindTargetable({blur:"blur",focus:"focus"},function(e,t,n,i,r,o){o&&"window"!==!o&&n.pushEvent(t,i,r,{type:e.type})})}},{key:"setPendingLink",value:function(e){this.linkRef++;this.linkRef;return 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:"bindTargetable",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("target"),a=e.target.getAttribute&&e.target.getAttribute(r);a&&!e.target.getAttribute(o)?n.owner(e.target,function(r){n.debounce(e.target,e,function(){return t(e,i,r,e.target,a,null)})}):F.all(document,"[".concat(r,"][").concat(o,"=window]"),function(o){var a=o.getAttribute(r);n.owner(o,function(r){n.debounce(o,e,function(){return t(e,i,r,o,a,"window")})})})})};for(var r in e)i(r)}},{key:"bindClicks",value:function(){var e=this;window.addEventListener("click",function(t){var n=e.binding("click"),i=R(t.target,n),r=i&&i.getAttribute(n);if(r){t.stopPropagation();var o={altKey:t.altKey,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,x:t.x||t.clientX,y:t.y||t.clientY,pageX:t.pageX,pageY:t.pageY,screenX:t.screenX,screenY:t.screenY};e.owner(i,function(n){e.debounce(i,t,function(){return n.pushEvent("click",i,r,o)})})}},!1)}},{key:"bindNav",value:function(){var e=this;j.canPushState()&&(window.onpopstate=function(t){if(e.registerNewLocation(window.location)){var n=window.location.href;e.root.isConnected()?e.root.pushInternalLink(n):e.replaceRoot(n)}},window.addEventListener("click",function(t){var n=R(t.target,"data-phx-live-link"),i=n&&n.getAttribute("data-phx-live-link");if(i){var r=n.href;t.preventDefault(),e.root.pushInternalLink(r,function(){j.pushState(i,{},r),e.registerNewLocation(window.location)})}},!1))}},{key:"registerNewLocation",value:function(e){var t=this.currentLocation;return t.pathname+t.search!==e.pathname+e.search&&(this.currentLocation=I(e),!0)}},{key:"bindForms",value:function(){var e=this;this.on("submit",function(t){var n=t.target.getAttribute(e.binding("submit"));n&&(t.preventDefault(),t.target.disabled=!0,e.owner(t.target,function(e){return e.submitForm(t.target,n)}))},!1);for(var t=["change","input"],n=0;n<t.length;n++){var i=t[n];this.on(i,function(t){var n=t.target,i=n.form&&n.form.getAttribute(e.binding("change"));if(i){var r=JSON.stringify(new FormData(n.form).getAll(n.name));e.prevInput===n&&e.prevValue===r||"number"===n.type&&n.validity&&n.validity.badInput||(e.prevInput=n,e.prevValue=r,e.owner(n,function(r){F.isTextualInput(n)?F.putPrivate(n,"phx-has-focused",!0):e.setActiveElement(n),e.debounce(n,t,function(){return r.pushInput(n,i,t)})}))}},!1)}}},{key:"debounce",value:function(e,t,n){F.debounce(e,t,this.binding("debounce"),this.binding("throttle"),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}(),j={canPushState:function(){return void 0!==history.pushState},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)return"live-link"!==n.getResponseHeader("x-requested-with")?t(400):200!==n.status?t(n.status):void t(200,n.responseText)},n.send()},pushState:function(e,t,n){this.canPushState()?n!==window.location.href&&history[e+"State"](t,"",n):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&&j.setCookie("__phoenix_flash__",t+"; max-age=60000; path=/"),window.location=e}},F={all:function(e,t,n){return Array.from(e.querySelectorAll(t)).forEach(n)},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=I(t.phxPrivate))},debounce:function(e,t,n,i,r){var o=this,a=e.getAttribute(n),u=e.getAttribute(i),c=a||u;switch(c){case null:return r();case"blur":if(this.private(e,"debounce-blur"))return;return e.addEventListener("blur",function(){return r()}),void this.putPrivate(e,"debounce-blur",c);default:var s=parseInt(c);if(isNaN(s))return _("invalid throttle/debounce value: ".concat(c));if(u&&"keydown"===t.type){var l=this.private(e,"debounce-prev-key");if(this.putPrivate(e,"debounce-prev-key",t.which),l!==t.which)return r()}if(this.private(e,"debounce-timer"))return;var d=function(t){u&&"phx-change"===t.type&&t.detail.triggeredBy.name===e.name||(clearTimeout(o.private(e,"debounce-timer")),o.deletePrivate(e,"debounce-timer"))};this.putPrivate(e,"debounce-timer",setTimeout(function(){e.form&&(e.form.removeEventListener("phx-change",d),e.form.removeEventListener("submit",d)),o.deletePrivate(e,"debounce-timer"),u||r()},s)),e.form&&(e.form.addEventListener("phx-change",d),e.form.addEventListener("submit",d)),u&&r()}},disableForm:function(e,t){var n="".concat(t).concat("disable-with");e.classList.add("phx-loading"),F.all(e,"[".concat(n,"]"),function(e){var t=e.getAttribute(n);e.setAttribute("".concat(n,"-restore"),e.innerText),e.innerText=t}),F.all(e,"button",function(e){e.setAttribute("data-phx-disabled",e.disabled),e.disabled=!0}),F.all(e,"input",function(e){e.setAttribute("data-phx-readonly",e.readOnly),e.readOnly=!0})},restoreDisabledForm:function(e,t){var n="".concat(t).concat("disable-with");e.classList.remove("phx-loading"),F.all(e,"[".concat(n,"]"),function(e){var t=e.getAttribute("".concat(n,"-restore"));t&&("INPUT"===e.nodeName?e.value=t:e.innerText=t,e.removeAttribute("".concat(n,"-restore")))}),F.all(e,"button",function(e){var t=e.getAttribute("data-phx-disabled");t&&(e.disabled="true"===t,e.removeAttribute("data-phx-disabled"))}),F.all(e,"input",function(e){var t=e.getAttribute("data-phx-readonly");t&&(e.readOnly="true"===t,e.removeAttribute("data-phx-readonly"))})},discardError:function(e,t){var n=t.getAttribute&&t.getAttribute("data-phx-error-for");if(n){var i=e.querySelector("#".concat(n));!n||this.private(i,"phx-has-focused")||this.private(i.form,"phx-has-submitted")||(t.style.display="none")}},isPhxChild:function(e){return e.getAttribute&&e.getAttribute("data-phx-parent-id")},patch:function(e,t,n,i){var r={added:[],updated:[],discarded:[],phxChildrenAdded:[]},o=e.liveSocket.getActiveElement(),a=o&&F.isTextualInput(o)?o:{},u=a.selectionStart,c=a.selectionEnd,s=e.liveSocket.binding("update"),l=this.buildDiffContainer(t,i,s);return m(t,l.outerHTML,{childrenOnly:!0,onBeforeNodeAdded:function(e){return F.discardError(t,e),e},onNodeAdded:function(t){F.isPhxChild(t)&&e.ownsElement(t)&&r.phxChildrenAdded.push(t),r.added.push(t)},onBeforeNodeDiscarded:function(t){if(F.isPhxChild(t))return e.liveSocket.destroyViewByEl(t),!0;r.discarded.push(t)},onBeforeElUpdated:function(e,n){if(e.isEqualNode(n))return!1;if("ignore"===e.getAttribute(s))return!1;if("number"===e.type&&e.validity&&e.validity.badInput)return!1;if(F.isPhxChild(n)){var i=e.getAttribute("data-phx-static");return F.mergeAttrs(e,n),e.setAttribute("data-phx-static",i),!1}return F.copyPrivates(n,e),F.discardError(t,n),F.isTextualInput(e)&&e===o?(F.mergeInputs(e,n),r.updated.push({fromEl:e,toEl:e}),!1):(r.updated.push({fromEl:e,toEl:n}),!0)}}),e.liveSocket.silenceEvents(function(){return F.restoreFocus(o,u,c)}),F.dispatchEvent(document,"phx:update"),r},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){var n=e.cloneNode();return n.innerHTML=t||e.innerHTML,n},buildDiffContainer:function(e,t,n){var i=this,r=this.cloneNode(e,t),o=function(e){return e.nodeType===Node.ELEMENT_NODE},a=function(e){return e.id||_("append/prepend children require IDs, got: ",e)};return F.all(r,"[".concat(n,"=append],[").concat(n,"=prepend]"),function(t){var r=t.id||_("append/prepend requires an ID, got: ",t),u=e.querySelector("#".concat(r));if(u){var c=i.cloneNode(u),s=t.getAttribute(n),l=Array.from(t.childNodes).filter(o).map(a),d=Array.from(c.childNodes).filter(o).map(a);if(l.toString()!==d.toString())l.filter(function(e){return d.indexOf(e)>=0}).forEach(function(e){var n=t.querySelector("#".concat(e));c.querySelector("#".concat(e)).replaceWith(n)}),t.insertAdjacentHTML("append"===s?"afterbegin":"beforeend",c.innerHTML)}}),r},mergeAttrs:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],i=t.attributes,r=0,o=i.length;r<o;r++){var a=i[r].name;n.indexOf(a)<0&&e.setAttribute(a,t.getAttribute(a))}},mergeInputs:function(e,t){F.mergeAttrs(e,t,["value"]),e.readOnly=t.readOnly},restoreFocus:function(e,t,n){F.isTextualInput(e)&&((""===e.value||e.readOnly)&&e.blur(),e.focus(),(e.setSelectionRange&&"text"===e.type||"textarea"===e.type)&&e.setSelectionRange(t,n))},isTextualInput:function(e){return L.indexOf(e.type)>=0}},K=function(){function e(t,n,i,r){var o=this;k(this,e),this.liveSocket=n,this.parent=i,this.gracefullyClosed=!1,this.el=t,this.id=this.el.id,this.view=this.el.getAttribute(A),this.loaderTimer=null,this.pendingDiffs=[],this.href=r,this.joinedOnce=!1,this.viewHooks={},this.channel=this.liveSocket.channel("lv:".concat(this.id),function(){return{url:o.href||o.liveSocket.root.href,params:o.liveSocket.params(o.view),session:o.getSession(),static:o.getStatic()}}),this.showLoader(C),this.bindChannel()}return w(e,[{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("data-phx-static");return""===e?null:e}},{key:"destroy",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){};clearTimeout(this.loaderTimer);var n=function(){for(var n in t(),e.viewHooks)e.destroyHook(e.viewHooks[n])};this.hasGracefullyClosed()?(this.log("destroyed",function(){return["the server view has gracefully closed"]}),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(){for(var e in clearTimeout(this.loaderTimer),this.viewHooks)this.viewHooks[e].__trigger__("reconnected");this.setContainerClasses("phx-connected")}},{key:"log",value:function(e,t){this.liveSocket.log(this,e,t)}},{key:"onJoin",value:function(e){var t=e.rendered,n=e.live_redirect;this.log("join",function(){return["",JSON.stringify(t)]}),this.rendered=t,this.hideLoader();var i=F.patch(this,this.el,this.id,V.toString(this.rendered));if(i.added.push(this.el),F.all(this.el,"[".concat(this.binding("hook"),"]"),function(e){return i.added.push(e)}),this.triggerHooks(i),this.joinNewChildren(),n){var r=n.kind,o=n.to;j.pushState(r,{},o)}}},{key:"joinNewChildren",value:function(){var e=this;F.all(document,"".concat(S,"[").concat("data-phx-parent-id",'="').concat(this.id,'"]'),function(t){e.liveSocket.getViewByEl(t)||e.liveSocket.joinView(t,e)})}},{key:"update",value:function(e){if(!function(e){for(var t in e)return!1;return!0}(e)){if(this.liveSocket.hasPendingLink())return this.pendingDiffs.push(e);this.log("update",function(){return["",JSON.stringify(e)]}),this.rendered=V.mergeDiff(this.rendered,e);var t=V.toString(this.rendered),n=F.patch(this,this.el,this.id,t);n.phxChildrenAdded.length>0&&this.joinNewChildren(),this.triggerHooks(n)}}},{key:"getHook",value:function(e){return this.viewHooks[M.elementID(e)]}},{key:"addHook",value:function(e){if(!M.elementID(e)&&e.getAttribute){var t=this.liveSocket.getHookCallbacks(e.getAttribute(this.binding("hook")));if(t&&this.ownsElement(e)){var n=new M(this,e,t);this.viewHooks[M.elementID(n.el)]=n,n.__trigger__("mounted")}}}},{key:"destroyHook",value:function(e){e.__trigger__("destroyed"),delete this.viewHooks[M.elementID(e.el)]}},{key:"triggerHooks",value:function(e){var t=this,n=[];e.updated.push({fromEl:this.el,toEl:this.el}),e.added.forEach(function(e){return t.addHook(e)}),e.updated.forEach(function(e){var n=e.fromEl,i=e.toEl,r=t.getHook(n),o=t.binding("hook");r&&i.getAttribute&&n.getAttribute(o)===i.getAttribute(o)?r.__trigger__("updated"):r&&(t.destroyHook(r),t.addHook(n))}),e.discarded.forEach(function(e){var i=t.componentID(e);i&&n.push(i);var r=t.getHook(e);r&&t.destroyHook(r)}),n.length>0&&this.pushComponentsDestroyed(n)}},{key:"applyPendingUpdates",value:function(){var e=this;this.pendingDiffs.forEach(function(t){return e.update(t)}),this.pendingDiffs=[]}},{key:"bindChannel",value:function(){var e=this;this.channel.on("diff",function(t){return e.update(t)}),this.channel.on("redirect",function(t){var n=t.to,i=t.flash;return e.onRedirect({to:n,flash:i})}),this.channel.on("live_redirect",function(t){var n=t.to,i=t.kind;return e.onLiveRedirect({to:n,kind:i})}),this.channel.on("external_live_redirect",function(t){var n=t.to,i=t.kind;return e.onExternalLiveRedirect({to:n,kind:i})}),this.channel.on("session",function(t){var n=t.token;return e.el.setAttribute("data-phx-session",n)}),this.channel.onError(function(t){return e.onError(t)}),this.channel.onClose(function(){return e.onGracefulClose()})}},{key:"onGracefulClose",value:function(){this.gracefullyClosed=!0,this.liveSocket.destroyViewById(this.id)}},{key:"onExternalLiveRedirect",value:function(e){var t=this,n=e.to,i=e.kind;this.liveSocket.replaceRoot(n,function(){j.pushState(i,{},n),t.liveSocket.registerNewLocation(window.location)})}},{key:"onLiveRedirect",value:function(e){var t=e.to,n=e.kind;this.href=t,j.pushState(n,{},t)}},{key:"onRedirect",value:function(e){var t=e.to,n=e.flash;j.redirect(t,n)}},{key:"hasGracefullyClosed",value:function(){return this.gracefullyClosed}},{key:"join",value:function(e){var t=this;this.parent&&(this.parent.channel.onClose(function(){return t.onGracefulClose()}),this.parent.channel.onError(function(){return t.liveSocket.destroyViewById(t.id)})),this.channel.join().receive("ok",function(n){t.joinedOnce||e&&e(t),t.joinedOnce=!0,t.onJoin(n)}).receive("error",function(e){return t.onJoinError(e)}).receive("timeout",function(){return t.onJoinError("timeout")})}},{key:"onJoinError",value:function(e){return(e.redirect||e.external_live_redirect)&&this.channel.leave(),e.redirect?this.onRedirect(e.redirect):e.external_live_redirect?this.onExternalLiveRedirect(e.external_live_redirect):(this.displayError(),void this.log("error",function(){return["unable to join",e]}))}},{key:"onError",value:function(e){this.log("error",function(){return["view crashed",e]}),this.liveSocket.onViewError(this),document.activeElement.blur(),this.liveSocket.isUnloaded()?this.showLoader(200):this.displayError()}},{key:"displayError",value:function(){this.showLoader(),this.setContainerClasses("phx-disconnected","phx-error")}},{key:"pushWithReply",value:function(e,t){var n=this,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){};return this.channel.push(e,t,3e4).receive("ok",function(e){e.diff&&n.update(e.diff),e.redirect&&n.onRedirect(e.redirect),e.live_redirect&&n.onLiveRedirect(e.live_redirect),e.external_live_redirect&&n.onExternalLiveRedirect(e.external_live_redirect),i(e)})}},{key:"componentID",value:function(e){return e.getAttribute&&e.getAttribute("data-phx-component")&&e.id}},{key:"targetComponentID",value:function(e){var t=this;return D(e.closest("[".concat("data-phx-component","]")),function(e){return t.ownsElement(e)&&t.componentID(e)})}},{key:"pushEvent",value:function(e,t,n,i){for(var r=this.binding("value-"),o=0;o<t.attributes.length;o++){var a=t.attributes[o].name;a.startsWith(r)&&(i[a.replace(r,"")]=t.getAttribute(a))}void 0!==t.value&&(i.value=t.value),this.pushWithReply("event",{type:e,event:n,value:i,cid:this.targetComponentID(t)||void 0})}},{key:"pushKey",value:function(e,t,n,i){void 0!==e.value&&(i.value=e.value),this.pushWithReply("event",{type:t,event:n,value:i,cid:this.targetComponentID(e)||void 0})}},{key:"pushInput",value:function(e,t,n){F.dispatchEvent(e.form,"phx-change",{triggeredBy:e}),this.pushWithReply("event",{type:"form",event:t,value:O(e.form,{_target:n.target.name}),cid:this.targetComponentID(e)||void 0})}},{key:"pushFormSubmit",value:function(e,t,n){this.pushWithReply("event",{type:"form",event:t,value:O(e),cid:this.targetComponentID(e)||void 0},n)}},{key:"pushInternalLink",value:function(e,t){var n=this;this.isLoading()||this.showLoader(C);var i=this.liveSocket.setPendingLink(e);this.pushWithReply("link",{url:e},function(r){r.link_redirect?n.liveSocket.replaceRoot(e,t,i):n.liveSocket.commitPendingLink(i)&&(n.href=e,n.applyPendingUpdates(),n.hideLoader(),t&&t())}).receive("timeout",function(){return j.redirect(window.location.href)})}},{key:"pushComponentsDestroyed",value:function(e){this.pushWithReply("cids_destroyed",{cids:e})}},{key:"ownsElement",value:function(e){return e.getAttribute("data-phx-parent-id")===this.id||D(e.closest(S),function(e){return e.id})===this.id}},{key:"submitForm",value:function(e,t){var n=this,i=this.liveSocket.getBindingPrefix();F.putPrivate(e,"phx-has-submitted",!0),F.disableForm(e,i),this.liveSocket.blurActiveElement(this),this.pushFormSubmit(e,t,function(){F.restoreDisabledForm(e,i),n.liveSocket.restorePreviouslyActiveFocus()})}},{key:"binding",value:function(e){return this.liveSocket.binding(e)}}]),e}(),U=1,M=function(){function e(t,n,i){for(var r in k(this,e),this.__view=t,this.__callbacks=i,this.el=n,this.viewName=t.view,this.el.phxHookId=this.constructor.makeID(),this.__callbacks)this[r]=this.__callbacks[r]}return w(e,null,[{key:"makeID",value:function(){return U++}},{key:"elementID",value:function(e){return e.phxHookId}}]),w(e,[{key:"pushEvent",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.__view.pushWithReply("event",{type:"hook",event:e,value:t})}},{key:"__trigger__",value:function(e){var t=this.__callbacks[e];t&&t.call(this)}}]),e}();t.default=B},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))}])});