@massimo-cassandro/minimo 0.12.7 → 0.12.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massimo-cassandro/minimo",
3
- "version": "0.12.7",
3
+ "version": "0.12.8",
4
4
  "description": "Light css framework & utilities",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/massimo-cassandro/minimo#readme",
@@ -88,6 +88,13 @@ import caretRightIcon from '../../icons/caret-right.svg?inline';
88
88
  * in tutte le colonne. Può essere sovrascritto per singola
89
89
  * colonna con `_renderNullAs`.
90
90
  * Default: `\u2014` (em dash)
91
+ *
92
+ * @param {string[]} allowedReferrer Elenco di percorsi URL da cui, se si proviene,
93
+ * la pagina corrente viene ripristinata dal cookie
94
+ * di sessione `sd-pag`. Se il referrer non è tra
95
+ * quelli indicati, il cookie viene eliminato.
96
+ * Confronto su `pathname` (query string e hash ignorati).
97
+ * Esempio: `['/utenti', '/utenti/nuovo']`
91
98
  */
92
99
 
93
100
 
@@ -378,6 +385,34 @@ class SimpleDatatableAdapter extends HTMLElement {
378
385
  this._config[name] = value;
379
386
  }
380
387
 
388
+ /**
389
+ * Restituisce true se il referrer corrisponde a uno dei percorsi in `allowedReferrer`.
390
+ * Il confronto avviene su `pathname` per ignorare query string e hash.
391
+ */
392
+ _isReferrerAllowed() {
393
+ const allowed = this._getParam('allowedReferrer', []);
394
+ if (!allowed.length || !document.referrer) return false;
395
+ const referrerPath = new URL(document.referrer).pathname;
396
+ return allowed.some(path => referrerPath === path);
397
+ }
398
+
399
+ /** Salva la pagina corrente nel cookie di sessione `sd-pag`. */
400
+ _savePageCookie(page) {
401
+ document.cookie = `sd-pag=${page}; path=${location.pathname}`;
402
+ }
403
+
404
+ /** Legge la pagina dal cookie `sd-pag`. Restituisce null se assente. */
405
+ _readPageCookie() {
406
+ const match = document.cookie.match(/(?:^|;\s*)sd-pag=(\d+)/);
407
+ return match ? parseInt(match[1], 10) : null;
408
+ }
409
+
410
+ /** Elimina il cookie `sd-pag`. */
411
+ _deletePageCookie() {
412
+ document.cookie = `sd-pag=; path=${location.pathname}; max-age=0`;
413
+ }
414
+
415
+
381
416
  /**
382
417
  * Ritorna true se questo elemento è il target dell'evento.
383
418
  * Se detail.target è assente, risponde sempre;
@@ -685,6 +720,16 @@ class SimpleDatatableAdapter extends HTMLElement {
685
720
  pagination.querySelectorAll(`.${styles.paginationListItemBtn}:has(svg)`)
686
721
  .forEach(btn => btn.classList.add(styles.hasSvg));
687
722
 
723
+ // Ripristino pagina dal cookie di sessione (se referrer autorizzato)
724
+ if (this._isReferrerAllowed()) {
725
+ const savedPage = this._readPageCookie();
726
+ if (savedPage !== null) {
727
+ this._dt.page(savedPage);
728
+ }
729
+ } else {
730
+ this._deletePageCookie();
731
+ }
732
+
688
733
  // Applica eventuale filtro contestuale passato via reload({ search: … })
689
734
  // Lo facciamo qui, dentro datatable.init, per essere certi che
690
735
  // simple-datatables abbia completato il render dei nuovi dati.
@@ -700,6 +745,11 @@ class SimpleDatatableAdapter extends HTMLElement {
700
745
  }
701
746
  });
702
747
 
748
+ // Salva la pagina corrente nel cookie ad ogni cambio di pagina
749
+ this._dt.on('datatable.page', page => {
750
+ this._savePageCookie(page);
751
+ });
752
+
703
753
  } // end _render
704
754
 
705
755
  } // end component