@massimo-cassandro/minimo 1.21.6 → 1.21.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 +5 -1
- package/src/web-components/s-datatable-component/docs.md +27 -3
- package/src/web-components/s-datatable-component/s-datatable-component.js +14 -16
- package/src/web-components/s-datatable-component/src/parse-cols.js +8 -5
- package/src/web-components/s-datatable-component/src/search-method.js +84 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@massimo-cassandro/minimo",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.8",
|
|
4
4
|
"description": "Light css framework & utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"@svgdotjs/svg.js": "^3.2.7",
|
|
76
76
|
"blurhash": "^2.0.5",
|
|
77
|
+
"simple-datatables": "^10.3.0",
|
|
77
78
|
"style-dictionary": "^5.0.0"
|
|
78
79
|
},
|
|
79
80
|
"peerDependenciesMeta": {
|
|
@@ -83,6 +84,9 @@
|
|
|
83
84
|
"blurhash": {
|
|
84
85
|
"optional": true
|
|
85
86
|
},
|
|
87
|
+
"simple-datatables": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
86
90
|
"style-dictionary": {
|
|
87
91
|
"optional": true
|
|
88
92
|
}
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
<https://fiduswriter.github.io/simple-datatables/documentation/>
|
|
4
4
|
|
|
5
|
+
## Installazione
|
|
6
|
+
|
|
7
|
+
`simple-datatables` è una **peer dependency opzionale** di minimo: va installata
|
|
8
|
+
solo nei progetti che usano questo componente.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm i simple-datatables
|
|
12
|
+
```
|
|
5
13
|
|
|
6
14
|
## Utilizzo da markup
|
|
7
15
|
|
|
@@ -211,13 +219,29 @@ cols: [
|
|
|
211
219
|
// _sortValue: 'owner.cognome' → ordina per cognome
|
|
212
220
|
|
|
213
221
|
_searchValue, // Percorso/i del campo da usare per la RICERCA al posto del contenuto
|
|
214
|
-
// visualizzato. Accetta uno o più percorsi separati da spazio
|
|
222
|
+
// visualizzato. Accetta uno o più percorsi separati da spazio,
|
|
223
|
+
// oppure una funzione (row) => string|number|boolean.
|
|
215
224
|
// Supporta notazione punto.
|
|
216
|
-
// Implementato tramite searchMethod di colonna (API simple-datatables)
|
|
217
|
-
//
|
|
225
|
+
// Implementato tramite searchMethod di colonna (API simple-datatables):
|
|
226
|
+
// il valore viene scritto in attributes['data-search'] della cella e
|
|
227
|
+
// la searchMethod lo legge dall'OGGETTO DATI INTERNO di
|
|
228
|
+
// simple-datatables (cellType: { data, text?, order?, attributes? }),
|
|
229
|
+
// NON dal nodo DOM <td> (la libreria passa alla callback
|
|
230
|
+
// `searchRow[index]`, non l'elemento renderizzato).
|
|
231
|
+
// Ordine di lettura: attributes['data-search'] → text → data.
|
|
232
|
+
// Il valore viene convertito con String(), quindi sono ammessi
|
|
233
|
+
// numeri e booleani (es. `_searchValue: row => row.id`).
|
|
218
234
|
// La ricerca è di tipo AND: tutti i termini digitati devono essere
|
|
219
235
|
// presenti nel valore del campo (o dei campi) indicati.
|
|
220
236
|
//
|
|
237
|
+
// Normalizzazione: simple-datatables normalizza solo i termini
|
|
238
|
+
// digitati (default `sensitivity: 'base'`, `ignorePunctuation: true`).
|
|
239
|
+
// La searchMethod applica la stessa catena anche al contenuto della
|
|
240
|
+
// cella (minuscole + NFD senza diacritici + rimozione punteggiatura),
|
|
241
|
+
// così "citta" trova "Città" e "spa" trova "S.p.A.".
|
|
242
|
+
// Se sulla colonna sono impostate `sensitivity` / `ignorePunctuation`,
|
|
243
|
+
// vengono rispettate.
|
|
244
|
+
//
|
|
221
245
|
// Esempio: _searchValue: 'owner.cognome owner.nome'
|
|
222
246
|
// cerca su entrambi i campi concatenati; "rossi mario" trova solo
|
|
223
247
|
// le righe che contengono entrambe le parole, in qualsiasi ordine.
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { DataTable } from 'simple-datatables';
|
|
6
6
|
|
|
7
7
|
import { parseCols } from './src/parse-cols.js';
|
|
8
|
+
import { makeSearchMethod } from './src/search-method.js';
|
|
8
9
|
|
|
9
10
|
import * as styles from './s-datatable-component.module.css';
|
|
10
11
|
|
|
@@ -640,10 +641,13 @@ class SimpleDatatableAdapter extends HTMLElement {
|
|
|
640
641
|
value = nullAs;
|
|
641
642
|
}
|
|
642
643
|
|
|
643
|
-
// _searchValue: valore alternativo per la ricerca
|
|
644
|
-
// Viene scritto
|
|
645
|
-
//
|
|
646
|
-
//
|
|
644
|
+
// _searchValue: valore alternativo per la ricerca.
|
|
645
|
+
// Viene scritto in `attributes['data-search']` della cella: la
|
|
646
|
+
// searchMethod di colonna lo legge dall'oggetto dati interno di
|
|
647
|
+
// simple-datatables (cellType), non dal DOM.
|
|
648
|
+
// Accetta un percorso (o più percorsi separati da spazio) oppure una
|
|
649
|
+
// funzione (row) => string|number: il valore viene normalizzato con
|
|
650
|
+
// String() al momento del confronto.
|
|
647
651
|
const searchValue = col_item._searchValue
|
|
648
652
|
? typeof col_item._searchValue === 'function'
|
|
649
653
|
? (col_item._searchValue(row) ?? '')
|
|
@@ -702,20 +706,14 @@ class SimpleDatatableAdapter extends HTMLElement {
|
|
|
702
706
|
// data-search invece che sul testo visualizzato.
|
|
703
707
|
// L'API simple-datatables prevede: (terms, cell, row, colIdx, source)
|
|
704
708
|
// - terms: array di stringhe (uno per parola cercata)
|
|
705
|
-
// - cell:
|
|
709
|
+
// - cell: oggetto dati interno `cellType` ({ data, text?, order?, attributes? }),
|
|
710
|
+
// NON il nodo DOM <td>: la libreria passa `searchRow[index]`
|
|
711
|
+
// (vedi `multiSearch` in src/datatable.ts).
|
|
706
712
|
// La funzione deve restituire true se la riga è da includere.
|
|
707
|
-
//
|
|
708
|
-
//
|
|
709
|
-
// come plain object, restituendo sempre undefined).
|
|
710
|
-
// Comportamento AND: tutti i termini devono essere presenti (come
|
|
711
|
-
// nella demo https://fiduswriter.github.io/simple-datatables/demos/22-and-search/).
|
|
713
|
+
// Vedi ./src/search-method.js per la lettura del valore e la
|
|
714
|
+
// normalizzazione (allineata a quella che la libreria applica ai termini).
|
|
712
715
|
if (col_settings._searchValue) {
|
|
713
|
-
colObj.searchMethod = (
|
|
714
|
-
const haystack = (
|
|
715
|
-
cell.getAttribute?.('data-search') ?? cell.textContent ?? ''
|
|
716
|
-
).toLowerCase();
|
|
717
|
-
return terms.every(term => haystack.includes(term.toLowerCase()));
|
|
718
|
-
};
|
|
716
|
+
colObj.searchMethod = makeSearchMethod(col_settings);
|
|
719
717
|
}
|
|
720
718
|
|
|
721
719
|
return colObj;
|
|
@@ -121,13 +121,15 @@ export function parseCols(col_obj){
|
|
|
121
121
|
|
|
122
122
|
} else if(col_obj._renderMode === 'numeric') {
|
|
123
123
|
return {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
...col_obj,
|
|
125
|
+
// le classi definite dall'utente vengono unite, non sostituite
|
|
126
|
+
cellClass: classnames('text-end text-numeric', col_obj.cellClass),
|
|
127
|
+
headerClass: classnames('text-end text-numeric', col_obj.headerClass), // NB: usata anche per il footer
|
|
127
128
|
};
|
|
128
129
|
|
|
129
130
|
} else if(col_obj._renderMode === 'euro_no_dec') {
|
|
130
131
|
return {
|
|
132
|
+
...col_obj,
|
|
131
133
|
render: (value, cell) => {
|
|
132
134
|
// console.log(value);
|
|
133
135
|
if(value == null || isNaN(value)) {
|
|
@@ -143,8 +145,9 @@ export function parseCols(col_obj){
|
|
|
143
145
|
});
|
|
144
146
|
}
|
|
145
147
|
},
|
|
146
|
-
|
|
147
|
-
|
|
148
|
+
// le classi definite dall'utente vengono unite, non sostituite
|
|
149
|
+
cellClass: classnames('text-nowrap text-end text-numeric', col_obj.cellClass),
|
|
150
|
+
headerClass: classnames('text-nowrap text-end text-numeric', col_obj.headerClass), // NB: usata anche per il footer
|
|
148
151
|
type: 'number'
|
|
149
152
|
};
|
|
150
153
|
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
// Generazione della `searchMethod` di colonna usata da `_searchValue`.
|
|
4
|
+
//
|
|
5
|
+
// simple-datatables NON passa alla searchMethod il nodo DOM della cella, ma
|
|
6
|
+
// l'oggetto dati interno `cellType` ({ data, text?, order?, attributes? }):
|
|
7
|
+
// vedi `multiSearch` in `src/datatable.ts` (`customSearchMethod(queryColumnWord,
|
|
8
|
+
// searchRow[index], row, index, source)`). Gli `attributes` sono conservati
|
|
9
|
+
// nell'oggetto dati (`readDataCell` in `src/read_data.ts` ammette le chiavi
|
|
10
|
+
// "text", "order", "data", "attributes"), quindi `data-search` va letto da
|
|
11
|
+
// `cell.attributes['data-search']`, non con `cell.getAttribute()`.
|
|
12
|
+
|
|
13
|
+
// Punteggiatura rimossa quando `ignorePunctuation` è attivo
|
|
14
|
+
const PUNCTUATION_RX = /[.,/#!$%^&*;:{}=\-_`~()]/g;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Normalizza una stringa replicando il trattamento che simple-datatables
|
|
18
|
+
* applica ai termini di ricerca quando è attiva una `searchMethod` personalizzata.
|
|
19
|
+
*
|
|
20
|
+
* La libreria normalizza solo i termini digitati (non il contenuto della cella),
|
|
21
|
+
* con i default `sensitivity: 'base'` e `ignorePunctuation: true`: se l'haystack
|
|
22
|
+
* non riceve lo stesso trattamento, "citta" non troverebbe "Città" e "spa" non
|
|
23
|
+
* troverebbe "S.p.A.".
|
|
24
|
+
*
|
|
25
|
+
* @param {*} str Valore da normalizzare (convertito con String()).
|
|
26
|
+
* @param {object} [opts]
|
|
27
|
+
* @param {'base'|'accent'|'case'|'variant'} [opts.sensitivity='base']
|
|
28
|
+
* 'base' → ignora maiuscole/minuscole e diacritici
|
|
29
|
+
* 'accent' → ignora maiuscole/minuscole, mantiene i diacritici
|
|
30
|
+
* 'case' → distingue maiuscole/minuscole, ignora i diacritici
|
|
31
|
+
* 'variant' → distingue tutto
|
|
32
|
+
* @param {boolean} [opts.ignorePunctuation=true]
|
|
33
|
+
* @returns {string}
|
|
34
|
+
*/
|
|
35
|
+
export function normalizeSearchString(str, opts = {}) {
|
|
36
|
+
const sensitivity = opts.sensitivity ?? 'base';
|
|
37
|
+
const ignorePunctuation = opts.ignorePunctuation ?? true;
|
|
38
|
+
|
|
39
|
+
// String() anche su numeri/booleani: `_searchValue` come funzione può
|
|
40
|
+
// restituire un id numerico o un flag
|
|
41
|
+
let out = String(str ?? '');
|
|
42
|
+
|
|
43
|
+
if (sensitivity === 'base' || sensitivity === 'accent') {
|
|
44
|
+
out = out.toLowerCase();
|
|
45
|
+
}
|
|
46
|
+
if (sensitivity === 'base' || sensitivity === 'case') {
|
|
47
|
+
out = out.normalize('NFD').replace(/\p{Diacritic}/gu, '');
|
|
48
|
+
}
|
|
49
|
+
if (ignorePunctuation) {
|
|
50
|
+
out = out.replace(PUNCTUATION_RX, '');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Restituisce la `searchMethod` di colonna per le colonne con `_searchValue`.
|
|
58
|
+
*
|
|
59
|
+
* API simple-datatables: (terms, cell, row, colIdx, source) => boolean
|
|
60
|
+
* - `terms` array di stringhe (una per parola cercata), già normalizzate dalla libreria
|
|
61
|
+
* - `cell` oggetto dati `cellType` ({ data, text?, order?, attributes? })
|
|
62
|
+
*
|
|
63
|
+
* Comportamento AND: tutti i termini devono essere presenti
|
|
64
|
+
* (come nella demo https://fiduswriter.github.io/simple-datatables/demos/22-and-search/).
|
|
65
|
+
*
|
|
66
|
+
* @param {object} [colSettings] Definizione della colonna (per `sensitivity` / `ignorePunctuation`).
|
|
67
|
+
* @returns {(terms: string[], cell: object) => boolean}
|
|
68
|
+
*/
|
|
69
|
+
export function makeSearchMethod(colSettings = {}) {
|
|
70
|
+
const opts = {
|
|
71
|
+
sensitivity: colSettings.sensitivity,
|
|
72
|
+
ignorePunctuation: colSettings.ignorePunctuation,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return (terms, cell) => {
|
|
76
|
+
const raw = cell?.attributes?.['data-search']
|
|
77
|
+
?? cell?.text
|
|
78
|
+
?? (typeof cell?.data === 'string' || typeof cell?.data === 'number' ? cell.data : '');
|
|
79
|
+
|
|
80
|
+
const haystack = normalizeSearchString(raw, opts);
|
|
81
|
+
|
|
82
|
+
return terms.every(term => haystack.includes(normalizeSearchString(term, opts)));
|
|
83
|
+
};
|
|
84
|
+
}
|