katalyst-kpop 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41e97c3878b81b50b1d698ae4cc33d3bb8ed4881a5768a5977e62e9e282c46b0
4
- data.tar.gz: 62be5f4be46723f17da8e6380465e1b0b25227751d451d3b14138543a02349b6
3
+ metadata.gz: 233c69ba524a23278a5e817247218b300546dd1c0c5f39955d7b95bda8f3cbc2
4
+ data.tar.gz: 8aa9b7a40abe1e1639b557f1afe13222b5388a936756157f3833139aca7983d4
5
5
  SHA512:
6
- metadata.gz: cecf864ccadd4b1e5c4b0cf224e7377fb58ec7fe58b6c186c8c44a19e9872bd8ec10ba5a6e25617d6decd8e334af81363af033950cda2c1548892bb3736ff1a2
7
- data.tar.gz: 51cee27e61a12ad90aa1da523feaaa56a74bb67261102ab41b27362f7e4f4d19258eea7636af8712a92662e3dd7d438975393c7f8f60a901b1339cf49d89c1f0
6
+ metadata.gz: 74e640946e90e7e6c5dea614098691fc522119f87eec520c0f7d4d71f445bad74e79a1915dd05e826f01db6de16684752c371262a5ce818dec8f574b2f1ea402
7
+ data.tar.gz: 17cabd08350b484c47970853cac90e6449ebecb586c503ce1a74b7c37f69535b9b0655a1f676956889227509e96b7ba550bd21310b4ecf4663c34ce58e620114
@@ -93,19 +93,6 @@ class Modal {
93
93
  this.element.close();
94
94
  }
95
95
 
96
- /**
97
- * When user navigates from inside a modal, dismiss the modal first so
98
- * that the modal does not appear in the history stack.
99
- *
100
- * @param frame FrameController
101
- * @param e Turbo navigation event
102
- */
103
- beforeVisit(frame, e) {
104
- this.debug(`before-visit`, e.detail.url);
105
-
106
- this.frame.clear();
107
- }
108
-
109
96
  static get debug() {
110
97
  return debug(this.name);
111
98
  }
@@ -180,27 +167,16 @@ class FrameModal extends Modal {
180
167
  }
181
168
 
182
169
  /**
183
- * When a user clicks a kpop link, turbo intercepts the click and calls
184
- * #navigateFrame on the turbo frame controller before setting the TurboFrame
185
- * element's src attribute. KPOP intercepts this call and calls this method
186
- * first so we cancel problematic navigations that might cache invalid states.
170
+ * When the FrameController reloads the open modal's location, it runs this
171
+ * method to open the new content in place, without animating.
187
172
  *
188
- * @param location URL requested by turbo
189
- * @param frame FrameController
190
- * @param element TurboFrame element
191
- * @param resolve continuation chain
173
+ * @param {Kpop__FrameController} frame
174
+ * @param {HTMLDialogElement} dialog
175
+ * @param {String} src
192
176
  */
193
- static visit(location, frame, element, resolve) {
194
- // Ensure that turbo doesn't cache the frame in a loading state by cancelling
195
- // the current request (if any) by clearing the src.
196
- // Known issue: this won't work if the frame was previously rendering a useful src.
197
- if (element.hasAttribute("busy")) {
198
- this.debug("clearing src to cancel turbo request");
199
- element.src = "";
200
- }
201
-
202
- this.debug("navigate to", location);
203
- resolve();
177
+ static reload(frame, dialog, src) {
178
+ this.debug("reload", src);
179
+ return frame.open(new FrameModal(frame, dialog, src), { animate: false });
204
180
  }
205
181
  }
206
182
 
@@ -214,9 +190,6 @@ class Kpop__FrameController extends Controller {
214
190
 
215
191
  this.element.kpop = this;
216
192
 
217
- // allow our code to intercept frame navigation requests before dom changes
218
- installNavigationInterception(this);
219
-
220
193
  const dialog = this.element.querySelector("dialog");
221
194
 
222
195
  if (this.element.src && dialog) {
@@ -321,6 +294,8 @@ class Kpop__FrameController extends Controller {
321
294
 
322
295
  if (event.detail.newFrame.id !== this.element.id) return;
323
296
 
297
+ if (this.#isReload()) return this.#reload(event);
298
+
324
299
  event.preventDefault();
325
300
 
326
301
  this.dismiss({ animate: true, reason: "before-frame-render" }).then(() => {
@@ -346,24 +321,6 @@ class Kpop__FrameController extends Controller {
346
321
  };
347
322
  }
348
323
 
349
- beforeVisit(e) {
350
- this.debug("before-visit", e.detail.url);
351
-
352
- // ignore visits to the current frame, these fire when the frame navigates
353
- if (e.detail.url === this.element.src) return;
354
-
355
- const url = new URL(e.detail.url.toString(), document.baseURI);
356
- if (url.pathname === "/resume_historical_location") {
357
- e.preventDefault();
358
- return this.dismiss();
359
- }
360
-
361
- // ignore unless we're open
362
- if (!this.isOpen) return;
363
-
364
- this.modal.beforeVisit(this, e);
365
- }
366
-
367
324
  frameLoad(e) {
368
325
  this.debug("frame-load");
369
326
 
@@ -389,6 +346,47 @@ class Kpop__FrameController extends Controller {
389
346
  return this.openValue && !this.dismissing;
390
347
  }
391
348
 
349
+ /**
350
+ * The frame is loading the location of the open modal again, e.g. from
351
+ * `Turbo.visit` or a link in the modal to its own location.
352
+ */
353
+ #isReload() {
354
+ if (!this.isOpen || !this.modal) return false;
355
+
356
+ const url = new URL(this.element.src, document.baseURI);
357
+ const { uri } = this.modal;
358
+ return url.pathname + url.search === uri.pathname + uri.search;
359
+ }
360
+
361
+ /**
362
+ * Like a Turbo page reload, swap the content in place: replace the modal
363
+ * as the frame renders, without animating out and in. Turbo waits for
364
+ * repaints before frame-load, so opening the new dialog any later would
365
+ * show a frame without a modal.
366
+ *
367
+ * @param event turbo:before-frame-render
368
+ */
369
+ #reload(event) {
370
+ this.debug("reload", this.element.src);
371
+
372
+ const render = event.detail.render;
373
+ event.detail.render = (currentElement, newElement) => {
374
+ render(currentElement, newElement);
375
+
376
+ // Keep the focus target from when the modal first opened
377
+ const previousFocusRef = this.previousFocusRef;
378
+ const dialog = this.element.querySelector("dialog");
379
+
380
+ this.modal.disconnect();
381
+ delete this.modal;
382
+ this.openValue = false;
383
+
384
+ FrameModal.reload(this, dialog, this.element.src).then(() => {
385
+ this.previousFocusRef = previousFocusRef;
386
+ });
387
+ };
388
+ }
389
+
392
390
  async #open(modal, { animate = true } = {}) {
393
391
  this.debug("open-start", { animate });
394
392
 
@@ -453,50 +451,6 @@ class Kpop__FrameController extends Controller {
453
451
  }
454
452
  }
455
453
 
456
- /**
457
- * Monkey patch for Turbo#FrameController.
458
- *
459
- * Intercept calls to linkClickIntercepted(element, location) and ensures
460
- * that src is cleared if the frame is busy so that we don't restore an
461
- * in-progress src on restoration visits.
462
- *
463
- * See Turbo issue: https://github.com/hotwired/turbo/issues/1055
464
- *
465
- * @param controller FrameController
466
- */
467
- function installNavigationInterception(controller) {
468
- const TurboFrameController =
469
- controller.element.delegate.constructor.prototype;
470
-
471
- if (TurboFrameController._linkClickIntercepted) return;
472
-
473
- TurboFrameController._linkClickIntercepted =
474
- TurboFrameController.linkClickIntercepted;
475
- TurboFrameController.linkClickIntercepted = function (element, location) {
476
- // #findFrameElement
477
- const id =
478
- element?.getAttribute("data-turbo-frame") ||
479
- this.element.getAttribute("target");
480
- let frame = document.getElementById(id);
481
- if (!(frame instanceof Turbo.FrameElement)) {
482
- frame = this.element;
483
- }
484
-
485
- if (frame.kpop) {
486
- frame.kpop.debug("navigate-frame %s => %s", frame.src, location);
487
- FrameModal.visit(location, frame.kpop, frame, () => {
488
- TurboFrameController._linkClickIntercepted.call(
489
- this,
490
- element,
491
- location,
492
- );
493
- });
494
- } else {
495
- TurboFrameController._linkClickIntercepted.call(this, element, location);
496
- }
497
- };
498
- }
499
-
500
454
  function autofocus(container) {
501
455
  if (!container) return null;
502
456
 
@@ -743,10 +697,14 @@ function openStreamModal() {
743
697
  }
744
698
 
745
699
  /**
746
- * Routes Turbo visits to locations that match a modal rule into the kpop
747
- * frame, the way Hotwire Native routes visits with its path configuration.
700
+ * Decides how each Turbo visit shows, the way Hotwire Native routes visits
701
+ * with its path configuration. Visits to locations that match a modal rule
702
+ * open in the kpop frame, and page visits close any open modal first.
748
703
  * Callers use `Turbo.visit` and the ruleset decides how the location shows.
749
704
  *
705
+ * Turbo dispatches `turbo:before-visit` before the adapter knows where the
706
+ * visit goes, so kpop handles visits here rather than in that event.
707
+ *
750
708
  * Wraps Turbo's browser adapter, which Turbo does not export, so every other
751
709
  * adapter call reaches the browser adapter unchanged.
752
710
  */
@@ -766,11 +724,7 @@ class VisitAdapter {
766
724
  Turbo$1.registerAdapter(
767
725
  Object.assign(Object.create(adapter), {
768
726
  visitProposedToLocation(location, options) {
769
- if (visitAdapter.#shouldVisitInFrame(location, options)) {
770
- Turbo$1.visit(location, { frame: "kpop" });
771
- } else {
772
- adapter.visitProposedToLocation(location, options);
773
- }
727
+ visitAdapter.#visitProposedToLocation(location, options);
774
728
  },
775
729
  }),
776
730
  );
@@ -787,6 +741,29 @@ class VisitAdapter {
787
741
  this.started = false;
788
742
  }
789
743
 
744
+ #visitProposedToLocation(location, options) {
745
+ const frame = document.getElementById("kpop");
746
+ const kpop = frame?.kpop;
747
+
748
+ // `resume_or_redirect_back_or_to` redirects here to close the modal and
749
+ // stay on the current page, so don't visit it.
750
+ if (kpop && location.pathname === "/resume_historical_location") {
751
+ kpop.dismiss({ reason: "resume-historical-location" });
752
+ } else if (this.#shouldVisitInFrame(location, options)) {
753
+ Turbo$1.visit(location, { frame: "kpop" });
754
+ } else {
755
+ // Close any open modal first so it doesn't appear in the history stack.
756
+ if (kpop?.isOpen) kpop.clear({ reason: "page-visit" });
757
+
758
+ // A modal that is still loading isn't open yet. Turbo cancels its request
759
+ // when the page changes, but caches its src with the page snapshot and
760
+ // loads it again on restore, so clear the src first.
761
+ if (frame?.src) frame.src = "";
762
+
763
+ this.adapter.visitProposedToLocation(location, options);
764
+ }
765
+ }
766
+
790
767
  /**
791
768
  * Like Hotwire Native, the rules decide how a location shows, whatever the
792
769
  * link that proposed it says, so `data-turbo-frame="_top"` does not opt out.
@@ -93,19 +93,6 @@ class Modal {
93
93
  this.element.close();
94
94
  }
95
95
 
96
- /**
97
- * When user navigates from inside a modal, dismiss the modal first so
98
- * that the modal does not appear in the history stack.
99
- *
100
- * @param frame FrameController
101
- * @param e Turbo navigation event
102
- */
103
- beforeVisit(frame, e) {
104
- this.debug(`before-visit`, e.detail.url);
105
-
106
- this.frame.clear();
107
- }
108
-
109
96
  static get debug() {
110
97
  return debug(this.name);
111
98
  }
@@ -180,27 +167,16 @@ class FrameModal extends Modal {
180
167
  }
181
168
 
182
169
  /**
183
- * When a user clicks a kpop link, turbo intercepts the click and calls
184
- * #navigateFrame on the turbo frame controller before setting the TurboFrame
185
- * element's src attribute. KPOP intercepts this call and calls this method
186
- * first so we cancel problematic navigations that might cache invalid states.
170
+ * When the FrameController reloads the open modal's location, it runs this
171
+ * method to open the new content in place, without animating.
187
172
  *
188
- * @param location URL requested by turbo
189
- * @param frame FrameController
190
- * @param element TurboFrame element
191
- * @param resolve continuation chain
173
+ * @param {Kpop__FrameController} frame
174
+ * @param {HTMLDialogElement} dialog
175
+ * @param {String} src
192
176
  */
193
- static visit(location, frame, element, resolve) {
194
- // Ensure that turbo doesn't cache the frame in a loading state by cancelling
195
- // the current request (if any) by clearing the src.
196
- // Known issue: this won't work if the frame was previously rendering a useful src.
197
- if (element.hasAttribute("busy")) {
198
- this.debug("clearing src to cancel turbo request");
199
- element.src = "";
200
- }
201
-
202
- this.debug("navigate to", location);
203
- resolve();
177
+ static reload(frame, dialog, src) {
178
+ this.debug("reload", src);
179
+ return frame.open(new FrameModal(frame, dialog, src), { animate: false });
204
180
  }
205
181
  }
206
182
 
@@ -214,9 +190,6 @@ class Kpop__FrameController extends Controller {
214
190
 
215
191
  this.element.kpop = this;
216
192
 
217
- // allow our code to intercept frame navigation requests before dom changes
218
- installNavigationInterception(this);
219
-
220
193
  const dialog = this.element.querySelector("dialog");
221
194
 
222
195
  if (this.element.src && dialog) {
@@ -321,6 +294,8 @@ class Kpop__FrameController extends Controller {
321
294
 
322
295
  if (event.detail.newFrame.id !== this.element.id) return;
323
296
 
297
+ if (this.#isReload()) return this.#reload(event);
298
+
324
299
  event.preventDefault();
325
300
 
326
301
  this.dismiss({ animate: true, reason: "before-frame-render" }).then(() => {
@@ -346,24 +321,6 @@ class Kpop__FrameController extends Controller {
346
321
  };
347
322
  }
348
323
 
349
- beforeVisit(e) {
350
- this.debug("before-visit", e.detail.url);
351
-
352
- // ignore visits to the current frame, these fire when the frame navigates
353
- if (e.detail.url === this.element.src) return;
354
-
355
- const url = new URL(e.detail.url.toString(), document.baseURI);
356
- if (url.pathname === "/resume_historical_location") {
357
- e.preventDefault();
358
- return this.dismiss();
359
- }
360
-
361
- // ignore unless we're open
362
- if (!this.isOpen) return;
363
-
364
- this.modal.beforeVisit(this, e);
365
- }
366
-
367
324
  frameLoad(e) {
368
325
  this.debug("frame-load");
369
326
 
@@ -389,6 +346,47 @@ class Kpop__FrameController extends Controller {
389
346
  return this.openValue && !this.dismissing;
390
347
  }
391
348
 
349
+ /**
350
+ * The frame is loading the location of the open modal again, e.g. from
351
+ * `Turbo.visit` or a link in the modal to its own location.
352
+ */
353
+ #isReload() {
354
+ if (!this.isOpen || !this.modal) return false;
355
+
356
+ const url = new URL(this.element.src, document.baseURI);
357
+ const { uri } = this.modal;
358
+ return url.pathname + url.search === uri.pathname + uri.search;
359
+ }
360
+
361
+ /**
362
+ * Like a Turbo page reload, swap the content in place: replace the modal
363
+ * as the frame renders, without animating out and in. Turbo waits for
364
+ * repaints before frame-load, so opening the new dialog any later would
365
+ * show a frame without a modal.
366
+ *
367
+ * @param event turbo:before-frame-render
368
+ */
369
+ #reload(event) {
370
+ this.debug("reload", this.element.src);
371
+
372
+ const render = event.detail.render;
373
+ event.detail.render = (currentElement, newElement) => {
374
+ render(currentElement, newElement);
375
+
376
+ // Keep the focus target from when the modal first opened
377
+ const previousFocusRef = this.previousFocusRef;
378
+ const dialog = this.element.querySelector("dialog");
379
+
380
+ this.modal.disconnect();
381
+ delete this.modal;
382
+ this.openValue = false;
383
+
384
+ FrameModal.reload(this, dialog, this.element.src).then(() => {
385
+ this.previousFocusRef = previousFocusRef;
386
+ });
387
+ };
388
+ }
389
+
392
390
  async #open(modal, { animate = true } = {}) {
393
391
  this.debug("open-start", { animate });
394
392
 
@@ -453,50 +451,6 @@ class Kpop__FrameController extends Controller {
453
451
  }
454
452
  }
455
453
 
456
- /**
457
- * Monkey patch for Turbo#FrameController.
458
- *
459
- * Intercept calls to linkClickIntercepted(element, location) and ensures
460
- * that src is cleared if the frame is busy so that we don't restore an
461
- * in-progress src on restoration visits.
462
- *
463
- * See Turbo issue: https://github.com/hotwired/turbo/issues/1055
464
- *
465
- * @param controller FrameController
466
- */
467
- function installNavigationInterception(controller) {
468
- const TurboFrameController =
469
- controller.element.delegate.constructor.prototype;
470
-
471
- if (TurboFrameController._linkClickIntercepted) return;
472
-
473
- TurboFrameController._linkClickIntercepted =
474
- TurboFrameController.linkClickIntercepted;
475
- TurboFrameController.linkClickIntercepted = function (element, location) {
476
- // #findFrameElement
477
- const id =
478
- element?.getAttribute("data-turbo-frame") ||
479
- this.element.getAttribute("target");
480
- let frame = document.getElementById(id);
481
- if (!(frame instanceof Turbo.FrameElement)) {
482
- frame = this.element;
483
- }
484
-
485
- if (frame.kpop) {
486
- frame.kpop.debug("navigate-frame %s => %s", frame.src, location);
487
- FrameModal.visit(location, frame.kpop, frame, () => {
488
- TurboFrameController._linkClickIntercepted.call(
489
- this,
490
- element,
491
- location,
492
- );
493
- });
494
- } else {
495
- TurboFrameController._linkClickIntercepted.call(this, element, location);
496
- }
497
- };
498
- }
499
-
500
454
  function autofocus(container) {
501
455
  if (!container) return null;
502
456
 
@@ -743,10 +697,14 @@ function openStreamModal() {
743
697
  }
744
698
 
745
699
  /**
746
- * Routes Turbo visits to locations that match a modal rule into the kpop
747
- * frame, the way Hotwire Native routes visits with its path configuration.
700
+ * Decides how each Turbo visit shows, the way Hotwire Native routes visits
701
+ * with its path configuration. Visits to locations that match a modal rule
702
+ * open in the kpop frame, and page visits close any open modal first.
748
703
  * Callers use `Turbo.visit` and the ruleset decides how the location shows.
749
704
  *
705
+ * Turbo dispatches `turbo:before-visit` before the adapter knows where the
706
+ * visit goes, so kpop handles visits here rather than in that event.
707
+ *
750
708
  * Wraps Turbo's browser adapter, which Turbo does not export, so every other
751
709
  * adapter call reaches the browser adapter unchanged.
752
710
  */
@@ -766,11 +724,7 @@ class VisitAdapter {
766
724
  Turbo$1.registerAdapter(
767
725
  Object.assign(Object.create(adapter), {
768
726
  visitProposedToLocation(location, options) {
769
- if (visitAdapter.#shouldVisitInFrame(location, options)) {
770
- Turbo$1.visit(location, { frame: "kpop" });
771
- } else {
772
- adapter.visitProposedToLocation(location, options);
773
- }
727
+ visitAdapter.#visitProposedToLocation(location, options);
774
728
  },
775
729
  }),
776
730
  );
@@ -787,6 +741,29 @@ class VisitAdapter {
787
741
  this.started = false;
788
742
  }
789
743
 
744
+ #visitProposedToLocation(location, options) {
745
+ const frame = document.getElementById("kpop");
746
+ const kpop = frame?.kpop;
747
+
748
+ // `resume_or_redirect_back_or_to` redirects here to close the modal and
749
+ // stay on the current page, so don't visit it.
750
+ if (kpop && location.pathname === "/resume_historical_location") {
751
+ kpop.dismiss({ reason: "resume-historical-location" });
752
+ } else if (this.#shouldVisitInFrame(location, options)) {
753
+ Turbo$1.visit(location, { frame: "kpop" });
754
+ } else {
755
+ // Close any open modal first so it doesn't appear in the history stack.
756
+ if (kpop?.isOpen) kpop.clear({ reason: "page-visit" });
757
+
758
+ // A modal that is still loading isn't open yet. Turbo cancels its request
759
+ // when the page changes, but caches its src with the page snapshot and
760
+ // loads it again on restore, so clear the src first.
761
+ if (frame?.src) frame.src = "";
762
+
763
+ this.adapter.visitProposedToLocation(location, options);
764
+ }
765
+ }
766
+
790
767
  /**
791
768
  * Like Hotwire Native, the rules decide how a location shows, whatever the
792
769
  * link that proposed it says, so `data-turbo-frame="_top"` does not opt out.
@@ -1,2 +1,2 @@
1
- import{Controller as e}from"@hotwired/stimulus";import{Turbo as t}from"@hotwired/turbo-rails";let s=!1;const i=function(e){return s?console.debug.bind(console,"[%s] %s",e):n},n=()=>{};Object.defineProperty(i,"enabled",{get:function(){return s},set:function(e){s=e}});class r{constructor(e,t,s=null){this.frame=e,this.element=t,this.uri=new URL(s||t.dataset.src,window.location.origin)}connect(){this.element.addEventListener("cancel",this.cancel),this.element.addEventListener("close",this.close),this.element.addEventListener("mousedown",this.scrim)}disconnect(){this.element.removeEventListener("cancel",this.cancel),this.element.removeEventListener("close",this.close),this.element.removeEventListener("mousedown",this.scrim)}get src(){return this.uri.pathname+this.uri.search+this.uri.hash}cancel=e=>{this.debug("event:cancel",e),e.preventDefault(),this.frame.dismiss({animate:!0,reason:"dialog:cancel"})};close=e=>{this.debug("event:close",e),this.frame.clear({reason:"dialog:close"})};scrim=e=>{"DIALOG"===e.target.tagName&&(this.debug("event:scrim",e),this.frame.dismiss({animate:!0,reason:"dialog:scrim"}))};async open({animate:e=!0}={}){this.debug("open-start",e),await a(this.element,e,()=>this.element.showModal()),this.debug("open-end")}async dismiss({animate:e=!0}={}){this.debug("dismiss-start",e),await a(this.element,e,()=>this.element.removeAttribute("open")),this.debug("dismiss-end"),this.element.close()}beforeVisit(e,t){this.debug("before-visit",t.detail.url),this.frame.clear()}static get debug(){return i(this.name)}get debug(){return i(this.constructor.name)}}function a(e,t,s){if(!t)return s();const i=function(e,t="0.2s"){const s=getComputedStyle(e).getPropertyValue("--animation-duration")||t,i=parseFloat(s);return s.endsWith("ms")?i:1e3*i}(e);return new Promise(n=>{const r=()=>{e.removeEventListener("animationend",r,{once:!0}),clearTimeout(a),e.toggleAttribute("animate",!1),n()};e.addEventListener("animationend",r,{once:!0});const a=setTimeout(r,i);e.toggleAttribute("animate",t),s()})}class o extends r{static connect(e,t){e.open(new o(e,t),{animate:!1})}}class d extends r{static connect(e,t,s){return this.debug("restore",s),e.open(new d(e,t,s),{animate:!1})}static load(e,t,s){return this.debug("load",s),e.open(new d(e,t,s),{animate:!0})}static visit(e,t,s,i){s.hasAttribute("busy")&&(this.debug("clearing src to cancel turbo request"),s.src=""),this.debug("navigate to",e),i()}}class c extends e{static values={open:Boolean};connect(){this.debug("connect",this.element.src),this.element.kpop=this,function(e){const t=e.element.delegate.constructor.prototype;if(t._linkClickIntercepted)return;t._linkClickIntercepted=t.linkClickIntercepted,t.linkClickIntercepted=function(e,s){const i=e?.getAttribute("data-turbo-frame")||this.element.getAttribute("target");let n=document.getElementById(i);n instanceof Turbo.FrameElement||(n=this.element),n.kpop?(n.kpop.debug("navigate-frame %s => %s",n.src,s),d.visit(s,n.kpop,n,()=>{t._linkClickIntercepted.call(this,e,s)})):t._linkClickIntercepted.call(this,e,s)}}(this);const e=this.element.querySelector("dialog");this.element.src&&e?(this.debug("new frame modal",this.element.src),d.connect(this,e,this.element.src).then(()=>{})):e?(this.debug("new content modal",e),o.connect(this,e)):(this.debug("no modal"),this.clear())}disconnect(){this.debug("disconnect",this.element.src),delete this.element.kpop,delete this.modal}openValueChanged(e){this.debug("open-changed",e)}async open(e,{animate:t=!0}={}){return this.isOpen?(this.debug("skip open as already open"),this.modal||=e,!1):(await this.dismissing,this.opening||=Promise.resolve().then(()=>(e.connect(),this.#e(e,{animate:t}))))}async dismiss({animate:e=!0,reason:t=""}={}){return this.debug("event:dismiss",t),this.isOpen?(await this.opening,this.dismissing||=this.#t({animate:e,reason:t})):(this.debug("skip dismiss as already closed"),!1)}clear({reason:e=""}={}){this.debug("event:clear",e),this.modal?.src===this.element.src&&(this.element.src=""),this.element.innerHTML="",this.openValue=!1,this.modal&&this.modal.disconnect(),delete this.modal,delete this.dismissing}beforeFrameRender(e){this.debug("before-frame-render",e.detail.newFrame.baseURI),e.detail.newFrame.id===this.element.id&&(e.preventDefault(),this.dismiss({animate:!0,reason:"before-frame-render"}).then(()=>{this.debug("resume-frame-render",e.detail.newFrame.baseURI),e.detail.resume()}))}beforeStreamRender(e){this.debug("before-stream-render",e.detail);const t=e.detail.render;e.detail.render=async e=>{await this.dismissing,this.debug("stream-render",e),await t(e)}}beforeVisit(e){if(this.debug("before-visit",e.detail.url),e.detail.url===this.element.src)return;if("/resume_historical_location"===new URL(e.detail.url.toString(),document.baseURI).pathname)return e.preventDefault(),this.dismiss();this.isOpen&&this.modal.beforeVisit(this,e)}frameLoad(e){this.debug("frame-load"),d.load(this,e.target.firstElementChild,e.target.src).then(()=>{})}beforeFetchRequest(){const e=document.activeElement;e===document.body?delete this.lastFetchFocusRef:this.lastFetchFocusRef=new WeakRef(e)}get isOpen(){return this.openValue&&!this.dismissing}async#e(e,{animate:t=!0}={}){var s;return this.debug("open-start",{animate:t}),this.previousFocusRef=document.activeElement===document.body?this.lastFetchFocusRef:new WeakRef(document.activeElement),this.debug("capture focus",this.previousFocusRef?.deref()),this.modal=e,this.openValue=!0,this.element.delegate.sourceURL=this.modal.src,await e.open({animate:t}),delete this.opening,this.debug("open-end"),(s=this.modal?.element,s?s.querySelector("[autofocus]")??s.querySelector("button:not([disabled])"):null)?.focus(),Turbo.session.view.forceReloaded&&console.error("Turbo-Frame response is incompatible with current page"),!0}async#t({animate:e=!0,reason:t=""}={}){this.debug("dismiss-start",{animate:e,reason:t}),this.element.isConnected?(this.modal||console.warn("modal missing on dismiss"),await(this.modal?.dismiss({animate:e})),this.clear(),this.previousFocusRef?.deref()?.focus(),this.debug("restore focus",this.previousFocusRef?.deref()),delete this.previousFocusRef,this.debug("dismiss-end")):this.debug("skip dismiss, element detached")}async#s(e){return new Promise(window.requestAnimationFrame).then(e)}get debug(){return i("FrameController")}}class h{started=!1;constructor(e,t){this.delegate=e,this.eventTarget=t}start(){this.started||("loading"===this.eventTarget.readyState?this.eventTarget.addEventListener("DOMContentLoaded",this.#i,{once:!0}):this.#i())}stop(){this.started&&(this.eventTarget.removeEventListener("mouseenter",this.#n,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("turbo:before-prefetch",this.#n,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("focusin",this.#n,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("mouseleave",this.#r,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("focusout",this.#r,{capture:!0,passive:!0}),this.started=!1)}#i=()=>{this.started||(this.started=!0,this.eventTarget.addEventListener("mouseenter",this.#n,{capture:!0,passive:!0}),this.eventTarget.addEventListener("focusin",this.#n,{capture:!0,passive:!0}),this.eventTarget.addEventListener("turbo:before-prefetch",this.#n,{capture:!0,passive:!0}),this.eventTarget.addEventListener("mouseleave",this.#r,{capture:!0,passive:!0}),this.eventTarget.addEventListener("focusout",this.#r,{capture:!0,passive:!0}))};#n=e=>{const t=e.target;if(t.matches&&t.matches("a[href]:not([target^=_]):not([download]):not([data-turbo-frame]")&&this.#a(t)){const e=t,s=function(e){return new URL(e.getAttribute("href").toString(),document.baseURI)}(e);this.delegate.isModalLink(e,s)&&(e.dataset.turboFrame="kpop")}};#r=e=>{const t=e.target;t.matches&&t.matches("a[href][data-turbo-frame='kpop']")&&delete t.dataset.turboFrame};#a(e){return!!e.getAttribute("href")&&(!u(e)&&(!l(e)&&(!m(e)&&!p(e))))}}const u=e=>e.origin!==document.location.origin||!["http:","https:"].includes(e.protocol)||e.hasAttribute("target"),l=e=>e.pathname+e.search===document.location.pathname+document.location.search||e.href.startsWith("#"),m=e=>"false"===e.getAttribute("data-turbo"),p=e=>{const t=e.getAttribute("data-turbo-method");return!(!t||"get"===t.toLowerCase())||(!!g(e)||(!!e.hasAttribute("data-turbo-confirm")||!!e.hasAttribute("data-turbo-stream")))},g=e=>e.hasAttribute("data-remote")||e.hasAttribute("data-behavior")||e.hasAttribute("data-confirm")||e.hasAttribute("data-method");class b{constructor(e=[]){this.rules=[],e.forEach(e=>{this.#o(e)})}properties(e){return this.rules.reduce((t,s)=>s(e,t),{})}#o({patterns:e,properties:t}){e.forEach(e=>{this.rules.push(function(e,t){return(s,i)=>e.test(s.pathname)?{...i,...t}:i}(new RegExp(e),t))})}}class f extends r{static async open(e,t){const s=!e.isOpen;await e.dismiss({animate:s,reason:"turbo-stream.kpop_open"}),e.element.append(t.templateContent);const i=e.element.querySelector("dialog"),n=i.dataset.src;await e.open(new f(e,i,n),{animate:s})}}class v{start(){t.StreamActions.kpop_open=L}stop(){delete t.StreamActions.kpop_open}}function L(){const e=this.targetElements[0]?.kpop;e&&f.open(e,this).then(()=>{})}class w{started=!1;constructor(e){this.delegate=e}start(){if(this.started)return;const e=this.adapter=t.session.adapter,s=this;t.registerAdapter(Object.assign(Object.create(e),{visitProposedToLocation(i,n){s.#d(i,n)?t.visit(i,{frame:"kpop"}):e.visitProposedToLocation(i,n)}})),this.started=!0}stop(){this.started&&(t.registerAdapter(this.adapter),delete this.adapter,this.started=!1)}#d(e,s){return!s?.response&&(!function(e){return e.pathname+e.search===document.location.pathname+document.location.search}(e)&&(document.getElementById("kpop")instanceof t.FrameElement&&this.delegate.isModalLocation(e)))}}const k=[{identifier:"kpop--frame",controllerConstructor:c}];class E{static configure(e={}){return this.instance||=new this(e),i.enabled=this.instance.debug,this.instance}constructor({rules:e=[],debug:t=!1}={}){this.config={rules:e,debug:t},this.ruleset=new b(e),this.linkObserver=new h(this,document),this.streamActions=new v,this.visitAdapter=new w(this)}start(){return this.streamActions.start(),this.linkObserver.start(),this.visitAdapter.start(),window.addEventListener("turbo:before-fetch-request",y),this.debug&&(document.addEventListener("focusin",A),document.addEventListener("focusout",F)),this}stop(){window.removeEventListener("turbo:before-fetch-request",y),document.removeEventListener("focusin",A),document.removeEventListener("focusout",F),this.visitAdapter.stop(),this.streamActions.stop(),this.linkObserver.stop()}isModalLink(e,t){return this.isModalLocation(t)}isModalLocation(e){return"modal"===this.ruleset.properties(e).context}get debug(){return Boolean(this.config.debug)}}const A=e=>i("Application")("focus",e.target),F=e=>i("Application")("blur",e.target),y=e=>{const t=e.detail.fetchOptions.headers;t.Accept?.includes("text/vnd.turbo-stream.html")&&(t["Kpop-Available"]="true")};export{k as controllers,E as default};
1
+ import{Controller as e}from"@hotwired/stimulus";import{Turbo as t}from"@hotwired/turbo-rails";let s=!1;const i=function(e){return s?console.debug.bind(console,"[%s] %s",e):n},n=()=>{};Object.defineProperty(i,"enabled",{get:function(){return s},set:function(e){s=e}});class a{constructor(e,t,s=null){this.frame=e,this.element=t,this.uri=new URL(s||t.dataset.src,window.location.origin)}connect(){this.element.addEventListener("cancel",this.cancel),this.element.addEventListener("close",this.close),this.element.addEventListener("mousedown",this.scrim)}disconnect(){this.element.removeEventListener("cancel",this.cancel),this.element.removeEventListener("close",this.close),this.element.removeEventListener("mousedown",this.scrim)}get src(){return this.uri.pathname+this.uri.search+this.uri.hash}cancel=e=>{this.debug("event:cancel",e),e.preventDefault(),this.frame.dismiss({animate:!0,reason:"dialog:cancel"})};close=e=>{this.debug("event:close",e),this.frame.clear({reason:"dialog:close"})};scrim=e=>{"DIALOG"===e.target.tagName&&(this.debug("event:scrim",e),this.frame.dismiss({animate:!0,reason:"dialog:scrim"}))};async open({animate:e=!0}={}){this.debug("open-start",e),await r(this.element,e,()=>this.element.showModal()),this.debug("open-end")}async dismiss({animate:e=!0}={}){this.debug("dismiss-start",e),await r(this.element,e,()=>this.element.removeAttribute("open")),this.debug("dismiss-end"),this.element.close()}static get debug(){return i(this.name)}get debug(){return i(this.constructor.name)}}function r(e,t,s){if(!t)return s();const i=function(e,t="0.2s"){const s=getComputedStyle(e).getPropertyValue("--animation-duration")||t,i=parseFloat(s);return s.endsWith("ms")?i:1e3*i}(e);return new Promise(n=>{const a=()=>{e.removeEventListener("animationend",a,{once:!0}),clearTimeout(r),e.toggleAttribute("animate",!1),n()};e.addEventListener("animationend",a,{once:!0});const r=setTimeout(a,i);e.toggleAttribute("animate",t),s()})}class o extends a{static connect(e,t){e.open(new o(e,t),{animate:!1})}}class d extends a{static connect(e,t,s){return this.debug("restore",s),e.open(new d(e,t,s),{animate:!1})}static load(e,t,s){return this.debug("load",s),e.open(new d(e,t,s),{animate:!0})}static reload(e,t,s){return this.debug("reload",s),e.open(new d(e,t,s),{animate:!1})}}class c extends e{static values={open:Boolean};connect(){this.debug("connect",this.element.src),this.element.kpop=this;const e=this.element.querySelector("dialog");this.element.src&&e?(this.debug("new frame modal",this.element.src),d.connect(this,e,this.element.src).then(()=>{})):e?(this.debug("new content modal",e),o.connect(this,e)):(this.debug("no modal"),this.clear())}disconnect(){this.debug("disconnect",this.element.src),delete this.element.kpop,delete this.modal}openValueChanged(e){this.debug("open-changed",e)}async open(e,{animate:t=!0}={}){return this.isOpen?(this.debug("skip open as already open"),this.modal||=e,!1):(await this.dismissing,this.opening||=Promise.resolve().then(()=>(e.connect(),this.#e(e,{animate:t}))))}async dismiss({animate:e=!0,reason:t=""}={}){return this.debug("event:dismiss",t),this.isOpen?(await this.opening,this.dismissing||=this.#t({animate:e,reason:t})):(this.debug("skip dismiss as already closed"),!1)}clear({reason:e=""}={}){this.debug("event:clear",e),this.modal?.src===this.element.src&&(this.element.src=""),this.element.innerHTML="",this.openValue=!1,this.modal&&this.modal.disconnect(),delete this.modal,delete this.dismissing}beforeFrameRender(e){if(this.debug("before-frame-render",e.detail.newFrame.baseURI),e.detail.newFrame.id===this.element.id){if(this.#s())return this.#i(e);e.preventDefault(),this.dismiss({animate:!0,reason:"before-frame-render"}).then(()=>{this.debug("resume-frame-render",e.detail.newFrame.baseURI),e.detail.resume()})}}beforeStreamRender(e){this.debug("before-stream-render",e.detail);const t=e.detail.render;e.detail.render=async e=>{await this.dismissing,this.debug("stream-render",e),await t(e)}}frameLoad(e){this.debug("frame-load"),d.load(this,e.target.firstElementChild,e.target.src).then(()=>{})}beforeFetchRequest(){const e=document.activeElement;e===document.body?delete this.lastFetchFocusRef:this.lastFetchFocusRef=new WeakRef(e)}get isOpen(){return this.openValue&&!this.dismissing}#s(){if(!this.isOpen||!this.modal)return!1;const e=new URL(this.element.src,document.baseURI),{uri:t}=this.modal;return e.pathname+e.search===t.pathname+t.search}#i(e){this.debug("reload",this.element.src);const t=e.detail.render;e.detail.render=(e,s)=>{t(e,s);const i=this.previousFocusRef,n=this.element.querySelector("dialog");this.modal.disconnect(),delete this.modal,this.openValue=!1,d.reload(this,n,this.element.src).then(()=>{this.previousFocusRef=i})}}async#e(e,{animate:t=!0}={}){var s;return this.debug("open-start",{animate:t}),this.previousFocusRef=document.activeElement===document.body?this.lastFetchFocusRef:new WeakRef(document.activeElement),this.debug("capture focus",this.previousFocusRef?.deref()),this.modal=e,this.openValue=!0,this.element.delegate.sourceURL=this.modal.src,await e.open({animate:t}),delete this.opening,this.debug("open-end"),(s=this.modal?.element,s?s.querySelector("[autofocus]")??s.querySelector("button:not([disabled])"):null)?.focus(),Turbo.session.view.forceReloaded&&console.error("Turbo-Frame response is incompatible with current page"),!0}async#t({animate:e=!0,reason:t=""}={}){this.debug("dismiss-start",{animate:e,reason:t}),this.element.isConnected?(this.modal||console.warn("modal missing on dismiss"),await(this.modal?.dismiss({animate:e})),this.clear(),this.previousFocusRef?.deref()?.focus(),this.debug("restore focus",this.previousFocusRef?.deref()),delete this.previousFocusRef,this.debug("dismiss-end")):this.debug("skip dismiss, element detached")}async#n(e){return new Promise(window.requestAnimationFrame).then(e)}get debug(){return i("FrameController")}}class h{started=!1;constructor(e,t){this.delegate=e,this.eventTarget=t}start(){this.started||("loading"===this.eventTarget.readyState?this.eventTarget.addEventListener("DOMContentLoaded",this.#a,{once:!0}):this.#a())}stop(){this.started&&(this.eventTarget.removeEventListener("mouseenter",this.#r,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("turbo:before-prefetch",this.#r,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("focusin",this.#r,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("mouseleave",this.#o,{capture:!0,passive:!0}),this.eventTarget.removeEventListener("focusout",this.#o,{capture:!0,passive:!0}),this.started=!1)}#a=()=>{this.started||(this.started=!0,this.eventTarget.addEventListener("mouseenter",this.#r,{capture:!0,passive:!0}),this.eventTarget.addEventListener("focusin",this.#r,{capture:!0,passive:!0}),this.eventTarget.addEventListener("turbo:before-prefetch",this.#r,{capture:!0,passive:!0}),this.eventTarget.addEventListener("mouseleave",this.#o,{capture:!0,passive:!0}),this.eventTarget.addEventListener("focusout",this.#o,{capture:!0,passive:!0}))};#r=e=>{const t=e.target;if(t.matches&&t.matches("a[href]:not([target^=_]):not([download]):not([data-turbo-frame]")&&this.#d(t)){const e=t,s=function(e){return new URL(e.getAttribute("href").toString(),document.baseURI)}(e);this.delegate.isModalLink(e,s)&&(e.dataset.turboFrame="kpop")}};#o=e=>{const t=e.target;t.matches&&t.matches("a[href][data-turbo-frame='kpop']")&&delete t.dataset.turboFrame};#d(e){return!!e.getAttribute("href")&&(!u(e)&&(!m(e)&&(!l(e)&&!p(e))))}}const u=e=>e.origin!==document.location.origin||!["http:","https:"].includes(e.protocol)||e.hasAttribute("target"),m=e=>e.pathname+e.search===document.location.pathname+document.location.search||e.href.startsWith("#"),l=e=>"false"===e.getAttribute("data-turbo"),p=e=>{const t=e.getAttribute("data-turbo-method");return!(!t||"get"===t.toLowerCase())||(!!g(e)||(!!e.hasAttribute("data-turbo-confirm")||!!e.hasAttribute("data-turbo-stream")))},g=e=>e.hasAttribute("data-remote")||e.hasAttribute("data-behavior")||e.hasAttribute("data-confirm")||e.hasAttribute("data-method");class b{constructor(e=[]){this.rules=[],e.forEach(e=>{this.#c(e)})}properties(e){return this.rules.reduce((t,s)=>s(e,t),{})}#c({patterns:e,properties:t}){e.forEach(e=>{this.rules.push(function(e,t){return(s,i)=>e.test(s.pathname)?{...i,...t}:i}(new RegExp(e),t))})}}class v extends a{static async open(e,t){const s=!e.isOpen;await e.dismiss({animate:s,reason:"turbo-stream.kpop_open"}),e.element.append(t.templateContent);const i=e.element.querySelector("dialog"),n=i.dataset.src;await e.open(new v(e,i,n),{animate:s})}}class f{start(){t.StreamActions.kpop_open=L}stop(){delete t.StreamActions.kpop_open}}function L(){const e=this.targetElements[0]?.kpop;e&&v.open(e,this).then(()=>{})}class w{started=!1;constructor(e){this.delegate=e}start(){if(this.started)return;const e=this.adapter=t.session.adapter,s=this;t.registerAdapter(Object.assign(Object.create(e),{visitProposedToLocation(e,t){s.#h(e,t)}})),this.started=!0}stop(){this.started&&(t.registerAdapter(this.adapter),delete this.adapter,this.started=!1)}#h(e,s){const i=document.getElementById("kpop"),n=i?.kpop;n&&"/resume_historical_location"===e.pathname?n.dismiss({reason:"resume-historical-location"}):this.#u(e,s)?t.visit(e,{frame:"kpop"}):(n?.isOpen&&n.clear({reason:"page-visit"}),i?.src&&(i.src=""),this.adapter.visitProposedToLocation(e,s))}#u(e,s){return!s?.response&&(!function(e){return e.pathname+e.search===document.location.pathname+document.location.search}(e)&&(document.getElementById("kpop")instanceof t.FrameElement&&this.delegate.isModalLocation(e)))}}const E=[{identifier:"kpop--frame",controllerConstructor:c}];class k{static configure(e={}){return this.instance||=new this(e),i.enabled=this.instance.debug,this.instance}constructor({rules:e=[],debug:t=!1}={}){this.config={rules:e,debug:t},this.ruleset=new b(e),this.linkObserver=new h(this,document),this.streamActions=new f,this.visitAdapter=new w(this)}start(){return this.streamActions.start(),this.linkObserver.start(),this.visitAdapter.start(),window.addEventListener("turbo:before-fetch-request",F),this.debug&&(document.addEventListener("focusin",A),document.addEventListener("focusout",R)),this}stop(){window.removeEventListener("turbo:before-fetch-request",F),document.removeEventListener("focusin",A),document.removeEventListener("focusout",R),this.visitAdapter.stop(),this.streamActions.stop(),this.linkObserver.stop()}isModalLink(e,t){return this.isModalLocation(t)}isModalLocation(e){return"modal"===this.ruleset.properties(e).context}get debug(){return Boolean(this.config.debug)}}const A=e=>i("Application")("focus",e.target),R=e=>i("Application")("blur",e.target),F=e=>{const t=e.detail.fetchOptions.headers;t.Accept?.includes("text/vnd.turbo-stream.html")&&(t["Kpop-Available"]="true")};export{E as controllers,k as default};
2
2
  //# sourceMappingURL=kpop.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"kpop.min.js","sources":["../../../javascript/kpop/utils/debug.js","../../../javascript/kpop/modals/modal.js","../../../javascript/kpop/modals/content_modal.js","../../../javascript/kpop/modals/frame_modal.js","../../../javascript/kpop/controllers/frame_controller.js","../../../javascript/kpop/utils/link_observer.js","../../../javascript/kpop/utils/ruleset.js","../../../javascript/kpop/modals/stream_modal.js","../../../javascript/kpop/utils/stream_actions.js","../../../javascript/kpop/utils/visit_adapter.js","../../../javascript/kpop/application.js"],"sourcesContent":["let enabled = false;\n\nconst debug = function (receiver) {\n if (enabled) {\n return console.debug.bind(console, \"[%s] %s\", receiver);\n } else {\n return noop;\n }\n};\n\nconst noop = () => {};\n\nObject.defineProperty(debug, \"enabled\", {\n get: function () {\n return enabled;\n },\n set: function (debug) {\n enabled = debug;\n },\n});\n\nexport default debug;\n","import debug from \"../utils/debug\";\n\nexport class Modal {\n constructor(frame, dialog, src = null) {\n this.frame = frame;\n this.element = dialog;\n this.uri = new URL(src || dialog.dataset.src, window.location.origin);\n }\n\n connect() {\n this.element.addEventListener(\"cancel\", this.cancel);\n this.element.addEventListener(\"close\", this.close);\n this.element.addEventListener(\"mousedown\", this.scrim);\n }\n\n disconnect() {\n this.element.removeEventListener(\"cancel\", this.cancel);\n this.element.removeEventListener(\"close\", this.close);\n this.element.removeEventListener(\"mousedown\", this.scrim);\n }\n\n get src() {\n return this.uri.pathname + this.uri.search + this.uri.hash;\n }\n\n cancel = (e) => {\n this.debug(\"event:cancel\", e);\n\n e.preventDefault();\n\n this.frame.dismiss({ animate: true, reason: \"dialog:cancel\" });\n };\n\n close = (e) => {\n this.debug(\"event:close\", e);\n\n this.frame.clear({ reason: \"dialog:close\" });\n };\n\n scrim = (e) => {\n if (e.target.tagName === \"DIALOG\") {\n this.debug(\"event:scrim\", e);\n\n this.frame.dismiss({ animate: true, reason: \"dialog:scrim\" });\n }\n };\n\n async open({ animate = true } = {}) {\n this.debug(\"open-start\", animate);\n\n await animation(this.element, animate, () => this.element.showModal());\n\n this.debug(\"open-end\");\n }\n\n /**\n * Modals are closed by animating out the modal then removing the modal\n * element from the wrapping frame.\n *\n * @returns {Promise<void>}\n */\n async dismiss({ animate = true } = {}) {\n this.debug(\"dismiss-start\", animate);\n\n await animation(this.element, animate, () =>\n this.element.removeAttribute(\"open\"),\n );\n\n this.debug(\"dismiss-end\");\n\n this.element.close();\n }\n\n /**\n * When user navigates from inside a modal, dismiss the modal first so\n * that the modal does not appear in the history stack.\n *\n * @param frame FrameController\n * @param e Turbo navigation event\n */\n beforeVisit(frame, e) {\n this.debug(`before-visit`, e.detail.url);\n\n this.frame.clear();\n }\n\n static get debug() {\n return debug(this.name);\n }\n\n get debug() {\n return debug(this.constructor.name);\n }\n}\n\nfunction animation(el, animate, trigger) {\n if (!animate) return trigger();\n\n const duration = animationDuration(el);\n\n return new Promise((resolve) => {\n const resolver = () => {\n el.removeEventListener(\"animationend\", resolver, { once: true });\n clearTimeout(timeout);\n el.toggleAttribute(\"animate\", false);\n resolve();\n };\n\n el.addEventListener(\"animationend\", resolver, { once: true });\n const timeout = setTimeout(resolver, duration);\n\n el.toggleAttribute(\"animate\", animate);\n trigger();\n });\n}\n\nfunction animationDuration(el, defaultValue = \"0.2s\") {\n const value =\n getComputedStyle(el).getPropertyValue(\"--animation-duration\") ||\n defaultValue;\n const num = parseFloat(value);\n if (value.endsWith(\"ms\")) return num;\n return num * 1000;\n}\n","import { Modal } from \"./modal\";\n\nexport class ContentModal extends Modal {\n static connect(frame, dialog) {\n frame.open(new ContentModal(frame, dialog), { animate: false });\n }\n}\n","import { Modal } from \"./modal\";\n\nexport class FrameModal extends Modal {\n /**\n * When the FrameController detects a frame element on connect, it runs this\n * method to sanity check the frame src and restore the modal state.\n *\n * @param {Kpop__FrameController} frame\n * @param {HTMLDialogElement} dialog\n * @param {String} src\n */\n static connect(frame, dialog, src) {\n // restoration visit\n this.debug(\"restore\", src);\n return frame.open(new FrameModal(frame, dialog, src), { animate: false });\n }\n\n /**\n * When the FrameController detects a frame load event, it runs this\n * method to open the modal.\n *\n * @param {Kpop__FrameController} frame\n * @param {HTMLDialogElement} dialog\n * @param {String} src\n */\n static load(frame, dialog, src) {\n this.debug(\"load\", src);\n return frame.open(new FrameModal(frame, dialog, src), { animate: true });\n }\n\n /**\n * When a user clicks a kpop link, turbo intercepts the click and calls\n * #navigateFrame on the turbo frame controller before setting the TurboFrame\n * element's src attribute. KPOP intercepts this call and calls this method\n * first so we cancel problematic navigations that might cache invalid states.\n *\n * @param location URL requested by turbo\n * @param frame FrameController\n * @param element TurboFrame element\n * @param resolve continuation chain\n */\n static visit(location, frame, element, resolve) {\n // Ensure that turbo doesn't cache the frame in a loading state by cancelling\n // the current request (if any) by clearing the src.\n // Known issue: this won't work if the frame was previously rendering a useful src.\n if (element.hasAttribute(\"busy\")) {\n this.debug(\"clearing src to cancel turbo request\");\n element.src = \"\";\n }\n\n this.debug(\"navigate to\", location);\n resolve();\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nimport { ContentModal } from \"../modals/content_modal\";\nimport { FrameModal } from \"../modals/frame_modal\";\n\nimport debug from \"../utils/debug\";\n\nexport default class Kpop__FrameController extends Controller {\n static values = {\n open: Boolean,\n };\n\n connect() {\n this.debug(\"connect\", this.element.src);\n\n this.element.kpop = this;\n\n // allow our code to intercept frame navigation requests before dom changes\n installNavigationInterception(this);\n\n const dialog = this.element.querySelector(\"dialog\");\n\n if (this.element.src && dialog) {\n this.debug(\"new frame modal\", this.element.src);\n FrameModal.connect(this, dialog, this.element.src).then(() => {});\n } else if (dialog) {\n this.debug(\"new content modal\", dialog);\n ContentModal.connect(this, dialog);\n } else {\n this.debug(\"no modal\");\n this.clear();\n }\n }\n\n disconnect() {\n this.debug(\"disconnect\", this.element.src);\n\n delete this.element.kpop;\n delete this.modal;\n }\n\n openValueChanged(open) {\n this.debug(\"open-changed\", open);\n }\n\n /**\n * Animate an attached modal into the foreground. Returns a promise that\n * resolves when the animation is complete.\n *\n * @param modal\n * @param animate\n * @returns {Promise<Boolean>}\n */\n async open(modal, { animate = true } = {}) {\n if (this.isOpen) {\n this.debug(\"skip open as already open\");\n this.modal ||= modal;\n return false;\n }\n\n await this.dismissing;\n\n return (this.opening ||= Promise.resolve().then(() => {\n modal.connect();\n return this.#open(modal, { animate });\n }));\n }\n\n /**\n * Cause a modal to hide. Returns a promise that will resolve when the\n * animation (if requested) is finished.\n *\n * If the modal is already animating out, returns the existing promise instead.\n *\n * @param {Boolean} animate\n * @param {String} reason\n * @returns {Promise}\n */\n async dismiss({ animate = true, reason = \"\" } = {}) {\n this.debug(\"event:dismiss\", reason);\n\n if (!this.isOpen) {\n this.debug(\"skip dismiss as already closed\");\n return false;\n }\n\n await this.opening;\n\n return (this.dismissing ||= this.#dismiss({ animate, reason }));\n }\n\n /**\n * Clean up after a modal is finished dismissing.\n */\n clear({ reason = \"\" } = {}) {\n this.debug(\"event:clear\", reason);\n\n // clear the src from the frame (if any)\n if (this.modal?.src === this.element.src) this.element.src = \"\";\n this.element.innerHTML = \"\";\n\n // mark the modal as hidden\n this.openValue = false;\n\n // unset modal\n if (this.modal) this.modal.disconnect();\n delete this.modal;\n delete this.dismissing;\n }\n\n // EVENTS\n\n /**\n * Incoming frame render, dismiss the current modal (if any) first.\n *\n * We're starting the actual visit\n *\n * @param event turbo:before-render\n */\n beforeFrameRender(event) {\n this.debug(\"before-frame-render\", event.detail.newFrame.baseURI);\n\n if (event.detail.newFrame.id !== this.element.id) return;\n\n event.preventDefault();\n\n this.dismiss({ animate: true, reason: \"before-frame-render\" }).then(() => {\n this.debug(\"resume-frame-render\", event.detail.newFrame.baseURI);\n event.detail.resume();\n });\n }\n\n beforeStreamRender(event) {\n this.debug(\"before-stream-render\", event.detail);\n\n const resume = event.detail.render;\n\n // Defer rendering until dismiss is complete.\n // Dismiss may change history so we need to wait for it to complete to avoid\n // losing DOM changes on restoration visits.\n event.detail.render = async (stream) => {\n await this.dismissing;\n\n this.debug(\"stream-render\", stream);\n\n await resume(stream);\n };\n }\n\n beforeVisit(e) {\n this.debug(\"before-visit\", e.detail.url);\n\n // ignore visits to the current frame, these fire when the frame navigates\n if (e.detail.url === this.element.src) return;\n\n const url = new URL(e.detail.url.toString(), document.baseURI);\n if (url.pathname === \"/resume_historical_location\") {\n e.preventDefault();\n return this.dismiss();\n }\n\n // ignore unless we're open\n if (!this.isOpen) return;\n\n this.modal.beforeVisit(this, e);\n }\n\n frameLoad(e) {\n this.debug(\"frame-load\");\n\n FrameModal.load(this, e.target.firstElementChild, e.target.src).then(\n () => {},\n );\n }\n\n /**\n * Outgoing fetch request. Capture the initiator so we can return focus if it causes a modal to show.\n */\n beforeFetchRequest() {\n const focusElement = document.activeElement;\n\n if (focusElement === document.body) {\n delete this.lastFetchFocusRef;\n } else {\n this.lastFetchFocusRef = new WeakRef(focusElement);\n }\n }\n\n get isOpen() {\n return this.openValue && !this.dismissing;\n }\n\n async #open(modal, { animate = true } = {}) {\n this.debug(\"open-start\", { animate });\n\n this.previousFocusRef =\n document.activeElement === document.body\n ? this.lastFetchFocusRef\n : new WeakRef(document.activeElement);\n this.debug(\"capture focus\", this.previousFocusRef?.deref());\n\n this.modal = modal;\n this.openValue = true;\n\n // Set turbo-frame[src] without causing a load event\n this.element.delegate.sourceURL = this.modal.src;\n\n await modal.open({ animate });\n\n delete this.opening;\n\n this.debug(\"open-end\");\n\n autofocus(this.modal?.element)?.focus();\n\n // Detect https://github.com/hotwired/turbo-rails/issues/580\n if (Turbo.session.view.forceReloaded) {\n console.error(\"Turbo-Frame response is incompatible with current page\");\n }\n\n return true;\n }\n\n async #dismiss({ animate = true, reason = \"\" } = {}) {\n this.debug(\"dismiss-start\", { animate, reason });\n\n // if this element is detached then we've experienced a turbo navigation\n if (!this.element.isConnected) {\n this.debug(\"skip dismiss, element detached\");\n return;\n }\n\n if (!this.modal) {\n console.warn(\"modal missing on dismiss\");\n }\n\n await this.modal?.dismiss({ animate });\n\n this.clear();\n\n this.previousFocusRef?.deref()?.focus();\n this.debug(\"restore focus\", this.previousFocusRef?.deref());\n delete this.previousFocusRef;\n\n this.debug(\"dismiss-end\");\n }\n\n async #nextFrame(callback) {\n return new Promise(window.requestAnimationFrame).then(callback);\n }\n\n get debug() {\n return debug(\"FrameController\");\n }\n}\n\n/**\n * Monkey patch for Turbo#FrameController.\n *\n * Intercept calls to linkClickIntercepted(element, location) and ensures\n * that src is cleared if the frame is busy so that we don't restore an\n * in-progress src on restoration visits.\n *\n * See Turbo issue: https://github.com/hotwired/turbo/issues/1055\n *\n * @param controller FrameController\n */\nfunction installNavigationInterception(controller) {\n const TurboFrameController =\n controller.element.delegate.constructor.prototype;\n\n if (TurboFrameController._linkClickIntercepted) return;\n\n TurboFrameController._linkClickIntercepted =\n TurboFrameController.linkClickIntercepted;\n TurboFrameController.linkClickIntercepted = function (element, location) {\n // #findFrameElement\n const id =\n element?.getAttribute(\"data-turbo-frame\") ||\n this.element.getAttribute(\"target\");\n let frame = document.getElementById(id);\n if (!(frame instanceof Turbo.FrameElement)) {\n frame = this.element;\n }\n\n if (frame.kpop) {\n frame.kpop.debug(\"navigate-frame %s => %s\", frame.src, location);\n FrameModal.visit(location, frame.kpop, frame, () => {\n TurboFrameController._linkClickIntercepted.call(\n this,\n element,\n location,\n );\n });\n } else {\n TurboFrameController._linkClickIntercepted.call(this, element, location);\n }\n };\n}\n\nfunction autofocus(container) {\n if (!container) return null;\n\n return (\n container.querySelector(\"[autofocus]\") ??\n container.querySelector(\"button:not([disabled])\")\n );\n}\n","/**\n * Based on Turbo's LinkObserver, checks links on mouse-over and focus to see\n * whether they should open in modals. If they should, then sets the\n * data-turbo-frame attribute so it will be prefetched and opened in the context\n * of the kpop turbo frame.\n */\nexport default class LinkObserver {\n started = false;\n\n constructor(delegate, eventTarget) {\n this.delegate = delegate;\n this.eventTarget = eventTarget;\n }\n\n start() {\n if (this.started) return;\n if (this.eventTarget.readyState === \"loading\") {\n this.eventTarget.addEventListener(\"DOMContentLoaded\", this.#enable, {\n once: true,\n });\n } else {\n this.#enable();\n }\n }\n\n stop() {\n if (!this.started) return;\n this.eventTarget.removeEventListener(\"mouseenter\", this.#addKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.removeEventListener(\n \"turbo:before-prefetch\",\n this.#addKpopLink,\n {\n capture: true,\n passive: true,\n },\n );\n this.eventTarget.removeEventListener(\"focusin\", this.#addKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.removeEventListener(\"mouseleave\", this.#removeKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.removeEventListener(\"focusout\", this.#removeKpopLink, {\n capture: true,\n passive: true,\n });\n this.started = false;\n }\n\n #enable = () => {\n if (this.started) return;\n this.started = true;\n this.eventTarget.addEventListener(\"mouseenter\", this.#addKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.addEventListener(\"focusin\", this.#addKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.addEventListener(\n \"turbo:before-prefetch\",\n this.#addKpopLink,\n {\n capture: true,\n passive: true,\n },\n );\n this.eventTarget.addEventListener(\"mouseleave\", this.#removeKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.addEventListener(\"focusout\", this.#removeKpopLink, {\n capture: true,\n passive: true,\n });\n };\n\n #addKpopLink = (event) => {\n const target = event.target;\n const isLink =\n target.matches &&\n target.matches(\n \"a[href]:not([target^=_]):not([download]):not([data-turbo-frame]\",\n );\n if (isLink && this.#isPrefetchable(target)) {\n const link = target;\n const location = getLocationForLink(link);\n if (this.delegate.isModalLink(link, location)) {\n link.dataset.turboFrame = \"kpop\";\n }\n }\n };\n\n #removeKpopLink = (event) => {\n const target = event.target;\n const isLink =\n target.matches && target.matches(\"a[href][data-turbo-frame='kpop']\");\n if (isLink) {\n delete target.dataset.turboFrame;\n }\n };\n\n #isPrefetchable(link) {\n const href = link.getAttribute(\"href\");\n if (!href) return false;\n if (unfetchableLink(link)) return false;\n if (linkToTheSamePage(link)) return false;\n if (linkOptsOut(link)) return false;\n if (nonSafeLink(link)) return false;\n return true;\n }\n}\n\nfunction getLocationForLink(link) {\n return new URL(link.getAttribute(\"href\").toString(), document.baseURI);\n}\n\nconst unfetchableLink = (link) =>\n link.origin !== document.location.origin ||\n ![\"http:\", \"https:\"].includes(link.protocol) ||\n link.hasAttribute(\"target\");\n\nconst linkToTheSamePage = (link) =>\n link.pathname + link.search ===\n document.location.pathname + document.location.search ||\n link.href.startsWith(\"#\");\n\nconst linkOptsOut = (link) => {\n return link.getAttribute(\"data-turbo\") === \"false\";\n};\n\nconst nonSafeLink = (link) => {\n const turboMethod = link.getAttribute(\"data-turbo-method\");\n if (turboMethod && turboMethod.toLowerCase() !== \"get\") return true;\n if (isUJS(link)) return true;\n if (link.hasAttribute(\"data-turbo-confirm\")) return true;\n if (link.hasAttribute(\"data-turbo-stream\")) return true;\n return false;\n};\n\nconst isUJS = (link) =>\n link.hasAttribute(\"data-remote\") ||\n link.hasAttribute(\"data-behavior\") ||\n link.hasAttribute(\"data-confirm\") ||\n link.hasAttribute(\"data-method\");\n","/**\n * Similar to Hotwire's PathConfiguration.json, this class compiles a list of\n * rules to check link hrefs against so that we can identify links that\n * should open in a KPOP modal.\n *\n * Unlike Hotwire Native, we can't intercept 303s in the browser before they\n * load. Browser sandbox prevents us from inspecting the location of redirect\n * requests so we can only intercept links that match modals directly.\n *\n * For posts and redirects, we need server support (flash modals, streams).\n */\nexport default class Ruleset {\n constructor(rules = []) {\n this.rules = [];\n\n rules.forEach((rule) => {\n this.#compileRule(rule);\n });\n }\n\n /**\n * Returns properties for the given URL\n *\n * @param {URL} location\n * @returns {} properties\n */\n properties(location) {\n return this.rules.reduce((c, f) => f(location, c), {});\n }\n\n #compileRule({ patterns, properties }) {\n patterns.forEach((pattern) => {\n this.rules.push(locationMatcher(new RegExp(pattern), properties));\n });\n }\n}\n\nfunction locationMatcher(re, properties) {\n return (location, accumulator) =>\n re.test(location.pathname)\n ? { ...accumulator, ...properties }\n : accumulator;\n}\n","import { Modal } from \"./modal\";\n\nexport class StreamModal extends Modal {\n /**\n * When a turbo-stream[action=kpop_open] element is rendered, it runs this\n * method to load the modal template as a StreamModal.\n *\n * @param {Kpop__FrameController} frame\n * @param {Turbo.StreamElement} action\n */\n static async open(frame, action) {\n const animate = !frame.isOpen;\n\n await frame.dismiss({ animate, reason: \"turbo-stream.kpop_open\" });\n\n frame.element.append(action.templateContent);\n\n const dialog = frame.element.querySelector(\"dialog\");\n const src = dialog.dataset.src;\n\n await frame.open(new StreamModal(frame, dialog, src), { animate });\n }\n}\n","import { Turbo } from \"@hotwired/turbo-rails\";\n\nimport { StreamModal } from \"../modals/stream_modal\";\n\nexport default class StreamActions {\n start() {\n Turbo.StreamActions.kpop_open = openStreamModal;\n }\n\n stop() {\n delete Turbo.StreamActions.kpop_open;\n }\n}\n\nfunction openStreamModal() {\n const frame = this.targetElements[0]?.kpop;\n\n if (frame) {\n StreamModal.open(frame, this).then(() => {});\n }\n}\n","import { Turbo } from \"@hotwired/turbo-rails\";\n\n/**\n * Routes Turbo visits to locations that match a modal rule into the kpop\n * frame, the way Hotwire Native routes visits with its path configuration.\n * Callers use `Turbo.visit` and the ruleset decides how the location shows.\n *\n * Wraps Turbo's browser adapter, which Turbo does not export, so every other\n * adapter call reaches the browser adapter unchanged.\n */\nexport default class VisitAdapter {\n started = false;\n\n constructor(delegate) {\n this.delegate = delegate;\n }\n\n start() {\n if (this.started) return;\n\n const adapter = (this.adapter = Turbo.session.adapter);\n const visitAdapter = this;\n\n Turbo.registerAdapter(\n Object.assign(Object.create(adapter), {\n visitProposedToLocation(location, options) {\n if (visitAdapter.#shouldVisitInFrame(location, options)) {\n Turbo.visit(location, { frame: \"kpop\" });\n } else {\n adapter.visitProposedToLocation(location, options);\n }\n },\n }),\n );\n\n this.started = true;\n }\n\n stop() {\n if (!this.started) return;\n\n Turbo.registerAdapter(this.adapter);\n delete this.adapter;\n\n this.started = false;\n }\n\n /**\n * Like Hotwire Native, the rules decide how a location shows, whatever the\n * link that proposed it says, so `data-turbo-frame=\"_top\"` does not opt out.\n * Use a rule override or `data-turbo=\"false\"` instead. Turbo submits\n * `data-turbo-stream` links as forms, so they never reach the adapter.\n */\n #shouldVisitInFrame(location, options) {\n // A response means Turbo has already fetched the page, e.g. after a form\n // submission or a redirect, so let it render.\n if (options?.response) return false;\n\n // Refreshes and visits to the current page should not open a modal.\n if (isCurrentPage(location)) return false;\n\n // Without a frame, Turbo.visit would propose this visit again.\n if (!(document.getElementById(\"kpop\") instanceof Turbo.FrameElement)) {\n return false;\n }\n\n return this.delegate.isModalLocation(location);\n }\n}\n\nfunction isCurrentPage(location) {\n return (\n location.pathname + location.search ===\n document.location.pathname + document.location.search\n );\n}\n","import FrameController from \"../kpop/controllers/frame_controller\";\n\nimport debug from \"./utils/debug\";\nimport LinkObserver from \"./utils/link_observer\";\nimport Ruleset from \"./utils/ruleset\";\nimport StreamActions from \"./utils/stream_actions\";\nimport VisitAdapter from \"./utils/visit_adapter\";\n\nexport const controllers = [\n { identifier: \"kpop--frame\", controllerConstructor: FrameController },\n];\n\nexport default class Application {\n static configure(config = {}) {\n this.instance ||= new this(config);\n debug.enabled = this.instance.debug;\n return this.instance;\n }\n\n constructor({ rules = [], debug = false } = {}) {\n this.config = { rules, debug };\n this.ruleset = new Ruleset(rules);\n this.linkObserver = new LinkObserver(this, document);\n this.streamActions = new StreamActions();\n this.visitAdapter = new VisitAdapter(this);\n }\n\n start() {\n this.streamActions.start();\n this.linkObserver.start();\n this.visitAdapter.start();\n\n window.addEventListener(\n \"turbo:before-fetch-request\",\n addKpopToRequestHeaders,\n );\n\n if (this.debug) {\n document.addEventListener(\"focusin\", debugFocusIn);\n document.addEventListener(\"focusout\", debugFocusOut);\n }\n\n return this;\n }\n\n stop() {\n window.removeEventListener(\n \"turbo:before-fetch-request\",\n addKpopToRequestHeaders,\n );\n document.removeEventListener(\"focusin\", debugFocusIn);\n document.removeEventListener(\"focusout\", debugFocusOut);\n\n this.visitAdapter.stop();\n this.streamActions.stop();\n this.linkObserver.stop();\n }\n\n isModalLink(link, location) {\n return this.isModalLocation(location);\n }\n\n isModalLocation(location) {\n const properties = this.ruleset.properties(location);\n return properties.context === \"modal\";\n }\n\n get debug() {\n return Boolean(this.config.debug);\n }\n}\n\nconst debugFocusIn = (e) => debug(\"Application\")(\"focus\", e.target);\nconst debugFocusOut = (e) => debug(\"Application\")(\"blur\", e.target);\n\nconst addKpopToRequestHeaders = (e) => {\n const headers = e.detail.fetchOptions.headers;\n\n if (headers[\"Accept\"]?.includes(\"text/vnd.turbo-stream.html\")) {\n headers[\"Kpop-Available\"] = \"true\";\n }\n};\n"],"names":["enabled","debug","receiver","console","bind","noop","Object","defineProperty","get","set","Modal","constructor","frame","dialog","src","this","element","uri","URL","dataset","window","location","origin","connect","addEventListener","cancel","close","scrim","disconnect","removeEventListener","pathname","search","hash","e","preventDefault","dismiss","animate","reason","clear","target","tagName","open","animation","showModal","removeAttribute","beforeVisit","detail","url","name","el","trigger","duration","defaultValue","value","getComputedStyle","getPropertyValue","num","parseFloat","endsWith","animationDuration","Promise","resolve","resolver","once","clearTimeout","timeout","toggleAttribute","setTimeout","ContentModal","FrameModal","load","visit","hasAttribute","Kpop__FrameController","Controller","static","Boolean","kpop","controller","TurboFrameController","delegate","prototype","_linkClickIntercepted","linkClickIntercepted","id","getAttribute","document","getElementById","Turbo","FrameElement","call","installNavigationInterception","querySelector","then","modal","openValueChanged","isOpen","dismissing","opening","innerHTML","openValue","beforeFrameRender","event","newFrame","baseURI","resume","beforeStreamRender","render","async","stream","toString","frameLoad","firstElementChild","beforeFetchRequest","focusElement","activeElement","body","lastFetchFocusRef","WeakRef","container","previousFocusRef","deref","sourceURL","focus","session","view","forceReloaded","error","isConnected","warn","nextFrame","callback","requestAnimationFrame","LinkObserver","started","eventTarget","start","readyState","enable","stop","addKpopLink","capture","passive","removeKpopLink","matches","isPrefetchable","link","getLocationForLink","isModalLink","turboFrame","unfetchableLink","linkToTheSamePage","linkOptsOut","nonSafeLink","includes","protocol","href","startsWith","turboMethod","toLowerCase","isUJS","Ruleset","rules","forEach","rule","compileRule","properties","reduce","c","f","patterns","pattern","push","re","accumulator","test","locationMatcher","RegExp","StreamModal","action","append","templateContent","StreamActions","kpop_open","openStreamModal","targetElements","VisitAdapter","adapter","visitAdapter","registerAdapter","assign","create","visitProposedToLocation","options","shouldVisitInFrame","response","isCurrentPage","isModalLocation","controllers","identifier","controllerConstructor","FrameController","Application","configure","config","instance","ruleset","linkObserver","streamActions","addKpopToRequestHeaders","debugFocusIn","debugFocusOut","context","headers","fetchOptions"],"mappings":"8FAAA,IAAIA,GAAU,EAEd,MAAMC,EAAQ,SAAUC,GACtB,OAAIF,EACKG,QAAQF,MAAMG,KAAKD,QA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AqB,QAASgC,EAAEM,QACtD4K,EAAiBlL,GAAMhC,EAAM,cAANA,CAAqB,OAAQgC,EAAEM,QAEtD0K,EAA2BhL,IAC/B,MAAMoL,EAAUpL,EAAEa,OAAOwK,aAAaD,QAElCA,EAAgB,QAAG3D,SAAS,gCAC9B2D,EAAQ,kBAAoB"}
1
+ {"version":3,"file":"kpop.min.js","sources":["../../../javascript/kpop/utils/debug.js","../../../javascript/kpop/modals/modal.js","../../../javascript/kpop/modals/content_modal.js","../../../javascript/kpop/modals/frame_modal.js","../../../javascript/kpop/controllers/frame_controller.js","../../../javascript/kpop/utils/link_observer.js","../../../javascript/kpop/utils/ruleset.js","../../../javascript/kpop/modals/stream_modal.js","../../../javascript/kpop/utils/stream_actions.js","../../../javascript/kpop/utils/visit_adapter.js","../../../javascript/kpop/application.js"],"sourcesContent":["let enabled = false;\n\nconst debug = function (receiver) {\n if (enabled) {\n return console.debug.bind(console, \"[%s] %s\", receiver);\n } else {\n return noop;\n }\n};\n\nconst noop = () => {};\n\nObject.defineProperty(debug, \"enabled\", {\n get: function () {\n return enabled;\n },\n set: function (debug) {\n enabled = debug;\n },\n});\n\nexport default debug;\n","import debug from \"../utils/debug\";\n\nexport class Modal {\n constructor(frame, dialog, src = null) {\n this.frame = frame;\n this.element = dialog;\n this.uri = new URL(src || dialog.dataset.src, window.location.origin);\n }\n\n connect() {\n this.element.addEventListener(\"cancel\", this.cancel);\n this.element.addEventListener(\"close\", this.close);\n this.element.addEventListener(\"mousedown\", this.scrim);\n }\n\n disconnect() {\n this.element.removeEventListener(\"cancel\", this.cancel);\n this.element.removeEventListener(\"close\", this.close);\n this.element.removeEventListener(\"mousedown\", this.scrim);\n }\n\n get src() {\n return this.uri.pathname + this.uri.search + this.uri.hash;\n }\n\n cancel = (e) => {\n this.debug(\"event:cancel\", e);\n\n e.preventDefault();\n\n this.frame.dismiss({ animate: true, reason: \"dialog:cancel\" });\n };\n\n close = (e) => {\n this.debug(\"event:close\", e);\n\n this.frame.clear({ reason: \"dialog:close\" });\n };\n\n scrim = (e) => {\n if (e.target.tagName === \"DIALOG\") {\n this.debug(\"event:scrim\", e);\n\n this.frame.dismiss({ animate: true, reason: \"dialog:scrim\" });\n }\n };\n\n async open({ animate = true } = {}) {\n this.debug(\"open-start\", animate);\n\n await animation(this.element, animate, () => this.element.showModal());\n\n this.debug(\"open-end\");\n }\n\n /**\n * Modals are closed by animating out the modal then removing the modal\n * element from the wrapping frame.\n *\n * @returns {Promise<void>}\n */\n async dismiss({ animate = true } = {}) {\n this.debug(\"dismiss-start\", animate);\n\n await animation(this.element, animate, () =>\n this.element.removeAttribute(\"open\"),\n );\n\n this.debug(\"dismiss-end\");\n\n this.element.close();\n }\n\n static get debug() {\n return debug(this.name);\n }\n\n get debug() {\n return debug(this.constructor.name);\n }\n}\n\nfunction animation(el, animate, trigger) {\n if (!animate) return trigger();\n\n const duration = animationDuration(el);\n\n return new Promise((resolve) => {\n const resolver = () => {\n el.removeEventListener(\"animationend\", resolver, { once: true });\n clearTimeout(timeout);\n el.toggleAttribute(\"animate\", false);\n resolve();\n };\n\n el.addEventListener(\"animationend\", resolver, { once: true });\n const timeout = setTimeout(resolver, duration);\n\n el.toggleAttribute(\"animate\", animate);\n trigger();\n });\n}\n\nfunction animationDuration(el, defaultValue = \"0.2s\") {\n const value =\n getComputedStyle(el).getPropertyValue(\"--animation-duration\") ||\n defaultValue;\n const num = parseFloat(value);\n if (value.endsWith(\"ms\")) return num;\n return num * 1000;\n}\n","import { Modal } from \"./modal\";\n\nexport class ContentModal extends Modal {\n static connect(frame, dialog) {\n frame.open(new ContentModal(frame, dialog), { animate: false });\n }\n}\n","import { Modal } from \"./modal\";\n\nexport class FrameModal extends Modal {\n /**\n * When the FrameController detects a frame element on connect, it runs this\n * method to sanity check the frame src and restore the modal state.\n *\n * @param {Kpop__FrameController} frame\n * @param {HTMLDialogElement} dialog\n * @param {String} src\n */\n static connect(frame, dialog, src) {\n // restoration visit\n this.debug(\"restore\", src);\n return frame.open(new FrameModal(frame, dialog, src), { animate: false });\n }\n\n /**\n * When the FrameController detects a frame load event, it runs this\n * method to open the modal.\n *\n * @param {Kpop__FrameController} frame\n * @param {HTMLDialogElement} dialog\n * @param {String} src\n */\n static load(frame, dialog, src) {\n this.debug(\"load\", src);\n return frame.open(new FrameModal(frame, dialog, src), { animate: true });\n }\n\n /**\n * When the FrameController reloads the open modal's location, it runs this\n * method to open the new content in place, without animating.\n *\n * @param {Kpop__FrameController} frame\n * @param {HTMLDialogElement} dialog\n * @param {String} src\n */\n static reload(frame, dialog, src) {\n this.debug(\"reload\", src);\n return frame.open(new FrameModal(frame, dialog, src), { animate: false });\n }\n}\n","import { Controller } from \"@hotwired/stimulus\";\n\nimport { ContentModal } from \"../modals/content_modal\";\nimport { FrameModal } from \"../modals/frame_modal\";\n\nimport debug from \"../utils/debug\";\n\nexport default class Kpop__FrameController extends Controller {\n static values = {\n open: Boolean,\n };\n\n connect() {\n this.debug(\"connect\", this.element.src);\n\n this.element.kpop = this;\n\n const dialog = this.element.querySelector(\"dialog\");\n\n if (this.element.src && dialog) {\n this.debug(\"new frame modal\", this.element.src);\n FrameModal.connect(this, dialog, this.element.src).then(() => {});\n } else if (dialog) {\n this.debug(\"new content modal\", dialog);\n ContentModal.connect(this, dialog);\n } else {\n this.debug(\"no modal\");\n this.clear();\n }\n }\n\n disconnect() {\n this.debug(\"disconnect\", this.element.src);\n\n delete this.element.kpop;\n delete this.modal;\n }\n\n openValueChanged(open) {\n this.debug(\"open-changed\", open);\n }\n\n /**\n * Animate an attached modal into the foreground. Returns a promise that\n * resolves when the animation is complete.\n *\n * @param modal\n * @param animate\n * @returns {Promise<Boolean>}\n */\n async open(modal, { animate = true } = {}) {\n if (this.isOpen) {\n this.debug(\"skip open as already open\");\n this.modal ||= modal;\n return false;\n }\n\n await this.dismissing;\n\n return (this.opening ||= Promise.resolve().then(() => {\n modal.connect();\n return this.#open(modal, { animate });\n }));\n }\n\n /**\n * Cause a modal to hide. Returns a promise that will resolve when the\n * animation (if requested) is finished.\n *\n * If the modal is already animating out, returns the existing promise instead.\n *\n * @param {Boolean} animate\n * @param {String} reason\n * @returns {Promise}\n */\n async dismiss({ animate = true, reason = \"\" } = {}) {\n this.debug(\"event:dismiss\", reason);\n\n if (!this.isOpen) {\n this.debug(\"skip dismiss as already closed\");\n return false;\n }\n\n await this.opening;\n\n return (this.dismissing ||= this.#dismiss({ animate, reason }));\n }\n\n /**\n * Clean up after a modal is finished dismissing.\n */\n clear({ reason = \"\" } = {}) {\n this.debug(\"event:clear\", reason);\n\n // clear the src from the frame (if any)\n if (this.modal?.src === this.element.src) this.element.src = \"\";\n this.element.innerHTML = \"\";\n\n // mark the modal as hidden\n this.openValue = false;\n\n // unset modal\n if (this.modal) this.modal.disconnect();\n delete this.modal;\n delete this.dismissing;\n }\n\n // EVENTS\n\n /**\n * Incoming frame render, dismiss the current modal (if any) first.\n *\n * We're starting the actual visit\n *\n * @param event turbo:before-render\n */\n beforeFrameRender(event) {\n this.debug(\"before-frame-render\", event.detail.newFrame.baseURI);\n\n if (event.detail.newFrame.id !== this.element.id) return;\n\n if (this.#isReload()) return this.#reload(event);\n\n event.preventDefault();\n\n this.dismiss({ animate: true, reason: \"before-frame-render\" }).then(() => {\n this.debug(\"resume-frame-render\", event.detail.newFrame.baseURI);\n event.detail.resume();\n });\n }\n\n beforeStreamRender(event) {\n this.debug(\"before-stream-render\", event.detail);\n\n const resume = event.detail.render;\n\n // Defer rendering until dismiss is complete.\n // Dismiss may change history so we need to wait for it to complete to avoid\n // losing DOM changes on restoration visits.\n event.detail.render = async (stream) => {\n await this.dismissing;\n\n this.debug(\"stream-render\", stream);\n\n await resume(stream);\n };\n }\n\n frameLoad(e) {\n this.debug(\"frame-load\");\n\n FrameModal.load(this, e.target.firstElementChild, e.target.src).then(\n () => {},\n );\n }\n\n /**\n * Outgoing fetch request. Capture the initiator so we can return focus if it causes a modal to show.\n */\n beforeFetchRequest() {\n const focusElement = document.activeElement;\n\n if (focusElement === document.body) {\n delete this.lastFetchFocusRef;\n } else {\n this.lastFetchFocusRef = new WeakRef(focusElement);\n }\n }\n\n get isOpen() {\n return this.openValue && !this.dismissing;\n }\n\n /**\n * The frame is loading the location of the open modal again, e.g. from\n * `Turbo.visit` or a link in the modal to its own location.\n */\n #isReload() {\n if (!this.isOpen || !this.modal) return false;\n\n const url = new URL(this.element.src, document.baseURI);\n const { uri } = this.modal;\n return url.pathname + url.search === uri.pathname + uri.search;\n }\n\n /**\n * Like a Turbo page reload, swap the content in place: replace the modal\n * as the frame renders, without animating out and in. Turbo waits for\n * repaints before frame-load, so opening the new dialog any later would\n * show a frame without a modal.\n *\n * @param event turbo:before-frame-render\n */\n #reload(event) {\n this.debug(\"reload\", this.element.src);\n\n const render = event.detail.render;\n event.detail.render = (currentElement, newElement) => {\n render(currentElement, newElement);\n\n // Keep the focus target from when the modal first opened\n const previousFocusRef = this.previousFocusRef;\n const dialog = this.element.querySelector(\"dialog\");\n\n this.modal.disconnect();\n delete this.modal;\n this.openValue = false;\n\n FrameModal.reload(this, dialog, this.element.src).then(() => {\n this.previousFocusRef = previousFocusRef;\n });\n };\n }\n\n async #open(modal, { animate = true } = {}) {\n this.debug(\"open-start\", { animate });\n\n this.previousFocusRef =\n document.activeElement === document.body\n ? this.lastFetchFocusRef\n : new WeakRef(document.activeElement);\n this.debug(\"capture focus\", this.previousFocusRef?.deref());\n\n this.modal = modal;\n this.openValue = true;\n\n // Set turbo-frame[src] without causing a load event\n this.element.delegate.sourceURL = this.modal.src;\n\n await modal.open({ animate });\n\n delete this.opening;\n\n this.debug(\"open-end\");\n\n autofocus(this.modal?.element)?.focus();\n\n // Detect https://github.com/hotwired/turbo-rails/issues/580\n if (Turbo.session.view.forceReloaded) {\n console.error(\"Turbo-Frame response is incompatible with current page\");\n }\n\n return true;\n }\n\n async #dismiss({ animate = true, reason = \"\" } = {}) {\n this.debug(\"dismiss-start\", { animate, reason });\n\n // if this element is detached then we've experienced a turbo navigation\n if (!this.element.isConnected) {\n this.debug(\"skip dismiss, element detached\");\n return;\n }\n\n if (!this.modal) {\n console.warn(\"modal missing on dismiss\");\n }\n\n await this.modal?.dismiss({ animate });\n\n this.clear();\n\n this.previousFocusRef?.deref()?.focus();\n this.debug(\"restore focus\", this.previousFocusRef?.deref());\n delete this.previousFocusRef;\n\n this.debug(\"dismiss-end\");\n }\n\n async #nextFrame(callback) {\n return new Promise(window.requestAnimationFrame).then(callback);\n }\n\n get debug() {\n return debug(\"FrameController\");\n }\n}\n\nfunction autofocus(container) {\n if (!container) return null;\n\n return (\n container.querySelector(\"[autofocus]\") ??\n container.querySelector(\"button:not([disabled])\")\n );\n}\n","/**\n * Based on Turbo's LinkObserver, checks links on mouse-over and focus to see\n * whether they should open in modals. If they should, then sets the\n * data-turbo-frame attribute so it will be prefetched and opened in the context\n * of the kpop turbo frame.\n */\nexport default class LinkObserver {\n started = false;\n\n constructor(delegate, eventTarget) {\n this.delegate = delegate;\n this.eventTarget = eventTarget;\n }\n\n start() {\n if (this.started) return;\n if (this.eventTarget.readyState === \"loading\") {\n this.eventTarget.addEventListener(\"DOMContentLoaded\", this.#enable, {\n once: true,\n });\n } else {\n this.#enable();\n }\n }\n\n stop() {\n if (!this.started) return;\n this.eventTarget.removeEventListener(\"mouseenter\", this.#addKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.removeEventListener(\n \"turbo:before-prefetch\",\n this.#addKpopLink,\n {\n capture: true,\n passive: true,\n },\n );\n this.eventTarget.removeEventListener(\"focusin\", this.#addKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.removeEventListener(\"mouseleave\", this.#removeKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.removeEventListener(\"focusout\", this.#removeKpopLink, {\n capture: true,\n passive: true,\n });\n this.started = false;\n }\n\n #enable = () => {\n if (this.started) return;\n this.started = true;\n this.eventTarget.addEventListener(\"mouseenter\", this.#addKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.addEventListener(\"focusin\", this.#addKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.addEventListener(\n \"turbo:before-prefetch\",\n this.#addKpopLink,\n {\n capture: true,\n passive: true,\n },\n );\n this.eventTarget.addEventListener(\"mouseleave\", this.#removeKpopLink, {\n capture: true,\n passive: true,\n });\n this.eventTarget.addEventListener(\"focusout\", this.#removeKpopLink, {\n capture: true,\n passive: true,\n });\n };\n\n #addKpopLink = (event) => {\n const target = event.target;\n const isLink =\n target.matches &&\n target.matches(\n \"a[href]:not([target^=_]):not([download]):not([data-turbo-frame]\",\n );\n if (isLink && this.#isPrefetchable(target)) {\n const link = target;\n const location = getLocationForLink(link);\n if (this.delegate.isModalLink(link, location)) {\n link.dataset.turboFrame = \"kpop\";\n }\n }\n };\n\n #removeKpopLink = (event) => {\n const target = event.target;\n const isLink =\n target.matches && target.matches(\"a[href][data-turbo-frame='kpop']\");\n if (isLink) {\n delete target.dataset.turboFrame;\n }\n };\n\n #isPrefetchable(link) {\n const href = link.getAttribute(\"href\");\n if (!href) return false;\n if (unfetchableLink(link)) return false;\n if (linkToTheSamePage(link)) return false;\n if (linkOptsOut(link)) return false;\n if (nonSafeLink(link)) return false;\n return true;\n }\n}\n\nfunction getLocationForLink(link) {\n return new URL(link.getAttribute(\"href\").toString(), document.baseURI);\n}\n\nconst unfetchableLink = (link) =>\n link.origin !== document.location.origin ||\n ![\"http:\", \"https:\"].includes(link.protocol) ||\n link.hasAttribute(\"target\");\n\nconst linkToTheSamePage = (link) =>\n link.pathname + link.search ===\n document.location.pathname + document.location.search ||\n link.href.startsWith(\"#\");\n\nconst linkOptsOut = (link) => {\n return link.getAttribute(\"data-turbo\") === \"false\";\n};\n\nconst nonSafeLink = (link) => {\n const turboMethod = link.getAttribute(\"data-turbo-method\");\n if (turboMethod && turboMethod.toLowerCase() !== \"get\") return true;\n if (isUJS(link)) return true;\n if (link.hasAttribute(\"data-turbo-confirm\")) return true;\n if (link.hasAttribute(\"data-turbo-stream\")) return true;\n return false;\n};\n\nconst isUJS = (link) =>\n link.hasAttribute(\"data-remote\") ||\n link.hasAttribute(\"data-behavior\") ||\n link.hasAttribute(\"data-confirm\") ||\n link.hasAttribute(\"data-method\");\n","/**\n * Similar to Hotwire's PathConfiguration.json, this class compiles a list of\n * rules to check link hrefs against so that we can identify links that\n * should open in a KPOP modal.\n *\n * Unlike Hotwire Native, we can't intercept 303s in the browser before they\n * load. Browser sandbox prevents us from inspecting the location of redirect\n * requests so we can only intercept links that match modals directly.\n *\n * For posts and redirects, we need server support (flash modals, streams).\n */\nexport default class Ruleset {\n constructor(rules = []) {\n this.rules = [];\n\n rules.forEach((rule) => {\n this.#compileRule(rule);\n });\n }\n\n /**\n * Returns properties for the given URL\n *\n * @param {URL} location\n * @returns {} properties\n */\n properties(location) {\n return this.rules.reduce((c, f) => f(location, c), {});\n }\n\n #compileRule({ patterns, properties }) {\n patterns.forEach((pattern) => {\n this.rules.push(locationMatcher(new RegExp(pattern), properties));\n });\n }\n}\n\nfunction locationMatcher(re, properties) {\n return (location, accumulator) =>\n re.test(location.pathname)\n ? { ...accumulator, ...properties }\n : accumulator;\n}\n","import { Modal } from \"./modal\";\n\nexport class StreamModal extends Modal {\n /**\n * When a turbo-stream[action=kpop_open] element is rendered, it runs this\n * method to load the modal template as a StreamModal.\n *\n * @param {Kpop__FrameController} frame\n * @param {Turbo.StreamElement} action\n */\n static async open(frame, action) {\n const animate = !frame.isOpen;\n\n await frame.dismiss({ animate, reason: \"turbo-stream.kpop_open\" });\n\n frame.element.append(action.templateContent);\n\n const dialog = frame.element.querySelector(\"dialog\");\n const src = dialog.dataset.src;\n\n await frame.open(new StreamModal(frame, dialog, src), { animate });\n }\n}\n","import { Turbo } from \"@hotwired/turbo-rails\";\n\nimport { StreamModal } from \"../modals/stream_modal\";\n\nexport default class StreamActions {\n start() {\n Turbo.StreamActions.kpop_open = openStreamModal;\n }\n\n stop() {\n delete Turbo.StreamActions.kpop_open;\n }\n}\n\nfunction openStreamModal() {\n const frame = this.targetElements[0]?.kpop;\n\n if (frame) {\n StreamModal.open(frame, this).then(() => {});\n }\n}\n","import { Turbo } from \"@hotwired/turbo-rails\";\n\n/**\n * Decides how each Turbo visit shows, the way Hotwire Native routes visits\n * with its path configuration. Visits to locations that match a modal rule\n * open in the kpop frame, and page visits close any open modal first.\n * Callers use `Turbo.visit` and the ruleset decides how the location shows.\n *\n * Turbo dispatches `turbo:before-visit` before the adapter knows where the\n * visit goes, so kpop handles visits here rather than in that event.\n *\n * Wraps Turbo's browser adapter, which Turbo does not export, so every other\n * adapter call reaches the browser adapter unchanged.\n */\nexport default class VisitAdapter {\n started = false;\n\n constructor(delegate) {\n this.delegate = delegate;\n }\n\n start() {\n if (this.started) return;\n\n const adapter = (this.adapter = Turbo.session.adapter);\n const visitAdapter = this;\n\n Turbo.registerAdapter(\n Object.assign(Object.create(adapter), {\n visitProposedToLocation(location, options) {\n visitAdapter.#visitProposedToLocation(location, options);\n },\n }),\n );\n\n this.started = true;\n }\n\n stop() {\n if (!this.started) return;\n\n Turbo.registerAdapter(this.adapter);\n delete this.adapter;\n\n this.started = false;\n }\n\n #visitProposedToLocation(location, options) {\n const frame = document.getElementById(\"kpop\");\n const kpop = frame?.kpop;\n\n // `resume_or_redirect_back_or_to` redirects here to close the modal and\n // stay on the current page, so don't visit it.\n if (kpop && location.pathname === \"/resume_historical_location\") {\n kpop.dismiss({ reason: \"resume-historical-location\" });\n } else if (this.#shouldVisitInFrame(location, options)) {\n Turbo.visit(location, { frame: \"kpop\" });\n } else {\n // Close any open modal first so it doesn't appear in the history stack.\n if (kpop?.isOpen) kpop.clear({ reason: \"page-visit\" });\n\n // A modal that is still loading isn't open yet. Turbo cancels its request\n // when the page changes, but caches its src with the page snapshot and\n // loads it again on restore, so clear the src first.\n if (frame?.src) frame.src = \"\";\n\n this.adapter.visitProposedToLocation(location, options);\n }\n }\n\n /**\n * Like Hotwire Native, the rules decide how a location shows, whatever the\n * link that proposed it says, so `data-turbo-frame=\"_top\"` does not opt out.\n * Use a rule override or `data-turbo=\"false\"` instead. Turbo submits\n * `data-turbo-stream` links as forms, so they never reach the adapter.\n */\n #shouldVisitInFrame(location, options) {\n // A response means Turbo has already fetched the page, e.g. after a form\n // submission or a redirect, so let it render.\n if (options?.response) return false;\n\n // Refreshes and visits to the current page should not open a modal.\n if (isCurrentPage(location)) return false;\n\n // Without a frame, Turbo.visit would propose this visit again.\n if (!(document.getElementById(\"kpop\") instanceof Turbo.FrameElement)) {\n return false;\n }\n\n return this.delegate.isModalLocation(location);\n }\n}\n\nfunction isCurrentPage(location) {\n return (\n location.pathname + location.search ===\n document.location.pathname + document.location.search\n );\n}\n","import FrameController from \"../kpop/controllers/frame_controller\";\n\nimport debug from \"./utils/debug\";\nimport LinkObserver from \"./utils/link_observer\";\nimport Ruleset from \"./utils/ruleset\";\nimport StreamActions from \"./utils/stream_actions\";\nimport VisitAdapter from \"./utils/visit_adapter\";\n\nexport const controllers = [\n { identifier: \"kpop--frame\", controllerConstructor: FrameController },\n];\n\nexport default class Application {\n static configure(config = {}) {\n this.instance ||= new this(config);\n debug.enabled = this.instance.debug;\n return this.instance;\n }\n\n constructor({ rules = [], debug = false } = {}) {\n this.config = { rules, debug };\n this.ruleset = new Ruleset(rules);\n this.linkObserver = new LinkObserver(this, document);\n this.streamActions = new StreamActions();\n this.visitAdapter = new VisitAdapter(this);\n }\n\n start() {\n this.streamActions.start();\n this.linkObserver.start();\n this.visitAdapter.start();\n\n window.addEventListener(\n \"turbo:before-fetch-request\",\n addKpopToRequestHeaders,\n );\n\n if (this.debug) {\n document.addEventListener(\"focusin\", debugFocusIn);\n document.addEventListener(\"focusout\", debugFocusOut);\n }\n\n return this;\n }\n\n stop() {\n window.removeEventListener(\n \"turbo:before-fetch-request\",\n addKpopToRequestHeaders,\n );\n document.removeEventListener(\"focusin\", debugFocusIn);\n document.removeEventListener(\"focusout\", debugFocusOut);\n\n this.visitAdapter.stop();\n this.streamActions.stop();\n this.linkObserver.stop();\n }\n\n isModalLink(link, location) {\n return this.isModalLocation(location);\n }\n\n isModalLocation(location) {\n const properties = this.ruleset.properties(location);\n return properties.context === \"modal\";\n }\n\n get debug() {\n return Boolean(this.config.debug);\n }\n}\n\nconst debugFocusIn = (e) => debug(\"Application\")(\"focus\", e.target);\nconst debugFocusOut = (e) => debug(\"Application\")(\"blur\", e.target);\n\nconst addKpopToRequestHeaders = (e) => {\n const headers = e.detail.fetchOptions.headers;\n\n if (headers[\"Accept\"]?.includes(\"text/vnd.turbo-stream.html\")) {\n headers[\"Kpop-Available\"] = \"true\";\n }\n};\n"],"names":["enabled","debug","receiver","console","bind","noop","Object","defineProperty","get","set","Modal","constructor","frame","dialog","src","this","element","uri","URL","dataset","window","location","origin","connect","addEventListener","cancel","close","scrim","disconnect","removeEventListener","pathname","search","hash","e","preventDefault","dismiss","animate","reason","clear","target","tagName","open","animation","showModal","removeAttribute","name","el","trigger","duration","defaultValue","value","getComputedStyle","getPropertyValue","num","parseFloat","endsWith","animationDuration","Promise","resolve","resolver","once","clearTimeout","timeout","toggleAttribute","setTimeout","ContentModal","FrameModal","load","reload","Kpop__FrameController","Controller","static","Boolean","kpop","querySelector","then","modal","openValueChanged","isOpen","dismissing","opening","innerHTML","openValue","beforeFrameRender","event","detail","newFrame","baseURI","id","isReload","resume","beforeStreamRender","render","async","stream","frameLoad","firstElementChild","beforeFetchRequest","focusElement","document","activeElement","body","lastFetchFocusRef","WeakRef","url","currentElement","newElement","previousFocusRef","container","deref","delegate","sourceURL","focus","Turbo","session","view","forceReloaded","error","isConnected","warn","nextFrame","callback","requestAnimationFrame","LinkObserver","started","eventTarget","start","readyState","enable","stop","addKpopLink","capture","passive","removeKpopLink","matches","isPrefetchable","link","getAttribute","toString","getLocationForLink","isModalLink","turboFrame","unfetchableLink","linkToTheSamePage","linkOptsOut","nonSafeLink","includes","protocol","hasAttribute","href","startsWith","turboMethod","toLowerCase","isUJS","Ruleset","rules","forEach","rule","compileRule","properties","reduce","c","f","patterns","pattern","push","re","accumulator","test","locationMatcher","RegExp","StreamModal","action","append","templateContent","StreamActions","kpop_open","openStreamModal","targetElements","VisitAdapter","adapter","visitAdapter","registerAdapter","assign","create","visitProposedToLocation","options","getElementById","shouldVisitInFrame","visit","response","isCurrentPage","FrameElement","isModalLocation","controllers","identifier","controllerConstructor","FrameController","Application","configure","config","instance","ruleset","linkObserver","streamActions","addKpopToRequestHeaders","debugFocusIn","debugFocusOut","context","headers","fetchOptions"],"mappings":"8FAAA,IAAIA,GAAU,EAEd,MAAMC,EAAQ,SAAUC,GACtB,OAAIF,EACKG,QAAQF,MAAMG,KAAKD,QAAS,UAAWD,GAEvCG,CAEX,EAEMA,EAAO,OAEbC,OAAOC,eAAeN,EAAO,UAAW,CACtCO,IAAK,WACH,OAAOR,CACT,EACAS,IAAK,SAAUR,GACbD,EAAUC,CACZ,IChBK,MAAMS,EACX,WAAAC,CAAYC,EAAOC,EAAQC,EAAM,MAC/BC,KAAKH,MAAQA,EACbG,KAAKC,QAAUH,EACfE,KAAKE,IAAM,IAAIC,IAAIJ,GAAOD,EAAOM,QAAQL,IAAKM,OAAOC,SAASC,OAChE,CAEA,OAAAC,GACER,KAAKC,QAAQQ,iBAAiB,SAAUT,KAAKU,QAC7CV,KAAKC,QAAQQ,iBAAiB,QAAST,KAAKW,OAC5CX,KAAKC,QAAQQ,iBAAiB,YAAaT,KAAKY,MAClD,CAEA,UAAAC,GACEb,KAAKC,QAAQa,oBAAoB,SAAUd,KAAKU,QAChDV,KAAKC,QAAQa,oBAAoB,QAASd,KAAKW,OAC/CX,KAAKC,QAAQa,oBAAoB,YAAad,KAAKY,MACrD,CAEA,OAAIb,GACF,OAAOC,KAAKE,IAAIa,SAAWf,KAAKE,IAAIc,OAAShB,KAAKE,IAAIe,IACxD,CAEAP,OAAUQ,IACRlB,KAAKd,MAAM,eAAgBgC,GAE3BA,EAAEC,iBAEFnB,KAAKH,MAAMuB,QAAQ,CAAEC,SAAS,EAAMC,OAAQ,mBAG9CX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AClBlH,KAAK6L,cAAc3E,OACnBlH,KAAK4L,aAAa1E,MACpB,CAEA,WAAAW,CAAYJ,EAAMnH,GAChB,OAAON,KAAKkL,gBAAgB5K,EAC9B,CAEA,eAAA4K,CAAgB5K,GAEd,MAA8B,UADXN,KAAK2L,QAAQ3C,WAAW1I,GACzB2L,OACpB,CAEA,SAAI/M,GACF,OAAOuE,QAAQzD,KAAKyL,OAAOvM,MAC7B,EAGF,MAAM6M,EAAgB7K,GAAMhC,EAAM,cAANA,CAAqB,QAASgC,EAAEM,QACtDwK,EAAiB9K,GAAMhC,EAAM,cAANA,CAAqB,OAAQgC,EAAEM,QAEtDsK,EAA2B5K,IAC/B,MAAMgL,EAAUhL,EAAEoD,OAAO6H,aAAaD,QAElCA,EAAgB,QAAG/D,SAAS,gCAC9B+D,EAAQ,kBAAoB"}
@@ -11,7 +11,6 @@ module Kpop
11
11
  turbo:before-fetch-request@window->kpop--frame#beforeFetchRequest
12
12
  turbo:before-frame-render->kpop--frame#beforeFrameRender
13
13
  turbo:before-stream-render@window->kpop--frame#beforeStreamRender
14
- turbo:before-visit@window->kpop--frame#beforeVisit
15
14
  turbo:frame-load->kpop--frame#frameLoad
16
15
  ].freeze
17
16
 
@@ -15,9 +15,6 @@ export default class Kpop__FrameController extends Controller {
15
15
 
16
16
  this.element.kpop = this;
17
17
 
18
- // allow our code to intercept frame navigation requests before dom changes
19
- installNavigationInterception(this);
20
-
21
18
  const dialog = this.element.querySelector("dialog");
22
19
 
23
20
  if (this.element.src && dialog) {
@@ -122,6 +119,8 @@ export default class Kpop__FrameController extends Controller {
122
119
 
123
120
  if (event.detail.newFrame.id !== this.element.id) return;
124
121
 
122
+ if (this.#isReload()) return this.#reload(event);
123
+
125
124
  event.preventDefault();
126
125
 
127
126
  this.dismiss({ animate: true, reason: "before-frame-render" }).then(() => {
@@ -147,24 +146,6 @@ export default class Kpop__FrameController extends Controller {
147
146
  };
148
147
  }
149
148
 
150
- beforeVisit(e) {
151
- this.debug("before-visit", e.detail.url);
152
-
153
- // ignore visits to the current frame, these fire when the frame navigates
154
- if (e.detail.url === this.element.src) return;
155
-
156
- const url = new URL(e.detail.url.toString(), document.baseURI);
157
- if (url.pathname === "/resume_historical_location") {
158
- e.preventDefault();
159
- return this.dismiss();
160
- }
161
-
162
- // ignore unless we're open
163
- if (!this.isOpen) return;
164
-
165
- this.modal.beforeVisit(this, e);
166
- }
167
-
168
149
  frameLoad(e) {
169
150
  this.debug("frame-load");
170
151
 
@@ -190,6 +171,47 @@ export default class Kpop__FrameController extends Controller {
190
171
  return this.openValue && !this.dismissing;
191
172
  }
192
173
 
174
+ /**
175
+ * The frame is loading the location of the open modal again, e.g. from
176
+ * `Turbo.visit` or a link in the modal to its own location.
177
+ */
178
+ #isReload() {
179
+ if (!this.isOpen || !this.modal) return false;
180
+
181
+ const url = new URL(this.element.src, document.baseURI);
182
+ const { uri } = this.modal;
183
+ return url.pathname + url.search === uri.pathname + uri.search;
184
+ }
185
+
186
+ /**
187
+ * Like a Turbo page reload, swap the content in place: replace the modal
188
+ * as the frame renders, without animating out and in. Turbo waits for
189
+ * repaints before frame-load, so opening the new dialog any later would
190
+ * show a frame without a modal.
191
+ *
192
+ * @param event turbo:before-frame-render
193
+ */
194
+ #reload(event) {
195
+ this.debug("reload", this.element.src);
196
+
197
+ const render = event.detail.render;
198
+ event.detail.render = (currentElement, newElement) => {
199
+ render(currentElement, newElement);
200
+
201
+ // Keep the focus target from when the modal first opened
202
+ const previousFocusRef = this.previousFocusRef;
203
+ const dialog = this.element.querySelector("dialog");
204
+
205
+ this.modal.disconnect();
206
+ delete this.modal;
207
+ this.openValue = false;
208
+
209
+ FrameModal.reload(this, dialog, this.element.src).then(() => {
210
+ this.previousFocusRef = previousFocusRef;
211
+ });
212
+ };
213
+ }
214
+
193
215
  async #open(modal, { animate = true } = {}) {
194
216
  this.debug("open-start", { animate });
195
217
 
@@ -254,50 +276,6 @@ export default class Kpop__FrameController extends Controller {
254
276
  }
255
277
  }
256
278
 
257
- /**
258
- * Monkey patch for Turbo#FrameController.
259
- *
260
- * Intercept calls to linkClickIntercepted(element, location) and ensures
261
- * that src is cleared if the frame is busy so that we don't restore an
262
- * in-progress src on restoration visits.
263
- *
264
- * See Turbo issue: https://github.com/hotwired/turbo/issues/1055
265
- *
266
- * @param controller FrameController
267
- */
268
- function installNavigationInterception(controller) {
269
- const TurboFrameController =
270
- controller.element.delegate.constructor.prototype;
271
-
272
- if (TurboFrameController._linkClickIntercepted) return;
273
-
274
- TurboFrameController._linkClickIntercepted =
275
- TurboFrameController.linkClickIntercepted;
276
- TurboFrameController.linkClickIntercepted = function (element, location) {
277
- // #findFrameElement
278
- const id =
279
- element?.getAttribute("data-turbo-frame") ||
280
- this.element.getAttribute("target");
281
- let frame = document.getElementById(id);
282
- if (!(frame instanceof Turbo.FrameElement)) {
283
- frame = this.element;
284
- }
285
-
286
- if (frame.kpop) {
287
- frame.kpop.debug("navigate-frame %s => %s", frame.src, location);
288
- FrameModal.visit(location, frame.kpop, frame, () => {
289
- TurboFrameController._linkClickIntercepted.call(
290
- this,
291
- element,
292
- location,
293
- );
294
- });
295
- } else {
296
- TurboFrameController._linkClickIntercepted.call(this, element, location);
297
- }
298
- };
299
- }
300
-
301
279
  function autofocus(container) {
302
280
  if (!container) return null;
303
281
 
@@ -29,26 +29,15 @@ export class FrameModal extends Modal {
29
29
  }
30
30
 
31
31
  /**
32
- * When a user clicks a kpop link, turbo intercepts the click and calls
33
- * #navigateFrame on the turbo frame controller before setting the TurboFrame
34
- * element's src attribute. KPOP intercepts this call and calls this method
35
- * first so we cancel problematic navigations that might cache invalid states.
32
+ * When the FrameController reloads the open modal's location, it runs this
33
+ * method to open the new content in place, without animating.
36
34
  *
37
- * @param location URL requested by turbo
38
- * @param frame FrameController
39
- * @param element TurboFrame element
40
- * @param resolve continuation chain
35
+ * @param {Kpop__FrameController} frame
36
+ * @param {HTMLDialogElement} dialog
37
+ * @param {String} src
41
38
  */
42
- static visit(location, frame, element, resolve) {
43
- // Ensure that turbo doesn't cache the frame in a loading state by cancelling
44
- // the current request (if any) by clearing the src.
45
- // Known issue: this won't work if the frame was previously rendering a useful src.
46
- if (element.hasAttribute("busy")) {
47
- this.debug("clearing src to cancel turbo request");
48
- element.src = "";
49
- }
50
-
51
- this.debug("navigate to", location);
52
- resolve();
39
+ static reload(frame, dialog, src) {
40
+ this.debug("reload", src);
41
+ return frame.open(new FrameModal(frame, dialog, src), { animate: false });
53
42
  }
54
43
  }
@@ -71,19 +71,6 @@ export class Modal {
71
71
  this.element.close();
72
72
  }
73
73
 
74
- /**
75
- * When user navigates from inside a modal, dismiss the modal first so
76
- * that the modal does not appear in the history stack.
77
- *
78
- * @param frame FrameController
79
- * @param e Turbo navigation event
80
- */
81
- beforeVisit(frame, e) {
82
- this.debug(`before-visit`, e.detail.url);
83
-
84
- this.frame.clear();
85
- }
86
-
87
74
  static get debug() {
88
75
  return debug(this.name);
89
76
  }
@@ -1,10 +1,14 @@
1
1
  import { Turbo } from "@hotwired/turbo-rails";
2
2
 
3
3
  /**
4
- * Routes Turbo visits to locations that match a modal rule into the kpop
5
- * frame, the way Hotwire Native routes visits with its path configuration.
4
+ * Decides how each Turbo visit shows, the way Hotwire Native routes visits
5
+ * with its path configuration. Visits to locations that match a modal rule
6
+ * open in the kpop frame, and page visits close any open modal first.
6
7
  * Callers use `Turbo.visit` and the ruleset decides how the location shows.
7
8
  *
9
+ * Turbo dispatches `turbo:before-visit` before the adapter knows where the
10
+ * visit goes, so kpop handles visits here rather than in that event.
11
+ *
8
12
  * Wraps Turbo's browser adapter, which Turbo does not export, so every other
9
13
  * adapter call reaches the browser adapter unchanged.
10
14
  */
@@ -24,11 +28,7 @@ export default class VisitAdapter {
24
28
  Turbo.registerAdapter(
25
29
  Object.assign(Object.create(adapter), {
26
30
  visitProposedToLocation(location, options) {
27
- if (visitAdapter.#shouldVisitInFrame(location, options)) {
28
- Turbo.visit(location, { frame: "kpop" });
29
- } else {
30
- adapter.visitProposedToLocation(location, options);
31
- }
31
+ visitAdapter.#visitProposedToLocation(location, options);
32
32
  },
33
33
  }),
34
34
  );
@@ -45,6 +45,29 @@ export default class VisitAdapter {
45
45
  this.started = false;
46
46
  }
47
47
 
48
+ #visitProposedToLocation(location, options) {
49
+ const frame = document.getElementById("kpop");
50
+ const kpop = frame?.kpop;
51
+
52
+ // `resume_or_redirect_back_or_to` redirects here to close the modal and
53
+ // stay on the current page, so don't visit it.
54
+ if (kpop && location.pathname === "/resume_historical_location") {
55
+ kpop.dismiss({ reason: "resume-historical-location" });
56
+ } else if (this.#shouldVisitInFrame(location, options)) {
57
+ Turbo.visit(location, { frame: "kpop" });
58
+ } else {
59
+ // Close any open modal first so it doesn't appear in the history stack.
60
+ if (kpop?.isOpen) kpop.clear({ reason: "page-visit" });
61
+
62
+ // A modal that is still loading isn't open yet. Turbo cancels its request
63
+ // when the page changes, but caches its src with the page snapshot and
64
+ // loads it again on restore, so clear the src first.
65
+ if (frame?.src) frame.src = "";
66
+
67
+ this.adapter.visitProposedToLocation(location, options);
68
+ }
69
+ }
70
+
48
71
  /**
49
72
  * Like Hotwire Native, the rules decide how a location shows, whatever the
50
73
  * link that proposed it says, so `data-turbo-frame="_top"` does not opt out.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-kpop
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive