@unabridged/midwest 0.27.3 → 0.27.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/assets/javascript/midwest.js +43 -6
- package/app/assets/javascript/midwest.js.map +1 -1
- package/app/assets/stylesheets/midwest.css +1 -1
- package/dist/css/midwest.css +1 -1
- package/dist/javascript/collection/app/components/midwest/card_component/card_component_controller.js +43 -6
- package/dist/javascript/collection/app/components/midwest/card_component/card_component_controller.js.map +1 -1
- package/dist/javascript/midwest.d.ts +4 -0
- package/dist/javascript/midwest.js +43 -6
- package/dist/javascript/midwest.js.map +1 -1
- package/package.json +1 -1
|
@@ -507,18 +507,30 @@ class Card extends Controller {
|
|
|
507
507
|
get flippable() {
|
|
508
508
|
return this.element.classList.contains("flippable");
|
|
509
509
|
}
|
|
510
|
+
// Both faces are re-measured whenever either is replaced, which is what happens
|
|
511
|
+
// when a card rendered with `frame:` has its contents swapped by a response.
|
|
512
|
+
// Without this the min-heights keep whatever the faces measured on first
|
|
513
|
+
// connect, and a card whose back grew or shrank is left at the wrong size.
|
|
514
|
+
frontTargetConnected() {
|
|
515
|
+
this.measureFaces();
|
|
516
|
+
}
|
|
517
|
+
backTargetConnected() {
|
|
518
|
+
this.measureFaces();
|
|
519
|
+
}
|
|
510
520
|
async applyReady() {
|
|
511
521
|
if (this.flippable) {
|
|
512
|
-
this.
|
|
513
|
-
this.backHeightValue = this.backTarget.offsetHeight;
|
|
522
|
+
this.measureFaces();
|
|
514
523
|
this.element.classList.add("flip-ready");
|
|
515
|
-
this.resizeHandler = () =>
|
|
516
|
-
this.originalHeightValue = this.frontTarget.offsetHeight;
|
|
517
|
-
this.backHeightValue = this.backTarget.offsetHeight;
|
|
518
|
-
};
|
|
524
|
+
this.resizeHandler = () => this.measureFaces();
|
|
519
525
|
window.addEventListener("resize", this.resizeHandler);
|
|
520
526
|
}
|
|
521
527
|
}
|
|
528
|
+
measureFaces() {
|
|
529
|
+
if (!this.flippable || !this.hasFrontTarget || !this.hasBackTarget)
|
|
530
|
+
return;
|
|
531
|
+
this.originalHeightValue = this.frontTarget.offsetHeight;
|
|
532
|
+
this.backHeightValue = this.backTarget.offsetHeight;
|
|
533
|
+
}
|
|
522
534
|
originalHeightValueChanged() {
|
|
523
535
|
this.element.style.setProperty("--min-height", `${this.originalHeightValue}px`);
|
|
524
536
|
}
|
|
@@ -528,6 +540,31 @@ class Card extends Controller {
|
|
|
528
540
|
flip() {
|
|
529
541
|
this.element.classList.toggle("flipped");
|
|
530
542
|
}
|
|
543
|
+
// Returns the card to its front, animating rather than cutting because the
|
|
544
|
+
// element is never replaced. Pairs with `frame:`: a form on the back can save,
|
|
545
|
+
// let the response swap the faces, and turn the card back over.
|
|
546
|
+
//
|
|
547
|
+
// data-action="turbo:frame-render->midwest-card#returnToFront"
|
|
548
|
+
//
|
|
549
|
+
// Bind it to `turbo:frame-render`, not `turbo:submit-end`. The form lives
|
|
550
|
+
// inside the frame the response replaces, so by the time the submission ends
|
|
551
|
+
// it is detached — and Turbo redispatches events whose target is disconnected
|
|
552
|
+
// onto documentElement instead, where they never reach this card.
|
|
553
|
+
// `turbo:frame-render` targets the frame itself, which survives the swap.
|
|
554
|
+
//
|
|
555
|
+
// A failed response is ignored so a form that came back carrying errors stays
|
|
556
|
+
// where the errors are: `success` covers turbo:submit-end, `fetchResponse`
|
|
557
|
+
// covers turbo:frame-render. An event carrying neither — a click, a custom
|
|
558
|
+
// event — is an unconditional request to show the front.
|
|
559
|
+
returnToFront(event) {
|
|
560
|
+
const detail = event?.detail;
|
|
561
|
+
if (detail?.success === false)
|
|
562
|
+
return;
|
|
563
|
+
const status = detail?.fetchResponse?.statusCode;
|
|
564
|
+
if (typeof status === "number" && status >= 400)
|
|
565
|
+
return;
|
|
566
|
+
this.element.classList.remove("flipped");
|
|
567
|
+
}
|
|
531
568
|
}
|
|
532
569
|
|
|
533
570
|
class Banner extends Controller {
|