@italia/modal 1.0.0-alpha.17 → 1.0.0-alpha.19
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/custom-elements.json +16 -14
- package/dist/src/index.js.map +1 -1
- package/dist/src/it-modal.d.ts.map +1 -1
- package/dist/src/it-modal.js +154 -13
- package/dist/src/it-modal.js.map +1 -1
- package/dist/src/types.d.ts +5 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +6 -6
package/custom-elements.json
CHANGED
|
@@ -530,20 +530,6 @@
|
|
|
530
530
|
"privacy": "private"
|
|
531
531
|
}
|
|
532
532
|
],
|
|
533
|
-
"events": [
|
|
534
|
-
{
|
|
535
|
-
"name": "it-modal-open",
|
|
536
|
-
"type": {
|
|
537
|
-
"text": "CustomEvent"
|
|
538
|
-
}
|
|
539
|
-
},
|
|
540
|
-
{
|
|
541
|
-
"name": "it-modal-close",
|
|
542
|
-
"type": {
|
|
543
|
-
"text": "CustomEvent"
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
],
|
|
547
533
|
"attributes": [
|
|
548
534
|
{
|
|
549
535
|
"name": "open",
|
|
@@ -883,6 +869,14 @@
|
|
|
883
869
|
"text": "Story"
|
|
884
870
|
},
|
|
885
871
|
"default": "{ name: 'Attivazione manuale via JS', decorators: [ (story) => html` <div style=\"display:flex; height:100%; align-items:center; gap:2rem;\">${story()}</div> `, ], parameters: { docs: { source: { excludeDecorators: true, code: ` <it-modal disable-animation close-label=\"Chiudi finestra modale\"> <it-button slot=\"trigger\" variant=\"primary\">Modale con apertura manuale (show)</it-button> <span slot=\"header\">Modale con apertura manuale</span> <p slot=\"content\">Questa modale appare immediatamente senza animazione di dissolvenza.</p> <it-button slot=\"footer\" variant=\"outline-primary\">Annulla</it-button> <it-button slot=\"footer\" variant=\"primary\">Conferma</it-button> </it-modal> <it-modal disable-animation close-label=\"Chiudi finestra modale\"> <it-button slot=\"trigger\" variant=\"primary\">Modale con apertura manuale (toggle)</it-button > <span slot=\"header\">Modale con toggle manuale</span> <p slot=\"content\">Questa modale appare immediatamente senza animazione di dissolvenza.</p> <it-button slot=\"footer\" variant=\"outline-primary\">Annulla</it-button> <it-button slot=\"footer\" variant=\"primary\">Conferma</it-button> </it-modal> <script> // Script di esempio per mostrare come attivare la modale via JS utilizzando i metodi show(), hide() e toggle() const modals = document.querySelectorAll('it-modal'); const [modalShow, modalToggle] = modals; const openModal = (event) => { const el = event.currentTarget; const modal = el.closest('it-modal'); console.log('openModal -> modal', modal); modal?.show(); }; const closeModal = (event) => { const el = event.currentTarget; const modal = el.closest('it-modal'); console.log('closeModal -> modal', modal); modal?.hide(); }; const toggleModal = (event) => { const el = event.currentTarget; const modal = el.closest('it-modal'); console.log('toggleModal -> modal', modal); modal?.toggle(); }; // Assegna gli event listener ai bottoni di trigger e footer modalShow.querySelector('[slot=\"trigger\"]').addEventListener('click', openModal); modalShow.querySelectorAll('[slot=\"footer\"] it-button').forEach((btn) => btn.addEventListener('click', closeModal)); modalToggle.querySelector('[slot=\"trigger\"]').addEventListener('click', toggleModal); modalToggle.querySelectorAll('[slot=\"footer\"] it-button').forEach((btn) => btn.addEventListener('click', toggleModal)); </script> `, }, }, }, render: () => html` <it-modal disable-animation close-label=\"Chiudi finestra modale\"> <it-button slot=\"trigger\" variant=\"primary\" @click=\"${openModal}\">Modale con apertura manuale (show)</it-button> <span slot=\"header\">Modale con apertura manuale</span> <p slot=\"content\">Questa modale appare immediatamente senza animazione di dissolvenza.</p> <it-button slot=\"footer\" variant=\"outline-primary\" @click=\"${closeModal}\">Annulla</it-button> <it-button slot=\"footer\" variant=\"primary\" @click=\"${closeModal}\">Conferma</it-button> </it-modal> <it-modal disable-animation close-label=\"Chiudi finestra modale\"> <it-button slot=\"trigger\" variant=\"primary\" @click=\"${toggleModal}\" >Modale con apertura manuale (toggle)</it-button > <span slot=\"header\">Modale con toggle manuale</span> <p slot=\"content\">Questa modale appare immediatamente senza animazione di dissolvenza.</p> <it-button slot=\"footer\" variant=\"outline-primary\" @click=\"${toggleModal}\">Annulla</it-button> <it-button slot=\"footer\" variant=\"primary\" @click=\"${toggleModal}\">Conferma</it-button> </it-modal> `, }"
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
"kind": "variable",
|
|
875
|
+
"name": "ChiusuraConConferma",
|
|
876
|
+
"type": {
|
|
877
|
+
"text": "Story"
|
|
878
|
+
},
|
|
879
|
+
"default": "{ name: 'Chiusura con logica personalizzata', parameters: { docs: { description: { story: `L'evento \\`it-modal-close\\` è **cancelable**. Chiamando \\`event.preventDefault()\\` puoi intercettare la chiusura, eseguire una logica personalizzata — in questo esempio viene mostrato un messaggio informativo — e poi richiamare \\`hide()\\` per chiudere effettivamente la modale. Lo stesso schema si applica a \\`it-modal-open\\`.`, }, source: { code: `<it-modal id=\"modal-custom-close\"> <it-button variant=\"primary\" slot=\"trigger\">Apri modale</it-button> <span slot=\"header\">Chiusura con logica personalizzata</span> <p slot=\"content\">Prova a chiudere la modale: verrà eseguita una logica personalizzata prima della chiusura effettiva.</p> <it-button slot=\"footer\" variant=\"primary\" id=\"modal-custom-close-footer\">Chiudi</it-button> </it-modal> <div id=\"modal-close-alert\" class=\"alert alert-info\" role=\"alert\" style=\"display:none\"> <strong>Operazione completata.</strong> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </div> <script type=\"module\"> const modal = document.getElementById('modal-custom-close'); const alertEl = document.getElementById('modal-close-alert'); let _closing = false; modal.addEventListener('it-modal-close', (e) => { if (_closing) return; e.preventDefault(); alertEl.style.display = ''; _closing = true; modal.hide(); _closing = false; }); document.getElementById('modal-custom-close-footer') ?.addEventListener('click', () => modal.hide()); </script>`, }, }, }, render: () => { let _closing = false; return html` <it-modal id=\"modal-custom-close\" @it-modal-close=${(e: Event) => { if (_closing) return; e.preventDefault(); const alertEl = document.getElementById('modal-close-alert'); if (alertEl) alertEl.style.display = ''; _closing = true; (e.currentTarget as HTMLElement & { hide(): void }).hide(); _closing = false; }} > <it-button variant=\"primary\" slot=\"trigger\">Apri modale</it-button> <span slot=\"header\">Chiusura con logica personalizzata</span> <p slot=\"content\"> Prova a chiudere la modale: verrà eseguita una logica personalizzata prima della chiusura effettiva. </p> <it-button slot=\"footer\" variant=\"primary\" @click=${(e: Event) => { (e.currentTarget as HTMLElement).closest<HTMLElement & { hide(): void }>('it-modal')?.hide(); }} >Chiudi</it-button > </it-modal> <div id=\"modal-close-alert\" class=\"alert alert-info\" role=\"alert\" style=\"display:none\"> <strong>Operazione completata.</strong> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </div> `; }, }"
|
|
886
880
|
}
|
|
887
881
|
],
|
|
888
882
|
"exports": [
|
|
@@ -1021,6 +1015,14 @@
|
|
|
1021
1015
|
"name": "AttivazioneViaJS",
|
|
1022
1016
|
"module": "stories/it-modal.stories.ts"
|
|
1023
1017
|
}
|
|
1018
|
+
},
|
|
1019
|
+
{
|
|
1020
|
+
"kind": "js",
|
|
1021
|
+
"name": "ChiusuraConConferma",
|
|
1022
|
+
"declaration": {
|
|
1023
|
+
"name": "ChiusuraConConferma",
|
|
1024
|
+
"module": "stories/it-modal.stories.ts"
|
|
1025
|
+
}
|
|
1024
1026
|
}
|
|
1025
1027
|
]
|
|
1026
1028
|
}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/types.ts"],"sourcesContent":["export const MODAL_SIZES = ['sm', 'lg', 'xl'] as const;\nexport const MODAL_POSITIONS = ['center', 'left', 'right'] as const;\nexport const MODAL_VARIANTS = ['alert', 'popconfirm', 'link-list'] as const;\n\nexport type ModalSize = (typeof MODAL_SIZES)[number] | '';\nexport type ModalPosition = (typeof MODAL_POSITIONS)[number];\nexport type ModalVariant = (typeof MODAL_VARIANTS)[number];\n\nexport interface ModalEventDetail {\n /** Riferimento all'elemento modale */\n modal: HTMLElement;\n}\n"],"names":[],"mappings":";;;;;;;AAAO,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI;AACrC,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO;AAClD,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/types.ts"],"sourcesContent":["export const MODAL_SIZES = ['sm', 'lg', 'xl'] as const;\nexport const MODAL_POSITIONS = ['center', 'left', 'right'] as const;\nexport const MODAL_VARIANTS = ['alert', 'popconfirm', 'link-list'] as const;\n\nexport type ModalSize = (typeof MODAL_SIZES)[number] | '';\nexport type ModalPosition = (typeof MODAL_POSITIONS)[number];\nexport type ModalVariant = (typeof MODAL_VARIANTS)[number];\n\n/**\n * Detail degli eventi `it-modal-open` / `it-modal-close`.\n * Entrambi gli eventi sono cancelable: `event.preventDefault()` impedisce\n * rispettivamente l'apertura e la chiusura della modale.\n */\nexport interface ModalEventDetail {\n /** Riferimento all'elemento modale */\n modal: HTMLElement;\n}\n"],"names":[],"mappings":";;;;;;;AAAO,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI;AACrC,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO;AAClD,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"it-modal.d.ts","sourceRoot":"","sources":["../../src/it-modal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"it-modal.d.ts","sourceRoot":"","sources":["../../src/it-modal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAA0D,MAAM,iBAAiB,CAAC;AACxG,OAAO,EAAQ,cAAc,EAAE,MAAM,KAAK,CAAC;AAI3C,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAyB,MAAM,YAAY,CAAC;AAqB1G,qBACa,OAAQ,SAAQ,aAAa;IACxC,MAAM,CAAC,MAAM,+BAAU;IAEvB,OAAgB,iBAAiB;;;;;;;MAAgE;IAErD,IAAI,EAAE,OAAO,GAAG,SAAS,CAAa;IAEb,UAAU,SAAM;IAEV,gBAAgB,SAAM;IAEzB,YAAY,UAAS;IAElD,IAAI,EAAE,SAAS,CAAM;IAErB,QAAQ,CAAC,EAAE,aAAa,CAAC;IAExB,UAAU,UAAS;IAEW,cAAc,UAAS;IAErB,eAAe,UAAS;IAEpB,oBAAoB,EAChG,QAAQ,GACR,UAAU,CAAY;IAEiB,OAAO,CAAC,EAAE,YAAY,CAAC;IAEV,WAAW,SAAM;IAEJ,UAAU,SAAM;IAET,gBAAgB,UAAS;IAE7B,YAAY,UAAS;IAEnE,OAAO,CAAC,aAAa,CAAe;IAE/B,OAAO,CAAC,YAAY,CAAmB;IAExC,OAAO,CAAC,WAAW,CAAmB;IAEjC,OAAO,CAAC,gBAAgB,CAAmB;IAEpD,OAAO,CAAC,gBAAgB,CAAe;IAEzC,OAAO,CAAC,cAAc,CAAe;IAE7D,OAAO,CAAC,QAAQ,CAAM;IAEtB,OAAO,CAAC,UAAU,CAAM;IAExB,OAAO,CAAC,cAAc,CAAM;IAE5B,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,cAAc,CAAS;IAE/B,OAAO,CAAC,gBAAgB,CAA4B;IAGpD,OAAO,CAAC,uBAAuB,CAAS;IAExC,OAAO,CAAC,gBAAgB,CAAC,CAAY;IAErC,OAAO,CAAC,kBAAkB,CAAC,CAAY;IAEvC,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAO;IAEhD,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAO;IAElD,OAAO,CAAC,cAAc,CAAqB;IAE3C,OAAO,CAAC,qBAAqB,CAAuB;IAEpD;yFACqF;IACrF,OAAO,CAAC,kBAAkB,CAA8C;IAExE,OAAO,CAAC,UAAU,CAAsB;IAExC,IAAI,eAAe,IAAI,WAAW,GAAG,IAAI,CAGxC;;IAkBD,iBAAiB,IAAI,IAAI;IAIzB,oBAAoB,IAAI,IAAI;IAYrB,IAAI,IAAI,IAAI;IAWZ,IAAI,IAAI,IAAI;IASZ,MAAM,IAAI,IAAI;IAQrB,SAAS,CAAC,OAAO,CAAC,iBAAiB,EAAE,cAAc,GAAG,IAAI;IA6B1D,OAAO,CAAC,WAAW;IAiCnB,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,kBAAkB,CAQxB;IAEF,OAAO,CAAC,oBAAoB,CAI1B;YAEY,UAAU;IAoExB,OAAO,CAAC,UAAU;IAuFlB,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,oBAAoB,CAE1B;IAEF,OAAO,CAAC,mBAAmB,CAEzB;IAEF,OAAO,CAAC,sBAAsB;IAc9B,OAAO,CAAC,uBAAuB;IAQ/B,OAAO,CAAC,eAAe,CASrB;IAEF,OAAO,CAAC,iBAAiB,CAYvB;IAEF,OAAO,KAAK,aAAa,GAUxB;IAED,OAAO,KAAK,iBAAiB,GAW5B;IAED,OAAO,CAAC,kBAAkB;IAkB1B,MAAM;CAwEP"}
|
package/dist/src/it-modal.js
CHANGED
|
@@ -37,14 +37,80 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
37
37
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
const ARIA_IDREF_ATTRIBUTES = new Map([
|
|
41
|
+
['aria-activedescendant', 'ariaActivedescendantElement'],
|
|
42
|
+
['aria-controls', 'ariaControlsElements'],
|
|
43
|
+
['aria-describedby', 'ariaDescribedByElements'],
|
|
44
|
+
['aria-details', 'ariaDetailsElements'],
|
|
45
|
+
['aria-errormessage', 'ariaErrormessageElements'],
|
|
46
|
+
['aria-flowto', 'ariaFlowtoElements'],
|
|
47
|
+
['aria-labelledby', 'ariaLabelledByElements'],
|
|
48
|
+
['aria-owns', 'ariaOwnsElements'],
|
|
49
|
+
]);
|
|
50
|
+
function resolveAriaIdRefs(element, value) {
|
|
51
|
+
const ids = value
|
|
52
|
+
.trim()
|
|
53
|
+
.split(/\s+/)
|
|
54
|
+
.filter((id) => id.length > 0);
|
|
55
|
+
if (ids.length === 0)
|
|
56
|
+
return null;
|
|
57
|
+
const root = element.getRootNode();
|
|
58
|
+
let resolvedElements = [];
|
|
59
|
+
if (root instanceof ShadowRoot) {
|
|
60
|
+
resolvedElements = ids.map((id) => root.getElementById(id));
|
|
61
|
+
}
|
|
62
|
+
else if (root instanceof Document) {
|
|
63
|
+
resolvedElements = ids.map((id) => root.getElementById(id));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
resolvedElements = ids.map((id) => document.getElementById(id));
|
|
67
|
+
}
|
|
68
|
+
if (resolvedElements.filter((el) => el !== null).length === 0) {
|
|
69
|
+
resolvedElements = ids.map((id) => document.getElementById(id));
|
|
70
|
+
}
|
|
71
|
+
const validElements = resolvedElements.filter((el) => el !== null);
|
|
72
|
+
return validElements.length === ids.length ? validElements : null;
|
|
73
|
+
}
|
|
74
|
+
function setInternalsProperty(el, name, resolvedElements) {
|
|
75
|
+
if (name === 'aria-activedescendant') {
|
|
76
|
+
const [firstElement] = resolvedElements;
|
|
77
|
+
// eslint-disable-next-line no-param-reassign
|
|
78
|
+
el[name] = firstElement;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// eslint-disable-next-line no-param-reassign
|
|
82
|
+
el[name] = resolvedElements;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
40
85
|
class SetAttributesDirective extends Directive {
|
|
41
86
|
update(part, [attributes]) {
|
|
42
87
|
const el = part.element;
|
|
88
|
+
const internals = el.internals ?? null;
|
|
43
89
|
for (const [name, value] of Object.entries(attributes)) {
|
|
44
|
-
if (value
|
|
45
|
-
el.setAttribute(name, value);
|
|
46
|
-
else
|
|
90
|
+
if (value == null) {
|
|
47
91
|
el.removeAttribute(name);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const internalsPropertyName = ARIA_IDREF_ATTRIBUTES.get(name);
|
|
95
|
+
if (internalsPropertyName) {
|
|
96
|
+
const resolvedElements = resolveAriaIdRefs(el, String(value));
|
|
97
|
+
if (resolvedElements) {
|
|
98
|
+
if (internals) {
|
|
99
|
+
// Set on ElementInternals
|
|
100
|
+
setInternalsProperty(internals, internalsPropertyName, resolvedElements);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Set internals property on shadowdom item
|
|
104
|
+
el.setAttribute(name, String(value));
|
|
105
|
+
setInternalsProperty(el, internalsPropertyName, resolvedElements);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// Non-ARIA IDREF attributes: set normally
|
|
111
|
+
el.setAttribute(name, String(value));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
48
114
|
}
|
|
49
115
|
return null;
|
|
50
116
|
}
|
|
@@ -412,6 +478,26 @@ class BaseComponent extends LitElement {
|
|
|
412
478
|
// generate internal _id
|
|
413
479
|
const prefix = this.id?.length > 0 ? this.id : this.tagName.toLowerCase();
|
|
414
480
|
this._id = this.generateId(prefix);
|
|
481
|
+
this.ariaAttributesObserver = new MutationObserver((mutations) => {
|
|
482
|
+
const shouldUpdate = mutations.some((mutation) => {
|
|
483
|
+
if (mutation.type !== 'attributes' || !mutation.attributeName) {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
return mutation.attributeName === 'it-role' || mutation.attributeName.startsWith('it-aria-');
|
|
487
|
+
});
|
|
488
|
+
if (shouldUpdate) {
|
|
489
|
+
this.requestUpdate();
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
this.ariaAttributesObserver.observe(this, {
|
|
493
|
+
attributes: true,
|
|
494
|
+
attributeOldValue: true,
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
disconnectedCallback() {
|
|
498
|
+
this.ariaAttributesObserver?.disconnect();
|
|
499
|
+
this.ariaAttributesObserver = undefined;
|
|
500
|
+
super.disconnectedCallback();
|
|
415
501
|
}
|
|
416
502
|
}
|
|
417
503
|
const BaseLocalizedComponent = LocalizeMixin(BaseComponent);
|
|
@@ -719,6 +805,7 @@ class FocusTrapController {
|
|
|
719
805
|
}
|
|
720
806
|
}
|
|
721
807
|
else {
|
|
808
|
+
// eslint-disable-next-line no-console
|
|
722
809
|
console.warn("FocusTrap: missing 'initialFocus' callback, provide one");
|
|
723
810
|
}
|
|
724
811
|
});
|
|
@@ -1339,7 +1426,7 @@ class FormControl extends BaseLocalizedComponent {
|
|
|
1339
1426
|
});
|
|
1340
1427
|
// TODO: verificare se serve davvero con il fatto che usiamo form-controller
|
|
1341
1428
|
// static formAssociated = true;
|
|
1342
|
-
//
|
|
1429
|
+
// @property()
|
|
1343
1430
|
// internals = this.attachInternals();
|
|
1344
1431
|
this._touched = false;
|
|
1345
1432
|
/** The name of the input, submitted as a name/value pair with form data. */
|
|
@@ -1583,6 +1670,49 @@ __decorate([
|
|
|
1583
1670
|
__metadata("design:type", Object)
|
|
1584
1671
|
], FormControl.prototype, "validationMessage", void 0);
|
|
1585
1672
|
|
|
1673
|
+
/**
|
|
1674
|
+
* Dispatches a cancelable custom event and runs the provided default action
|
|
1675
|
+
* only if the consumer did not call `event.preventDefault()`.
|
|
1676
|
+
*
|
|
1677
|
+
* This is the shared convention used across components (Tabs, Modal, Chip, Alert,
|
|
1678
|
+
* Forward, Back) to provide a sensible default JavaScript behavior out of the box
|
|
1679
|
+
* while letting consumers intercept and override it. Notification deliberately does
|
|
1680
|
+
* NOT use this: its show/close are always caller-initiated (no default markup-driven
|
|
1681
|
+
* trigger to override), so there was no real use case for blocking them — see
|
|
1682
|
+
* it-notification.ts for the plain (non-cancelable) events it fires instead.
|
|
1683
|
+
*
|
|
1684
|
+
* ```js
|
|
1685
|
+
* el.addEventListener('it-alert-close', (e) => {
|
|
1686
|
+
* e.preventDefault(); // block the default removal
|
|
1687
|
+
* fetchConfirmation().then((ok) => { // async logic runs after prevention
|
|
1688
|
+
* if (ok) e.target.close();
|
|
1689
|
+
* });
|
|
1690
|
+
* });
|
|
1691
|
+
* ```
|
|
1692
|
+
*
|
|
1693
|
+
* Note: `preventDefault()` must be called synchronously inside the listener.
|
|
1694
|
+
* Async code can run afterward; call the component's public method when ready.
|
|
1695
|
+
*
|
|
1696
|
+
* @param host the element dispatching the event
|
|
1697
|
+
* @param name the event name (kebab-case, `it-` prefixed)
|
|
1698
|
+
* @param detail the event `detail` payload
|
|
1699
|
+
* @param defaultAction the behavior executed when the event is not prevented
|
|
1700
|
+
* @returns the dispatched event (inspect `defaultPrevented` if needed)
|
|
1701
|
+
*/
|
|
1702
|
+
function dispatchCancelable(host, name, detail, defaultAction) {
|
|
1703
|
+
const event = new CustomEvent(name, {
|
|
1704
|
+
bubbles: true,
|
|
1705
|
+
composed: true,
|
|
1706
|
+
cancelable: true,
|
|
1707
|
+
detail,
|
|
1708
|
+
});
|
|
1709
|
+
host.dispatchEvent(event);
|
|
1710
|
+
if (!event.defaultPrevented) {
|
|
1711
|
+
defaultAction();
|
|
1712
|
+
}
|
|
1713
|
+
return event;
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1586
1716
|
class WindowManager {
|
|
1587
1717
|
static init() {
|
|
1588
1718
|
if (this.initialized)
|
|
@@ -1665,7 +1795,7 @@ if (typeof window !== 'undefined') {
|
|
|
1665
1795
|
window._itAnalytics = window._itAnalytics || {};
|
|
1666
1796
|
window._itAnalytics = {
|
|
1667
1797
|
...window._itAnalytics,
|
|
1668
|
-
version: '1.0.0-alpha.
|
|
1798
|
+
version: '1.0.0-alpha.19',
|
|
1669
1799
|
};
|
|
1670
1800
|
}
|
|
1671
1801
|
|
|
@@ -2862,8 +2992,8 @@ blockquote.blockquote-card.dark .blockquote-footer,
|
|
|
2862
2992
|
* @slot header-icon - Icona opzionale nell'header
|
|
2863
2993
|
* @slot footer - Azioni del footer (pulsanti)
|
|
2864
2994
|
*
|
|
2865
|
-
* @fires it-modal-open - Quando la modale si apre
|
|
2866
|
-
* @fires it-modal-close - Quando la modale si chiude
|
|
2995
|
+
* @fires it-modal-open - Quando la modale si apre (cancelable: `preventDefault()` impedisce l'apertura)
|
|
2996
|
+
* @fires it-modal-close - Quando la modale si chiude (cancelable: `preventDefault()` impedisce la chiusura)
|
|
2867
2997
|
*
|
|
2868
2998
|
* @prop {string} close-button-placement - Posizione del pulsante di chiusura: `header` (default) o `backdrop` (sopra lo sfondo scuro, utile per menu offcanvas)
|
|
2869
2999
|
*/
|
|
@@ -2978,18 +3108,29 @@ let ItModal = class ItModal extends BaseComponent {
|
|
|
2978
3108
|
show() {
|
|
2979
3109
|
if (this.open || this.isAnimating)
|
|
2980
3110
|
return;
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
this
|
|
3111
|
+
// `it-modal-open` is cancelable: calling `preventDefault()` stops the modal
|
|
3112
|
+
// from opening (the consumer can open it later by calling `show()` again).
|
|
3113
|
+
dispatchCancelable(this, 'it-modal-open', { modal: this }, () => {
|
|
3114
|
+
this._originalTrigger = this._triggerElement;
|
|
3115
|
+
this.open = true;
|
|
3116
|
+
});
|
|
2984
3117
|
}
|
|
2985
3118
|
hide() {
|
|
2986
3119
|
if (!this.open || this.isAnimating)
|
|
2987
3120
|
return;
|
|
2988
|
-
|
|
2989
|
-
|
|
3121
|
+
// `it-modal-close` is cancelable: calling `preventDefault()` keeps the modal
|
|
3122
|
+
// open (the consumer can close it later by calling `hide()`).
|
|
3123
|
+
dispatchCancelable(this, 'it-modal-close', { modal: this }, () => {
|
|
3124
|
+
this._hideModal();
|
|
3125
|
+
});
|
|
2990
3126
|
}
|
|
2991
3127
|
toggle() {
|
|
2992
|
-
this.open
|
|
3128
|
+
if (this.open) {
|
|
3129
|
+
this.hide();
|
|
3130
|
+
}
|
|
3131
|
+
else {
|
|
3132
|
+
this.show();
|
|
3133
|
+
}
|
|
2993
3134
|
}
|
|
2994
3135
|
updated(changedProperties) {
|
|
2995
3136
|
if (changedProperties.has('open')) {
|