@massimo-cassandro/minimo 1.27.0 → 1.27.2
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
|
@@ -19,41 +19,52 @@ export function sf_macro({
|
|
|
19
19
|
insertAtTop = false
|
|
20
20
|
}={}) {
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
// Single delegated listener: resolves the nearest wrapper_selector ancestor
|
|
23
|
+
// of the click target at click time, instead of binding one listener per
|
|
24
|
+
// wrapper found at init time. This is required for wrapper_selector to be
|
|
25
|
+
// shared by nested wrapper instances (the nearest one always wins, with no
|
|
26
|
+
// propagation to outer ones) and to work on wrappers created dynamically
|
|
27
|
+
// after this call (e.g. a nested wrapper inside a newly added row), which
|
|
28
|
+
// would otherwise never get their own listener.
|
|
29
|
+
document.addEventListener('click', e => {
|
|
30
|
+
const target = /** @type {HTMLElement} */ (e.target);
|
|
31
|
+
|
|
32
|
+
const action_btn = /** @type {HTMLElement | null} */ (
|
|
33
|
+
target.closest('.sf-macro-riga-add, .sf-macro-close-btn')
|
|
34
|
+
);
|
|
35
|
+
if (!action_btn) return;
|
|
36
|
+
|
|
37
|
+
const fset = /** @type {HTMLElement | null} */ (target.closest(wrapper_selector));
|
|
38
|
+
if (!fset) return;
|
|
39
|
+
|
|
23
40
|
const macro_container = /** @type {HTMLElement | null} */ (fset.querySelector('.sf-macro-container'));
|
|
24
41
|
if (!macro_container) return;
|
|
25
|
-
const macro_template = macro_container.dataset.template ?? '';
|
|
26
42
|
|
|
27
|
-
|
|
28
|
-
fset.addEventListener('click', e => {
|
|
29
|
-
const target = /** @type {HTMLElement} */ (e.target);
|
|
43
|
+
if(action_btn.matches('.sf-macro-riga-add')) {
|
|
30
44
|
|
|
31
|
-
|
|
45
|
+
const macro_template = macro_container.dataset.template ?? '';
|
|
46
|
+
const righe_macro = macro_container.querySelectorAll(row_selector).length;
|
|
32
47
|
|
|
33
|
-
|
|
48
|
+
macro_container.insertAdjacentHTML(insertAtTop? 'afterbegin' : 'beforeend',
|
|
49
|
+
macro_template.replace(/__indice\d?__/g, String(righe_macro + 1))
|
|
50
|
+
);
|
|
34
51
|
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
if(add_callback && typeof add_callback === 'function') {
|
|
53
|
+
add_callback(
|
|
54
|
+
insertAtTop
|
|
55
|
+
? macro_container.querySelector(`${row_selector}:first-child`)
|
|
56
|
+
: macro_container.querySelector(`${row_selector}:last-child`),
|
|
57
|
+
action_btn
|
|
37
58
|
);
|
|
59
|
+
}
|
|
38
60
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
insertAtTop
|
|
42
|
-
? macro_container.querySelector('.sf-macro-riga:first-child')
|
|
43
|
-
: macro_container.querySelector('.sf-macro-riga:last-child'),
|
|
44
|
-
target.closest('.sf-macro-riga-add')
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} else if(target.closest('.sf-macro-close-btn')) {
|
|
50
|
-
target.closest(row_selector)?.remove();
|
|
61
|
+
} else {
|
|
62
|
+
target.closest(row_selector)?.remove();
|
|
51
63
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
64
|
+
if(del_callback && typeof del_callback === 'function') {
|
|
65
|
+
del_callback();
|
|
55
66
|
}
|
|
67
|
+
}
|
|
56
68
|
|
|
57
|
-
|
|
58
|
-
});
|
|
69
|
+
}, false);
|
|
59
70
|
}
|
|
@@ -409,7 +409,6 @@ export function buildFakeField({
|
|
|
409
409
|
* domBuilder items is passed, it is rendered via `children` instead of `content`.
|
|
410
410
|
* @param {string} [args.type=button] - button type.
|
|
411
411
|
* @param {string | null} args.id - `id` attribute.
|
|
412
|
-
* @param {string | number | null} [args.value=null] - button `value` attribute.
|
|
413
412
|
* @param {string | null} [args.class=null] - optional class to be added to the button element.
|
|
414
413
|
* @param {string | null} [args.classname=null] - Alias for `class`.
|
|
415
414
|
* @param {string | null} [args.className=null] - Alias for `class`.
|
|
@@ -422,7 +421,6 @@ export function buildButton({
|
|
|
422
421
|
content,
|
|
423
422
|
type = 'button',
|
|
424
423
|
id = null,
|
|
425
|
-
value = null,
|
|
426
424
|
class: classArg = null,
|
|
427
425
|
classname: classnameArg = null,
|
|
428
426
|
className: classNameArg = null,
|
|
@@ -440,8 +438,7 @@ export function buildButton({
|
|
|
440
438
|
id: id,
|
|
441
439
|
attrs: {
|
|
442
440
|
...(attrs??{}),
|
|
443
|
-
type: type
|
|
444
|
-
value: value
|
|
441
|
+
type: type
|
|
445
442
|
},
|
|
446
443
|
...(Array.isArray(content)
|
|
447
444
|
? { children: content }
|