@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
|
@@ -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
|
|
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
|
-
|
|
82
|
-
|
|
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
|
-
|
|
89
|
+
if(preDelCallback && typeof preDelCallback === 'function') {
|
|
90
|
+
const pre_del_result = preDelCallback(riga, action_btn);
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
|
|
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);
|
package/src/css/forms/forms.css
CHANGED