@vettvangur/vanilla 0.0.3 → 0.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.
package/dist/index.esm.js CHANGED
@@ -416,11 +416,42 @@ function onDomReady(moduleMap, initCoreScriptsCallback, callback = null) {
416
416
  */
417
417
  function onPopstate(moduleMap, initCoreScriptsCallback, callback = null) {
418
418
  window.addEventListener('popstate', e => {
419
- initCoreScripts(initCoreScriptsCallback);
420
- lazyModules(moduleMap);
421
- if (callback) {
422
- callback(e);
423
- }
419
+ setTimeout(() => {
420
+ initCoreScripts(initCoreScriptsCallback);
421
+ lazyModules(moduleMap);
422
+ if (callback) {
423
+ callback(e);
424
+ }
425
+ }, 0);
426
+ });
427
+ }
428
+
429
+ /**
430
+ * Handles the "pageshow" event to initialize core scripts and lazy load modules.
431
+ *
432
+ * This function listens for the "pageshow" event—which fires when a page is loaded from the bfcache
433
+ * or initially loaded. After a short delay, it calls the provided core scripts initialization callback
434
+ * and lazy loads modules using the supplied module map. An optional callback is executed with the event object.
435
+ *
436
+ * @function onPageShow
437
+ * @param {Map} moduleMap - The compiled module map for lazy loading.
438
+ * @param {Function} initCoreScriptsCallback - The callback function used to initialize core scripts.
439
+ * @param {Function} [callback] - An optional callback to execute during event handling.
440
+ *
441
+ * @example
442
+ * onPageShow(moduleMap, () => { console.log('Core scripts initialized'); }, (e) => {
443
+ * console.log('Pageshow event triggered', e);
444
+ * });
445
+ */
446
+ function onPageShow(moduleMap, initCoreScriptsCallback, callback = null) {
447
+ window.addEventListener('pageshow', e => {
448
+ setTimeout(() => {
449
+ initCoreScripts(initCoreScriptsCallback);
450
+ lazyModules(moduleMap);
451
+ if (callback) {
452
+ callback(e);
453
+ }
454
+ }, 0);
424
455
  });
425
456
  }
426
457
 
@@ -584,4 +615,4 @@ function clickOutside(callback) {
584
615
  });
585
616
  }
586
617
 
587
- export { capitalize, clickOutside, createModuleMap, dictionary, fetcher, flatten, getTemplate, initCoreScripts, isEmpty, lazyModules, loadEnvFiles, onDomReady, onHtmxAfterSettle, onHtmxAfterSwap, onHtmxBeforeSwap, onPopstate, preloadTimeout, regexr };
618
+ export { capitalize, clickOutside, createModuleMap, dictionary, fetcher, flatten, getTemplate, initCoreScripts, isEmpty, lazyModules, loadEnvFiles, onDomReady, onHtmxAfterSettle, onHtmxAfterSwap, onHtmxBeforeSwap, onPageShow, onPopstate, preloadTimeout, regexr };
@@ -163,6 +163,24 @@ export function onDomReady(moduleMap: Map<any, any>, initCoreScriptsCallback: Fu
163
163
  * onPopstate(moduleMap, () => { console.log('Core scripts initialized'); }, () => { console.log('Popstate event triggered'); });
164
164
  */
165
165
  export function onPopstate(moduleMap: Map<any, any>, initCoreScriptsCallback: Function, callback?: Function): void;
166
+ /**
167
+ * Handles the "pageshow" event to initialize core scripts and lazy load modules.
168
+ *
169
+ * This function listens for the "pageshow" event—which fires when a page is loaded from the bfcache
170
+ * or initially loaded. After a short delay, it calls the provided core scripts initialization callback
171
+ * and lazy loads modules using the supplied module map. An optional callback is executed with the event object.
172
+ *
173
+ * @function onPageShow
174
+ * @param {Map} moduleMap - The compiled module map for lazy loading.
175
+ * @param {Function} initCoreScriptsCallback - The callback function used to initialize core scripts.
176
+ * @param {Function} [callback] - An optional callback to execute during event handling.
177
+ *
178
+ * @example
179
+ * onPageShow(moduleMap, () => { console.log('Core scripts initialized'); }, (e) => {
180
+ * console.log('Pageshow event triggered', e);
181
+ * });
182
+ */
183
+ export function onPageShow(moduleMap: Map<any, any>, initCoreScriptsCallback: Function, callback?: Function): void;
166
184
  /**
167
185
  * Handles the `htmx:beforeSwap` event to perform actions before HTMX swaps.
168
186
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vettvangur/vanilla",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Vettvangur | Vanilla JS Utility Library",
5
5
  "access": "private",
6
6
  "type": "module",