@massimo-cassandro/minimo 1.5.1 → 1.5.3

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/index.js CHANGED
@@ -5,6 +5,7 @@ export { domBuilder } from './src/utilities/dom-builder/dom-builder.js';
5
5
  export { enableSubmitBtns } from './src/utilities/enable-submit-btns.js';
6
6
  export { titleCase } from './src/utilities/title-case.js';
7
7
  export { sentenceCase } from './src/utilities/sentence-case.js';
8
+ export { escapeHTML, unescapeHTML } from './src/utilities/escapeHTML.js';
8
9
  export { ValidationError } from './src/utilities/validation-error-class.js';
9
10
 
10
11
  // components
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massimo-cassandro/minimo",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "Light css framework & utilities",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/massimo-cassandro/minimo#readme",
@@ -0,0 +1,18 @@
1
+ const characters_to_escape = {
2
+ '&': '&',
3
+ '"': '"',
4
+ '\'': ''',
5
+ '<': '&lt;',
6
+ '>': '&gt;'
7
+ };
8
+ export function escapeHTML(str) {
9
+ const regexp = new RegExp(`[${Object.keys(characters_to_escape).join('')}]`, 'g');
10
+ return str?.replace(regexp, m => characters_to_escape[m])?? '';
11
+ }
12
+
13
+ export function unescapeHTML(str) {
14
+ const regexp = new RegExp(Object.values(characters_to_escape).join('|'), 'g'),
15
+ entities_to_unescape = Object.fromEntries(Object.entries(characters_to_escape).map(a => a.reverse()));
16
+
17
+ return str?.replace(regexp, m => entities_to_unescape[m] )?? '';
18
+ }
@@ -146,7 +146,9 @@ function getNestedValue(obj, path) {
146
146
  * resolveTemplate
147
147
  *
148
148
  * Risolve un template in base al suo tipo:
149
- * - Funzione: invocata con `row`, deve restituire una stringa.
149
+ * - Elemento DOM: restituisce `outerHTML` dell'elemento.
150
+ * - Funzione: invocata con `row`, può restituire una stringa o un elemento DOM
151
+ * (in tal caso viene serializzato con `outerHTML`).
150
152
  * - Stringa mustache-like ([[key]]): i segnaposto vengono sostituiti con i
151
153
  * valori corrispondenti dell'oggetto riga.
152
154
  * - Stringa semplice: restituita così com'è (utile per tooltip statici).
@@ -155,7 +157,7 @@ function getNestedValue(obj, path) {
155
157
  * comunque chiamate con null; la stringa mustache-like viene restituita
156
158
  * letteralmente perché non ci sono dati da interpolare.
157
159
  *
158
- * @param {string|Function} tpl Template da risolvere.
160
+ * @param {string|Function|Node} tpl Template da risolvere.
159
161
  * @param {object|null} row Oggetto riga corrente (null per le intestazioni).
160
162
  * @param {object} [opts] Opzioni aggiuntive.
161
163
  * @param {string} [opts.nullAs] Stringa da usare come fallback per i segnaposto
@@ -169,8 +171,14 @@ function getNestedValue(obj, path) {
169
171
  function resolveTemplate(tpl, row, { nullAs = '', warnColIdx } = {}) {
170
172
  if (!tpl) return null;
171
173
 
174
+ if (tpl instanceof Node) {
175
+ return tpl.outerHTML;
176
+ }
177
+
172
178
  if (typeof tpl === 'function') {
173
- return tpl(row) ?? null;
179
+ const result = tpl(row);
180
+ if (result instanceof Node) return result.outerHTML;
181
+ return result ?? null;
174
182
  }
175
183
 
176
184
  // Stringa mustache-like: interpola solo se row è disponibile
@@ -591,7 +599,8 @@ class SimpleDatatableAdapter extends HTMLElement {
591
599
 
592
600
 
593
601
  // _cellRender: template per il rendering del valore.
594
- // Accetta stringa mustache-like ([[key]]) o funzione (row) => string.
602
+ // Accetta stringa mustache-like ([[key]]), funzione (row) => string|Node,
603
+ // oppure un elemento DOM direttamente (serializzato via outerHTML).
595
604
  // Delega a resolveTemplate, passando nullAs e l'indice di colonna
596
605
  // per i warning di chiavi mancanti.
597
606
  if (col_item._cellRender) {
@@ -605,7 +614,7 @@ class SimpleDatatableAdapter extends HTMLElement {
605
614
  }
606
615
 
607
616
  // TODO rendere più snella la gestione di questi casi (???)
608
- // TODO pasare il valore `nullAs` al render predefinito
617
+ // TODO passare il valore `nullAs` al render predefinito
609
618
  // Applica _renderNullAs al valore della cella se null/undefined
610
619
  // e la cella non ha già un template che gestisce la visualizzazione.
611
620
  // se _renderMode è impostato, il valore null è gestito direttamente dal gestore predefinito