rails_modal_manager 1.0.12 → 1.0.13

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: e3731afb3a3d006cd6256e0e19780bb24e433153ca2f459807137ef52e0cfaf7
4
- data.tar.gz: 6acd94d81d76b5490185a8675b8ddacd3a2759fe5f039f765ed23e31f17d4020
3
+ metadata.gz: 3aef02a89c60f4390647bdb318057751ef19caea49b2849ab1af859412267d54
4
+ data.tar.gz: aafa0a2b8165398b4f91dcb5ea3e3b013433550b227a0c6e0a5df9c6f2840b15
5
5
  SHA512:
6
- metadata.gz: e81f5871bc33494bd283ac5adb41ca84571bfb9e3f9a23597e8a1b37ab1dfd62cd4033958030d2aaca80becc305593a68a0762d92d3d88c394d3ae80b693e22d
7
- data.tar.gz: d87f1982e1dd5cb3df4c50f3ceea6a9fe1605ea789711528a89e942de5533d25fbdb8673d55a2d4b2e06ebc3305d9aeed27f58307c285887135f20bb873dd1ea
6
+ metadata.gz: f5e26d4b12715b984126fa2a4262a56e9f23a238fdc68c5c89c7179c159b7abb36fe93cb789be1f834ba51d720ace3bf66f24aa4a65266433ab166f8b30f68ad
7
+ data.tar.gz: af75896852ef1fc10956a6b8d305da635e074655dff95082234999de0b43ff379b58c22e5d39190007e28858af0e14819f57a67177de7841a34200c779491d5c
@@ -147,6 +147,9 @@ export default class extends Controller {
147
147
  // Register close callback
148
148
  modalStore.registerCloseCallback(modalId, () => this.close('programmatic'))
149
149
 
150
+ // Move to persistent container (outside Turbo Frame) to survive navigation
151
+ this.moveToChildModalsContainer()
152
+
150
153
  // Add to history stack
151
154
  if (this.enableHistoryStackValue && !historyStackManager.hasHisData('modal', modalId)) {
152
155
  historyStackManager.addHisData('modal', modalId, () => this.close('history'))
@@ -682,9 +685,48 @@ export default class extends Controller {
682
685
  historyStackManager.removeMultipleHisData('modal', allModalIds)
683
686
  }
684
687
 
688
+ // Move modal DOM to persistent container (outside Turbo Frame)
689
+ // This ensures minimized modals survive Turbo Frame navigation
690
+ this.moveToChildModalsContainer()
691
+
685
692
  this.dispatch('minimize', { detail: { modalId: modalId } })
686
693
  }
687
694
 
695
+ /**
696
+ * Move modal (with wrapper if exists) to #child-modals-container
697
+ * This prevents DOM removal when Turbo Frame content is replaced
698
+ */
699
+ moveToChildModalsContainer() {
700
+ const container = document.getElementById('child-modals-container')
701
+ if (!container) return
702
+
703
+ const overlay = this.getOverlay()
704
+ const parent = this.element.parentElement
705
+
706
+ // Determine what to move: wrapper (if exists) or just modal
707
+ let elementToMove = this.element
708
+
709
+ // Check if parent is a wrapper (has data-controller and is not body/frame/container)
710
+ if (parent &&
711
+ parent.dataset.controller &&
712
+ parent.id !== 'child-modals-container' &&
713
+ parent.tagName !== 'TURBO-FRAME' &&
714
+ parent.tagName !== 'BODY') {
715
+ elementToMove = parent
716
+ }
717
+
718
+ // Skip if already in container
719
+ if (elementToMove.parentElement === container) return
720
+
721
+ // If overlay is outside the element to move, move it first
722
+ if (overlay && !elementToMove.contains(overlay) && overlay.parentElement !== container) {
723
+ container.appendChild(overlay)
724
+ }
725
+
726
+ // Move the element (modal or wrapper including overlay)
727
+ container.appendChild(elementToMove)
728
+ }
729
+
688
730
  maximize() {
689
731
  const modalId = this.effectiveModalId
690
732
  const config = modalStore.getModalConfig(modalId)
@@ -777,7 +819,18 @@ export default class extends Controller {
777
819
  // ============================================
778
820
 
779
821
  getOverlay() {
780
- return document.getElementById(`${this.effectiveModalId}-overlay`)
822
+ const overlayId = `${this.effectiveModalId}-overlay`
823
+
824
+ // If this modal is inside child-modals-container, search there first
825
+ // This prevents finding duplicate overlays in turbo-frame
826
+ const container = document.getElementById('child-modals-container')
827
+ if (container && container.contains(this.element)) {
828
+ const overlayInContainer = container.querySelector(`#${overlayId}`)
829
+ if (overlayInContainer) return overlayInContainer
830
+ }
831
+
832
+ // Fallback to document-level search
833
+ return document.getElementById(overlayId)
781
834
  }
782
835
 
783
836
  hasAttribute(attr) {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsModalManager
4
- VERSION = "1.0.12"
4
+ VERSION = "1.0.13"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_modal_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - reshacs