rails_modal_manager 1.0.4 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2f67902f2a1a7d3f98a0318b84ebd2adeeec5d1d8067ead263ea394fc76d64a
4
- data.tar.gz: 88ab650eaaf8eb145a1fe7844dec22acf2e0e61381e2e1217ee172fea6bee283
3
+ metadata.gz: 07e612cdd8425a4042524c46b43900aae571126866f8b6816a6f4b3174941cdc
4
+ data.tar.gz: ac92ca48a207e80b7a00bbcf2346820ec6bfaa9dd94ad2c07840331fdc109ed4
5
5
  SHA512:
6
- metadata.gz: 120b2415ca136f031f10805151f948e6616754c2e6c07c303fb115f9f87f56f66037688f93fbfd95398a3612d79f84f0c398e006654f434222b5304cfb1fa3d8
7
- data.tar.gz: 29edd0abdbc5cf321eb818366a86998e18cdc3dce2b39cf37e5a4ba75866224e8b8750adbc32548167ddefa217302a86a518de6610eeb6dbe659b397791cb063
6
+ metadata.gz: d1a29aa6ff0dc96b8acd0f503b325eeba85f6961b3cb28be80f62a0f3af2061be43b7c9488a1b1e3d4e5e6bfb9b0929afb96794070af2db202145c882f409762
7
+ data.tar.gz: feaa856f515612f6080bd5f51c3b1b8ed18b877992df59013143b280644e5af3622fba89537d4ad1b2bddd6aa14ebd4ebb0f92bf1a461f060dbc31f8697f6951
@@ -186,11 +186,10 @@ export default class extends Controller {
186
186
 
187
187
  // Remove from history stack (unless closed by history)
188
188
  if (this.enableHistoryStackValue && source !== 'history') {
189
- // Remove descendants from history first (in reverse order)
190
- [...descendants].reverse().forEach(descId => {
191
- historyStackManager.removeHisData('modal', descId)
192
- })
193
- historyStackManager.removeHisData('modal', modalId)
189
+ // Collect all modal IDs to remove (descendants + current modal)
190
+ const allIdsToRemove = [...[...descendants].reverse(), modalId]
191
+ // Remove all at once with single history.go() call
192
+ historyStackManager.removeMultipleHisData('modal', allIdsToRemove)
194
193
  }
195
194
 
196
195
  // Close all descendants first (in reverse order - newest first)
@@ -673,16 +672,14 @@ export default class extends Controller {
673
672
  // Minimize entire group if has parent
674
673
  modalStore.minimizeModalGroup(modalId)
675
674
 
676
- // Remove from history stack (use removeHisData to sync browser history)
675
+ // Remove from history stack (use removeMultipleHisData to sync browser history)
677
676
  if (this.enableHistoryStackValue) {
678
677
  const rootId = modalStore.getRootModal(modalId)
679
678
  const descendants = modalStore.getAllDescendants(rootId)
680
- const allModalIds = [rootId, ...descendants]
679
+ const allModalIds = [rootId, ...descendants].reverse()
681
680
 
682
- // Remove in reverse order (newest first)
683
- allModalIds.reverse().forEach(id => {
684
- historyStackManager.removeHisData('modal', id)
685
- })
681
+ // Remove all at once with single history.go() call
682
+ historyStackManager.removeMultipleHisData('modal', allModalIds)
686
683
  }
687
684
 
688
685
  this.dispatch('minimize', { detail: { modalId: modalId } })
@@ -199,6 +199,55 @@ function silentRemoveHisData(type, id) {
199
199
  return true;
200
200
  }
201
201
 
202
+ /**
203
+ * Remove multiple items from history stack at once
204
+ * - Remove all specified items from stack
205
+ * - Remove functions from closeFunctions (memory cleanup)
206
+ * - Synchronize browser history with single history.go(-count) call
207
+ *
208
+ * @param {string} type - Target type
209
+ * @param {string[]} ids - Array of target IDs to remove
210
+ * @returns {number} Number of items successfully removed
211
+ */
212
+ function removeMultipleHisData(type, ids) {
213
+ if (typeof window === 'undefined') return 0;
214
+ if (!isEnabledForDevice(type)) return 0;
215
+ if (!ids || ids.length === 0) return 0;
216
+
217
+ const hisData = loadHisData();
218
+ let removedCount = 0;
219
+
220
+ // Remove each item silently (without history.back)
221
+ ids.forEach(id => {
222
+ const index = hisData.findIndex(
223
+ (item) => item.type === type && item.id === id
224
+ );
225
+
226
+ if (index !== -1) {
227
+ const item = hisData[index];
228
+
229
+ // Remove function from closeFunctions (memory cleanup)
230
+ if (item.closeKey) {
231
+ closeFunctions.delete(item.closeKey);
232
+ }
233
+
234
+ // Remove item from stack
235
+ hisData.splice(index, 1);
236
+ removedCount++;
237
+ }
238
+ });
239
+
240
+ if (removedCount > 0) {
241
+ saveHisData(hisData);
242
+
243
+ // Synchronize browser history with single call
244
+ isDirectClose = true;
245
+ window.history.go(-removedCount);
246
+ }
247
+
248
+ return removedCount;
249
+ }
250
+
202
251
  /**
203
252
  * Remove last item from history stack and execute close function (used for back button)
204
253
  * @returns {Object|null} Closed item info or null
@@ -310,6 +359,7 @@ const historyStackManager = {
310
359
  // Core functions
311
360
  addHisData,
312
361
  removeHisData,
362
+ removeMultipleHisData,
313
363
  silentRemoveHisData,
314
364
  popHisData,
315
365
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsModalManager
4
- VERSION = "1.0.4"
4
+ VERSION = "1.0.5"
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.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - reshacs