@massimo-cassandro/minimo 0.12.6 → 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
|
@@ -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;
|
|
@@ -485,9 +520,13 @@ class SimpleDatatableAdapter extends HTMLElement {
|
|
|
485
520
|
(value.timezone === 'UTC' ? 'Z' : '');
|
|
486
521
|
}
|
|
487
522
|
|
|
523
|
+
|
|
524
|
+
// TODO rendere più snella la gestione di questoi casi (???)
|
|
525
|
+
// TODO pasare il valore `nullAs` al render predefinito
|
|
488
526
|
// Applica _renderNullAs al valore della cella se null/undefined
|
|
489
527
|
// e la cella non ha già un template che gestisce la visualizzazione.
|
|
490
|
-
|
|
528
|
+
// se _renderMode è impostato, il valore null è gestito direttamente dal gestore predefinito
|
|
529
|
+
if (value == null && col_item._cellRender == null && col_item._renderMode == null) {
|
|
491
530
|
value = nullAs;
|
|
492
531
|
}
|
|
493
532
|
|
|
@@ -681,6 +720,16 @@ class SimpleDatatableAdapter extends HTMLElement {
|
|
|
681
720
|
pagination.querySelectorAll(`.${styles.paginationListItemBtn}:has(svg)`)
|
|
682
721
|
.forEach(btn => btn.classList.add(styles.hasSvg));
|
|
683
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
|
+
|
|
684
733
|
// Applica eventuale filtro contestuale passato via reload({ search: … })
|
|
685
734
|
// Lo facciamo qui, dentro datatable.init, per essere certi che
|
|
686
735
|
// simple-datatables abbia completato il render dei nuovi dati.
|
|
@@ -696,6 +745,11 @@ class SimpleDatatableAdapter extends HTMLElement {
|
|
|
696
745
|
}
|
|
697
746
|
});
|
|
698
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
|
+
|
|
699
753
|
} // end _render
|
|
700
754
|
|
|
701
755
|
} // end component
|