@massimo-cassandro/minimo 1.28.1 → 1.28.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massimo-cassandro/minimo",
3
- "version": "1.28.1",
3
+ "version": "1.28.3",
4
4
  "description": "Light css framework & utilities",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -16,7 +16,7 @@ import './sf-macro.css';
16
16
  * @param {string} [options.addBtnClass='sf-macro-riga-add'] - Class name of the row-add button. (default: 'sf-macro-riga-add')
17
17
  * @param {string} [options.containerClass='sf-macro-container'] - Class name of the rows container. (default: 'sf-macro-container')
18
18
  * @param {((newRow: Element | null, addBtn: Element | null) => void) | null} [options.add_callback=null] - Called after a row is added; receives the new row and the add button. (default: null)
19
- * @param {((row: Element | null, closeBtn: Element | null) => boolean) | null} [options.preDelCallback=null] - Called when the row-remove button is pressed, before the row is removed; receives the row and the close button; if it returns false, the removal is aborted. (default: null)
19
+ * @param {((row: Element | null, closeBtn: Element | null) => boolean | Promise<boolean>) | null} [options.preDelCallback=null] - Called when the row-remove button is pressed, before the row is removed; receives the row and the close button. May return a Promise (e.g. to await a confirm dialog): the row is removed only if the resolved value is not `false`. (default: null)
20
20
  * @param {((row: Element | null, closeBtn: Element | null) => void) | null} [options.del_callback=null] - Called after a row is removed; receives the removed row (now detached) and the close button. (default: null)
21
21
  * @param {boolean} [options.insertAtTop=false] - When true, new rows are inserted at the top. (default: false)
22
22
  * @returns {void}
@@ -78,15 +78,33 @@ export function sf_macro({
78
78
  } else {
79
79
  const riga = target.closest(row_selector);
80
80
 
81
- if(preDelCallback && typeof preDelCallback === 'function' && preDelCallback(riga, action_btn) === false) {
82
- return;
83
- }
81
+ const remove_row = () => {
82
+ riga?.remove();
83
+
84
+ if(del_callback && typeof del_callback === 'function') {
85
+ del_callback(riga, action_btn);
86
+ }
87
+ };
84
88
 
85
- riga?.remove();
89
+ if(preDelCallback && typeof preDelCallback === 'function') {
90
+ const pre_del_result = preDelCallback(riga, action_btn);
86
91
 
87
- if(del_callback && typeof del_callback === 'function') {
88
- del_callback(riga, action_btn);
92
+ // Supports both a sync boolean and an async (Promise-returning)
93
+ // preDelCallback (e.g. awaiting a confirm dialog) without requiring
94
+ // the caller to manage the row removal itself.
95
+ if(pre_del_result instanceof Promise) {
96
+ pre_del_result.then(ok => {
97
+ if(ok !== false) remove_row();
98
+ });
99
+ return;
100
+ }
101
+
102
+ if(pre_del_result === false) {
103
+ return;
104
+ }
89
105
  }
106
+
107
+ remove_row();
90
108
  }
91
109
 
92
110
  }, false);
@@ -39,6 +39,11 @@
39
39
  color: var(--form-label-color);
40
40
  }
41
41
 
42
+ /* per uso label implicito, senza id e for */
43
+ label:has(.form-control) {
44
+ display: block;
45
+ width: 100%;
46
+ }
42
47
 
43
48
  .form-control, .form-control-static {
44
49
  display: block;