@italia/globals 1.0.0-alpha.9 → 1.0.0-beta.1

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.
Files changed (59) hide show
  1. package/README.md +5 -67
  2. package/custom-elements.json +319 -3
  3. package/dist/src/base-component/base-component.d.ts +2 -0
  4. package/dist/src/base-component/base-component.d.ts.map +1 -1
  5. package/dist/src/base-component/base-component.js +20 -0
  6. package/dist/src/base-component/base-component.js.map +1 -1
  7. package/dist/src/controllers/aria-keyboard-list-controller.d.ts +0 -0
  8. package/dist/src/controllers/aria-keyboard-list-controller.d.ts.map +0 -0
  9. package/dist/src/controllers/aria-keyboard-list-controller.js +0 -0
  10. package/dist/src/controllers/aria-keyboard-list-controller.js.map +0 -0
  11. package/dist/src/controllers/focus-trap-controller.d.ts +16 -2
  12. package/dist/src/controllers/focus-trap-controller.d.ts.map +1 -1
  13. package/dist/src/controllers/focus-trap-controller.js +265 -22
  14. package/dist/src/controllers/focus-trap-controller.js.map +1 -1
  15. package/dist/src/directives/setAttributes.d.ts +0 -0
  16. package/dist/src/directives/setAttributes.d.ts.map +1 -1
  17. package/dist/src/directives/setAttributes.js +69 -3
  18. package/dist/src/directives/setAttributes.js.map +1 -1
  19. package/dist/src/form/form-control.d.ts +0 -0
  20. package/dist/src/form/form-control.d.ts.map +0 -0
  21. package/dist/src/form/form-control.js +1 -1
  22. package/dist/src/form/form-control.js.map +1 -1
  23. package/dist/src/form/form-controller.d.ts +0 -0
  24. package/dist/src/form/form-controller.d.ts.map +0 -0
  25. package/dist/src/form/form-controller.js +0 -0
  26. package/dist/src/form/form-controller.js.map +0 -0
  27. package/dist/src/index.d.ts +2 -0
  28. package/dist/src/index.d.ts.map +1 -1
  29. package/dist/src/index.js +3 -1
  30. package/dist/src/index.js.map +1 -1
  31. package/dist/src/stories/formControlReusableStories.d.ts +0 -0
  32. package/dist/src/stories/formControlReusableStories.d.ts.map +0 -0
  33. package/dist/src/stories/formControlReusableStories.js +0 -0
  34. package/dist/src/stories/formControlReusableStories.js.map +0 -0
  35. package/dist/src/stories/reusableUsageGuidelinesStories.d.ts +13 -0
  36. package/dist/src/stories/reusableUsageGuidelinesStories.d.ts.map +1 -0
  37. package/dist/src/stories/reusableUsageGuidelinesStories.js +39 -0
  38. package/dist/src/stories/reusableUsageGuidelinesStories.js.map +1 -0
  39. package/dist/src/utils/cookies.d.ts +0 -0
  40. package/dist/src/utils/cookies.d.ts.map +0 -0
  41. package/dist/src/utils/cookies.js +0 -0
  42. package/dist/src/utils/cookies.js.map +0 -0
  43. package/dist/src/utils/dispatch-cancelable.d.ts +31 -0
  44. package/dist/src/utils/dispatch-cancelable.d.ts.map +1 -0
  45. package/dist/src/utils/dispatch-cancelable.js +43 -0
  46. package/dist/src/utils/dispatch-cancelable.js.map +1 -0
  47. package/dist/src/utils/focus-fallback.d.ts +27 -0
  48. package/dist/src/utils/focus-fallback.d.ts.map +1 -0
  49. package/dist/src/utils/focus-fallback.js +63 -0
  50. package/dist/src/utils/focus-fallback.js.map +1 -0
  51. package/dist/src/utils/logger.d.ts +0 -0
  52. package/dist/src/utils/logger.d.ts.map +0 -0
  53. package/dist/src/utils/logger.js +0 -0
  54. package/dist/src/utils/logger.js.map +0 -0
  55. package/dist/src/utils/track-focus.d.ts +0 -0
  56. package/dist/src/utils/track-focus.d.ts.map +0 -0
  57. package/dist/src/utils/track-focus.js +0 -0
  58. package/dist/src/utils/track-focus.js.map +0 -0
  59. package/package.json +19 -19
@@ -1 +1 @@
1
- {"version":3,"file":"form-control.js","sourceRoot":"","sources":["../../../src/form/form-control.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,s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AAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;6CAC9C;AAO0B;IAA1C,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCAAW;AAIrD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;;qDAClD;AAIzB;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;mDAC/B;AAI5B;IADC,QAAQ,EAAE;;4CACM;AAIjB;IADC,QAAQ,EAAE;;wCAC6B;AAIxC;IADC,QAAQ,EAAE;;wCAC6B;AAOxC;IADC,QAAQ,EAAE;;yCACkB;AAI7B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;6CAC9C;AAIP;IADT,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;8CACA;AAQrB;IADN,KAAK,EAAE;;sDACsB","sourcesContent":["import { property, query, state } from 'lit/decorators.js';\nimport { registerTranslation } from '@italia/i18n';\nimport { BaseLocalizedComponent } from '../base-component/base-component.js';\nimport { FormControlController } from './form-controller.js';\nimport it from './locales/it.js';\n\nregisterTranslation(it);\n\nexport class FormControl extends BaseLocalizedComponent {\n protected readonly formControlController = new FormControlController(this, {\n assumeInteractionOn: ['it-input', 'it-blur', 'it-change'],\n });\n\n // TODO: verificare se serve davvero con il fatto che usiamo form-controller\n // static formAssociated = true;\n\n // @property()\n // internals = this.attachInternals();\n\n @state()\n _touched = false;\n\n @query('.it-form__control')\n inputElement!: HTMLInputElement; // from FormControl\n\n /** The name of the input, submitted as a name/value pair with form data. */\n @property({ type: String, reflect: true }) // from FormControl\n name = '';\n\n /** The current value of the input, submitted as a name/value pair with form data. */\n @property({ reflect: true })\n value = '';\n\n /** If the input is disabled. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n disabled = false;\n\n /**\n * By default, form controls are associated with the nearest containing `<form>` element. This attribute allows you\n * to place the form control outside of a form and associate it with the form that has this `id`. The form must be in\n * the same document or shadow root for this to work.\n */\n @property({ reflect: true, type: String }) form = '';\n\n /** If you implement your custom validation and you won't to trigger default validation */\n @property({ type: Boolean, reflect: true, attribute: 'custom-validation' })\n customValidation = false;\n\n /** If your input is invalid from your custom validition, set this attribute with message validation */\n @property({ attribute: 'validity-message', reflect: true })\n validationText: string = '';\n\n /** Pattern the `value` must match to be valid */\n @property()\n pattern?: string;\n\n /** The input's minimum value. Only applies to date and number input types. */\n @property()\n min: number | string | Date | undefined;\n\n /** The input's maximum value. Only applies to date and number input types. */\n @property()\n max: number | string | Date | undefined;\n\n /**\n * Specifies the granularity that the value must adhere to, or the special value `any` which means no stepping is\n * implied, allowing any numeric value. Only applies to date and number input types.\n */\n @property()\n step: number | 'any' = 'any';\n\n /** The input's minimum length. */\n @property({ type: Number })\n minlength = -1;\n\n /** The input's maximum length. */\n @property({ type: Number })\n maxlength = -1;\n\n /** If the input is required. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n required = false;\n\n /* For grouped input, like checkbox-group */\n @property({ type: Boolean })\n protected isInGroup = false;\n\n /** Gets the validity state object */\n public get validity(): ValidityState {\n return this.inputElement?.validity;\n }\n\n @state()\n public validationMessage = '';\n\n /** Gets the associated form, if one exists. */\n public getForm(): HTMLFormElement | null {\n return this.formControlController.getForm();\n }\n\n // Form validation methods\n public checkValidity(): boolean {\n const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser\n return inputValid;\n }\n\n /** Checks for validity and shows the browser's validation message if the control is invalid. */\n public reportValidity() {\n // const ret = this.inputElement.checkValidity();\n const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella\n this.handleValidationMessages();\n return ret; // this.inputElement.reportValidity();\n }\n\n /** Sets a custom validation message. Pass an empty string to restore validity. */\n public setCustomValidity(message: string) {\n this.inputElement.setCustomValidity(message);\n this.validationMessage = this.inputElement.validationMessage;\n this.formControlController.updateValidity();\n }\n\n // Handlers\n protected _handleReady() {\n requestAnimationFrame(() => {\n this.dispatchEvent(new CustomEvent('it-input-ready', { bubbles: true, detail: { el: this.inputElement } }));\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleInput(e: Event) {\n this.handleValidationMessages();\n this.dispatchEvent(\n new CustomEvent('it-input', {\n detail: { value: this.inputElement.value, el: this.inputElement },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleBlur(e: Event) {\n this._touched = true;\n this.handleValidationMessages();\n this.dispatchEvent(new FocusEvent('it-blur', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleFocus(e: Event) {\n this.dispatchEvent(new FocusEvent('it-focus', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleClick(e: Event) {\n this.dispatchEvent(new MouseEvent('it-click', { bubbles: true, composed: true }));\n }\n\n /*\n Override default browser validation messages\n */\n protected handleValidationMessages() {\n if (!this.customValidation) {\n const _v = this.inputElement.validity;\n\n const isRequiredHandledByGroup = this.isInGroup === true;\n\n if (_v.valueMissing && !isRequiredHandledByGroup) {\n this.setCustomValidity(this.$t('validityRequired'));\n } else if (_v.patternMismatch) {\n this.setCustomValidity(this.$t('validityPattern'));\n } else if (_v.tooShort) {\n this.setCustomValidity(this.$t('validityMinlength').replace('{minlength}', this.minlength.toString()));\n } else if (_v.tooLong) {\n this.setCustomValidity(this.$t('validityMaxlength').replace('{maxlength}', this.maxlength.toString()));\n } else {\n /* nothing. Usa il messaggio di errore della validazione\n di default del browser per altri errori di validità come:\n - typeMismatch\n - rangeUnderflow\n - rangeOverflow\n - stepMismatch\n - badInput */\n\n const otherConstraintErrors =\n _v.typeMismatch || _v.rangeUnderflow || _v.rangeOverflow || _v.stepMismatch || _v.badInput;\n\n if (!otherConstraintErrors) {\n this.setCustomValidity('');\n }\n }\n }\n\n this.validationMessage = this.inputElement.validationMessage;\n }\n\n protected _handleInvalid(event: Event) {\n this.formControlController.setValidity(false);\n this.formControlController.emitInvalidEvent(event);\n }\n\n protected _handleChange(e: Event) {\n const target = e.target as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;\n let value: unknown;\n\n if (target instanceof HTMLInputElement) {\n switch (target.type) {\n case 'checkbox':\n case 'radio':\n value = target.checked;\n break;\n case 'file':\n value = target.files; // FileList\n break;\n default:\n value = target.value;\n }\n } else if (target instanceof HTMLSelectElement) {\n if (target.multiple) {\n value = Array.from(target.selectedOptions).map((o) => o.value);\n } else {\n value = target.value;\n }\n } else {\n // textarea o altri input con value\n value = (target as any).value;\n }\n\n this.dispatchEvent(\n new CustomEvent('it-change', {\n detail: { value, el: target },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n override updated(changedProperties: Map<string | number | symbol, unknown>) {\n super.updated?.(changedProperties);\n\n if (this.customValidation) {\n this.setCustomValidity(this.validationText ?? '');\n } else if (this.formControlController.userInteracted()) {\n this.formControlController.updateValidity();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"form-control.js","sourceRoot":"","sources":["../../../src/form/form-control.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,s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,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;6CAC9C;AAO0B;IAA1C,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCAAW;AAIrD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;;qDAClD;AAIzB;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;mDAC/B;AAI5B;IADC,QAAQ,EAAE;;4CACM;AAIjB;IADC,QAAQ,EAAE;;wCAC6B;AAIxC;IADC,QAAQ,EAAE;;wCAC6B;AAOxC;IADC,QAAQ,EAAE;;yCACkB;AAI7B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;8CACZ;AAIf;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,mBAAmB;;;6CAC9C;AAIP;IADT,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;8CACA;AAQrB;IADN,KAAK,EAAE;;sDACsB","sourcesContent":["import { property, query, state } from 'lit/decorators.js';\nimport { registerTranslation } from '@italia/i18n';\nimport { BaseLocalizedComponent } from '../base-component/base-component.js';\nimport { FormControlController } from './form-controller.js';\nimport it from './locales/it.js';\n\nregisterTranslation(it);\n\nexport class FormControl extends BaseLocalizedComponent {\n protected readonly formControlController = new FormControlController(this, {\n assumeInteractionOn: ['it-input', 'it-blur', 'it-change'],\n });\n\n // TODO: verificare se serve davvero con il fatto che usiamo form-controller\n // static formAssociated = true;\n\n // @property()\n // internals = this.attachInternals();\n\n @state()\n _touched = false;\n\n @query('.it-form__control')\n inputElement!: HTMLInputElement; // from FormControl\n\n /** The name of the input, submitted as a name/value pair with form data. */\n @property({ type: String, reflect: true }) // from FormControl\n name = '';\n\n /** The current value of the input, submitted as a name/value pair with form data. */\n @property({ reflect: true })\n value = '';\n\n /** If the input is disabled. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n disabled = false;\n\n /**\n * By default, form controls are associated with the nearest containing `<form>` element. This attribute allows you\n * to place the form control outside of a form and associate it with the form that has this `id`. The form must be in\n * the same document or shadow root for this to work.\n */\n @property({ reflect: true, type: String }) form = '';\n\n /** If you implement your custom validation and you won't to trigger default validation */\n @property({ type: Boolean, reflect: true, attribute: 'custom-validation' })\n customValidation = false;\n\n /** If your input is invalid from your custom validition, set this attribute with message validation */\n @property({ attribute: 'validity-message', reflect: true })\n validationText: string = '';\n\n /** Pattern the `value` must match to be valid */\n @property()\n pattern?: string;\n\n /** The input's minimum value. Only applies to date and number input types. */\n @property()\n min: number | string | Date | undefined;\n\n /** The input's maximum value. Only applies to date and number input types. */\n @property()\n max: number | string | Date | undefined;\n\n /**\n * Specifies the granularity that the value must adhere to, or the special value `any` which means no stepping is\n * implied, allowing any numeric value. Only applies to date and number input types.\n */\n @property()\n step: number | 'any' = 'any';\n\n /** The input's minimum length. */\n @property({ type: Number })\n minlength = -1;\n\n /** The input's maximum length. */\n @property({ type: Number })\n maxlength = -1;\n\n /** If the input is required. */\n @property({ type: Boolean, reflect: true }) // from FormControl\n required = false;\n\n /* For grouped input, like checkbox-group */\n @property({ type: Boolean })\n protected isInGroup = false;\n\n /** Gets the validity state object */\n public get validity(): ValidityState {\n return this.inputElement?.validity;\n }\n\n @state()\n public validationMessage = '';\n\n /** Gets the associated form, if one exists. */\n public getForm(): HTMLFormElement | null {\n return this.formControlController.getForm();\n }\n\n // Form validation methods\n public checkValidity(): boolean {\n const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser\n return inputValid;\n }\n\n /** Checks for validity and shows the browser's validation message if the control is invalid. */\n public reportValidity() {\n // const ret = this.inputElement.checkValidity();\n const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella\n this.handleValidationMessages();\n return ret; // this.inputElement.reportValidity();\n }\n\n /** Sets a custom validation message. Pass an empty string to restore validity. */\n public setCustomValidity(message: string) {\n this.inputElement.setCustomValidity(message);\n this.validationMessage = this.inputElement.validationMessage;\n this.formControlController.updateValidity();\n }\n\n // Handlers\n protected _handleReady() {\n requestAnimationFrame(() => {\n this.dispatchEvent(new CustomEvent('it-input-ready', { bubbles: true, detail: { el: this.inputElement } }));\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleInput(e: Event) {\n this.handleValidationMessages();\n this.dispatchEvent(\n new CustomEvent('it-input', {\n detail: { value: this.inputElement.value, el: this.inputElement },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleBlur(e: Event) {\n this._touched = true;\n this.handleValidationMessages();\n this.dispatchEvent(new FocusEvent('it-blur', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleFocus(e: Event) {\n this.dispatchEvent(new FocusEvent('it-focus', { bubbles: true, composed: true }));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n protected _handleClick(e: Event) {\n this.dispatchEvent(new MouseEvent('it-click', { bubbles: true, composed: true }));\n }\n\n /*\n Override default browser validation messages\n */\n protected handleValidationMessages() {\n if (!this.customValidation) {\n const _v = this.inputElement.validity;\n\n const isRequiredHandledByGroup = this.isInGroup === true;\n\n if (_v.valueMissing && !isRequiredHandledByGroup) {\n this.setCustomValidity(this.$t('validityRequired'));\n } else if (_v.patternMismatch) {\n this.setCustomValidity(this.$t('validityPattern'));\n } else if (_v.tooShort) {\n this.setCustomValidity(this.$t('validityMinlength').replace('{minlength}', this.minlength.toString()));\n } else if (_v.tooLong) {\n this.setCustomValidity(this.$t('validityMaxlength').replace('{maxlength}', this.maxlength.toString()));\n } else {\n /* nothing. Usa il messaggio di errore della validazione\n di default del browser per altri errori di validità come:\n - typeMismatch\n - rangeUnderflow\n - rangeOverflow\n - stepMismatch\n - badInput */\n\n const otherConstraintErrors =\n _v.typeMismatch || _v.rangeUnderflow || _v.rangeOverflow || _v.stepMismatch || _v.badInput;\n\n if (!otherConstraintErrors) {\n this.setCustomValidity('');\n }\n }\n }\n\n this.validationMessage = this.inputElement.validationMessage;\n }\n\n protected _handleInvalid(event: Event) {\n this.formControlController.setValidity(false);\n this.formControlController.emitInvalidEvent(event);\n }\n\n protected _handleChange(e: Event) {\n const target = e.target as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;\n let value: unknown;\n\n if (target instanceof HTMLInputElement) {\n switch (target.type) {\n case 'checkbox':\n case 'radio':\n value = target.checked;\n break;\n case 'file':\n value = target.files; // FileList\n break;\n default:\n value = target.value;\n }\n } else if (target instanceof HTMLSelectElement) {\n if (target.multiple) {\n value = Array.from(target.selectedOptions).map((o) => o.value);\n } else {\n value = target.value;\n }\n } else {\n // textarea o altri input con value\n value = (target as any).value;\n }\n\n this.dispatchEvent(\n new CustomEvent('it-change', {\n detail: { value, el: target },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n override updated(changedProperties: Map<string | number | symbol, unknown>) {\n super.updated?.(changedProperties);\n\n if (this.customValidation) {\n this.setCustomValidity(this.validationText ?? '');\n } else if (this.formControlController.userInteracted()) {\n this.formControlController.updateValidity();\n }\n }\n}\n"]}
File without changes
File without changes
File without changes
File without changes
@@ -20,6 +20,8 @@ export { FocusTrapController, type FocusTrapConfig } from './controllers/focus-t
20
20
  export { FormControl } from './form/form-control.js';
21
21
  export { formCollections, FormControlControllerOptions, FormControlController } from './form/form-controller.js';
22
22
  export { cookies } from './utils/cookies.js';
23
+ export { dispatchCancelable } from './utils/dispatch-cancelable.js';
24
+ export { focusableFallbackAncestor, nearestFocusableInDocument } from './utils/focus-fallback.js';
23
25
  export type Constructor<T = {}> = new (...args: any[]) => T;
24
26
  export { WindowManager, type ScrollCallback, type ScrollState } from './window-manager.js';
25
27
  export { StoryFormControlMethodAndProps };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAEzF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,YAAY,EAAE;YACZ,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH;CACF;AAUD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,CAAC;AACjE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AACvF,YAAY,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,+BAA+B,EAC/B,KAAK,2BAA2B,GACjC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAEnG,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,GAAG,IAAI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AAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAClG,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
package/dist/src/index.js CHANGED
@@ -6,7 +6,7 @@ if (typeof window !== 'undefined') {
6
6
  window._itAnalytics = window._itAnalytics || {};
7
7
  window._itAnalytics = {
8
8
  ...window._itAnalytics,
9
- version: '1.0.0-alpha.9',
9
+ version: '1.0.0-beta.1',
10
10
  };
11
11
  }
12
12
  export { TrackFocus, setAttributes, AriaKeyboardListController };
@@ -18,6 +18,8 @@ export { FocusTrapController } from './controllers/focus-trap-controller.js';
18
18
  export { FormControl } from './form/form-control.js';
19
19
  export { formCollections, FormControlController } from './form/form-controller.js';
20
20
  export { cookies } from './utils/cookies.js';
21
+ export { dispatchCancelable } from './utils/dispatch-cancelable.js';
22
+ export { focusableFallbackAncestor, nearestFocusableInDocument } from './utils/focus-fallback.js';
21
23
  export { WindowManager } from './window-manager.js';
22
24
  export { StoryFormControlMethodAndProps };
23
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAUzF,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAChD,MAAM,CAAC,YAAY,GAAG;QACpB,GAAG,MAAM,CAAC,YAAY;QACtB,OAAO,EAAE,eAAe;KACzB,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AAEvF,OAAO,EACL,aAAa,EAGb,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,+BAA+B,GAEhC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAwB,MAAM,wCAAwC,CAAC;AAEnG,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAgC,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAyC,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,8BAA8B,EAAE,CAAC","sourcesContent":["import TrackFocus from './utils/track-focus.js';\n\nimport setAttributes from './directives/setAttributes.js';\nimport AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';\nimport { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';\n\ndeclare global {\n interface Window {\n _itAnalytics: {\n version: string;\n };\n }\n}\n\nif (typeof window !== 'undefined') {\n window._itAnalytics = window._itAnalytics || {};\n window._itAnalytics = {\n ...window._itAnalytics,\n version: '1.0.0-alpha.9',\n };\n}\n\nexport { TrackFocus, setAttributes, AriaKeyboardListController };\nexport type { AriaKeyboardConfig } from './controllers/aria-keyboard-list-controller.js';\nexport { RovingTabindexController } from './controllers/roving-tabindex-controller.js';\nexport type { RovingTabindexConfig } from './controllers/roving-tabindex-controller.js';\nexport {\n BaseComponent,\n BaseComponentInterface,\n BaseComponentType,\n BaseLocalizedComponent,\n} from './base-component/base-component.js';\nexport {\n AriaKeyboardAccordionController,\n type AriaKeyboardAccordionConfig,\n} from './controllers/aria-keyboard-accordion-controller.js';\nexport { CollapseAnimationController } from './controllers/collapse-controller.js';\nexport { FocusTrapController, type FocusTrapConfig } from './controllers/focus-trap-controller.js';\n\nexport { FormControl } from './form/form-control.js';\nexport { formCollections, FormControlControllerOptions, FormControlController } from './form/form-controller.js';\nexport { cookies } from './utils/cookies.js';\nexport type Constructor<T = {}> = new (...args: any[]) => T;\nexport { WindowManager, type ScrollCallback, type ScrollState } from './window-manager.js';\n\nexport { StoryFormControlMethodAndProps };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAEhD,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,0BAA0B,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAUzF,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAChD,MAAM,CAAC,YAAY,GAAG;QACpB,GAAG,MAAM,CAAC,YAAY;QACtB,OAAO,EAAE,cAAc;KACxB,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,0BAA0B,EAAE,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AAEvF,OAAO,EACL,aAAa,EAGb,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,+BAA+B,GAEhC,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAwB,MAAM,wCAAwC,CAAC;AAEnG,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAgC,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAElG,OAAO,EAAE,aAAa,EAAyC,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,8BAA8B,EAAE,CAAC","sourcesContent":["import TrackFocus from './utils/track-focus.js';\n\nimport setAttributes from './directives/setAttributes.js';\nimport AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';\nimport { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';\n\ndeclare global {\n interface Window {\n _itAnalytics: {\n version: string;\n };\n }\n}\n\nif (typeof window !== 'undefined') {\n window._itAnalytics = window._itAnalytics || {};\n window._itAnalytics = {\n ...window._itAnalytics,\n version: '1.0.0-beta.1',\n };\n}\n\nexport { TrackFocus, setAttributes, AriaKeyboardListController };\nexport type { AriaKeyboardConfig } from './controllers/aria-keyboard-list-controller.js';\nexport { RovingTabindexController } from './controllers/roving-tabindex-controller.js';\nexport type { RovingTabindexConfig } from './controllers/roving-tabindex-controller.js';\nexport {\n BaseComponent,\n BaseComponentInterface,\n BaseComponentType,\n BaseLocalizedComponent,\n} from './base-component/base-component.js';\nexport {\n AriaKeyboardAccordionController,\n type AriaKeyboardAccordionConfig,\n} from './controllers/aria-keyboard-accordion-controller.js';\nexport { CollapseAnimationController } from './controllers/collapse-controller.js';\nexport { FocusTrapController, type FocusTrapConfig } from './controllers/focus-trap-controller.js';\n\nexport { FormControl } from './form/form-control.js';\nexport { formCollections, FormControlControllerOptions, FormControlController } from './form/form-controller.js';\nexport { cookies } from './utils/cookies.js';\nexport { dispatchCancelable } from './utils/dispatch-cancelable.js';\nexport { focusableFallbackAncestor, nearestFocusableInDocument } from './utils/focus-fallback.js';\nexport type Constructor<T = {}> = new (...args: any[]) => T;\nexport { WindowManager, type ScrollCallback, type ScrollState } from './window-manager.js';\n\nexport { StoryFormControlMethodAndProps };\n"]}
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+ export declare const CollapsibleOrHiddenContentGuidelines: () => {
2
+ name: string;
3
+ tags: string[];
4
+ render: () => import("lit").TemplateResult<1>;
5
+ parameters: {
6
+ docs: {
7
+ description: {
8
+ story: string;
9
+ };
10
+ };
11
+ };
12
+ };
13
+ //# sourceMappingURL=reusableUsageGuidelinesStories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reusableUsageGuidelinesStories.d.ts","sourceRoot":"","sources":["../../../src/stories/reusableUsageGuidelinesStories.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oCAAoC;;;;;;;;;;;CAmChD,CAAC"}
@@ -0,0 +1,39 @@
1
+ /* eslint-disable arrow-body-style */
2
+ import { html } from 'lit';
3
+ export const CollapsibleOrHiddenContentGuidelines = () => {
4
+ return {
5
+ name: 'Differenza tra Collapse, Accordion e Tabs',
6
+ tags: ['!dev', '!autodocs'],
7
+ render: () => html `<div class="hide-preview"></div>`,
8
+ parameters: {
9
+ // viewMode: 'docs', // assicura che si apra la tab Docs anziché Canvas
10
+ docs: {
11
+ description: {
12
+ story: `
13
+ #### Differenza tra Collapse, Accordion e Tabs
14
+ I componenti Accordion, Tabs e Collapse funzionano tutti nascondendo sezioni di contenuto che l'utente può scegliere di visualizzare. Evitare di usare questi componenti l'uno all'interno dell'altro.
15
+
16
+ Se decidi di usare uno di questi componenti, considera quanto segue:
17
+
18
+ - L'utente ha bisogno di visualizzare più di una sezione alla volta? L'accordion può mostrare più sezioni contemporaneamente, a differenza dei tabs.
19
+
20
+ - L'utente deve passare rapidamente tra le sezioni? I tabs permettono di cambiare contenuto senza spostare le altre sezioni nella pagina, a differenza dell'accordion.
21
+
22
+ - Ci sono molte sezioni di contenuto? L'accordion può contenere più sezioni perché sono disposte verticalmente, mentre i tabs sono disposti orizzontalmente.
23
+
24
+ - Ci sono solo uno o due contenuti brevi e meno importanti? Il componente Collapse è più adatto perché visivamente più piccolo e meno prominente rispetto a un accordion o ai tabs.
25
+
26
+ <br/>
27
+
28
+ | Componente | Contenuti multipli | Visibilità | Esclusività | Uso tipico | Esempi |
29
+ |----------|--------------------|-------------|--------------|-------------|---------|
30
+ | **Collapse** | No | Singolo contenuto mostrato o nascosto | N/A | Mostrare o nascondere dettagli secondari | "Mostra dettagli", "Visualizza termini" |
31
+ | **Accordion** | Sì | Più sezioni espandibili | Solo una aperta alla volta *(consigliato)* | Raggruppare contenuti correlati in blocchi espandibili | FAQ, elenchi informativi |
32
+ | **Tabs** | Sì | Una sezione visibile alla volta | Sempre esclusiva | Organizzare viste equivalenti o alternative | Schede di impostazioni, pannelli di dati |
33
+ `,
34
+ },
35
+ },
36
+ },
37
+ };
38
+ };
39
+ //# sourceMappingURL=reusableUsageGuidelinesStories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reusableUsageGuidelinesStories.js","sourceRoot":"","sources":["../../../src/stories/reusableUsageGuidelinesStories.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAE3B,MAAM,CAAC,MAAM,oCAAoC,GAAG,GAAG,EAAE;IACvD,OAAO;QACL,IAAI,EAAE,2CAA2C;QACjD,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC;QAC3B,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAA,kCAAkC;QACpD,UAAU,EAAE;YACV,uEAAuE;YACvE,IAAI,EAAE;gBACJ,WAAW,EAAE;oBACX,KAAK,EAAE;;;;;;;;;;;;;;;;;;;;;CAqBhB;iBACQ;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable arrow-body-style */\nimport { html } from 'lit';\n\nexport const CollapsibleOrHiddenContentGuidelines = () => {\n return {\n name: 'Differenza tra Collapse, Accordion e Tabs',\n tags: ['!dev', '!autodocs'],\n render: () => html`<div class=\"hide-preview\"></div>`,\n parameters: {\n // viewMode: 'docs', // assicura che si apra la tab Docs anziché Canvas\n docs: {\n description: {\n story: `\n#### Differenza tra Collapse, Accordion e Tabs\nI componenti Accordion, Tabs e Collapse funzionano tutti nascondendo sezioni di contenuto che l'utente può scegliere di visualizzare. Evitare di usare questi componenti l'uno all'interno dell'altro.\n\nSe decidi di usare uno di questi componenti, considera quanto segue:\n\n- L'utente ha bisogno di visualizzare più di una sezione alla volta? L'accordion può mostrare più sezioni contemporaneamente, a differenza dei tabs.\n\n- L'utente deve passare rapidamente tra le sezioni? I tabs permettono di cambiare contenuto senza spostare le altre sezioni nella pagina, a differenza dell'accordion.\n\n- Ci sono molte sezioni di contenuto? L'accordion può contenere più sezioni perché sono disposte verticalmente, mentre i tabs sono disposti orizzontalmente.\n\n- Ci sono solo uno o due contenuti brevi e meno importanti? Il componente Collapse è più adatto perché visivamente più piccolo e meno prominente rispetto a un accordion o ai tabs.\n\n<br/>\n\n| Componente | Contenuti multipli | Visibilità | Esclusività | Uso tipico | Esempi |\n|----------|--------------------|-------------|--------------|-------------|---------|\n| **Collapse** | No | Singolo contenuto mostrato o nascosto | N/A | Mostrare o nascondere dettagli secondari | \"Mostra dettagli\", \"Visualizza termini\" |\n| **Accordion** | Sì | Più sezioni espandibili | Solo una aperta alla volta *(consigliato)* | Raggruppare contenuti correlati in blocchi espandibili | FAQ, elenchi informativi |\n| **Tabs** | Sì | Una sezione visibile alla volta | Sempre esclusiva | Organizzare viste equivalenti o alternative | Schede di impostazioni, pannelli di dati |\n`,\n },\n },\n },\n };\n};\n"]}
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Dispatches a cancelable custom event and runs the provided default action
3
+ * only if the consumer did not call `event.preventDefault()`.
4
+ *
5
+ * This is the shared convention used across components (Tabs, Modal, Chip, Alert,
6
+ * Forward, Back) to provide a sensible default JavaScript behavior out of the box
7
+ * while letting consumers intercept and override it. Notification deliberately does
8
+ * NOT use this: its show/close are always caller-initiated (no default markup-driven
9
+ * trigger to override), so there was no real use case for blocking them — see
10
+ * it-notification.ts for the plain (non-cancelable) events it fires instead.
11
+ *
12
+ * ```js
13
+ * el.addEventListener('it-alert-close', (e) => {
14
+ * e.preventDefault(); // block the default removal
15
+ * fetchConfirmation().then((ok) => { // async logic runs after prevention
16
+ * if (ok) e.target.close();
17
+ * });
18
+ * });
19
+ * ```
20
+ *
21
+ * Note: `preventDefault()` must be called synchronously inside the listener.
22
+ * Async code can run afterward; call the component's public method when ready.
23
+ *
24
+ * @param host the element dispatching the event
25
+ * @param name the event name (kebab-case, `it-` prefixed)
26
+ * @param detail the event `detail` payload
27
+ * @param defaultAction the behavior executed when the event is not prevented
28
+ * @returns the dispatched event (inspect `defaultPrevented` if needed)
29
+ */
30
+ export declare function dispatchCancelable<T>(host: HTMLElement, name: string, detail: T, defaultAction: () => void): CustomEvent<T>;
31
+ //# sourceMappingURL=dispatch-cancelable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch-cancelable.d.ts","sourceRoot":"","sources":["../../../src/utils/dispatch-cancelable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,CAAC,EACT,aAAa,EAAE,MAAM,IAAI,GACxB,WAAW,CAAC,CAAC,CAAC,CAYhB"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Dispatches a cancelable custom event and runs the provided default action
3
+ * only if the consumer did not call `event.preventDefault()`.
4
+ *
5
+ * This is the shared convention used across components (Tabs, Modal, Chip, Alert,
6
+ * Forward, Back) to provide a sensible default JavaScript behavior out of the box
7
+ * while letting consumers intercept and override it. Notification deliberately does
8
+ * NOT use this: its show/close are always caller-initiated (no default markup-driven
9
+ * trigger to override), so there was no real use case for blocking them — see
10
+ * it-notification.ts for the plain (non-cancelable) events it fires instead.
11
+ *
12
+ * ```js
13
+ * el.addEventListener('it-alert-close', (e) => {
14
+ * e.preventDefault(); // block the default removal
15
+ * fetchConfirmation().then((ok) => { // async logic runs after prevention
16
+ * if (ok) e.target.close();
17
+ * });
18
+ * });
19
+ * ```
20
+ *
21
+ * Note: `preventDefault()` must be called synchronously inside the listener.
22
+ * Async code can run afterward; call the component's public method when ready.
23
+ *
24
+ * @param host the element dispatching the event
25
+ * @param name the event name (kebab-case, `it-` prefixed)
26
+ * @param detail the event `detail` payload
27
+ * @param defaultAction the behavior executed when the event is not prevented
28
+ * @returns the dispatched event (inspect `defaultPrevented` if needed)
29
+ */
30
+ export function dispatchCancelable(host, name, detail, defaultAction) {
31
+ const event = new CustomEvent(name, {
32
+ bubbles: true,
33
+ composed: true,
34
+ cancelable: true,
35
+ detail,
36
+ });
37
+ host.dispatchEvent(event);
38
+ if (!event.defaultPrevented) {
39
+ defaultAction();
40
+ }
41
+ return event;
42
+ }
43
+ //# sourceMappingURL=dispatch-cancelable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch-cancelable.js","sourceRoot":"","sources":["../../../src/utils/dispatch-cancelable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAiB,EACjB,IAAY,EACZ,MAAS,EACT,aAAyB;IAEzB,MAAM,KAAK,GAAG,IAAI,WAAW,CAAI,IAAI,EAAE;QACrC,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;QAChB,MAAM;KACP,CAAC,CAAC;IACH,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC1B,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC5B,aAAa,EAAE,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Dispatches a cancelable custom event and runs the provided default action\n * only if the consumer did not call `event.preventDefault()`.\n *\n * This is the shared convention used across components (Tabs, Modal, Chip, Alert,\n * Forward, Back) to provide a sensible default JavaScript behavior out of the box\n * while letting consumers intercept and override it. Notification deliberately does\n * NOT use this: its show/close are always caller-initiated (no default markup-driven\n * trigger to override), so there was no real use case for blocking them — see\n * it-notification.ts for the plain (non-cancelable) events it fires instead.\n *\n * ```js\n * el.addEventListener('it-alert-close', (e) => {\n * e.preventDefault(); // block the default removal\n * fetchConfirmation().then((ok) => { // async logic runs after prevention\n * if (ok) e.target.close();\n * });\n * });\n * ```\n *\n * Note: `preventDefault()` must be called synchronously inside the listener.\n * Async code can run afterward; call the component's public method when ready.\n *\n * @param host the element dispatching the event\n * @param name the event name (kebab-case, `it-` prefixed)\n * @param detail the event `detail` payload\n * @param defaultAction the behavior executed when the event is not prevented\n * @returns the dispatched event (inspect `defaultPrevented` if needed)\n */\nexport function dispatchCancelable<T>(\n host: HTMLElement,\n name: string,\n detail: T,\n defaultAction: () => void,\n): CustomEvent<T> {\n const event = new CustomEvent<T>(name, {\n bubbles: true,\n composed: true,\n cancelable: true,\n detail,\n });\n host.dispatchEvent(event);\n if (!event.defaultPrevented) {\n defaultAction();\n }\n return event;\n}\n"]}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Returns the nearest focusable ancestor of `el` by walking up parentElement.
3
+ * Used as the last-resort fallback when a self-removing component (chip, alert)
4
+ * has no adjacent sibling of the same type to shift focus to.
5
+ *
6
+ * "Focusable ancestor" means an element with tabindex >= 0. The container that
7
+ * wraps a chip group or alert list is the expected target; authors following the
8
+ * WAI-ARIA pattern should give it tabindex="0".
9
+ */
10
+ export declare function focusableFallbackAncestor(el: HTMLElement): HTMLElement | null;
11
+ /**
12
+ * True last-resort fallback for when a self-removing component (alert, chip,
13
+ * notification) has neither an adjacent sibling of the same type nor a
14
+ * `focusableFallbackAncestor` (i.e. no author-provided `tabindex="0"` wrapper) —
15
+ * the common case in practice, since most real usages don't add that wrapper.
16
+ * Without this, focus silently drops to `<body>` with no way for a keyboard/AT
17
+ * user to tell where they ended up.
18
+ *
19
+ * Finds the closest focusable element to `el` anywhere in the document, walking
20
+ * outward in document order: the nearest one that comes before `el` (closer to
21
+ * where the user's attention already was), falling back to the nearest one after.
22
+ * This is a coarse, page-wide search — it may land focus on something not
23
+ * visually adjacent — but it is deterministic and strictly better than silently
24
+ * losing focus.
25
+ */
26
+ export declare function nearestFocusableInDocument(el: HTMLElement): HTMLElement | null;
27
+ //# sourceMappingURL=focus-fallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus-fallback.d.ts","sourceRoot":"","sources":["../../../src/utils/focus-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAQ7E;AAcD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAiB9E"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Returns the nearest focusable ancestor of `el` by walking up parentElement.
3
+ * Used as the last-resort fallback when a self-removing component (chip, alert)
4
+ * has no adjacent sibling of the same type to shift focus to.
5
+ *
6
+ * "Focusable ancestor" means an element with tabindex >= 0. The container that
7
+ * wraps a chip group or alert list is the expected target; authors following the
8
+ * WAI-ARIA pattern should give it tabindex="0".
9
+ */
10
+ export function focusableFallbackAncestor(el) {
11
+ let current = el.parentElement;
12
+ while (current) {
13
+ const tab = current.getAttribute('tabindex');
14
+ if (tab !== null && parseInt(tab, 10) >= 0)
15
+ return current;
16
+ current = current.parentElement;
17
+ }
18
+ return null;
19
+ }
20
+ /** Mirrors FocusTrapController's notion of "focusable", scoped to the handful of
21
+ * interactive elements consumers actually place next to alert/chip/notification. */
22
+ const FOCUSABLE_SELECTORS = [
23
+ 'a[href]',
24
+ 'button:not([disabled])',
25
+ 'input:not([disabled]):not([type="hidden"])',
26
+ 'select:not([disabled])',
27
+ 'textarea:not([disabled])',
28
+ '[tabindex]:not([tabindex="-1"])',
29
+ 'it-button:not([disabled])',
30
+ ].join(',');
31
+ /**
32
+ * True last-resort fallback for when a self-removing component (alert, chip,
33
+ * notification) has neither an adjacent sibling of the same type nor a
34
+ * `focusableFallbackAncestor` (i.e. no author-provided `tabindex="0"` wrapper) —
35
+ * the common case in practice, since most real usages don't add that wrapper.
36
+ * Without this, focus silently drops to `<body>` with no way for a keyboard/AT
37
+ * user to tell where they ended up.
38
+ *
39
+ * Finds the closest focusable element to `el` anywhere in the document, walking
40
+ * outward in document order: the nearest one that comes before `el` (closer to
41
+ * where the user's attention already was), falling back to the nearest one after.
42
+ * This is a coarse, page-wide search — it may land focus on something not
43
+ * visually adjacent — but it is deterministic and strictly better than silently
44
+ * losing focus.
45
+ */
46
+ export function nearestFocusableInDocument(el) {
47
+ const candidates = Array.from(document.querySelectorAll(FOCUSABLE_SELECTORS)).filter((candidate) => candidate !== el && !el.contains(candidate));
48
+ if (!candidates.length)
49
+ return null;
50
+ let closestBefore = null;
51
+ let closestAfter = null;
52
+ candidates.forEach((candidate) => {
53
+ // eslint-disable-next-line no-bitwise
54
+ if (el.compareDocumentPosition(candidate) & Node.DOCUMENT_POSITION_PRECEDING) {
55
+ closestBefore = candidate; // querySelectorAll returns document order, so the last match wins
56
+ }
57
+ else if (!closestAfter) {
58
+ closestAfter = candidate; // first match after `el` in document order
59
+ }
60
+ });
61
+ return closestBefore ?? closestAfter;
62
+ }
63
+ //# sourceMappingURL=focus-fallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus-fallback.js","sourceRoot":"","sources":["../../../src/utils/focus-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,yBAAyB,CAAC,EAAe;I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,CAAC,CAAC,2CAA2C;QACvE,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,aAAa,IAAI,YAAY,CAAC;AACvC,CAAC","sourcesContent":["/**\n * Returns the nearest focusable ancestor of `el` by walking up parentElement.\n * Used as the last-resort fallback when a self-removing component (chip, alert)\n * has no adjacent sibling of the same type to shift focus to.\n *\n * \"Focusable ancestor\" means an element with tabindex >= 0. The container that\n * wraps a chip group or alert list is the expected target; authors following the\n * WAI-ARIA pattern should give it tabindex=\"0\".\n */\nexport function focusableFallbackAncestor(el: HTMLElement): HTMLElement | null {\n let current: HTMLElement | null = el.parentElement;\n while (current) {\n const tab = current.getAttribute('tabindex');\n if (tab !== null && parseInt(tab, 10) >= 0) return current;\n current = current.parentElement;\n }\n return null;\n}\n\n/** Mirrors FocusTrapController's notion of \"focusable\", scoped to the handful of\n * interactive elements consumers actually place next to alert/chip/notification. */\nconst FOCUSABLE_SELECTORS = [\n 'a[href]',\n 'button:not([disabled])',\n 'input:not([disabled]):not([type=\"hidden\"])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n '[tabindex]:not([tabindex=\"-1\"])',\n 'it-button:not([disabled])',\n].join(',');\n\n/**\n * True last-resort fallback for when a self-removing component (alert, chip,\n * notification) has neither an adjacent sibling of the same type nor a\n * `focusableFallbackAncestor` (i.e. no author-provided `tabindex=\"0\"` wrapper) —\n * the common case in practice, since most real usages don't add that wrapper.\n * Without this, focus silently drops to `<body>` with no way for a keyboard/AT\n * user to tell where they ended up.\n *\n * Finds the closest focusable element to `el` anywhere in the document, walking\n * outward in document order: the nearest one that comes before `el` (closer to\n * where the user's attention already was), falling back to the nearest one after.\n * This is a coarse, page-wide search — it may land focus on something not\n * visually adjacent — but it is deterministic and strictly better than silently\n * losing focus.\n */\nexport function nearestFocusableInDocument(el: HTMLElement): HTMLElement | null {\n const candidates = Array.from(document.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTORS)).filter(\n (candidate) => candidate !== el && !el.contains(candidate),\n );\n if (!candidates.length) return null;\n\n let closestBefore: HTMLElement | null = null;\n let closestAfter: HTMLElement | null = null;\n candidates.forEach((candidate) => {\n // eslint-disable-next-line no-bitwise\n if (el.compareDocumentPosition(candidate) & Node.DOCUMENT_POSITION_PRECEDING) {\n closestBefore = candidate; // querySelectorAll returns document order, so the last match wins\n } else if (!closestAfter) {\n closestAfter = candidate; // first match after `el` in document order\n }\n });\n return closestBefore ?? closestAfter;\n}\n"]}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@italia/globals",
3
3
  "description": "Utilities per i Web components del Design System .italia",
4
- "version": "1.0.0-alpha.9",
4
+ "version": "1.0.0-beta.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -31,30 +31,30 @@
31
31
  "LICENSE",
32
32
  "custom-elements.json"
33
33
  ],
34
+ "scripts": {
35
+ "analyze": "cem analyze --litelement --exclude dist",
36
+ "build": "tsc --build tsconfig.build.json",
37
+ "clean": "rimraf node_modules .turbo dist",
38
+ "prepublish": "pnpm build",
39
+ "lint": "eslint --ext .ts \"src/**/*.ts\" && prettier \"src/**/*.ts\" --check",
40
+ "format": "eslint --ext .ts \"src/**/*.ts\" --fix && prettier \"src/**/*.ts\" --write"
41
+ },
34
42
  "dependencies": {
43
+ "@italia/i18n": "workspace:^",
35
44
  "@floating-ui/dom": "^1.7.1",
36
45
  "clsx": "^2.1.1",
37
- "lit": "^3.3.0",
38
- "@italia/i18n": "^1.0.0-alpha.9"
46
+ "lit": "catalog:"
39
47
  },
40
48
  "devDependencies": {
41
49
  "@custom-elements-manifest/analyzer": "^0.10.3",
42
- "@open-wc/testing": "^4.0.0",
43
- "@types/mocha": "^10.0.10",
44
- "@web/test-runner": "^0.18.2",
50
+ "@italia/test-config": "workspace:^",
51
+ "@italia/typescript-config": "workspace:^",
52
+ "@open-wc/testing": "catalog:",
53
+ "@types/mocha": "catalog:",
54
+ "@web/test-runner": "catalog:",
45
55
  "rimraf": "^6.0.1",
46
56
  "tslib": "^2.6.3",
47
- "typescript": "^5.5.3",
48
- "@italia/test-config": "^0.0.0",
49
- "@italia/typescript-config": "^0.0.0"
57
+ "typescript": "catalog:"
50
58
  },
51
- "customElements": "custom-elements.json",
52
- "scripts": {
53
- "analyze": "cem analyze --litelement --exclude dist",
54
- "build": "tsc --build tsconfig.build.json",
55
- "clean": "rimraf node_modules .turbo dist",
56
- "prepublish": "pnpm build",
57
- "lint": "eslint --ext .ts \"src/**/*.ts\" && prettier \"src/**/*.ts\" --check",
58
- "format": "eslint --ext .ts \"src/**/*.ts\" --fix && prettier \"src/**/*.ts\" --write"
59
- }
60
- }
59
+ "customElements": "custom-elements.json"
60
+ }