@travelopia/web-components 0.9.7 → 0.9.8

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.
@@ -130,6 +130,90 @@ export class TPAccordionElement extends HTMLElement {
130
130
  export class TPFormErrorElement extends HTMLElement {
131
131
  }
132
132
 
133
+ /**
134
+ * TP Form Errors Error.
135
+ */
136
+ export class TPFormErrorsErrorElement extends HTMLElement {
137
+ /**
138
+ * Constructor.
139
+ */
140
+ constructor();
141
+ /**
142
+ * Handle click on error link.
143
+ *
144
+ * @param {Event} event Click event.
145
+ */
146
+ protected handleClick(event: Event): void;
147
+ }
148
+
149
+ /**
150
+ * TP Form Errors Heading.
151
+ *
152
+ * Displays the error count. User controls the heading element wrapper.
153
+ */
154
+ export class TPFormErrorsHeadingElement extends HTMLElement {
155
+ /**
156
+ * Get format.
157
+ *
158
+ * @return {string} Format with $count placeholder.
159
+ */
160
+ get format(): string;
161
+ /**
162
+ * Set format.
163
+ *
164
+ * @param {string} format Format string.
165
+ */
166
+ set format(format: string);
167
+ /**
168
+ * Update the heading with the error count.
169
+ *
170
+ * @param {number} count Number of errors.
171
+ */
172
+ update(count: number): void;
173
+ }
174
+
175
+ /**
176
+ * Internal dependencies.
177
+ */
178
+ import { TPFormFieldElement } from './tp-form-field';
179
+ /**
180
+ * TP Form Errors List.
181
+ *
182
+ * Displays the list of error links using tp-form-errors-error elements.
183
+ */
184
+ export class TPFormErrorsListElement extends HTMLElement {
185
+ /**
186
+ * Update the list with error links.
187
+ *
188
+ * @param {TPFormFieldElement[]} invalidFields Array of invalid form fields.
189
+ */
190
+ update(invalidFields: TPFormFieldElement[]): void;
191
+ /**
192
+ * Clear the list.
193
+ */
194
+ clear(): void;
195
+ }
196
+
197
+ /**
198
+ * Internal dependencies.
199
+ */
200
+ import { TPFormFieldElement } from './tp-form-field';
201
+ /**
202
+ * TP Form Errors.
203
+ */
204
+ export class TPFormErrorsElement extends HTMLElement {
205
+ /**
206
+ * Update the error summary with the given invalid fields.
207
+ *
208
+ * @param {TPFormFieldElement[]} invalidFields Array of invalid form fields.
209
+ */
210
+ update(invalidFields: TPFormFieldElement[]): void;
211
+ /**
212
+ * Clear the error summary.
213
+ */
214
+ clear(): void;
215
+ }
216
+
133
217
  /**
134
218
  * TP Form Field.
135
219
  */
@@ -138,6 +222,10 @@ export class TPFormFieldElement extends HTMLElement {
138
222
  * Constructor.
139
223
  */
140
224
  constructor();
225
+ /**
226
+ * Set up accessibility attributes (label linking, IDs).
227
+ */
228
+ private setupAccessibility;
141
229
  /**
142
230
  * Update validation when the field has changed.
143
231
  */
@@ -252,6 +340,16 @@ export class TPFormElement extends HTMLElement {
252
340
  * @return {boolean} Whether the form is valid or not.
253
341
  */
254
342
  validate(): Promise<boolean>;
343
+ /**
344
+ * Handle validation error - update error summary and manage focus.
345
+ *
346
+ * @param {NodeList} fields All form fields.
347
+ */
348
+ protected handleValidationError(fields: NodeListOf<TPFormFieldElement>): void;
349
+ /**
350
+ * Clear the error summary.
351
+ */
352
+ protected clearErrorSummary(): void;
255
353
  /**
256
354
  * Validate one field.
257
355
  *
@@ -426,6 +524,8 @@ export class TPLightboxElement extends HTMLElement {
426
524
  protected swipeThreshold: number;
427
525
  protected dialogElement: HTMLDialogElement | null;
428
526
  protected lightboxNavItems: NodeListOf<TPLightboxNavItemElement> | null;
527
+ protected previouslyFocusedElement: HTMLElement | null;
528
+ protected readonly boundHandleKeyDown: (e: KeyboardEvent) => void;
429
529
  /**
430
530
  * Constructor.
431
531
  */
@@ -444,6 +544,12 @@ export class TPLightboxElement extends HTMLElement {
444
544
  * @param {string} newValue New value.
445
545
  */
446
546
  attributeChangedCallback(name?: string, oldValue?: string, newValue?: string): void;
547
+ /**
548
+ * Check if ARIA management is enabled.
549
+ *
550
+ * @return {boolean} Whether ARIA is enabled.
551
+ */
552
+ isAriaEnabled(): boolean;
447
553
  /**
448
554
  * Get template.
449
555
  */
@@ -534,6 +640,17 @@ export class TPLightboxElement extends HTMLElement {
534
640
  * Update current item in navigation.
535
641
  */
536
642
  updateNavCurrentItem(): void;
643
+ /**
644
+ * Set initial focus when lightbox opens.
645
+ * Looks for [autofocus] element, otherwise focuses the dialog.
646
+ */
647
+ private setInitialFocus;
648
+ /**
649
+ * Handle keydown events for arrow navigation.
650
+ *
651
+ * @param {KeyboardEvent} e Keyboard event.
652
+ */
653
+ private handleKeyDown;
537
654
  }
538
655
 
539
656
  /**
@@ -617,6 +734,26 @@ export class TPMultiSelectFieldElement extends HTMLElement {
617
734
  * Constructor.
618
735
  */
619
736
  constructor();
737
+ /**
738
+ * Handle keydown events to open the dropdown.
739
+ *
740
+ * @param {KeyboardEvent} e Keyboard event.
741
+ */
742
+ handleKeydown(e: KeyboardEvent): void;
743
+ /**
744
+ * Connected callback.
745
+ */
746
+ connectedCallback(): void;
747
+ /**
748
+ * Setup label click to focus this field.
749
+ * Enables clicking the label to focus the field when aria-labelledby is present.
750
+ */
751
+ setupLabelClick(): void;
752
+ /**
753
+ * Setup ARIA attributes for the field element.
754
+ * Only applies when there is no search input (field acts as combobox).
755
+ */
756
+ setupAriaAttributes(): void;
620
757
  /**
621
758
  * Toggle opening this component.
622
759
  */
@@ -631,6 +768,32 @@ export class TPMultiSelectOptionElement extends HTMLElement {
631
768
  * Constructor.
632
769
  */
633
770
  constructor();
771
+ /**
772
+ * Get observed attributes.
773
+ *
774
+ * @return {Array} List of observed attributes.
775
+ */
776
+ static get observedAttributes(): string[];
777
+ /**
778
+ * Connected callback.
779
+ */
780
+ connectedCallback(): void;
781
+ /**
782
+ * Attribute changed callback.
783
+ *
784
+ * @param {string} name Attribute name.
785
+ * @param {string} oldValue Old value.
786
+ * @param {string} newValue New value.
787
+ */
788
+ attributeChangedCallback(name?: string, oldValue?: string, newValue?: string): void;
789
+ /**
790
+ * Setup ARIA attributes for the option.
791
+ */
792
+ setupAriaAttributes(): void;
793
+ /**
794
+ * Update ARIA state based on selected attribute.
795
+ */
796
+ updateAriaState(): void;
634
797
  /**
635
798
  * Select / un-select this option.
636
799
  *
@@ -643,6 +806,14 @@ export class TPMultiSelectOptionElement extends HTMLElement {
643
806
  * TP Multi Select Options.
644
807
  */
645
808
  export class TPMultiSelectOptionsElement extends HTMLElement {
809
+ /**
810
+ * Connected callback.
811
+ */
812
+ connectedCallback(): void;
813
+ /**
814
+ * Setup ARIA attributes for the listbox.
815
+ */
816
+ setupAriaAttributes(): void;
646
817
  }
647
818
 
648
819
  /**
@@ -695,6 +866,32 @@ export class TPMultiSelectPillsElement extends HTMLElement {
695
866
  export class TPMultiSelectPlaceholderElement extends HTMLElement {
696
867
  }
697
868
 
869
+ /**
870
+ * TP Multi Select Search Status.
871
+ */
872
+ export class TPMultiSelectSearchStatusElement extends HTMLElement {
873
+ /**
874
+ * Store the default role from markup.
875
+ */
876
+ protected defaultRole: string | null;
877
+ /**
878
+ * Store the default aria-live from markup.
879
+ */
880
+ protected defaultAriaLive: string | null;
881
+ /**
882
+ * Constructor.
883
+ */
884
+ constructor();
885
+ /**
886
+ * Connected callback.
887
+ */
888
+ connectedCallback(): void;
889
+ /**
890
+ * Update this component.
891
+ */
892
+ update(): void;
893
+ }
894
+
698
895
  /**
699
896
  * TP Multi Select Search.
700
897
  */
@@ -703,6 +900,14 @@ export class TPMultiSelectSearchElement extends HTMLElement {
703
900
  * Constructor.
704
901
  */
705
902
  constructor();
903
+ /**
904
+ * Connected callback.
905
+ */
906
+ connectedCallback(): void;
907
+ /**
908
+ * Setup ARIA attributes for the search input (combobox).
909
+ */
910
+ setupAriaAttributes(): void;
706
911
  /**
707
912
  * Handle keyboard inputs.
708
913
  *
@@ -737,6 +942,18 @@ export class TPMultiSelectSelectAllElement extends HTMLElement {
737
942
  * Constructor.
738
943
  */
739
944
  constructor();
945
+ /**
946
+ * Connected callback.
947
+ */
948
+ connectedCallback(): void;
949
+ /**
950
+ * Setup ARIA attributes for the select all option.
951
+ */
952
+ setupAriaAttributes(): void;
953
+ /**
954
+ * Update ARIA state based on selected attribute.
955
+ */
956
+ updateAriaState(): void;
740
957
  /**
741
958
  * Handle value changed.
742
959
  */
@@ -790,6 +1007,12 @@ export class TPMultiSelectElement extends HTMLElement {
790
1007
  * @return {Array} List of observed attributes.
791
1008
  */
792
1009
  static get observedAttributes(): string[];
1010
+ /**
1011
+ * Check if ARIA management is enabled.
1012
+ *
1013
+ * @return {boolean} Whether ARIA is enabled.
1014
+ */
1015
+ isAriaEnabled(): boolean;
793
1016
  /**
794
1017
  * Attribute changed callback.
795
1018
  *
@@ -870,6 +1093,30 @@ export class TPMultiSelectElement extends HTMLElement {
870
1093
  * Un-highlight all options.
871
1094
  */
872
1095
  unHighlightAllOptions(): void;
1096
+ /**
1097
+ * Get the combobox element (search input or field).
1098
+ *
1099
+ * @return {HTMLElement | null} The combobox element.
1100
+ */
1101
+ getComboboxElement(): HTMLElement | null;
1102
+ /**
1103
+ * Update aria-expanded on the combobox element.
1104
+ *
1105
+ * @param {boolean} isOpen Whether the dropdown is open.
1106
+ */
1107
+ updateAriaExpanded(isOpen: boolean): void;
1108
+ /**
1109
+ * Update aria-activedescendant on the combobox element.
1110
+ *
1111
+ * @param {string | null} optionId The ID of the highlighted option, or null to clear.
1112
+ */
1113
+ updateAriaActiveDescendant(optionId: string | null): void;
1114
+ /**
1115
+ * Handle focus out events to close the dropdown.
1116
+ *
1117
+ * @param {FocusEvent} e Focus event.
1118
+ */
1119
+ handleFocusOut(e: FocusEvent): void;
873
1120
  }
874
1121
 
875
1122
  /**
@@ -910,6 +1157,48 @@ export class TPNumberSpinnerInput extends HTMLElement {
910
1157
  * TP Number Spinner Element.
911
1158
  */
912
1159
  export class TPNumberSpinner extends HTMLElement {
1160
+ /**
1161
+ * Connected callback.
1162
+ */
1163
+ connectedCallback(): void;
1164
+ /**
1165
+ * Check if ARIA management is enabled.
1166
+ *
1167
+ * @return {boolean} Whether ARIA is enabled.
1168
+ */
1169
+ isAriaEnabled(): boolean;
1170
+ /**
1171
+ * Get the input element.
1172
+ *
1173
+ * @return {HTMLInputElement|null} The input element.
1174
+ */
1175
+ getInput(): HTMLInputElement | null;
1176
+ /**
1177
+ * Set up ARIA attributes on the input.
1178
+ */
1179
+ setupAria(): void;
1180
+ /**
1181
+ * Set tabindex="-1" on buttons if not already set by consumer.
1182
+ */
1183
+ setupButtonTabindex(): void;
1184
+ /**
1185
+ * Handle keydown events on the input.
1186
+ *
1187
+ * @param {KeyboardEvent} event The keyboard event.
1188
+ */
1189
+ handleInputKeydown(event: KeyboardEvent): void;
1190
+ /**
1191
+ * Update ARIA attributes on input and buttons.
1192
+ */
1193
+ updateAriaAttributes(): void;
1194
+ /**
1195
+ * Update aria-disabled state on buttons.
1196
+ *
1197
+ * @param {number} currentValue Current value.
1198
+ * @param {number|null} min Minimum value.
1199
+ * @param {number|null} max Maximum value.
1200
+ */
1201
+ updateButtonStates(currentValue: number, min: number | null, max: number | null): void;
913
1202
  /**
914
1203
  * Get minimum value.
915
1204
  *
@@ -1282,15 +1571,57 @@ export class TPTabsNavItemElement extends HTMLElement {
1282
1571
  */
1283
1572
  constructor();
1284
1573
  /**
1285
- * Handle link click.
1574
+ * Get the trigger element (button or anchor).
1575
+ *
1576
+ * @return {HTMLButtonElement | HTMLAnchorElement | null} The trigger element.
1577
+ */
1578
+ getTrigger(): HTMLButtonElement | HTMLAnchorElement | null;
1579
+ /**
1580
+ * Get observed attributes.
1581
+ *
1582
+ * @return {Array} List of observed attributes.
1583
+ */
1584
+ static get observedAttributes(): string[];
1585
+ /**
1586
+ * Attribute changed callback.
1587
+ *
1588
+ * @param {string} name Attribute name.
1589
+ * @param {string} oldValue Old value.
1590
+ * @param {string} newValue New value.
1591
+ */
1592
+ attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
1593
+ /**
1594
+ * Check if ARIA management is enabled.
1595
+ *
1596
+ * @return {boolean} Whether ARIA management is enabled.
1597
+ */
1598
+ private isAriaEnabled;
1599
+ /**
1600
+ * Set up ARIA attributes on the trigger element.
1601
+ */
1602
+ private setupAriaAttributes;
1603
+ /**
1604
+ * Get the panel ID that this nav item controls.
1605
+ *
1606
+ * @return {string} The panel ID.
1607
+ */
1608
+ getPanelId(): string;
1609
+ /**
1610
+ * Update ARIA state on the trigger element.
1611
+ *
1612
+ * @param {boolean} isActive Whether this tab is active.
1613
+ */
1614
+ private updateAriaState;
1615
+ /**
1616
+ * Handle trigger click.
1286
1617
  *
1287
1618
  * @param {Event} e Click event.
1288
1619
  *
1289
1620
  * @protected
1290
1621
  */
1291
- protected handleLinkClick(e: Event): void;
1622
+ protected handleTriggerClick(e: Event): void;
1292
1623
  /**
1293
- * Check if this component contains the link to the current tab.
1624
+ * Check if this component contains the trigger for the current tab.
1294
1625
  *
1295
1626
  * @param {string} currentTab Current tab ID.
1296
1627
  *
@@ -1303,12 +1634,68 @@ export class TPTabsNavItemElement extends HTMLElement {
1303
1634
  * TP Tabs Nav Element.
1304
1635
  */
1305
1636
  export class TPTabsNavElement extends HTMLElement {
1637
+ /**
1638
+ * Constructor.
1639
+ */
1640
+ constructor();
1641
+ /**
1642
+ * Check if ARIA management is enabled.
1643
+ *
1644
+ * @return {boolean} Whether ARIA management is enabled.
1645
+ */
1646
+ private isAriaEnabled;
1647
+ /**
1648
+ * Get all tab trigger elements (buttons or anchors).
1649
+ *
1650
+ * @return {Array<HTMLButtonElement | HTMLAnchorElement>} Array of trigger elements.
1651
+ */
1652
+ private getTabTriggers;
1653
+ /**
1654
+ * Handle keydown events for keyboard navigation.
1655
+ *
1656
+ * @param {KeyboardEvent} e Keyboard event.
1657
+ */
1658
+ private handleKeyDown;
1306
1659
  }
1307
1660
 
1308
1661
  /**
1309
1662
  * TP Tabs Tab Element.
1310
1663
  */
1311
1664
  export class TPTabsTabElement extends HTMLElement {
1665
+ /**
1666
+ * Constructor.
1667
+ */
1668
+ constructor();
1669
+ /**
1670
+ * Get observed attributes.
1671
+ *
1672
+ * @return {Array} List of observed attributes.
1673
+ */
1674
+ static get observedAttributes(): string[];
1675
+ /**
1676
+ * Attribute changed callback.
1677
+ *
1678
+ * @param {string} name Attribute name.
1679
+ * @param {string} oldValue Old value.
1680
+ * @param {string} newValue New value.
1681
+ */
1682
+ attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
1683
+ /**
1684
+ * Check if ARIA management is enabled.
1685
+ *
1686
+ * @return {boolean} Whether ARIA management is enabled.
1687
+ */
1688
+ private isAriaEnabled;
1689
+ /**
1690
+ * Set up ARIA attributes on this tab panel.
1691
+ */
1692
+ private setupAriaAttributes;
1693
+ /**
1694
+ * Update ARIA state on this tab panel.
1695
+ *
1696
+ * @param {boolean} isOpen Whether this panel is open.
1697
+ */
1698
+ private updateAriaState;
1312
1699
  }
1313
1700
 
1314
1701
  /**
@@ -1325,6 +1712,12 @@ export class TPTabsElement extends HTMLElement {
1325
1712
  * @return {Array} List of observed attributes.
1326
1713
  */
1327
1714
  static get observedAttributes(): string[];
1715
+ /**
1716
+ * Check if ARIA management is enabled.
1717
+ *
1718
+ * @return {boolean} Whether ARIA management is enabled.
1719
+ */
1720
+ isAriaEnabled(): boolean;
1328
1721
  /**
1329
1722
  * Attribute changed callback.
1330
1723
  *
@@ -1433,6 +1826,10 @@ export class TPToggleAttributeElement extends HTMLElement {
1433
1826
  export class TPTooltipArrow extends HTMLElement {
1434
1827
  }
1435
1828
 
1829
+ /**
1830
+ * Internal dependencies.
1831
+ */
1832
+ import { TPTooltip } from './tp-tooltip';
1436
1833
  /**
1437
1834
  * TP Tooltip Trigger.
1438
1835
  */
@@ -1441,6 +1838,38 @@ export class TPTooltipTrigger extends HTMLElement {
1441
1838
  * Constructor.
1442
1839
  */
1443
1840
  constructor();
1841
+ /**
1842
+ * Connected callback.
1843
+ */
1844
+ connectedCallback(): void;
1845
+ /**
1846
+ * Check if ARIA management is enabled.
1847
+ *
1848
+ * @return {boolean} Whether ARIA is enabled.
1849
+ */
1850
+ isAriaEnabled(): boolean;
1851
+ /**
1852
+ * Get the tooltip element.
1853
+ *
1854
+ * @return {TPTooltip|null} The tooltip element.
1855
+ */
1856
+ getTooltip(): TPTooltip | null;
1857
+ /**
1858
+ * Get the trigger element (focusable child).
1859
+ *
1860
+ * @return {HTMLElement|null} The trigger element.
1861
+ */
1862
+ getTriggerElement(): HTMLElement | null;
1863
+ /**
1864
+ * Set up ARIA attributes.
1865
+ */
1866
+ setupAria(): void;
1867
+ /**
1868
+ * Handle keydown events.
1869
+ *
1870
+ * @param {KeyboardEvent} event The keyboard event.
1871
+ */
1872
+ handleKeyDown(event: KeyboardEvent): void;
1444
1873
  /**
1445
1874
  * Toggle the tooltip.
1446
1875
  */
@@ -1483,6 +1912,20 @@ export class TPTooltip extends HTMLElement {
1483
1912
  * Constructor.
1484
1913
  */
1485
1914
  constructor();
1915
+ /**
1916
+ * Connected callback.
1917
+ */
1918
+ connectedCallback(): void;
1919
+ /**
1920
+ * Check if ARIA management is enabled.
1921
+ *
1922
+ * @return {boolean} Whether ARIA is enabled.
1923
+ */
1924
+ isAriaEnabled(): boolean;
1925
+ /**
1926
+ * Set up ARIA attributes.
1927
+ */
1928
+ setupAria(): void;
1486
1929
  /**
1487
1930
  * Get offset.
1488
1931
  */
@@ -1,2 +1,2 @@
1
- (()=>{"use strict";var e={d:(t,r)=>{for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{errorMessage:()=>l,name:()=>u,validator:()=>d});var r={};e.r(r),e.d(r,{errorMessage:()=>h,name:()=>v,validator:()=>c});var s={};e.r(s),e.d(s,{errorMessage:()=>b,name:()=>m,validator:()=>p});var i={};e.r(i),e.d(i,{errorMessage:()=>f,name:()=>g,validator:()=>A});var n={};e.r(n),e.d(n,{errorMessage:()=>y,name:()=>E,validator:()=>M});var o={};e.r(o),e.d(o,{errorMessage:()=>S,name:()=>w,validator:()=>F});const a=(e="")=>{const{tpFormErrors:t}=window;return t&&""!==e&&e in t&&"string"==typeof t[e]?t[e]:""},u="required",l="This field is required",d={validate:e=>{var t,r;return null!==(r=""!==(null===(t=e.getField())||void 0===t?void 0:t.value))&&void 0!==r?r:""},getErrorMessage:()=>a(u)},v="email",h="Please enter a valid email address",c={validate:e=>{var t,r;return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(null!==(r=null===(t=e.getField())||void 0===t?void 0:t.value)&&void 0!==r?r:"")},getErrorMessage:()=>a(v)},m="min-length",b="Must be at least %1 characters",p={validate:e=>{var t,r,s;const i=parseInt(null!==(t=e.getAttribute("min-length"))&&void 0!==t?t:"0"),n=null!==(s=null===(r=e.getField())||void 0===r?void 0:r.value)&&void 0!==s?s:"";return""===n||n.length>=i},getErrorMessage:e=>{var t;const r=a(m),s=null!==(t=e.getAttribute("min-length"))&&void 0!==t?t:"";return r.replace("%1",s)}},g="max-length",f="Must be less than %1 characters",A={validate:e=>{var t,r,s;const i=parseInt(null!==(t=e.getAttribute("max-length"))&&void 0!==t?t:"0"),n=null!==(s=null===(r=e.getField())||void 0===r?void 0:r.value)&&void 0!==s?s:"";return""===n||n.length<=i},getErrorMessage:e=>{var t;const r=a(g),s=null!==(t=e.getAttribute("max-length"))&&void 0!==t?t:"";return r.replace("%1",s)}},E="no-empty-spaces",y="This field should not contain only white-spaces",M={validate:e=>{const t=e.getField();return!!t&&(""===t.value||""!==t.value.trim())},getErrorMessage:()=>a(E)},w="zip",S="Please enter a valid zip code",F={validate:e=>{var t,r;const s=null!==(r=null===(t=e.getField())||void 0===t?void 0:t.value)&&void 0!==r?r:"",i=e.getAttribute("regex");return new RegExp(null!=i?i:"^[A-Za-z0-9][A-Za-z0-9\\- ]{1,8}[A-Za-z0-9]$").test(s.trim())},getErrorMessage:()=>a(w)};var x=function(e,t,r,s){return new(r||(r=Promise))((function(i,n){function o(e){try{u(s.next(e))}catch(e){n(e)}}function a(e){try{u(s.throw(e))}catch(e){n(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,a)}u((s=s.apply(e,t||[])).next())}))};class C extends HTMLElement{constructor(){var e;super(),this.form=this.querySelector("form"),null===(e=this.form)||void 0===e||e.addEventListener("submit",this.handleFormSubmit.bind(this))}handleFormSubmit(e){var t;return x(this,void 0,void 0,(function*(){e.preventDefault(),e.stopImmediatePropagation();const r=this.querySelector("tp-form-submit");null==r||r.setAttribute("submitting","yes"),"yes"!==this.getAttribute("suspense")&&((yield this.validate())?(this.dispatchEvent(new CustomEvent("submit-validation-success",{bubbles:!0})),"yes"!==this.getAttribute("prevent-submit")&&(null===(t=this.form)||void 0===t||t.submit())):null==r||r.removeAttribute("submitting"))}))}validate(){return x(this,void 0,void 0,(function*(){this.dispatchEvent(new CustomEvent("validate",{bubbles:!0}));const e=this.querySelectorAll("tp-form-field");if(!e)return this.dispatchEvent(new CustomEvent("validation-success",{bubbles:!0})),!0;this.setAttribute("suspense","yes");let t=!0;const r=Array.from(e).map((e=>x(this,void 0,void 0,(function*(){return yield e.validate()}))));return yield Promise.all(r).then((e=>{t=e.every((e=>e))})).catch((()=>{t=!1})).finally((()=>this.removeAttribute("suspense"))),t?this.dispatchEvent(new CustomEvent("validation-success",{bubbles:!0})):this.dispatchEvent(new CustomEvent("validation-error",{bubbles:!0})),t}))}validateField(e){return x(this,void 0,void 0,(function*(){this.setAttribute("suspense","yes");const t=yield e.validate();return this.removeAttribute("suspense"),t}))}resetValidation(){const e=this.querySelectorAll("tp-form-field");if(!e)return;e.forEach((e=>{e.removeAttribute("valid"),e.removeAttribute("error"),e.removeAttribute("suspense")})),this.removeAttribute("suspense");const t=this.querySelector("tp-form-submit");null==t||t.removeAttribute("submitting")}}class T extends HTMLElement{constructor(){super();const e=this.getField();null==e||e.addEventListener("keyup",this.handleFieldChanged.bind(this)),null==e||e.addEventListener("change",this.handleFieldChanged.bind(this))}handleFieldChanged(){if("no"!==this.getAttribute("revalidate-on-change")&&(this.getAttribute("valid")||this.getAttribute("error"))){const e=this.closest("tp-form");null==e||e.validateField(this)}}static get observedAttributes(){return["valid","error","suspense"]}attributeChangedCallback(e="",t="",r=""){"valid"!==e&&"error"!==e&&"suspense"!==e||t===r||this.dispatchEvent(new CustomEvent("validate",{bubbles:!0})),this.update()}update(){var e,t,r;const{tpFormValidators:s}=window;if(!s)return;const i=null!==(e=this.getAttribute("error"))&&void 0!==e?e:"";""!==i&&i in s&&"function"==typeof s[i].getErrorMessage?this.setErrorMessage(s[i].getErrorMessage(this)):this.removeErrorMessage();const n=null!==(t=this.getAttribute("suspense"))&&void 0!==t?t:"";""!==n&&n in s&&"function"==typeof s[n].getSuspenseMessage?this.setSuspenseMessage(null===(r=s[n])||void 0===r?void 0:r.getSuspenseMessage(this)):this.removeSuspenseMessage()}getField(){return this.querySelector("input,select,textarea")}validate(){return e=this,t=void 0,s=function*(){const{tpFormValidators:e}=window;if(!e)return!0;if(this.offsetWidth<=0||this.offsetHeight<=0)return!0;let t=!0,r=null,s="";return this.getAttributeNames().every((i=>{if(i in e&&"function"==typeof e[i].validate){const n=e[i].validate(this);if(s=i,n instanceof Promise)return t=!1,this.dispatchEvent(new CustomEvent("validation-suspense-start")),r=new Promise(((e,t)=>{n.then((t=>{!0===t?(this.setAttribute("valid","yes"),this.removeAttribute("error"),e(!0)):(this.removeAttribute("valid"),this.setAttribute("error",s),e(!1)),this.dispatchEvent(new CustomEvent("validation-suspense-success"))})).catch((()=>{this.removeAttribute("valid"),this.setAttribute("error",s),this.dispatchEvent(new CustomEvent("validation-suspense-error")),t(!1)})).finally((()=>{this.removeAttribute("suspense")}))})),!1;if(!1===n)return t=!1,!1}return!0})),t?(this.setAttribute("valid","yes"),this.removeAttribute("error"),this.removeAttribute("suspense")):(this.removeAttribute("valid"),r?(this.setAttribute("suspense",s),this.removeAttribute("error")):(this.removeAttribute("suspense"),this.setAttribute("error",s))),r||t},new((r=void 0)||(r=Promise))((function(i,n){function o(e){try{u(s.next(e))}catch(e){n(e)}}function a(e){try{u(s.throw(e))}catch(e){n(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,a)}u((s=s.apply(e,t||[])).next())}));var e,t,r,s}setErrorMessage(e=""){const t=this.querySelector("tp-form-error");if(t)t.innerHTML=e;else{const t=document.createElement("tp-form-error");t.innerHTML=e,this.appendChild(t)}this.dispatchEvent(new CustomEvent("validation-error"))}removeErrorMessage(){var e;null===(e=this.querySelector("tp-form-error"))||void 0===e||e.remove(),this.dispatchEvent(new CustomEvent("validation-success"))}setSuspenseMessage(e=""){const t=this.querySelector("tp-form-suspense");if(t)t.innerHTML=e;else{const t=document.createElement("tp-form-suspense");t.innerHTML=e,this.appendChild(t)}}removeSuspenseMessage(){var e;null===(e=this.querySelector("tp-form-suspense"))||void 0===e||e.remove()}}class L extends HTMLElement{}class q extends HTMLElement{}class H extends HTMLElement{static get observedAttributes(){return["submitting-text","original-text","submitting"]}attributeChangedCallback(e="",t="",r=""){t!==r&&this.update()}update(){var e,t;const r=this.querySelector('button[type="submit"]');if(!r)return;const s=null!==(e=this.getAttribute("submitting-text"))&&void 0!==e?e:"",i=null!==(t=this.getAttribute("original-text"))&&void 0!==t?t:r.innerHTML;"yes"===this.getAttribute("submitting")?(r.setAttribute("disabled","disabled"),this.setAttribute("original-text",i),r.innerHTML=s):(r.removeAttribute("disabled"),this.removeAttribute("submitting"),this.removeAttribute("original-text"),r.innerHTML=i)}}const P=[t,r,s,i,n,o];window.tpFormValidators={},window.tpFormErrors={},window.tpFormSuspenseMessages={},P.forEach((({name:e,validator:t,errorMessage:r})=>{window.tpFormValidators[e]=t,window.tpFormErrors[e]=r})),customElements.define("tp-form",C),customElements.define("tp-form-field",T),customElements.define("tp-form-error",L),customElements.define("tp-form-suspense",q),customElements.define("tp-form-submit",H)})();
1
+ (()=>{"use strict";var e={d:(t,r)=>{for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{errorMessage:()=>d,name:()=>u,summaryErrorMessage:()=>m,validator:()=>c});var r={};e.r(r),e.d(r,{errorMessage:()=>h,name:()=>v,summaryErrorMessage:()=>g,validator:()=>b});var s={};e.r(s),e.d(s,{errorMessage:()=>f,name:()=>p,summaryErrorMessage:()=>y,validator:()=>E});var i={};e.r(i),e.d(i,{errorMessage:()=>M,name:()=>A,summaryErrorMessage:()=>S,validator:()=>w});var n={};e.r(n),e.d(n,{errorMessage:()=>C,name:()=>x,summaryErrorMessage:()=>F,validator:()=>q});var o={};e.r(o),e.d(o,{errorMessage:()=>L,name:()=>T,summaryErrorMessage:()=>P,validator:()=>H});const a=(e="")=>{const{tpFormErrors:t}=window;return t&&""!==e&&e in t&&"string"==typeof t[e]?t[e]:""},l=(e="",t)=>{const{tpFormSummaryErrors:r}=window;if(!r||""===e||!(e in r))return"";const s=r[e];if("string"!=typeof s)return"";const i=(e=>{var t;const r=e.querySelector("label");return(null===(t=null==r?void 0:r.textContent)||void 0===t?void 0:t.trim())||""})(t);return s.replace("%label%",i)},u="required",d="This field is required",m="%label%: This field is required",c={validate:e=>{var t,r;return null!==(r=""!==(null===(t=e.getField())||void 0===t?void 0:t.value))&&void 0!==r?r:""},getErrorMessage:()=>a(u),getSummaryMessage:e=>l(u,e)},v="email",h="Please enter a valid email address",g="%label%: Please enter a valid email address",b={validate:e=>{var t,r;return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(null!==(r=null===(t=e.getField())||void 0===t?void 0:t.value)&&void 0!==r?r:"")},getErrorMessage:()=>a(v),getSummaryMessage:e=>l(v,e)},p="min-length",f="Must be at least %1 characters",y="%label%: Must be at least %1 characters",E={validate:e=>{var t,r,s;const i=parseInt(null!==(t=e.getAttribute("min-length"))&&void 0!==t?t:"0"),n=null!==(s=null===(r=e.getField())||void 0===r?void 0:r.value)&&void 0!==s?s:"";return""===n||n.length>=i},getErrorMessage:e=>{var t;const r=a(p),s=null!==(t=e.getAttribute("min-length"))&&void 0!==t?t:"";return r.replace("%1",s)},getSummaryMessage:e=>{var t;const r=l(p,e),s=null!==(t=e.getAttribute("min-length"))&&void 0!==t?t:"";return r.replace("%1",s)}},A="max-length",M="Must be less than %1 characters",S="%label%: Must be less than %1 characters",w={validate:e=>{var t,r,s;const i=parseInt(null!==(t=e.getAttribute("max-length"))&&void 0!==t?t:"0"),n=null!==(s=null===(r=e.getField())||void 0===r?void 0:r.value)&&void 0!==s?s:"";return""===n||n.length<=i},getErrorMessage:e=>{var t;const r=a(A),s=null!==(t=e.getAttribute("max-length"))&&void 0!==t?t:"";return r.replace("%1",s)},getSummaryMessage:e=>{var t;const r=l(A,e),s=null!==(t=e.getAttribute("max-length"))&&void 0!==t?t:"";return r.replace("%1",s)}},x="no-empty-spaces",C="This field should not contain only white-spaces",F="%label%: Should not contain only white-spaces",q={validate:e=>{const t=e.getField();return!!t&&(""===t.value||""!==t.value.trim())},getErrorMessage:()=>a(x),getSummaryMessage:e=>l(x,e)},T="zip",L="Please enter a valid zip code",P="%label%: Please enter a valid zip code",H={validate:e=>{var t,r;const s=null!==(r=null===(t=e.getField())||void 0===t?void 0:t.value)&&void 0!==r?r:"",i=e.getAttribute("regex");return new RegExp(null!=i?i:"^[A-Za-z0-9][A-Za-z0-9\\- ]{1,8}[A-Za-z0-9]$").test(s.trim())},getErrorMessage:()=>a(T),getSummaryMessage:e=>l(T,e)};var V=function(e,t,r,s){return new(r||(r=Promise))((function(i,n){function o(e){try{l(s.next(e))}catch(e){n(e)}}function a(e){try{l(s.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,a)}l((s=s.apply(e,t||[])).next())}))};class k extends HTMLElement{constructor(){var e;super(),this.form=this.querySelector("form"),null===(e=this.form)||void 0===e||e.addEventListener("submit",this.handleFormSubmit.bind(this))}handleFormSubmit(e){var t;return V(this,void 0,void 0,(function*(){e.preventDefault(),e.stopImmediatePropagation();const r=this.querySelector("tp-form-submit");null==r||r.setAttribute("submitting","yes"),"yes"!==this.getAttribute("suspense")&&((yield this.validate())?(this.dispatchEvent(new CustomEvent("submit-validation-success",{bubbles:!0})),"yes"!==this.getAttribute("prevent-submit")&&(null===(t=this.form)||void 0===t||t.submit())):null==r||r.removeAttribute("submitting"))}))}validate(){return V(this,void 0,void 0,(function*(){this.dispatchEvent(new CustomEvent("validate",{bubbles:!0}));const e=this.querySelectorAll("tp-form-field");if(!e)return this.dispatchEvent(new CustomEvent("validation-success",{bubbles:!0})),!0;this.setAttribute("suspense","yes");let t=!0;const r=Array.from(e).map((e=>V(this,void 0,void 0,(function*(){return yield e.validate()}))));return yield Promise.all(r).then((e=>{t=e.every((e=>e))})).catch((()=>{t=!1})).finally((()=>this.removeAttribute("suspense"))),t?(this.dispatchEvent(new CustomEvent("validation-success",{bubbles:!0})),this.clearErrorSummary()):(this.dispatchEvent(new CustomEvent("validation-error",{bubbles:!0})),this.handleValidationError(e)),t}))}handleValidationError(e){const t=Array.from(e).filter((e=>e.hasAttribute("error")&&e.offsetWidth>0&&e.offsetHeight>0)),r=this.querySelector("tp-form-errors");if(r)r.update(t),setTimeout((()=>r.focus()),0);else if(t.length>0){const e=t[0].getField();null==e||e.focus()}}clearErrorSummary(){const e=this.querySelector("tp-form-errors");null==e||e.clear()}validateField(e){return V(this,void 0,void 0,(function*(){this.setAttribute("suspense","yes");const t=yield e.validate();return this.removeAttribute("suspense"),t}))}resetValidation(){const e=this.querySelectorAll("tp-form-field");if(!e)return;e.forEach((e=>{e.removeAttribute("valid"),e.removeAttribute("error"),e.removeAttribute("suspense")})),this.removeAttribute("suspense");const t=this.querySelector("tp-form-submit");null==t||t.removeAttribute("submitting"),this.clearErrorSummary()}}class z extends HTMLElement{constructor(){super();const e=this.getField();null==e||e.addEventListener("keyup",this.handleFieldChanged.bind(this)),null==e||e.addEventListener("change",this.handleFieldChanged.bind(this)),this.setupAccessibility()}setupAccessibility(){const e=this.getField();if(!e)return;e.id||(e.id=`tp-field-${Math.random().toString(36).substring(2,9)}`);const t=this.querySelector("label");t&&!t.hasAttribute("for")&&t.setAttribute("for",e.id)}handleFieldChanged(){if("no"!==this.getAttribute("revalidate-on-change")&&(this.getAttribute("valid")||this.getAttribute("error"))){const e=this.closest("tp-form");null==e||e.validateField(this)}}static get observedAttributes(){return["valid","error","suspense"]}attributeChangedCallback(e="",t="",r=""){"valid"!==e&&"error"!==e&&"suspense"!==e||t===r||this.dispatchEvent(new CustomEvent("validate",{bubbles:!0})),this.update()}update(){var e,t,r;const{tpFormValidators:s}=window;if(!s)return;const i=null!==(e=this.getAttribute("error"))&&void 0!==e?e:"";""!==i&&i in s&&"function"==typeof s[i].getErrorMessage?this.setErrorMessage(s[i].getErrorMessage(this)):this.removeErrorMessage();const n=null!==(t=this.getAttribute("suspense"))&&void 0!==t?t:"";""!==n&&n in s&&"function"==typeof s[n].getSuspenseMessage?this.setSuspenseMessage(null===(r=s[n])||void 0===r?void 0:r.getSuspenseMessage(this)):this.removeSuspenseMessage()}getField(){return this.querySelector("input,select,textarea")}validate(){return e=this,t=void 0,s=function*(){const{tpFormValidators:e}=window;if(!e)return!0;if(this.offsetWidth<=0||this.offsetHeight<=0)return!0;let t=!0,r=null,s="";return this.getAttributeNames().every((i=>{if(i in e&&"function"==typeof e[i].validate){const n=e[i].validate(this);if(s=i,n instanceof Promise)return t=!1,this.dispatchEvent(new CustomEvent("validation-suspense-start")),r=new Promise(((e,t)=>{n.then((t=>{!0===t?(this.setAttribute("valid","yes"),this.removeAttribute("error"),e(!0)):(this.removeAttribute("valid"),this.setAttribute("error",s),e(!1)),this.dispatchEvent(new CustomEvent("validation-suspense-success"))})).catch((()=>{this.removeAttribute("valid"),this.setAttribute("error",s),this.dispatchEvent(new CustomEvent("validation-suspense-error")),t(!1)})).finally((()=>{this.removeAttribute("suspense")}))})),!1;if(!1===n)return t=!1,!1}return!0})),t?(this.setAttribute("valid","yes"),this.removeAttribute("error"),this.removeAttribute("suspense")):(this.removeAttribute("valid"),r?(this.setAttribute("suspense",s),this.removeAttribute("error")):(this.removeAttribute("suspense"),this.setAttribute("error",s))),r||t},new((r=void 0)||(r=Promise))((function(i,n){function o(e){try{l(s.next(e))}catch(e){n(e)}}function a(e){try{l(s.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,a)}l((s=s.apply(e,t||[])).next())}));var e,t,r,s}setErrorMessage(e=""){let t=this.querySelector("tp-form-error");t?t.textContent=e:(t=document.createElement("tp-form-error"),t.textContent=e,t.setAttribute("role","alert"),this.appendChild(t));const r=this.getField();r&&(r.setAttribute("aria-invalid","true"),t.id||(t.id=`tp-error-${Math.random().toString(36).substring(2,9)}`),r.setAttribute("aria-describedby",t.id)),this.dispatchEvent(new CustomEvent("validation-error"))}removeErrorMessage(){var e;null===(e=this.querySelector("tp-form-error"))||void 0===e||e.remove();const t=this.getField();t&&(t.removeAttribute("aria-invalid"),t.removeAttribute("aria-describedby")),this.dispatchEvent(new CustomEvent("validation-success"))}setSuspenseMessage(e=""){const t=this.querySelector("tp-form-suspense");if(t)t.textContent=e;else{const t=document.createElement("tp-form-suspense");t.textContent=e,t.setAttribute("aria-live","polite"),this.appendChild(t)}}removeSuspenseMessage(){var e;null===(e=this.querySelector("tp-form-suspense"))||void 0===e||e.remove()}}class $ extends HTMLElement{}class O extends HTMLElement{update(e){const t=this.querySelector("tp-form-errors-heading"),r=this.querySelector("tp-form-errors-list");if(0===e.length)return this.removeAttribute("active"),this.removeAttribute("tabindex"),null==t||t.update(0),void(null==r||r.clear());this.setAttribute("active","yes"),this.setAttribute("tabindex","-1"),null==t||t.update(e.length),null==r||r.update(e)}clear(){this.removeAttribute("active"),this.removeAttribute("tabindex");const e=this.querySelector("tp-form-errors-heading"),t=this.querySelector("tp-form-errors-list");null==e||e.update(0),null==t||t.clear()}}class j extends HTMLElement{get format(){var e;return null!==(e=this.getAttribute("format"))&&void 0!==e?e:""}set format(e){this.setAttribute("format",e)}update(e){this.textContent=this.format.replace("$count",e.toString())}}class I extends HTMLElement{update(e){this.textContent="";const{tpFormValidators:t}=window;e.forEach((e=>{var r,s;const i=e.getField(),n=null!==(r=null==i?void 0:i.id)&&void 0!==r?r:"";if(!n)return;const o=null!==(s=e.getAttribute("error"))&&void 0!==s?s:"";let a="";if(o&&t&&o in t){const r=t[o];"function"==typeof r.getSummaryMessage?a=r.getSummaryMessage(e):"function"==typeof r.getErrorMessage&&(a=r.getErrorMessage(e))}if(!a)return;const l=document.createElement("tp-form-errors-error");l.setAttribute("role","listitem");const u=document.createElement("a");u.href=`#${n}`,u.textContent=a,l.appendChild(u),this.appendChild(l)}))}clear(){this.textContent=""}}class Z extends HTMLElement{constructor(){super(),this.addEventListener("click",this.handleClick.bind(this))}handleClick(e){var t;const r=e.target.closest("a");if(!r)return;e.preventDefault();const s=(null!==(t=r.getAttribute("href"))&&void 0!==t?t:"").replace("#","");if(s){const e=document.getElementById(s);null==e||e.focus()}}}class D extends HTMLElement{}class W extends HTMLElement{static get observedAttributes(){return["submitting-text","original-text","submitting"]}attributeChangedCallback(e="",t="",r=""){t!==r&&this.update()}update(){var e,t;const r=this.querySelector('button[type="submit"]');if(!r)return;const s=null!==(e=this.getAttribute("submitting-text"))&&void 0!==e?e:"",i=null!==(t=this.getAttribute("original-text"))&&void 0!==t?t:r.innerHTML;"yes"===this.getAttribute("submitting")?(r.setAttribute("disabled","disabled"),this.setAttribute("original-text",i),r.textContent=s):(r.removeAttribute("disabled"),this.removeAttribute("submitting"),this.removeAttribute("original-text"),r.innerHTML=i)}}const _=[t,r,s,i,n,o];window.tpFormValidators={},window.tpFormErrors={},window.tpFormSummaryErrors={},window.tpFormSuspenseMessages={},_.forEach((({name:e,validator:t,errorMessage:r,summaryErrorMessage:s})=>{window.tpFormValidators[e]=t,window.tpFormErrors[e]=r,s&&(window.tpFormSummaryErrors[e]=s)})),customElements.define("tp-form",k),customElements.define("tp-form-field",z),customElements.define("tp-form-error",$),customElements.define("tp-form-errors",O),customElements.define("tp-form-errors-heading",j),customElements.define("tp-form-errors-list",I),customElements.define("tp-form-errors-error",Z),customElements.define("tp-form-suspense",D),customElements.define("tp-form-submit",W)})();
2
2
  //# sourceMappingURL=index.js.map