@italia/globals 0.1.0-alpha.2 → 1.0.0-alpha.11

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 (36) hide show
  1. package/custom-elements.json +680 -166
  2. package/dist/src/base-component/base-component.d.ts +19 -7
  3. package/dist/src/base-component/base-component.d.ts.map +1 -1
  4. package/dist/src/controllers/focus-trap-controller.d.ts +92 -0
  5. package/dist/src/controllers/focus-trap-controller.d.ts.map +1 -0
  6. package/dist/src/controllers/focus-trap-controller.js +497 -0
  7. package/dist/src/controllers/focus-trap-controller.js.map +1 -0
  8. package/dist/src/controllers/roving-tabindex-controller.d.ts +9 -2
  9. package/dist/src/controllers/roving-tabindex-controller.d.ts.map +1 -1
  10. package/dist/src/controllers/roving-tabindex-controller.js +11 -5
  11. package/dist/src/controllers/roving-tabindex-controller.js.map +1 -1
  12. package/dist/src/form/form-control.d.ts +2 -1
  13. package/dist/src/form/form-control.d.ts.map +1 -1
  14. package/dist/src/form/form-control.js +15 -7
  15. package/dist/src/form/form-control.js.map +1 -1
  16. package/dist/src/form/form-controller.d.ts +2 -0
  17. package/dist/src/form/form-controller.d.ts.map +1 -1
  18. package/dist/src/form/form-controller.js +45 -1
  19. package/dist/src/form/form-controller.js.map +1 -1
  20. package/dist/src/form/locales/it.d.ts.map +1 -1
  21. package/dist/src/form/locales/it.js +1 -0
  22. package/dist/src/form/locales/it.js.map +1 -1
  23. package/dist/src/index.d.ts +8 -0
  24. package/dist/src/index.d.ts.map +1 -1
  25. package/dist/src/index.js +8 -0
  26. package/dist/src/index.js.map +1 -1
  27. package/dist/src/mixins/validity.d.ts +18 -6
  28. package/dist/src/mixins/validity.d.ts.map +1 -1
  29. package/dist/src/stories/formControlReusableStories.d.ts.map +1 -1
  30. package/dist/src/stories/formControlReusableStories.js +5 -4
  31. package/dist/src/stories/formControlReusableStories.js.map +1 -1
  32. package/dist/src/window-manager.d.ts +13 -0
  33. package/dist/src/window-manager.d.ts.map +1 -1
  34. package/dist/src/window-manager.js +31 -0
  35. package/dist/src/window-manager.js.map +1 -1
  36. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"roving-tabindex-controller.js","sourceRoot":"","sources":["../../../src/controllers/roving-tabindex-controller.ts"],"names":[],"mappings":"AAsCA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,wBAAwB;IAUnC,YAAY,IAA4B,EAAE,MAA+B;QACvE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI,EAAE,IAAI;YACV,SAAS,EAAE,MAAM;YACjB,aAAa,EAAE,KAAK;YACpB,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAK,IAAY,CAAC,QAAQ,KAAK,IAAI;YACpF,GAAG,MAAM;SACV,CAAC;QACF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,kDAAkD;IAClD,aAAa;QACX,yCAAyC;IAC3C,CAAC;IAED,kDAAkD;IAClD,gBAAgB;QACd,oBAAoB;IACtB,CAAC;IAED;;;OAGG;IACH,gBAAgB,CAAC,WAAoB;QACnC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO;QACT,CAAC;QAED,wBAAwB;QACxB,IAAI,WAAW,GAAG,WAAW,IAAI,CAAC,CAAC;QAEnC,4DAA4D;QAC5D,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YACrE,IAAI,WAAW,KAAK,CAAC,CAAC,E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C,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport interface RovingTabindexConfig<T extends HTMLElement> {\n /**\n * Selector or function to get the items to manage\n */\n getItems: () => T[];\n\n /**\n * Callback when an item is selected/activated\n */\n onSelect?: (item: T, event: KeyboardEvent | PointerEvent | MouseEvent) => void;\n\n /**\n * Whether items wrap around (last -> first and vice versa)\n * @default true\n */\n wrap?: boolean;\n\n /**\n * Direction of navigation\n * @default 'both'\n */\n direction?: 'horizontal' | 'vertical' | 'both';\n\n /**\n * Whether to select items on focus (vs just focusing)\n * @default false\n */\n selectOnFocus?: boolean;\n\n /**\n * Custom logic to determine if an item should be skipped\n * @default (item) => item.hasAttribute('disabled')\n */\n skipItem?: (item: T) => boolean;\n}\n\n/**\n * Roving Tabindex Controller\n *\n * Implements the ARIA roving tabindex pattern for keyboard navigation.\n * See: https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex\n *\n * Usage:\n * ```ts\n * private rovingTabindex = new RovingTabindexController(this, {\n * getItems: () => Array.from(this.querySelectorAll('my-item')),\n * onSelect: (item) => this.selectItem(item),\n * });\n * ```\n */\nexport class RovingTabindexController<T extends HTMLElement> implements ReactiveController {\n private host: ReactiveControllerHost;\n\n private config: RovingTabindexConfig<T> & {\n wrap: boolean;\n direction: 'horizontal' | 'vertical' | 'both';\n selectOnFocus: boolean;\n skipItem: (item: T) => boolean;\n };\n\n constructor(host: ReactiveControllerHost, config: RovingTabindexConfig<T>) {\n this.host = host;\n this.config = {\n wrap: true,\n direction: 'both',\n selectOnFocus: false,\n skipItem: (item) => item.hasAttribute('disabled') || (item as any).disabled === true,\n ...config,\n };\n host.addController(this);\n }\n\n // eslint-disable-next-line class-methods-use-this\n hostConnected(): void {\n // Controller is ready when host connects\n }\n\n // eslint-disable-next-line class-methods-use-this\n hostDisconnected(): void {\n // Cleanup if needed\n }\n\n /**\n * Update tabindex values for all items\n * @param activeIndex - Index of the item that should be tabbable (default: 0 or first non-disabled)\n */\n updateTabindices(activeIndex?: number): void {\n const items = this.config.getItems();\n if (!items || items.length === 0) {\n return;\n }\n\n // Find the active index\n let targetIndex = activeIndex ?? 0;\n\n // If no active index specified, use first non-disabled item\n if (activeIndex === undefined) {\n targetIndex = items.findIndex((item) => !this.config.skipItem(item));\n if (targetIndex === -1) {\n targetIndex = 0; // Fallback to first item if all disabled\n }\n }\n\n // Set tabindex for all items\n items.forEach((item, index) => {\n const itemElement = item;\n if (this.config.skipItem(itemElement)) {\n // eslint-disable-next-line no-param-reassign\n itemElement.tabIndex = -1;\n } else {\n // eslint-disable-next-line no-param-reassign\n itemElement.tabIndex = index === targetIndex ? 0 : -1;\n }\n });\n }\n\n /**\n * Handle keyboard navigation\n * @param currentItem - The currently focused item\n * @param event - The keyboard event\n * @returns true if the event was handled, false otherwise\n */\n handleKeydown(currentItem: T, event: KeyboardEvent): boolean {\n const { direction } = this.config;\n const { key } = event;\n\n // Determine if this key should be handled based on direction\n const isVertical = key === 'ArrowUp' || key === 'ArrowDown';\n const isHorizontal = key === 'ArrowLeft' || key === 'ArrowRight';\n const isHome = key === 'Home';\n const isEnd = key === 'End';\n\n const shouldHandle =\n isHome ||\n isEnd ||\n (direction === 'both' && (isVertical || isHorizontal)) ||\n (direction === 'vertical' && isVertical) ||\n (direction === 'horizontal' && isHorizontal);\n\n if (!shouldHandle) {\n return false;\n }\n\n // Prevent default behavior (page scrolling)\n event.preventDefault();\n\n const items = this.config.getItems();\n const currentIndex = items.indexOf(currentItem);\n\n if (currentIndex === -1) {\n return false;\n }\n\n let nextIndex = currentIndex;\n\n // Handle Home/End keys\n if (isHome) {\n nextIndex = 0;\n } else if (isEnd) {\n nextIndex = items.length - 1;\n } else {\n // Handle arrow keys\n const isNext = key === 'ArrowDown' || key === 'ArrowRight';\n const isPrev = key === 'ArrowUp' || key === 'ArrowLeft';\n\n if (isNext) {\n nextIndex = this.getNextIndex(items, currentIndex, 1);\n } else if (isPrev) {\n nextIndex = this.getNextIndex(items, currentIndex, -1);\n }\n }\n\n // Skip disabled items\n nextIndex = this.findNextValidIndex(items, nextIndex, nextIndex > currentIndex ? 1 : -1);\n\n if (nextIndex !== -1 && nextIndex !== currentIndex) {\n const nextItem = items[nextIndex];\n\n // Update tabindices\n this.updateTabindices(nextIndex);\n\n // Focus the next item\n nextItem.focus();\n\n // Optionally select/activate the item\n if (this.config.selectOnFocus && this.config.onSelect) {\n this.config.onSelect(nextItem, event);\n }\n\n return true;\n }\n\n return false;\n }\n\n /**\n * Get the next index based on direction\n */\n private getNextIndex(items: T[], currentIndex: number, direction: 1 | -1): number {\n const { wrap } = this.config;\n let nextIndex = currentIndex + direction;\n\n if (wrap) {\n // Wrap around\n if (nextIndex < 0) {\n nextIndex = items.length - 1;\n } else if (nextIndex >= items.length) {\n nextIndex = 0;\n }\n } else {\n // Clamp to bounds\n nextIndex = Math.max(0, Math.min(items.length - 1, nextIndex));\n }\n\n return nextIndex;\n }\n\n /**\n * Find the next valid (non-disabled) index\n */\n private findNextValidIndex(items: T[], startIndex: number, direction: 1 | -1): number {\n const maxAttempts = items.length;\n let attempts = 0;\n let index = startIndex;\n\n while (attempts < maxAttempts) {\n if (!this.config.skipItem(items[index])) {\n return index;\n }\n\n index = this.getNextIndex(items, index, direction);\n attempts += 1;\n }\n\n // All items are disabled\n return -1;\n }\n\n /**\n * Set focus to a specific item\n */\n focusItem(item: T): void {\n const items = this.config.getItems();\n const index = items.indexOf(item);\n\n if (index !== -1) {\n this.updateTabindices(index);\n item.focus();\n }\n }\n\n /**\n * Set focus to the first non-disabled item\n */\n focusFirst(): void {\n const items = this.config.getItems();\n const firstValidIndex = this.findNextValidIndex(items, 0, 1);\n\n if (firstValidIndex !== -1) {\n this.focusItem(items[firstValidIndex]);\n }\n }\n\n /**\n * Set focus to the last non-disabled item\n */\n focusLast(): void {\n const items = this.config.getItems();\n const lastValidIndex = this.findNextValidIndex(items, items.length - 1, -1);\n\n if (lastValidIndex !== -1) {\n this.focusItem(items[lastValidIndex]);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"roving-tabindex-controller.js","sourceRoot":"","sources":["../../../src/controllers/roving-tabindex-controller.ts"],"names":[],"mappings":"AA8CA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,wBAAwB;IAWnC,YAAY,IAA4B,EAAE,MAA+B;QACvE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI,EAAE,IAAI;YACV,SAAS,EAAE,MAAM;YACjB,aAAa,EAAE,KAAK;YACpB,eAAe,EAAE,KAAK;YACtB,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAK,IAAY,CAAC,QAAQ,KAAK,IAAI;YACpF,GAAG,MAAM;SACV,CAAC;QACF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,kDAAkD;IAClD,aAAa;QACX,yCAAyC;IAC3C,CAAC;IAED,kDAAkD;IAClD,gBAAgB;QACd,oBAAoB;IACtB,CAAC;IAED;;;OAGG;IACH,gBAAgB,CAAC,WAAoB;QACnC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO;QACT,CAAC;QAED,wBAAwB;QACxB,IAAI,WAAW,GAAG,WAAW,IAAI,CAAC,CAAC;QAEnC,4DAA4D;QAC5D,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,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,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrC,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAE7D,IAAI,eAAe,KAAK,CAAC,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS;QACP,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrC,MAAM,cAAc,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAE5E,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport interface RovingTabindexConfig<T extends HTMLElement> {\n /**\n * Selector or function to get the items to manage\n */\n getItems: () => T[];\n\n /**\n * Callback when an item is selected/activated\n */\n onSelect?: (item: T, event: KeyboardEvent | PointerEvent | MouseEvent) => void;\n\n /**\n * Whether items wrap around (last -> first and vice versa)\n * @default true\n */\n wrap?: boolean;\n\n /**\n * Direction of navigation. Può essere una stringa statica o una funzione\n * che restituisce la direzione dinamicamente (utile quando la direzione\n * dipende dallo stato del componente, es. orientamento verticale/orizzontale).\n * @default 'both'\n */\n direction?: 'horizontal' | 'vertical' | 'both' | (() => 'horizontal' | 'vertical' | 'both');\n\n /**\n * Whether to select items on focus (vs just focusing)\n * @default false\n */\n selectOnFocus?: boolean;\n\n /**\n * Whether Home/End should *activate* (select) the item in addition to focusing it.\n * Default false to avoid changing downstream components; opt-in when needed.\n */\n selectOnHomeEnd?: boolean;\n\n /**\n * Custom logic to determine if an item should be skipped\n * @default (item) => item.hasAttribute('disabled')\n */\n skipItem?: (item: T) => boolean;\n}\n\n/**\n * Roving Tabindex Controller\n *\n * Implements the ARIA roving tabindex pattern for keyboard navigation.\n * See: https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex\n *\n * Usage:\n * ```ts\n * private rovingTabindex = new RovingTabindexController(this, {\n * getItems: () => Array.from(this.querySelectorAll('my-item')),\n * onSelect: (item) => this.selectItem(item),\n * });\n * ```\n */\nexport class RovingTabindexController<T extends HTMLElement> implements ReactiveController {\n private host: ReactiveControllerHost;\n\n private config: RovingTabindexConfig<T> & {\n wrap: boolean;\n direction: 'horizontal' | 'vertical' | 'both' | (() => 'horizontal' | 'vertical' | 'both');\n selectOnFocus: boolean;\n selectOnHomeEnd: boolean;\n skipItem: (item: T) => boolean;\n };\n\n constructor(host: ReactiveControllerHost, config: RovingTabindexConfig<T>) {\n this.host = host;\n this.config = {\n wrap: true,\n direction: 'both',\n selectOnFocus: false,\n selectOnHomeEnd: false,\n skipItem: (item) => item.hasAttribute('disabled') || (item as any).disabled === true,\n ...config,\n };\n host.addController(this);\n }\n\n // eslint-disable-next-line class-methods-use-this\n hostConnected(): void {\n // Controller is ready when host connects\n }\n\n // eslint-disable-next-line class-methods-use-this\n hostDisconnected(): void {\n // Cleanup if needed\n }\n\n /**\n * Update tabindex values for all items\n * @param activeIndex - Index of the item that should be tabbable (default: 0 or first non-disabled)\n */\n updateTabindices(activeIndex?: number): void {\n const items = this.config.getItems();\n if (!items || items.length === 0) {\n return;\n }\n\n // Find the active index\n let targetIndex = activeIndex ?? 0;\n\n // If no active index specified, use first non-disabled item\n if (activeIndex === undefined) {\n targetIndex = items.findIndex((item) => !this.config.skipItem(item));\n if (targetIndex === -1) {\n targetIndex = 0; // Fallback to first item if all disabled\n }\n }\n\n // Set tabindex for all items\n items.forEach((item, index) => {\n const itemElement = item;\n if (this.config.skipItem(itemElement)) {\n // eslint-disable-next-line no-param-reassign\n itemElement.tabIndex = -1;\n } else {\n // eslint-disable-next-line no-param-reassign\n itemElement.tabIndex = index === targetIndex ? 0 : -1;\n }\n });\n }\n\n /**\n * Handle keyboard navigation\n * @param currentItem - The currently focused item\n * @param event - The keyboard event\n * @returns true if the event was handled, false otherwise\n */\n handleKeydown(currentItem: T, event: KeyboardEvent): boolean {\n const direction = typeof this.config.direction === 'function' ? this.config.direction() : this.config.direction;\n const { key } = event;\n\n // Determine if this key should be handled based on direction\n const isVertical = key === 'ArrowUp' || key === 'ArrowDown';\n const isHorizontal = key === 'ArrowLeft' || key === 'ArrowRight';\n const isHome = key === 'Home';\n const isEnd = key === 'End';\n const shouldHandle =\n isHome ||\n isEnd ||\n (direction === 'both' && (isVertical || isHorizontal)) ||\n (direction === 'vertical' && isVertical) ||\n (direction === 'horizontal' && isHorizontal);\n\n if (!shouldHandle) {\n return false;\n }\n\n // Prevent default behavior (page scrolling)\n event.preventDefault();\n\n const items = this.config.getItems();\n const currentIndex = items.indexOf(currentItem);\n\n if (currentIndex === -1) {\n return false;\n }\n\n let nextIndex = currentIndex;\n\n // Handle Home/End keys\n if (isHome) {\n nextIndex = 0;\n } else if (isEnd) {\n nextIndex = items.length - 1;\n } else {\n // Handle arrow keys\n const isNext = key === 'ArrowDown' || key === 'ArrowRight';\n const isPrev = key === 'ArrowUp' || key === 'ArrowLeft';\n\n if (isNext) {\n nextIndex = this.getNextIndex(items, currentIndex, 1);\n } else if (isPrev) {\n nextIndex = this.getNextIndex(items, currentIndex, -1);\n }\n }\n\n // Skip disabled items — Home always searches forward, End always searches backward\n // eslint-disable-next-line no-nested-ternary\n const searchDirection: 1 | -1 = isHome ? 1 : isEnd ? -1 : nextIndex > currentIndex ? 1 : -1;\n nextIndex = this.findNextValidIndex(items, nextIndex, searchDirection);\n\n if (nextIndex !== -1 && nextIndex !== currentIndex) {\n const nextItem = items[nextIndex];\n\n // Update tabindices\n this.updateTabindices(nextIndex);\n\n // Focus the next item\n nextItem.focus();\n\n // Optionally select/activate the item.\n // Select when `selectOnFocus` is enabled, or when Home/End keys\n // were used and the consumer explicitly opted in via `selectOnHomeEnd`.\n const shouldSelect =\n this.config.selectOnFocus === true || ((isHome || isEnd) && this.config.selectOnHomeEnd === true);\n\n if (shouldSelect && this.config.onSelect) {\n this.config.onSelect(nextItem, event);\n }\n\n return true;\n }\n\n return false;\n }\n\n /**\n * Get the next index based on direction\n */\n private getNextIndex(items: T[], currentIndex: number, direction: 1 | -1): number {\n const { wrap } = this.config;\n let nextIndex = currentIndex + direction;\n\n if (wrap) {\n // Wrap around\n if (nextIndex < 0) {\n nextIndex = items.length - 1;\n } else if (nextIndex >= items.length) {\n nextIndex = 0;\n }\n } else {\n // Clamp to bounds\n nextIndex = Math.max(0, Math.min(items.length - 1, nextIndex));\n }\n\n return nextIndex;\n }\n\n /**\n * Find the next valid (non-disabled) index\n */\n private findNextValidIndex(items: T[], startIndex: number, direction: 1 | -1): number {\n const maxAttempts = items.length;\n let attempts = 0;\n let index = startIndex;\n\n while (attempts < maxAttempts) {\n if (!this.config.skipItem(items[index])) {\n return index;\n }\n\n index = this.getNextIndex(items, index, direction);\n attempts += 1;\n }\n\n // All items are disabled\n return -1;\n }\n\n /**\n * Set focus to a specific item\n */\n focusItem(item: T): void {\n const items = this.config.getItems();\n const index = items.indexOf(item);\n\n if (index !== -1) {\n this.updateTabindices(index);\n item.focus();\n }\n }\n\n /**\n * Set focus to the first non-disabled item\n */\n focusFirst(): void {\n const items = this.config.getItems();\n const firstValidIndex = this.findNextValidIndex(items, 0, 1);\n\n if (firstValidIndex !== -1) {\n this.focusItem(items[firstValidIndex]);\n }\n }\n\n /**\n * Set focus to the last non-disabled item\n */\n focusLast(): void {\n const items = this.config.getItems();\n const lastValidIndex = this.findNextValidIndex(items, items.length - 1, -1);\n\n if (lastValidIndex !== -1) {\n this.focusItem(items[lastValidIndex]);\n }\n }\n}\n"]}
@@ -37,12 +37,13 @@ export declare class FormControl extends BaseLocalizedComponent {
37
37
  maxlength: number;
38
38
  /** If the input is required. */
39
39
  required: boolean;
40
+ protected isInGroup: boolean;
40
41
  /** Gets the validity state object */
41
42
  get validity(): ValidityState;
42
43
  validationMessage: string;
43
- checkValidity(): boolean;
44
44
  /** Gets the associated form, if one exists. */
45
45
  getForm(): HTMLFormElement | null;
46
+ checkValidity(): boolean;
46
47
  /** Checks for validity and shows the browser's validation message if the control is invalid. */
47
48
  reportValidity(): boolean;
48
49
  /** Sets a custom validation message. Pass an empty string to restore validity. */
@@ -1 +1 @@
1
- {"version":3,"file":"form-control.d.ts","sourceRoot":"","sources":["../../../src/form/form-control.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAK7D,qBAAa,WAAY,SAAQ,sBAAsB;IACrD,SAAS,CAAC,QAAQ,CAAC,qBAAqB,wBAErC;IASH,QAAQ,UAAS;IAGjB,YAAY,EAAG,gBAAgB,CAAC;IAEhC,4EAA4E;IAE5E,IAAI,SAAM;IAEV,qFAAqF;IAErF,KAAK,SAAM;IAEX,gCAAgC;IAEhC,QAAQ,UAAS;IAEjB;;;;OAIG;IACwC,IAAI,SAAM;IAErD,0FAA0F;IAE1F,gBAAgB,UAAS;IAEzB,uGAAuG;IAEvG,cAAc,EAAE,MAAM,CAAM;IAE5B,iDAAiD;IAEjD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,8EAA8E;IAE9E,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAExC,8EAA8E;IAE9E,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAExC;;;OAGG;IAEH,IAAI,EAAE,MAAM,GAAG,KAAK,CAAS;IAE7B,kCAAkC;IAElC,SAAS,SAAM;IAEf,kCAAkC;IAElC,SAAS,SAAM;IAEf,gCAAgC;IAEhC,QAAQ,UA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E5B,iDAAiD;IAEjD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,8EAA8E;IAE9E,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAExC,8EAA8E;IAE9E,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAExC;;;OAGG;IAEH,IAAI,EAAE,MAAM,GAAG,KAAK,CAAS;IAE7B,kCAAkC;IAElC,SAAS,SAAM;IAEf,kCAAkC;IAElC,SAAS,SAAM;IAEf,gCAAgC;IAEhC,QAAQ,UAAS;IAIjB,SAAS,CAAC,SAAS,UAAS;IAE5B,qCAAqC;IACrC,IAAW,QAAQ,IAAI,aAAa,CAEnC;IAGM,iBAAiB,SAAM;IAE9B,+CAA+C;IACxC,OAAO,IAAI,eAAe,GAAG,IAAI;IAKjC,aAAa,IAAI,OAAO;IAK/B,gGAAgG;IACzF,cAAc;IAOrB,kFAAkF;IAC3E,iBAAiB,CAAC,OAAO,EAAE,MAAM;IAOxC,SAAS,CAAC,YAAY;IAOtB,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK;IAY/B,SAAS,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK;IAO9B,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK;IAK/B,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,KAAK;IAO/B,SAAS,CAAC,wBAAwB;IAmClC,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK;IAKrC,SAAS,CAAC,aAAa,CAAC,CAAC,EAAE,KAAK;IAoCvB,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC;CAS3E"}
@@ -43,24 +43,27 @@ export class FormControl extends BaseLocalizedComponent {
43
43
  this.maxlength = -1;
44
44
  /** If the input is required. */
45
45
  this.required = false;
46
+ /* For grouped input, like checkbox-group */
47
+ this.isInGroup = false;
46
48
  this.validationMessage = '';
47
49
  }
48
50
  /** Gets the validity state object */
49
51
  get validity() {
50
52
  return this.inputElement?.validity;
51
53
  }
54
+ /** Gets the associated form, if one exists. */
55
+ getForm() {
56
+ return this.formControlController.getForm();
57
+ }
52
58
  // Form validation methods
53
59
  checkValidity() {
54
60
  const inputValid = this.inputElement?.checkValidity() ?? true; // this.inputElement.checkValidity() è la validazione del browser
55
61
  return inputValid;
56
62
  }
57
- /** Gets the associated form, if one exists. */
58
- getForm() {
59
- return this.formControlController.getForm();
60
- }
61
63
  /** Checks for validity and shows the browser's validation message if the control is invalid. */
62
64
  reportValidity() {
63
- const ret = this.inputElement.checkValidity();
65
+ // const ret = this.inputElement.checkValidity();
66
+ const ret = this.checkValidity(); // chiama la checkValidity, che se è stata overridata chiama quella
64
67
  this.handleValidationMessages();
65
68
  return ret; // this.inputElement.reportValidity();
66
69
  }
@@ -105,7 +108,8 @@ export class FormControl extends BaseLocalizedComponent {
105
108
  handleValidationMessages() {
106
109
  if (!this.customValidation) {
107
110
  const _v = this.inputElement.validity;
108
- if (_v.valueMissing) {
111
+ const isRequiredHandledByGroup = this.isInGroup === true;
112
+ if (_v.valueMissing && !isRequiredHandledByGroup) {
109
113
  this.setCustomValidity(this.$t('validityRequired'));
110
114
  }
111
115
  else if (_v.patternMismatch) {
@@ -176,7 +180,7 @@ export class FormControl extends BaseLocalizedComponent {
176
180
  if (this.customValidation) {
177
181
  this.setCustomValidity(this.validationText ?? '');
178
182
  }
179
- else {
183
+ else if (this.formControlController.userInteracted()) {
180
184
  this.formControlController.updateValidity();
181
185
  }
182
186
  }
@@ -244,6 +248,10 @@ __decorate([
244
248
  ,
245
249
  __metadata("design:type", Object)
246
250
  ], FormControl.prototype, "required", void 0);
251
+ __decorate([
252
+ property({ type: Boolean }),
253
+ __metadata("design:type", Object)
254
+ ], FormControl.prototype, "isInGroup", void 0);
247
255
  __decorate([
248
256
  state(),
249
257
  __metadata("design:type", Object)
@@ -1 +1 @@
1
- {"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,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;0CACjB;AAIX;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,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;AAQV;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 /** Gets the validity state object */\n public get validity(): ValidityState {\n return this.inputElement?.validity;\n }\n\n @state()\n public validationMessage = '';\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 /** Gets the associated form, if one exists. */\n public getForm(): HTMLFormElement | null {\n return this.formControlController.getForm();\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 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\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\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\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 if (_v.valueMissing) {\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 {\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,sBAAsB,CAAC;AAC7D,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEjC,mBAAmB,CAAC,EAAE,CAAC,CAAC;AAExB,MAAM,OAAO,WAAY,SAAQ,sBAAsB;IAAvD;;QACq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AM,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"]}
@@ -24,6 +24,7 @@ export declare class FormControlController implements ReactiveController {
24
24
  host: FormControl & ReactiveControllerHost;
25
25
  form?: HTMLFormElement | null;
26
26
  options: FormControlControllerOptions;
27
+ submittedOnce: boolean;
27
28
  constructor(host: ReactiveControllerHost & FormControl, options?: Partial<FormControlControllerOptions>);
28
29
  hostConnected(): void;
29
30
  hostDisconnected(): void;
@@ -49,6 +50,7 @@ export declare class FormControlController implements ReactiveController {
49
50
  * the host element immediately, i.e. before Lit updates the component in the next update.
50
51
  */
51
52
  setValidity(isValid: boolean): void;
53
+ userInteracted(): boolean;
52
54
  /**
53
55
  * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
54
56
  * that affects constraint validation changes so the component receives the correct validity states.
@@ -1 +1 @@
1
- {"version":3,"file":"form-controller.d.ts","sourceRoot":"","sources":["../../../src/form/form-controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,WAAW,CAAC,CAAiB,CAAC;AAoBzF,MAAM,WAAW,4BAA4B;IAC3C,oEAAoE;IACpE,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,eAAe,GAAG,IAAI,CAAC;IACrD,mGAAmG;IACnG,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC;IACrC,gEAAgE;IAChE,KAAK,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,GAAG,OAAO,EAAE,CAAC;IACnD,oHAAoH;IACpH,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAK1C,cAAc,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAMhD,aAAa,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IAC/C,oDAAoD;IACpD,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACvD;;qFAEiF;IACjF,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC/B;AAED,uGAAuG;AACvG,qBAAa,qBAAsB,YAAW,kBAAkB;IAC9D,IAAI,EAAE,WAAW,GAAG,sBAAsB,CAAC;IAE3C,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAE9B,OAAO,EAAE,4BAA4B,CAAC;gBAE1B,IAAI,EAAE,sBAAsB,GAAG,WAAW,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,4BAA4B,CA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C,OAAO,EAAE,OAAO;IAmB5B,cAAc;IAMd;;;OAGG;IACH,cAAc;IAKd;;;;;;OAMG;IACH,gBAAgB,CAAC,oBAAoB,CAAC,EAAE,KAAK;CAgB9C"}
@@ -22,6 +22,7 @@ const interactions = new WeakMap();
22
22
  /** A reactive controller to allow form controls to participate in form submission, validation, etc. */
23
23
  export class FormControlController {
24
24
  constructor(host, options) {
25
+ this.submittedOnce = false;
25
26
  this.handleFormData = (event) => {
26
27
  // console.log('handleFormData');
27
28
  const disabled = this.options.disabled(this.host);
@@ -43,6 +44,27 @@ export class FormControlController {
43
44
  event.formData.append(name, value);
44
45
  }
45
46
  break;
47
+ case 'it-checkbox':
48
+ case 'it-toggle':
49
+ if (this.host.checked) {
50
+ if (event.formData.getAll(name).indexOf(value) < 0) {
51
+ // handle group checkbox
52
+ event.formData.append(name, value);
53
+ }
54
+ }
55
+ break;
56
+ case 'it-checkbox-group':
57
+ case 'it-toggle-group':
58
+ // non settare valori in formData, perchè ogni singola checkbox setta il suo valore
59
+ break;
60
+ case 'it-upload':
61
+ // value is File[] — append each File object directly (not as string)
62
+ if (Array.isArray(value)) {
63
+ value.forEach((file) => {
64
+ event.formData.append(name, file);
65
+ });
66
+ }
67
+ break;
46
68
  default:
47
69
  if (Array.isArray(value)) {
48
70
  value.forEach((val) => {
@@ -64,13 +86,30 @@ export class FormControlController {
64
86
  this.setUserInteracted(control, true);
65
87
  });
66
88
  }
67
- if (this.form && !this.form.noValidate && !disabled && !reportValidity(this.host)) {
89
+ const resReportValidity = reportValidity(this.host);
90
+ if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {
68
91
  event.preventDefault();
69
92
  // event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta
93
+ // Scroll al primo controllo non valido
94
+ const formControls = formCollections.get(this.form);
95
+ if (formControls) {
96
+ for (const control of formControls) {
97
+ if (!control.validity?.valid) {
98
+ // Scroll smooth verso il controllo non valido
99
+ control.scrollIntoView({
100
+ behavior: 'smooth',
101
+ block: 'center',
102
+ });
103
+ break;
104
+ }
105
+ }
106
+ }
70
107
  }
108
+ this.submittedOnce = true;
71
109
  };
72
110
  this.handleFormReset = () => {
73
111
  this.options.setValue(this.host, '');
112
+ this.submittedOnce = false;
74
113
  this.setUserInteracted(this.host, false);
75
114
  interactions.set(this.host, []);
76
115
  };
@@ -235,6 +274,7 @@ export class FormControlController {
235
274
  if (!formCollection) {
236
275
  return;
237
276
  }
277
+ this.submittedOnce = false;
238
278
  // Remove this host from the form's collection
239
279
  formCollection.delete(this.host);
240
280
  // Check to make sure there's no other form controls in the collection. If we do this
@@ -331,6 +371,10 @@ export class FormControlController {
331
371
  host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);
332
372
  host.toggleAttribute('data-user-valid', isValid && hasInteracted);
333
373
  }
374
+ userInteracted() {
375
+ const hasInteracted = Boolean(userInteractedControls.has(this.host));
376
+ return hasInteracted;
377
+ }
334
378
  /**
335
379
  * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
336
380
  * that affects constraint validation changes so the component receives the correct validity states.
@@ -1 +1 @@
1
- {"version":3,"file":"form-controller.js","sourceRoot":"","sources":["../../../src/form/form-controller.ts"],"names":[],"mappings":"AAIA,EAAE;AACF,8GAA8G;AAC9G,oHAAoH;AACpH,uDAAuD;AACvD,EAAE;AACF,MAAM,CAAC,MAAM,eAAe,GAA+C,IAAI,OAAO,EAAE,CAAC;AAEzF,EAAE;AACF,mHAAmH;AACnH,sDAAsD;AACtD,EAAE;AACF,MAAM,uBAAuB,GAA4C,IAAI,OAAO,EAAE,CAAC;AACvF,MAAM,sBAAsB,GAA4C,IAAI,OAAO,EAAE,CAAC;AAEtF,EAAE;AACF,gHAAgH;AAChH,6DAA6D;AAC7D,EAAE;AACF,MAAM,sBAAsB,GAAyB,IAAI,OAAO,EAAE,CAAC;AAEnE,EAAE;AACF,uHAAuH;AACvH,EAAE;AACF,MAAM,YAAY,GAAG,IAAI,OAAO,EAAyB,CAAC;AA8B1D,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,IAAI,WAAW,CAA6B,YAAY,EAAE;YAC/E,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,KAAK;YACf,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,EAAE;SACX,CAAC,CAAC;QAEH,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC1B,cAAc,CAAC,cAAc,EAAE,CAAC;QAClC,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,CAAC;YAC7C,oBAAoB,EAAE,cAAc,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["/* eslint-disable prefer-destructuring */\nimport type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport { FormControl } from './form-control.js';\n\n//\n// We store a WeakMap of forms + controls so we can keep references to all FormControl within a given form. As\n// elements connect and disconnect to/from the DOM, their containing form is used as the key and the form control is\n// added and removed from the form's set, respectively.\n//\nexport const formCollections: WeakMap<HTMLFormElement, Set<FormControl>> = new WeakMap();\n\n//\n// We store a WeakMap of reportValidity() overloads so we can override it when form controls connect to the DOM and\n// restore the original behavior when they disconnect.\n//\nconst reportValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\nconst checkValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\n\n//\n// We store a Set of controls that users have interacted with. This allows us to determine the interaction state\n// without littering the DOM with additional data attributes.\n//\nconst userInteractedControls: WeakSet<FormControl> = new WeakSet();\n\n//\n// We store a WeakMap of interactions for each form control so we can track when all conditions are met for validation.\n//\nconst interactions = new WeakMap<FormControl, string[]>();\n\nexport interface FormControlControllerOptions {\n /** A function that returns the form containing the form control. */\n form: (input: FormControl) => HTMLFormElement | null;\n /** A function that returns the form control's name, which will be submitted with the form data. */\n name: (input: FormControl) => string;\n /** A function that returns the form control's current value. */\n value: (input: FormControl) => unknown | unknown[];\n /** A function that returns the form control's current disabled state. If disabled, the value won't be submitted. */\n disabled: (input: FormControl) => boolean;\n // /**\n // * A function that maps to the form control's reportValidity() function. When the control is invalid, this will\n // * prevent submission and trigger the browser's constraint violation warning.\n // */\n reportValidity: (input: FormControl) => boolean;\n\n // /**\n // * A function that maps to the form control's `checkValidity()` function. When the control is invalid, this will return false.\n // * this is helpful is you want to check validation without triggering the native browser constraint violation warning.\n // */\n checkValidity: (input: FormControl) => boolean;\n /** A function that sets the form control's value */\n setValue: (input: FormControl, value: unknown) => void;\n /**\n * An array of event names to listen to. When all events in the list are emitted, the control will receive validity\n * states such as user-valid and user-invalid.user interacted validity states. */\n assumeInteractionOn: string[];\n}\n\n/** A reactive controller to allow form controls to participate in form submission, validation, etc. */\nexport class FormControlController implements ReactiveController {\n host: FormControl & ReactiveControllerHost;\n\n form?: HTMLFormElement | null;\n\n options: FormControlControllerOptions;\n\n constructor(host: ReactiveControllerHost & FormControl, options?: Partial<FormControlControllerOptions>) {\n (this.host = host).addController(this);\n this.options = {\n form: (input) => {\n // If there's a form attribute, use it to find the target form by id\n // Controls may not always reflect the 'form' property. For example, `<it-button>` doesn't reflect.\n const formId = input.form;\n\n if (formId) {\n const root = input.getRootNode() as Document | ShadowRoot | HTMLElement;\n const form = root.querySelector(`#${formId}`);\n\n if (form) {\n return form as HTMLFormElement;\n }\n }\n\n return input.closest('form');\n },\n name: (input) => input.name,\n value: (input) => input.value,\n disabled: (input) => input.disabled ?? false,\n reportValidity: (input: FormControl) =>\n typeof input.reportValidity === 'function' ? input.reportValidity() : true,\n checkValidity: (input: FormControl) => (typeof input.checkValidity === 'function' ? input.checkValidity() : true),\n setValue: (input, value) => {\n // eslint-disable-next-line no-param-reassign\n input.value = value as string;\n },\n assumeInteractionOn: ['it-input'],\n ...options,\n };\n }\n\n hostConnected() {\n const form = this.options.form(this.host);\n if (form) {\n this.attachForm(form);\n }\n\n // Listen for interactions\n interactions.set(this.host, []);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.addEventListener(event, this.handleInteraction);\n });\n }\n\n hostDisconnected() {\n this.detachForm();\n\n // Clean up interactions\n interactions.delete(this.host);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.removeEventListener(event, this.handleInteraction);\n });\n }\n\n hostUpdated() {\n const form = this.options.form(this.host);\n\n // Detach if the form no longer exists\n if (!form) {\n this.detachForm();\n }\n\n // If the form has changed, reattach it\n if (form && this.form !== form) {\n this.detachForm();\n this.attachForm(form);\n }\n\n if (this.host.hasUpdated) {\n this.setValidity(this.host.validity.valid);\n }\n }\n\n private attachForm(form?: HTMLFormElement) {\n if (form) {\n this.form = form;\n\n // Add this element to the form's collection\n if (formCollections.has(this.form)) {\n formCollections.get(this.form)!.add(this.host);\n } else {\n formCollections.set(this.form, new Set<FormControl>([this.host]));\n }\n\n this.form.addEventListener('formdata', this.handleFormData);\n this.form.addEventListener('submit', this.handleFormSubmit);\n this.form.addEventListener('reset', this.handleFormReset);\n\n // Overload the form's reportValidity() method so it looks at FormControl\n if (!reportValidityOverloads.has(this.form)) {\n reportValidityOverloads.set(this.form, this.form.reportValidity);\n this.form.reportValidity = () => this.reportFormValidity();\n }\n\n // Overload the form's checkValidity() method so it looks at FormControl\n if (!checkValidityOverloads.has(this.form)) {\n checkValidityOverloads.set(this.form, this.form.checkValidity);\n this.form.checkValidity = () => this.checkFormValidity();\n }\n } else {\n this.form = undefined;\n }\n }\n\n private detachForm() {\n if (!this.form) return;\n\n const formCollection = formCollections.get(this.form);\n\n if (!formCollection) {\n return;\n }\n\n // Remove this host from the form's collection\n formCollection.delete(this.host);\n\n // Check to make sure there's no other form controls in the collection. If we do this\n // without checking if any other controls are still in the collection, then we will wipe out the\n // validity checks for all other elements.\n // see: https://github.com/shoelace-style/shoelace/issues/1703\n if (formCollection.size <= 0) {\n this.form.removeEventListener('formdata', this.handleFormData);\n this.form.removeEventListener('submit', this.handleFormSubmit);\n this.form.removeEventListener('reset', this.handleFormReset);\n\n // Remove the overload and restore the original method\n if (reportValidityOverloads.has(this.form)) {\n this.form.reportValidity = reportValidityOverloads.get(this.form)!;\n reportValidityOverloads.delete(this.form);\n }\n\n if (checkValidityOverloads.has(this.form)) {\n this.form.checkValidity = checkValidityOverloads.get(this.form)!;\n checkValidityOverloads.delete(this.form);\n }\n\n // So it looks weird here to not always set the form to undefined. But I _think_ if we unattach this.form here,\n // we end up in this fun spot where future validity checks don't have a reference to the form validity handler.\n // First form element in sets the validity handler. So we can't clean up `this.form` until there are no other form elements in the form.\n this.form = undefined;\n }\n }\n\n private handleFormData = (event: FormDataEvent) => {\n // console.log('handleFormData');\n const disabled = this.options.disabled(this.host);\n const name = this.options.name(this.host);\n const value = this.options.value(this.host);\n const tagName = this.host.tagName.toLowerCase();\n\n // For buttons, we only submit the value if they were the submitter. This is currently done in doAction() by\n // injecting the name/value on a temporary button, so we can just skip them here.\n const isButton = tagName === 'it-button';\n\n if (\n this.host.isConnected &&\n !disabled &&\n !isButton &&\n typeof name === 'string' &&\n name.length > 0 &&\n typeof value !== 'undefined'\n ) {\n switch (tagName) {\n case 'it-radio':\n if ((this.host as any).checked) {\n event.formData.append(name, value as string);\n }\n break;\n default:\n if (Array.isArray(value)) {\n (value as unknown[]).forEach((val) => {\n event.formData.append(name, (val as string | number | boolean).toString());\n });\n } else {\n event.formData.append(name, (value as string | number | boolean).toString());\n }\n }\n }\n };\n\n private handleFormSubmit = (event: Event) => {\n const disabled = this.options.disabled(this.host);\n const reportValidity = this.options.reportValidity;\n\n // Update the interacted state for all controls when the form is submitted\n if (this.form && !this.form.noValidate) {\n formCollections.get(this.form)?.forEach((control) => {\n this.setUserInteracted(control, true);\n });\n }\n\n if (this.form && !this.form.noValidate && !disabled && !reportValidity(this.host)) {\n event.preventDefault();\n // event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta\n }\n };\n\n private handleFormReset = () => {\n this.options.setValue(this.host, '');\n this.setUserInteracted(this.host, false);\n interactions.set(this.host, []);\n };\n\n private handleInteraction = (event: Event) => {\n const emittedEvents = interactions.get(this.host)!;\n\n if (!emittedEvents.includes(event.type)) {\n emittedEvents.push(event.type);\n }\n\n // Mark it as user-interacted as soon as all associated events have been emitted\n if (emittedEvents.length === this.options.assumeInteractionOn.length) {\n this.setUserInteracted(this.host, true);\n }\n };\n\n private checkFormValidity = () => {\n // console.log('checkFormValidity');\n //\n // This is very similar to the `reportFormValidity` function, but it does not trigger native constraint validation\n // Allow the user to simply check if the form is valid and handling validity in their own way.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.checkValidity === 'function') {\n if (!element.checkValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n private reportFormValidity = () => {\n // console.log('reportFormValidity');\n //\n // FormControl work hard to act like regular form controls. They support the Constraint Validation API\n // and its associated methods such as setCustomValidity() and reportValidity(). However, the HTMLFormElement also\n // has a reportValidity() method that will trigger validation on all child controls. Since we're not yet using\n // ElementInternals, we need to overload this method so it looks for any element with the reportValidity() method.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.reportValidity === 'function') {\n if (!element.reportValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n // eslint-disable-next-line class-methods-use-this\n private setUserInteracted(el: FormControl, hasInteracted: boolean) {\n if (hasInteracted) {\n userInteractedControls.add(el);\n } else {\n userInteractedControls.delete(el);\n }\n\n el.requestUpdate();\n }\n\n private doAction(type: 'submit' | 'reset', submitter?: HTMLInputElement | any) {\n // console.log('doaction', type);\n if (this.form) {\n const button = document.createElement('button');\n button.type = type;\n button.style.position = 'absolute';\n button.style.width = '0';\n button.style.height = '0';\n button.style.clipPath = 'inset(50%)';\n button.style.overflow = 'hidden';\n button.style.whiteSpace = 'nowrap';\n\n // Pass name, value, and form attributes through to the temporary button\n if (submitter) {\n button.name = submitter.name;\n button.value = submitter.value;\n\n ['formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget'].forEach((attr) => {\n if (submitter.hasAttribute(attr)) {\n button.setAttribute(attr, submitter.getAttribute(attr)!);\n }\n });\n }\n\n this.form.append(button);\n button.click();\n button.remove();\n }\n }\n\n /** Returns the associated `<form>` element, if one exists. */\n getForm() {\n return this.form ?? null;\n }\n\n /** Resets the form, restoring all the control to their default value */\n reset(submitter?: HTMLInputElement | any) {\n this.doAction('reset', submitter);\n }\n\n /** Submits the form, triggering validation and form data injection. */\n submit(submitter?: HTMLInputElement | any) {\n // Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a\n // native submit button into the form, \"click\" it, then remove it to simulate a standard form submission.\n this.doAction('submit', submitter);\n }\n\n /**\n * Synchronously sets the form control's validity. Call this when you know the future validity but need to update\n * the host element immediately, i.e. before Lit updates the component in the next update.\n */\n setValidity(isValid: boolean) {\n const host = this.host;\n const hasInteracted = Boolean(userInteractedControls.has(host));\n const required = Boolean(host.required);\n\n //\n // We're mapping the following \"states\" to data attributes. In the future, we can use ElementInternals.states to\n // create a similar mapping, but instead of [data-invalid] it will look like :--invalid.\n //\n // See this RFC for more details: https://github.com/shoelace-style/shoelace/issues/1011\n //\n host.toggleAttribute('data-required', required);\n host.toggleAttribute('data-optional', !required);\n host.toggleAttribute('data-invalid', !isValid);\n host.toggleAttribute('data-valid', isValid);\n host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);\n host.toggleAttribute('data-user-valid', isValid && hasInteracted);\n }\n\n /**\n * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything\n * that affects constraint validation changes so the component receives the correct validity states.\n */\n updateValidity() {\n const host = this.host;\n this.setValidity(host.validity.valid);\n }\n\n /**\n * Dispatches a non-bubbling, cancelable custom event of type `it-invalid`.\n * If the `it-invalid` event will be cancelled then the original `invalid`\n * event (which may have been passed as argument) will also be cancelled.\n * If no original `invalid` event has been passed then the `it-invalid`\n * event will be cancelled before being dispatched.\n */\n emitInvalidEvent(originalInvalidEvent?: Event) {\n const itInvalidEvent = new CustomEvent<Record<PropertyKey, never>>('it-invalid', {\n bubbles: false,\n composed: false,\n cancelable: true,\n detail: {},\n });\n\n if (!originalInvalidEvent) {\n itInvalidEvent.preventDefault();\n }\n\n if (!this.host.dispatchEvent(itInvalidEvent)) {\n originalInvalidEvent?.preventDefault();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"form-controller.js","sourceRoot":"","sources":["../../../src/form/form-controller.ts"],"names":[],"mappings":"AAIA,EAAE;AACF,8GAA8G;AAC9G,oHAAoH;AACpH,uDAAuD;AACvD,EAAE;AACF,MAAM,CAAC,MAAM,eAAe,GAA+C,IAAI,OAAO,EAAE,CAAC;AAEzF,EAAE;AACF,mHAAmH;AACnH,sDAAsD;AACtD,EAAE;AACF,MAAM,uBAAuB,GAA4C,IAAI,OAAO,EAAE,CAAC;AACvF,MAAM,sBAAsB,GAA4C,IAAI,OAAO,EAAE,CAAC;AAEtF,EAAE;AACF,gHAAgH;AAChH,6DAA6D;AAC7D,EAAE;AACF,MAAM,sBAAsB,GAAyB,IAAI,OAAO,EAAE,CAAC;AAEnE,EAAE;AACF,uHAAuH;AACvH,EAAE;AACF,MAAM,YAAY,GAAG,IAAI,OAAO,EAAyB,CAAC;AA8B1D,uGAAuG;AACvG,MAAM,OAAO,qBAAqB;IAShC,YAAY,IAA0C,EAAE,OAA+C;QAFvG,kBAAa,GAAY,KAAK,CAAC;QAqJvB,mB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C,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,gBAAgB,CAAC,oBAA4B;QAC3C,MAAM,cAAc,GAAG,IAAI,WAAW,CAA6B,YAAY,EAAE;YAC/E,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,KAAK;YACf,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,EAAE;SACX,CAAC,CAAC;QAEH,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC1B,cAAc,CAAC,cAAc,EAAE,CAAC;QAClC,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,CAAC;YAC7C,oBAAoB,EAAE,cAAc,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["/* eslint-disable prefer-destructuring */\nimport type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport { FormControl } from './form-control.js';\n\n//\n// We store a WeakMap of forms + controls so we can keep references to all FormControl within a given form. As\n// elements connect and disconnect to/from the DOM, their containing form is used as the key and the form control is\n// added and removed from the form's set, respectively.\n//\nexport const formCollections: WeakMap<HTMLFormElement, Set<FormControl>> = new WeakMap();\n\n//\n// We store a WeakMap of reportValidity() overloads so we can override it when form controls connect to the DOM and\n// restore the original behavior when they disconnect.\n//\nconst reportValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\nconst checkValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();\n\n//\n// We store a Set of controls that users have interacted with. This allows us to determine the interaction state\n// without littering the DOM with additional data attributes.\n//\nconst userInteractedControls: WeakSet<FormControl> = new WeakSet();\n\n//\n// We store a WeakMap of interactions for each form control so we can track when all conditions are met for validation.\n//\nconst interactions = new WeakMap<FormControl, string[]>();\n\nexport interface FormControlControllerOptions {\n /** A function that returns the form containing the form control. */\n form: (input: FormControl) => HTMLFormElement | null;\n /** A function that returns the form control's name, which will be submitted with the form data. */\n name: (input: FormControl) => string;\n /** A function that returns the form control's current value. */\n value: (input: FormControl) => unknown | unknown[];\n /** A function that returns the form control's current disabled state. If disabled, the value won't be submitted. */\n disabled: (input: FormControl) => boolean;\n // /**\n // * A function that maps to the form control's reportValidity() function. When the control is invalid, this will\n // * prevent submission and trigger the browser's constraint violation warning.\n // */\n reportValidity: (input: FormControl) => boolean;\n\n // /**\n // * A function that maps to the form control's `checkValidity()` function. When the control is invalid, this will return false.\n // * this is helpful is you want to check validation without triggering the native browser constraint violation warning.\n // */\n checkValidity: (input: FormControl) => boolean;\n /** A function that sets the form control's value */\n setValue: (input: FormControl, value: unknown) => void;\n /**\n * An array of event names to listen to. When all events in the list are emitted, the control will receive validity\n * states such as user-valid and user-invalid.user interacted validity states. */\n assumeInteractionOn: string[];\n}\n\n/** A reactive controller to allow form controls to participate in form submission, validation, etc. */\nexport class FormControlController implements ReactiveController {\n host: FormControl & ReactiveControllerHost;\n\n form?: HTMLFormElement | null;\n\n options: FormControlControllerOptions;\n\n submittedOnce: boolean = false;\n\n constructor(host: ReactiveControllerHost & FormControl, options?: Partial<FormControlControllerOptions>) {\n (this.host = host).addController(this);\n this.options = {\n form: (input) => {\n // If there's a form attribute, use it to find the target form by id\n // Controls may not always reflect the 'form' property. For example, `<it-button>` doesn't reflect.\n const formId = input.form;\n\n if (formId) {\n const root = input.getRootNode() as Document | ShadowRoot | HTMLElement;\n const form = root.querySelector(`#${formId}`);\n\n if (form) {\n return form as HTMLFormElement;\n }\n }\n\n return input.closest('form');\n },\n name: (input) => input.name,\n value: (input) => input.value,\n disabled: (input) => input.disabled ?? false,\n reportValidity: (input: FormControl) =>\n typeof input.reportValidity === 'function' ? input.reportValidity() : true,\n checkValidity: (input: FormControl) => (typeof input.checkValidity === 'function' ? input.checkValidity() : true),\n setValue: (input, value) => {\n // eslint-disable-next-line no-param-reassign\n input.value = value as string;\n },\n assumeInteractionOn: ['it-input'],\n ...options,\n };\n }\n\n hostConnected() {\n const form = this.options.form(this.host);\n if (form) {\n this.attachForm(form);\n }\n\n // Listen for interactions\n interactions.set(this.host, []);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.addEventListener(event, this.handleInteraction);\n });\n }\n\n hostDisconnected() {\n this.detachForm();\n\n // Clean up interactions\n interactions.delete(this.host);\n this.options.assumeInteractionOn.forEach((event) => {\n this.host.removeEventListener(event, this.handleInteraction);\n });\n }\n\n hostUpdated() {\n const form = this.options.form(this.host);\n\n // Detach if the form no longer exists\n if (!form) {\n this.detachForm();\n }\n\n // If the form has changed, reattach it\n if (form && this.form !== form) {\n this.detachForm();\n this.attachForm(form);\n }\n\n if (this.host.hasUpdated) {\n this.setValidity(this.host.validity.valid);\n }\n }\n\n private attachForm(form?: HTMLFormElement) {\n if (form) {\n this.form = form;\n\n // Add this element to the form's collection\n if (formCollections.has(this.form)) {\n formCollections.get(this.form)!.add(this.host);\n } else {\n formCollections.set(this.form, new Set<FormControl>([this.host]));\n }\n\n this.form.addEventListener('formdata', this.handleFormData);\n this.form.addEventListener('submit', this.handleFormSubmit);\n this.form.addEventListener('reset', this.handleFormReset);\n\n // Overload the form's reportValidity() method so it looks at FormControl\n if (!reportValidityOverloads.has(this.form)) {\n reportValidityOverloads.set(this.form, this.form.reportValidity);\n this.form.reportValidity = () => this.reportFormValidity();\n }\n\n // Overload the form's checkValidity() method so it looks at FormControl\n if (!checkValidityOverloads.has(this.form)) {\n checkValidityOverloads.set(this.form, this.form.checkValidity);\n this.form.checkValidity = () => this.checkFormValidity();\n }\n } else {\n this.form = undefined;\n }\n }\n\n private detachForm() {\n if (!this.form) return;\n\n const formCollection = formCollections.get(this.form);\n\n if (!formCollection) {\n return;\n }\n this.submittedOnce = false;\n\n // Remove this host from the form's collection\n formCollection.delete(this.host);\n\n // Check to make sure there's no other form controls in the collection. If we do this\n // without checking if any other controls are still in the collection, then we will wipe out the\n // validity checks for all other elements.\n // see: https://github.com/shoelace-style/shoelace/issues/1703\n if (formCollection.size <= 0) {\n this.form.removeEventListener('formdata', this.handleFormData);\n this.form.removeEventListener('submit', this.handleFormSubmit);\n this.form.removeEventListener('reset', this.handleFormReset);\n\n // Remove the overload and restore the original method\n if (reportValidityOverloads.has(this.form)) {\n this.form.reportValidity = reportValidityOverloads.get(this.form)!;\n reportValidityOverloads.delete(this.form);\n }\n\n if (checkValidityOverloads.has(this.form)) {\n this.form.checkValidity = checkValidityOverloads.get(this.form)!;\n checkValidityOverloads.delete(this.form);\n }\n\n // So it looks weird here to not always set the form to undefined. But I _think_ if we unattach this.form here,\n // we end up in this fun spot where future validity checks don't have a reference to the form validity handler.\n // First form element in sets the validity handler. So we can't clean up `this.form` until there are no other form elements in the form.\n this.form = undefined;\n }\n }\n\n private handleFormData = (event: FormDataEvent) => {\n // console.log('handleFormData');\n const disabled = this.options.disabled(this.host);\n const name = this.options.name(this.host);\n const value = this.options.value(this.host);\n const tagName = this.host.tagName.toLowerCase();\n\n // For buttons, we only submit the value if they were the submitter. This is currently done in doAction() by\n // injecting the name/value on a temporary button, so we can just skip them here.\n const isButton = tagName === 'it-button';\n\n if (\n this.host.isConnected &&\n !disabled &&\n !isButton &&\n typeof name === 'string' &&\n name.length > 0 &&\n typeof value !== 'undefined'\n ) {\n switch (tagName) {\n case 'it-radio':\n if ((this.host as any).checked) {\n event.formData.append(name, value as string);\n }\n break;\n case 'it-checkbox':\n case 'it-toggle':\n if ((this.host as any).checked) {\n if (event.formData.getAll(name).indexOf(value as string) < 0) {\n // handle group checkbox\n event.formData.append(name, value as string);\n }\n }\n break;\n case 'it-checkbox-group':\n case 'it-toggle-group':\n // non settare valori in formData, perchè ogni singola checkbox setta il suo valore\n break;\n case 'it-upload':\n // value is File[] — append each File object directly (not as string)\n if (Array.isArray(value)) {\n (value as File[]).forEach((file) => {\n event.formData.append(name, file);\n });\n }\n break;\n default:\n if (Array.isArray(value)) {\n (value as unknown[]).forEach((val) => {\n event.formData.append(name, (val as string | number | boolean).toString());\n });\n } else {\n event.formData.append(name, (value as string | number | boolean).toString());\n }\n }\n }\n };\n\n private handleFormSubmit = (event: Event) => {\n const disabled = this.options.disabled(this.host);\n const reportValidity = this.options.reportValidity;\n\n // Update the interacted state for all controls when the form is submitted\n if (this.form && !this.form.noValidate) {\n formCollections.get(this.form)?.forEach((control) => {\n this.setUserInteracted(control, true);\n });\n }\n\n const resReportValidity = reportValidity(this.host);\n\n if (this.form && !this.form.noValidate && !disabled && !resReportValidity) {\n event.preventDefault();\n // event.stopImmediatePropagation(); // se lo attiviamo, valida un campo alla volta\n\n // Scroll al primo controllo non valido\n const formControls = formCollections.get(this.form);\n if (formControls) {\n for (const control of formControls) {\n if (!control.validity?.valid) {\n // Scroll smooth verso il controllo non valido\n control.scrollIntoView({\n behavior: 'smooth',\n block: 'center',\n });\n break;\n }\n }\n }\n }\n this.submittedOnce = true;\n };\n\n private handleFormReset = () => {\n this.options.setValue(this.host, '');\n this.submittedOnce = false;\n this.setUserInteracted(this.host, false);\n interactions.set(this.host, []);\n };\n\n private handleInteraction = (event: Event) => {\n const emittedEvents = interactions.get(this.host)!;\n\n if (!emittedEvents.includes(event.type)) {\n emittedEvents.push(event.type);\n }\n\n // Mark it as user-interacted as soon as all associated events have been emitted\n if (emittedEvents.length === this.options.assumeInteractionOn.length) {\n this.setUserInteracted(this.host, true);\n }\n };\n\n private checkFormValidity = () => {\n // console.log('checkFormValidity');\n //\n // This is very similar to the `reportFormValidity` function, but it does not trigger native constraint validation\n // Allow the user to simply check if the form is valid and handling validity in their own way.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.checkValidity === 'function') {\n if (!element.checkValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n private reportFormValidity = () => {\n // console.log('reportFormValidity');\n //\n // FormControl work hard to act like regular form controls. They support the Constraint Validation API\n // and its associated methods such as setCustomValidity() and reportValidity(). However, the HTMLFormElement also\n // has a reportValidity() method that will trigger validation on all child controls. Since we're not yet using\n // ElementInternals, we need to overload this method so it looks for any element with the reportValidity() method.\n //\n // We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger\n // validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't\n // be necessary once we can use ElementInternals.\n //\n // Note that we're also honoring the form's novalidate attribute.\n //\n if (this.form && !this.form.noValidate) {\n // This seems sloppy, but checking all elements will cover native inputs, Shoelace inputs, and other custom\n // elements that support the constraint validation API.\n const elements = this.form.querySelectorAll<HTMLInputElement>('*');\n\n for (const element of elements) {\n if (typeof element.reportValidity === 'function') {\n if (!element.reportValidity()) {\n return false;\n }\n }\n }\n }\n\n return true;\n };\n\n // eslint-disable-next-line class-methods-use-this\n private setUserInteracted(el: FormControl, hasInteracted: boolean) {\n if (hasInteracted) {\n userInteractedControls.add(el);\n } else {\n userInteractedControls.delete(el);\n }\n\n el.requestUpdate();\n }\n\n private doAction(type: 'submit' | 'reset', submitter?: HTMLInputElement | any) {\n // console.log('doaction', type);\n if (this.form) {\n const button = document.createElement('button');\n button.type = type;\n button.style.position = 'absolute';\n button.style.width = '0';\n button.style.height = '0';\n button.style.clipPath = 'inset(50%)';\n button.style.overflow = 'hidden';\n button.style.whiteSpace = 'nowrap';\n\n // Pass name, value, and form attributes through to the temporary button\n if (submitter) {\n button.name = submitter.name;\n button.value = submitter.value;\n\n ['formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget'].forEach((attr) => {\n if (submitter.hasAttribute(attr)) {\n button.setAttribute(attr, submitter.getAttribute(attr)!);\n }\n });\n }\n\n this.form.append(button);\n button.click();\n button.remove();\n }\n }\n\n /** Returns the associated `<form>` element, if one exists. */\n getForm() {\n return this.form ?? null;\n }\n\n /** Resets the form, restoring all the control to their default value */\n reset(submitter?: HTMLInputElement | any) {\n this.doAction('reset', submitter);\n }\n\n /** Submits the form, triggering validation and form data injection. */\n submit(submitter?: HTMLInputElement | any) {\n // Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a\n // native submit button into the form, \"click\" it, then remove it to simulate a standard form submission.\n this.doAction('submit', submitter);\n }\n\n /**\n * Synchronously sets the form control's validity. Call this when you know the future validity but need to update\n * the host element immediately, i.e. before Lit updates the component in the next update.\n */\n setValidity(isValid: boolean) {\n const host = this.host;\n const hasInteracted = Boolean(userInteractedControls.has(host));\n const required = Boolean(host.required);\n\n //\n // We're mapping the following \"states\" to data attributes. In the future, we can use ElementInternals.states to\n // create a similar mapping, but instead of [data-invalid] it will look like :--invalid.\n //\n // See this RFC for more details: https://github.com/shoelace-style/shoelace/issues/1011\n //\n host.toggleAttribute('data-required', required);\n host.toggleAttribute('data-optional', !required);\n host.toggleAttribute('data-invalid', !isValid);\n host.toggleAttribute('data-valid', isValid);\n host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);\n host.toggleAttribute('data-user-valid', isValid && hasInteracted);\n }\n\n userInteracted() {\n const hasInteracted = Boolean(userInteractedControls.has(this.host));\n\n return hasInteracted;\n }\n\n /**\n * Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything\n * that affects constraint validation changes so the component receives the correct validity states.\n */\n updateValidity() {\n const host = this.host;\n this.setValidity(host.validity.valid);\n }\n\n /**\n * Dispatches a non-bubbling, cancelable custom event of type `it-invalid`.\n * If the `it-invalid` event will be cancelled then the original `invalid`\n * event (which may have been passed as argument) will also be cancelled.\n * If no original `invalid` event has been passed then the `it-invalid`\n * event will be cancelled before being dispatched.\n */\n emitInvalidEvent(originalInvalidEvent?: Event) {\n const itInvalidEvent = new CustomEvent<Record<PropertyKey, never>>('it-invalid', {\n bubbles: false,\n composed: false,\n cancelable: true,\n detail: {},\n });\n\n if (!originalInvalidEvent) {\n itInvalidEvent.preventDefault();\n }\n\n if (!this.host.dispatchEvent(itInvalidEvent)) {\n originalInvalidEvent?.preventDefault();\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"it.d.ts","sourceRoot":"","sources":["../../../../src/form/locales/it.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,QAAA,MAAM,WAAW,EAAE,kBASlB,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"it.d.ts","sourceRoot":"","sources":["../../../../src/form/locales/it.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,QAAA,MAAM,WAAW,EAAE,kBAUlB,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -3,6 +3,7 @@ const translation = {
3
3
  $name: 'Italiano',
4
4
  $dir: 'ltr',
5
5
  validityRequired: 'Questo campo è obbligatorio.',
6
+ validityGroupRequired: "Scegli almeno un'opzione",
6
7
  validityPattern: 'Il valore non corrisponde al formato richiesto.',
7
8
  validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.',
8
9
  validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.',
@@ -1 +1 @@
1
- {"version":3,"file":"it.js","sourceRoot":"","sources":["../../../../src/form/locales/it.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAuB;IACtC,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,KAAK;IAEX,gBAAgB,EAAE,8BAA8B;IAChD,eAAe,EAAE,iDAAiD;IAClE,iBAAiB,EAAE,2DAA2D;IAC9E,iBAAiB,EAAE,+DAA+D;CACnF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import type { DefaultTranslation } from '@italia/i18n';\n\nconst translation: DefaultTranslation = {\n $code: 'it',\n $name: 'Italiano',\n $dir: 'ltr',\n\n validityRequired: 'Questo campo è obbligatorio.',\n validityPattern: 'Il valore non corrisponde al formato richiesto.',\n validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.',\n validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.',\n};\n\nexport default translation;\n"]}
1
+ {"version":3,"file":"it.js","sourceRoot":"","sources":["../../../../src/form/locales/it.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAuB;IACtC,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,KAAK;IAEX,gBAAgB,EAAE,8BAA8B;IAChD,qBAAqB,EAAE,0BAA0B;IACjD,eAAe,EAAE,iDAAiD;IAClE,iBAAiB,EAAE,2DAA2D;IAC9E,iBAAiB,EAAE,+DAA+D;CACnF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import type { DefaultTranslation } from '@italia/i18n';\n\nconst translation: DefaultTranslation = {\n $code: 'it',\n $name: 'Italiano',\n $dir: 'ltr',\n\n validityRequired: 'Questo campo è obbligatorio.',\n validityGroupRequired: \"Scegli almeno un'opzione\",\n validityPattern: 'Il valore non corrisponde al formato richiesto.',\n validityMinlength: 'Il valore deve essere lungo almeno {minlength} caratteri.',\n validityMaxlength: 'Il valore deve essere lungo al massimo {maxlength} caratteri.',\n};\n\nexport default translation;\n"]}
@@ -2,6 +2,13 @@ import TrackFocus from './utils/track-focus.js';
2
2
  import setAttributes from './directives/setAttributes.js';
3
3
  import AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';
4
4
  import { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';
5
+ declare global {
6
+ interface Window {
7
+ _itAnalytics: {
8
+ version: string;
9
+ };
10
+ }
11
+ }
5
12
  export { TrackFocus, setAttributes, AriaKeyboardListController };
6
13
  export type { AriaKeyboardConfig } from './controllers/aria-keyboard-list-controller.js';
7
14
  export { RovingTabindexController } from './controllers/roving-tabindex-controller.js';
@@ -9,6 +16,7 @@ export type { RovingTabindexConfig } from './controllers/roving-tabindex-control
9
16
  export { BaseComponent, BaseComponentInterface, BaseComponentType, BaseLocalizedComponent, } from './base-component/base-component.js';
10
17
  export { AriaKeyboardAccordionController, type AriaKeyboardAccordionConfig, } from './controllers/aria-keyboard-accordion-controller.js';
11
18
  export { CollapseAnimationController } from './controllers/collapse-controller.js';
19
+ export { FocusTrapController, type FocusTrapConfig } from './controllers/focus-trap-controller.js';
12
20
  export { FormControl } from './form/form-control.js';
13
21
  export { formCollections, FormControlControllerOptions, FormControlController } from './form/form-controller.js';
14
22
  export { cookies } from './utils/cookies.js';
@@ -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,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;AAEnF,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,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OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,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
@@ -2,11 +2,19 @@ import TrackFocus from './utils/track-focus.js';
2
2
  import setAttributes from './directives/setAttributes.js';
3
3
  import AriaKeyboardListController from './controllers/aria-keyboard-list-controller.js';
4
4
  import { StoryFormControlMethodAndProps } from './stories/formControlReusableStories.js';
5
+ if (typeof window !== 'undefined') {
6
+ window._itAnalytics = window._itAnalytics || {};
7
+ window._itAnalytics = {
8
+ ...window._itAnalytics,
9
+ version: '1.0.0-alpha.11',
10
+ };
11
+ }
5
12
  export { TrackFocus, setAttributes, AriaKeyboardListController };
6
13
  export { RovingTabindexController } from './controllers/roving-tabindex-controller.js';
7
14
  export { BaseComponent, BaseLocalizedComponent, } from './base-component/base-component.js';
8
15
  export { AriaKeyboardAccordionController, } from './controllers/aria-keyboard-accordion-controller.js';
9
16
  export { CollapseAnimationController } from './controllers/collapse-controller.js';
17
+ export { FocusTrapController } from './controllers/focus-trap-controller.js';
10
18
  export { FormControl } from './form/form-control.js';
11
19
  export { formCollections, FormControlController } from './form/form-controller.js';
12
20
  export { cookies } from './utils/cookies.js';
@@ -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;AAEzF,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;AAEnF,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\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';\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,gBAAgB;KAC1B,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.11',\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"]}