@massimo-cassandro/minimo 0.6.6 → 0.7.0
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/design-tokens/components/sf-macro.minimo.tokens.jsonc +20 -2
- package/design-tokens-src/components/sf-macro.minimo.tokens.mjs +32 -14
- package/package.json +1 -1
- package/src/components/sf-macro/sf-macro.css +9 -3
- package/src/components/sf-macro/sf-macro.js +3 -2
- package/src/custom-properties-default.css +6 -9
- package/src/icons/caret-down-bold.svg +1 -0
- package/design-tokens-src/components/recaptcha.minimo.tokens.jsonc +0 -24
- package/design-tokens-src/components/toast.minimo.tokens.jsonc +0 -29
- package/src/components/alert-autoclose.js +0 -9
- package/src/components/auto-datatable/auto-datatable.css +0 -355
- package/src/components/auto-datatable/auto-datatable.js +0 -154
- package/src/components/create-blurhash-canvas.js +0 -47
- package/src/components/img-viewer-dom-builder.js +0 -196
- package/src/components/modal-alert/flash-alerts.js +0 -32
- package/src/components/modal-content/modal-content.js +0 -152
- package/src/components/modal-content/modal-content.module.css +0 -142
- package/src/components/popup-page/popup-page.css +0 -72
- package/src/components/popup-page/popup-page.js +0 -84
- package/src/components/print-icon.js +0 -51
- package/src/components/recaptcha/recaptcha.css +0 -73
- package/src/components/spinner/TODO spinner-circle.css +0 -54
- package/src/components/spinner/TODO spinner-three-dots.css +0 -14
- package/src/components/spinner/readme.md +0 -1
- package/src/components/spinner/spinner-trailing-dots.css +0 -51
- package/src/components/spinner/spinner-wrapper.css +0 -20
- package/src/components/spinner/spinner.js +0 -30
- package/src/components/toast/toast.js +0 -77
- package/src/components/toast/toast.module.css +0 -59
- package/src/components/vanilla-cookie-consent/cookie-consent.css +0 -20
- package/src/components/vanilla-cookie-consent/cookie-consent.js +0 -76
- package/src/components/vanilla-cookie-consent/render-cookie-list.js +0 -32
- package/src/components/vanilla-cookie-consent/src/cookie-list.js +0 -85
- package/src/components/vanilla-cookie-consent/src/it-translation.js +0 -38
- package/src/components/vanilla-cookie-consent/src/run-analytics.js +0 -54
- package/src/components/vanilla-cookie-consent/src/run-recaptcha.js +0 -71
- package/src/css/forms/select-indicator.svg +0 -3
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/* global process */
|
|
2
|
-
|
|
3
|
-
import 'jquery?as_asset';
|
|
4
|
-
import 'datatables.net/js/jquery.dataTables.js?as_asset';
|
|
5
|
-
|
|
6
|
-
import { spinner } from '@minimo/spinner.js';
|
|
7
|
-
import svg_icons from '@imgs/icone.svg';
|
|
8
|
-
|
|
9
|
-
import { creaDT } from '@massimo-cassandro/auto-datatables-bs5';
|
|
10
|
-
import './auto-datatable.css?inline';
|
|
11
|
-
/*
|
|
12
|
-
per personalizzazioni datatable
|
|
13
|
-
da usare insieme alle opzioni globali
|
|
14
|
-
|
|
15
|
-
import {default_dt_options} from 'path/to/datatable.js';
|
|
16
|
-
import { dt_default_options, dt_classes } from '@massimo-cassandro/auto-datatables-bs5';
|
|
17
|
-
|
|
18
|
-
$.extend( $.fn.dataTable.ext.classes, dt_classes );
|
|
19
|
-
$(__table__).DataTable($.extend(true, {}, dt_default_options, ada_default_dt_options,
|
|
20
|
-
|
|
21
|
-
// opzioni specifiche, se necessarie, ad esempio per tabelle non ajax:
|
|
22
|
-
{
|
|
23
|
-
processing : false,
|
|
24
|
-
serverSide : false,
|
|
25
|
-
pageLength : 25,
|
|
26
|
-
order : [[ 1, 'asc' ]],
|
|
27
|
-
columns : null
|
|
28
|
-
}
|
|
29
|
-
));
|
|
30
|
-
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
export const default_dt_options = {
|
|
34
|
-
|
|
35
|
-
dom:
|
|
36
|
-
// controlli
|
|
37
|
-
'<\'dt-controls\'lf>' +
|
|
38
|
-
// table + processing
|
|
39
|
-
//"<'position-relative'tr>" +
|
|
40
|
-
// table + processing
|
|
41
|
-
'<\'dt-table-wrapper\'t>r' +
|
|
42
|
-
// info + paginazione
|
|
43
|
-
'<\'dt-footer\'ip>',
|
|
44
|
-
|
|
45
|
-
// renderer: 'bootstrap',
|
|
46
|
-
|
|
47
|
-
// serverSide : true,
|
|
48
|
-
// paging : true,
|
|
49
|
-
// pageLength : 25,
|
|
50
|
-
language: {
|
|
51
|
-
processing: spinner(),
|
|
52
|
-
|
|
53
|
-
lengthMenu:
|
|
54
|
-
'<di class"dt-control-label">Mostra</di>' +
|
|
55
|
-
'<div class="dt-control">_MENU_</div>' +
|
|
56
|
-
'<div>record per pagina</div>',
|
|
57
|
-
search:
|
|
58
|
-
'<div class="dt-control-label">Filtra risultati:</div>' +
|
|
59
|
-
'<div class="dt-control">_INPUT_</div>',
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
responsive : true,
|
|
63
|
-
stateSave : process.env.NODE_ENV === 'development',
|
|
64
|
-
stateDuration : -1, //sessionStorage
|
|
65
|
-
// columnDefs : [{
|
|
66
|
-
// orderable : true,
|
|
67
|
-
// targets : ['_all']
|
|
68
|
-
// }],
|
|
69
|
-
// ajax : null,
|
|
70
|
-
// order : [],
|
|
71
|
-
// columns : []
|
|
72
|
-
}, // end dt_options
|
|
73
|
-
|
|
74
|
-
default_cdt_options = {
|
|
75
|
-
|
|
76
|
-
icone: {
|
|
77
|
-
ok : `<svg class="icon text-success"><use href="${svg_icons}#check-circle-bold"></use></svg>`,
|
|
78
|
-
off : `<svg class="icon text-danger"><use href="${svg_icons}#x-circle-bold"></use></svg>`,
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
id_visible_default: true,
|
|
82
|
-
|
|
83
|
-
formats: {
|
|
84
|
-
decimals_class: 'data-dec',
|
|
85
|
-
euro_class: 'data-euro',
|
|
86
|
-
|
|
87
|
-
date: {
|
|
88
|
-
year: '2-digit',
|
|
89
|
-
month: 'short',
|
|
90
|
-
day: 'numeric'
|
|
91
|
-
},
|
|
92
|
-
time: {
|
|
93
|
-
hour12: false,
|
|
94
|
-
hour: '2-digit',
|
|
95
|
-
minute: '2-digit'
|
|
96
|
-
},
|
|
97
|
-
datetime: {
|
|
98
|
-
date: {
|
|
99
|
-
year: 'numeric',
|
|
100
|
-
month: 'short',
|
|
101
|
-
day: 'numeric'
|
|
102
|
-
},
|
|
103
|
-
time: {
|
|
104
|
-
hour12: false,
|
|
105
|
-
hour: '2-digit',
|
|
106
|
-
minute: '2-digit'
|
|
107
|
-
},
|
|
108
|
-
separator: ' ', // date-time separator
|
|
109
|
-
date_wrapper: '<span class="text-nowrap"></span>', // HTML string or null or ''
|
|
110
|
-
time_wrapper: '<small></small>' // HTML string or null or ''
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
use_sorting_arrow: false, // se true viene aggiunta al container la classe `w-arrow` che attiva la visualizzazione delle frecce dell'ordinamento
|
|
115
|
-
|
|
116
|
-
// container_header: '', //'Risultato della ricerca', // se presente aggiunge un header prima della tabella
|
|
117
|
-
|
|
118
|
-
// container_class: 'dt-container', // classe che viene assegnata al div che contiene la tabella
|
|
119
|
-
//container_header_level: 2, // livello gerarchico dell'header (h2, h3, ecc...)
|
|
120
|
-
// table_id: 'table_result',
|
|
121
|
-
table_class: 'table table-bordered'
|
|
122
|
-
//table_caption: '',
|
|
123
|
-
//table_footer: false, // se true aggiunge una riga tfoot alla tabella, da popolare con un callback
|
|
124
|
-
//extra_info:''
|
|
125
|
-
}
|
|
126
|
-
;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* _datatable
|
|
130
|
-
* crea e renderizza un datatable da un flusso json
|
|
131
|
-
*
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
export function _datatable(container, options = {}) {
|
|
135
|
-
|
|
136
|
-
options.dt_options = {...default_dt_options, ...(options.dt_options?? {}) };
|
|
137
|
-
options.cdt_options = {...default_cdt_options, ...(options.cdt_options?? {}) };
|
|
138
|
-
|
|
139
|
-
container.innerHTML = '<div class="datatable-spinner-wrapper">' +
|
|
140
|
-
spinner() +
|
|
141
|
-
'</div>';
|
|
142
|
-
|
|
143
|
-
creaDT(container, options.cdt_options, options.dt_options, options.dt_columns?? []);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
// utilizza _datatable per generare in modo automatico i datatable
|
|
148
|
-
// negli elementi con classe 'dt-container'
|
|
149
|
-
// i parametri datatable sono ricavati dagli attributi data di '.dt-container'
|
|
150
|
-
|
|
151
|
-
document.querySelectorAll('.dt-container').forEach(container => {
|
|
152
|
-
_datatable(container);
|
|
153
|
-
});
|
|
154
|
-
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { decodeBlurHash } from 'fast-blurhash';
|
|
2
|
-
|
|
3
|
-
// https://github.com/mad-gooze/fast-blurhash
|
|
4
|
-
// https://github.com/woltapp/blurhash/tree/master/TypeScript
|
|
5
|
-
// https://blurha.sh/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* restituisce un elemento canvas della stringa blurhash indicata
|
|
9
|
-
*
|
|
10
|
-
* @param {string} str - blurhash string
|
|
11
|
-
* @param {number} width
|
|
12
|
-
* @param {number} height
|
|
13
|
-
* @returns HTMLElement
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export function createBlurhashCanvas({str, width, height, className = null}) {
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
|
|
20
|
-
if(str && width && height) {
|
|
21
|
-
// decode blurHash image
|
|
22
|
-
const pixels = decodeBlurHash(str, width, height),
|
|
23
|
-
|
|
24
|
-
// draw it on canvas
|
|
25
|
-
canvas = document.createElement('canvas'),
|
|
26
|
-
ctx = canvas.getContext('2d'),
|
|
27
|
-
imageData = ctx.createImageData(width, height);
|
|
28
|
-
|
|
29
|
-
if(className) {
|
|
30
|
-
canvas.className = className;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
canvas.width = width;
|
|
34
|
-
canvas.height = height;
|
|
35
|
-
imageData.data.set(pixels);
|
|
36
|
-
ctx.putImageData(imageData, 0, 0);
|
|
37
|
-
|
|
38
|
-
return canvas;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
} catch(e) {
|
|
42
|
-
/* eslint-disable no-console */
|
|
43
|
-
console.error( e );
|
|
44
|
-
/* eslint-enable no-console */
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* minimo: img-viewer-dom-builder
|
|
3
|
-
* Produce un array da utilizzare con domBuilder per generare un tag `picture`
|
|
4
|
-
*
|
|
5
|
-
* @returns Array
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// TODO implementare getImgInfo (da ada)
|
|
9
|
-
// TODO detect se amabiente local per uso avif
|
|
10
|
-
|
|
11
|
-
/*
|
|
12
|
-
img_viewer_dom_builder({
|
|
13
|
-
viewer_url: 'iviewer',
|
|
14
|
-
sources: [
|
|
15
|
-
{
|
|
16
|
-
src: 'xxx',
|
|
17
|
-
crop: null, // 'x,y,w,h',
|
|
18
|
-
w: 100,
|
|
19
|
-
h: 100,
|
|
20
|
-
imgWidths: [100, 200, 300],
|
|
21
|
-
mq: null, // '(max-width: xxx)'
|
|
22
|
-
},
|
|
23
|
-
...
|
|
24
|
-
],
|
|
25
|
-
imgClassName: null,
|
|
26
|
-
// condition: true | false,
|
|
27
|
-
add2XWidths: false, // true,
|
|
28
|
-
alt_text: '',
|
|
29
|
-
useAvif: false | true,
|
|
30
|
-
// loadingMode: null | 'lazy' | 'eager'
|
|
31
|
-
})
|
|
32
|
-
*/
|
|
33
|
-
export function img_viewer_dom_builder({
|
|
34
|
-
/** url del viewer */
|
|
35
|
-
viewer_url,
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
array dei sorgenti
|
|
39
|
-
deve contenere almeno un oggetto configurato come `source_default`
|
|
40
|
-
l'ultimo oggetto della lista è quello sulla base el quale si costruirà il tag img
|
|
41
|
-
In mancanza di uno degli elementi richiesti (fatta eccezione per `mq` e `crop`),
|
|
42
|
-
il sorgente viene ignorato
|
|
43
|
-
*/
|
|
44
|
-
sources = [], // array dei sorgenti
|
|
45
|
-
|
|
46
|
-
/** se false, il markup non viene generato */
|
|
47
|
-
condition = true,
|
|
48
|
-
|
|
49
|
-
/** se true, alle dimensioni fornite, viene aggiunta la versione 2x */
|
|
50
|
-
add2XWidths = false,
|
|
51
|
-
|
|
52
|
-
/** testo alt */
|
|
53
|
-
alt_text = null,
|
|
54
|
-
|
|
55
|
-
/** classe del tag img */
|
|
56
|
-
imgClassName = null,
|
|
57
|
-
|
|
58
|
-
/** se true viene usato anche il formato avif, oltre a webp e jpg */
|
|
59
|
-
useAvif = false,
|
|
60
|
-
|
|
61
|
-
/** valore dell'attributo loading: eager o lazy */
|
|
62
|
-
loadingMode = null
|
|
63
|
-
}) {
|
|
64
|
-
|
|
65
|
-
if(!viewer_url || !condition) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const originalSourcesLength = (sources?? []).length,
|
|
70
|
-
source_default = {
|
|
71
|
-
id: null, // id per immagini da db
|
|
72
|
-
src: null, // percorso dalla root dell'immagine sorgente
|
|
73
|
-
crop: null, // eventuali coordinate per il crop dell'immagine sorgente
|
|
74
|
-
w: null, // larghezza e altezza dell'immagine da restituire
|
|
75
|
-
h: null,
|
|
76
|
-
imgWidths: [], // dimensioni dell'immagine
|
|
77
|
-
mq: null // media query, necessaria solo per gli oggetti prima dell'ultimo
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
sources = sources.map(item => {
|
|
81
|
-
item = {...source_default, ...item?? {}};
|
|
82
|
-
|
|
83
|
-
if((!item.src && !item.id) || !item.w || !item.h || !item.imgWidths?.length) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return item;
|
|
88
|
-
|
|
89
|
-
}).filter(result => result != null);
|
|
90
|
-
|
|
91
|
-
if(!sources.length || sources.length !== originalSourcesLength) {
|
|
92
|
-
// eslint-disable-next-line no-console
|
|
93
|
-
console.error('`sources` array error');
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// array per gli elementi <source>
|
|
98
|
-
const sourceTagsArray = [],
|
|
99
|
-
srcset_builder = (format, srcsetsArray) => {
|
|
100
|
-
return srcsetsArray.map(src => `${src[0]}${format? `&f=${format}` : ''} ${src[1]}`).join(',');
|
|
101
|
-
},
|
|
102
|
-
formats = (useAvif? ['avif','webp'] : ['webp']);
|
|
103
|
-
|
|
104
|
-
// sono definite fuori dal ciclo forEach perché saranno utilizzate anche dal tag img finale
|
|
105
|
-
let srcsetsArray, sizes;
|
|
106
|
-
|
|
107
|
-
// costruzione array `sourceTagsArray`
|
|
108
|
-
sources.forEach((item, sourceIdx) => {
|
|
109
|
-
|
|
110
|
-
item.imgWidths = item.imgWidths.map(w => add2XWidths? [w, w * 2] : w).flat().toSorted((a,b) => b - a);
|
|
111
|
-
|
|
112
|
-
const isLastSource = sourceIdx === sources.length - 1,
|
|
113
|
-
baseSrc = viewer_url + (item.src? `?src=${encodeURIComponent(item.src)}&` : `/${item.id}?`);
|
|
114
|
-
|
|
115
|
-
srcsetsArray = item.imgWidths.map(w =>{
|
|
116
|
-
const bbHeight = w / (item.w / item.h);
|
|
117
|
-
return [`${baseSrc}bb=${w}x${bbHeight}`, `${w}w`];
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
sizes = item.imgWidths.map((w,idx) => {
|
|
121
|
-
|
|
122
|
-
// la prima dimensione va ignorata (sarà utilizzata nell'iterazione successiva)
|
|
123
|
-
if(idx === 0) {
|
|
124
|
-
return null;
|
|
125
|
-
|
|
126
|
-
} else {
|
|
127
|
-
// elemento `sizes` diverso dal primo e dall'ultimo
|
|
128
|
-
const middle_size_mq = `(${w}px < width <= ${item.imgWidths.at(idx-1)}px) ${item.imgWidths.at(idx-1)}px`;
|
|
129
|
-
|
|
130
|
-
// primo elemento dell'attributo sizes
|
|
131
|
-
if(idx === 1) {
|
|
132
|
-
return `(width > ${w}px) ${item.imgWidths.at(0)}px`;
|
|
133
|
-
|
|
134
|
-
// ultimo
|
|
135
|
-
} else if(idx === item.imgWidths.length - 1) {
|
|
136
|
-
return [
|
|
137
|
-
middle_size_mq,
|
|
138
|
-
`${w}px`
|
|
139
|
-
];
|
|
140
|
-
|
|
141
|
-
// tutti gli altri
|
|
142
|
-
} else {
|
|
143
|
-
return middle_size_mq;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}).filter(s => s != null).flat().join(','); // rimuove elemento null, flat e crea stringa sizes
|
|
147
|
-
|
|
148
|
-
// il formato `null` è riferito a jpeg, che non è necessario indicare esplicitamente
|
|
149
|
-
// ed è utilizzato solo nel caso di presenza di media query per creare il tag source per il formato jpeg,
|
|
150
|
-
// non va inoltre considerato nell'ultimo elemento di source
|
|
151
|
-
// visto che, in questo caso, il formato jpeg viene gestito nel tag `img`
|
|
152
|
-
[...formats, ...(item.mq && !isLastSource? [null] : [])].forEach(format => {
|
|
153
|
-
sourceTagsArray.push({
|
|
154
|
-
tag: 'source',
|
|
155
|
-
attrs: {
|
|
156
|
-
type: format? `image/${format}` : null,
|
|
157
|
-
srcset: srcset_builder(format, srcsetsArray),
|
|
158
|
-
sizes: sizes,
|
|
159
|
-
media: item.mq,
|
|
160
|
-
|
|
161
|
-
// width e height sono necessarie solo in caso di presenza della media query
|
|
162
|
-
// presupponendo che in questi casi l'immagine abbia proporzioni diverse
|
|
163
|
-
// da quelle dell'immagine del tag `img`.
|
|
164
|
-
// In assenza di media query, vengono "ereditate" quelle indicate in `img`
|
|
165
|
-
width: item.mq? item.w : null,
|
|
166
|
-
height: item.mq? item.h : null,
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const img_source_obj = sources.at(-1);
|
|
174
|
-
|
|
175
|
-
return {
|
|
176
|
-
tag: 'picture',
|
|
177
|
-
condition: condition,
|
|
178
|
-
children: [
|
|
179
|
-
...sourceTagsArray,
|
|
180
|
-
{
|
|
181
|
-
tag: 'img',
|
|
182
|
-
className: imgClassName,
|
|
183
|
-
attrs: {
|
|
184
|
-
alt: alt_text,
|
|
185
|
-
width: img_source_obj.w,
|
|
186
|
-
height: img_source_obj.h,
|
|
187
|
-
srcset: srcset_builder(null, srcsetsArray),
|
|
188
|
-
sizes: sizes,
|
|
189
|
-
src: srcsetsArray.at(-1)[0],
|
|
190
|
-
loading: loadingMode,
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
]
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { mAlert } from './modal-alert.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
twig message labels:
|
|
6
|
-
- success
|
|
7
|
-
- notice
|
|
8
|
-
- error
|
|
9
|
-
- warning
|
|
10
|
-
*/
|
|
11
|
-
document.querySelectorAll('.flash-alert').forEach(item => {
|
|
12
|
-
|
|
13
|
-
mAlert({
|
|
14
|
-
// test
|
|
15
|
-
// type : 'confirm',
|
|
16
|
-
// timer: null,
|
|
17
|
-
|
|
18
|
-
type : item.dataset.label === 'notice'? 'warning' : item.dataset.label,
|
|
19
|
-
// title : item.message,
|
|
20
|
-
mes : item.dataset.message
|
|
21
|
-
// use_warning_icon: true, // solo confirm
|
|
22
|
-
// ok_btn_text: 'OK',
|
|
23
|
-
// cancel_btn_text: 'Annulla',
|
|
24
|
-
// callback: function(esito) {}, // confirm: console.log( esito? 'Confermato' : 'Annullato')
|
|
25
|
-
// timer: 4000 // ms
|
|
26
|
-
// extra_btn: '<button type="button" data-confirm-result="annulla" class="stop-btn btn btn-confirm">Annulla</button>',
|
|
27
|
-
// extra_btn_selector: '.stop-btn',
|
|
28
|
-
// extra_btn_focus: true,
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { domBuilder, classnames } from '@node_modules/@massimo-cassandro/js-utilities/index.js';
|
|
2
|
-
import { spinner } from '@minimo/spinner.js';
|
|
3
|
-
import * as styles from './modal-content.module.css?inline';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement
|
|
9
|
-
|
|
10
|
-
export function modalContent({
|
|
11
|
-
|
|
12
|
-
/** iframe | content */
|
|
13
|
-
mode = 'iframe',
|
|
14
|
-
|
|
15
|
-
/** dialog extra class */
|
|
16
|
-
dialogClassName = null,
|
|
17
|
-
|
|
18
|
-
/** iframe url */
|
|
19
|
-
iframeUrl = null,
|
|
20
|
-
|
|
21
|
-
/** content string (markup) o array */
|
|
22
|
-
content = null,
|
|
23
|
-
|
|
24
|
-
/** content extra classname */
|
|
25
|
-
contentClassName = null,
|
|
26
|
-
|
|
27
|
-
/** dimensione modal: full, large, medium o small */
|
|
28
|
-
size = 'large',
|
|
29
|
-
|
|
30
|
-
/** padding: std (var(--size-md) 0) o none */
|
|
31
|
-
padding = 'std'
|
|
32
|
-
}) {
|
|
33
|
-
|
|
34
|
-
if(!['content', 'iframe'].includes(mode)) {
|
|
35
|
-
throw `modalContent: parametro 'mode' non corretto (${mode})`;
|
|
36
|
-
}
|
|
37
|
-
if(!iframeUrl && mode === 'iframe') {
|
|
38
|
-
throw 'modalContent: parametro `iframeUrl` mancante';
|
|
39
|
-
}
|
|
40
|
-
if(content == null && mode === 'content') {
|
|
41
|
-
throw 'modalContent: parametro `content` mancante';
|
|
42
|
-
}
|
|
43
|
-
if(!['full', 'large', 'medium', 'small'].includes(size)) {
|
|
44
|
-
throw `modalContent: parametro 'size' non corretto (${size})`;
|
|
45
|
-
}
|
|
46
|
-
if(!['std', 'none'].includes(padding)) {
|
|
47
|
-
throw `modalContent: parametro 'padding' non corretto (${padding})`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
let dialog_element, dialog_inner, iframe_element = null, content_element = null;
|
|
51
|
-
const iframeLoadEventHandler = () => {
|
|
52
|
-
dialog_element.classList.add(styles.on);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
if(!dialog_element) {
|
|
56
|
-
|
|
57
|
-
domBuilder([
|
|
58
|
-
{
|
|
59
|
-
tag: 'dialog',
|
|
60
|
-
className: styles.dialog,
|
|
61
|
-
attrs: {
|
|
62
|
-
'closedby': 'any'
|
|
63
|
-
},
|
|
64
|
-
children: [
|
|
65
|
-
{
|
|
66
|
-
tag: 'button',
|
|
67
|
-
className: styles.closeButton, // TODO standardizzare close btn
|
|
68
|
-
attrs: {
|
|
69
|
-
'aria-label': 'Chiudi'
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
className: styles.dialogInner,
|
|
74
|
-
children: [
|
|
75
|
-
{
|
|
76
|
-
className: styles.modalSpinner,
|
|
77
|
-
content: spinner({container: null, withOverlay: false })
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
]
|
|
81
|
-
}
|
|
82
|
-
]
|
|
83
|
-
}
|
|
84
|
-
], document.body);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
dialog_element = document.querySelector(`.${styles.dialog}`);
|
|
88
|
-
dialog_inner = dialog_element.querySelector(`.${styles.dialogInner}`);
|
|
89
|
-
|
|
90
|
-
dialog_element.querySelector(`.${styles.closeButton}`).addEventListener('click', () => {
|
|
91
|
-
dialog_element.close();
|
|
92
|
-
}, false);
|
|
93
|
-
|
|
94
|
-
// listener chiusura
|
|
95
|
-
dialog_element.addEventListener('close', () => {
|
|
96
|
-
|
|
97
|
-
iframe_element?.removeEventListener('load', iframeLoadEventHandler, false);
|
|
98
|
-
iframe_element?.remove();
|
|
99
|
-
content_element?.remove();
|
|
100
|
-
|
|
101
|
-
document.body.classList.remove('overflow-hidden');
|
|
102
|
-
dialog_element.classList.remove(styles.on);
|
|
103
|
-
}, false);
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// aggiunta classi extra
|
|
109
|
-
dialog_element.className = classnames(
|
|
110
|
-
styles.dialog,
|
|
111
|
-
dialogClassName,
|
|
112
|
-
styles[`size-${size}`],
|
|
113
|
-
styles[`padding-${padding}`]
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
domBuilder([
|
|
117
|
-
{
|
|
118
|
-
condition: mode === 'iframe',
|
|
119
|
-
className: styles.iframeEl,
|
|
120
|
-
tag: 'iframe',
|
|
121
|
-
attrs: {
|
|
122
|
-
src: ''
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
condition: mode === 'content',
|
|
127
|
-
className: classnames(styles.contentEl, contentClassName),
|
|
128
|
-
content: (content && !Array.isArray(content))? content : null,
|
|
129
|
-
children: (content && Array.isArray(content))? content : null
|
|
130
|
-
}
|
|
131
|
-
], dialog_inner);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
document.body.classList.add('overflow-hidden');
|
|
135
|
-
dialog_element.showModal();
|
|
136
|
-
dialog_element.focus();
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if(mode === 'iframe') {
|
|
140
|
-
iframe_element = dialog_element.querySelector(`.${styles.iframeEl}`);
|
|
141
|
-
iframe_element.src = iframeUrl;
|
|
142
|
-
|
|
143
|
-
// listener load per i frame
|
|
144
|
-
iframe_element?.addEventListener('load', iframeLoadEventHandler, false);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
} else if (mode === 'content') {
|
|
148
|
-
content_element = dialog_element.querySelector(`.${styles.contentEl}`);
|
|
149
|
-
dialog_element.classList.add(styles.on);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
}
|