@authhero/widget 0.37.1 → 0.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authhero-widget/authhero-widget.esm.js +1 -1
- package/dist/authhero-widget/index.esm.js +1 -1
- package/dist/authhero-widget/p-c2744f87.entry.js +1 -0
- package/dist/authhero-widget/p-f94037cd.entry.js +1 -0
- package/dist/cjs/authhero-node.cjs.entry.js +526 -13
- package/dist/cjs/authhero-widget.cjs.entry.js +79 -10
- package/dist/cjs/authhero-widget.cjs.js +1 -1
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/authhero-node/authhero-node.css +94 -0
- package/dist/collection/components/authhero-node/authhero-node.js +302 -13
- package/dist/collection/components/authhero-widget/authhero-widget.js +98 -10
- package/dist/collection/utils/date-format.js +244 -0
- package/dist/components/authhero-node.js +1 -1
- package/dist/components/authhero-widget.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/p-B_R7ma-J.js +1 -0
- package/dist/esm/authhero-node.entry.js +526 -13
- package/dist/esm/authhero-widget.entry.js +79 -10
- package/dist/esm/authhero-widget.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/types/components/authhero-node/authhero-node.d.ts +83 -0
- package/dist/types/components/authhero-widget/authhero-widget.d.ts +19 -0
- package/dist/types/components.d.ts +18 -0
- package/dist/types/utils/date-format.d.ts +52 -0
- package/hydrate/index.js +609 -24
- package/hydrate/index.mjs +609 -24
- package/package.json +2 -2
- package/dist/authhero-widget/p-cdfc4555.entry.js +0 -1
- package/dist/authhero-widget/p-e95c436f.entry.js +0 -1
- package/dist/components/p-BP46GHTc.js +0 -1
package/hydrate/index.js
CHANGED
|
@@ -5500,7 +5500,252 @@ function getCountryByCode(code) {
|
|
|
5500
5500
|
countries.find((c) => c.code === "US"));
|
|
5501
5501
|
}
|
|
5502
5502
|
|
|
5503
|
-
const authheroNodeCss = () => `:host{display:block}.input-wrapper{display:flex;flex-direction:column;position:relative;margin-top:8px;margin-bottom:16px}.input-container{position:relative;width:100%}.input-label{position:absolute;left:16px;top:50%;transform:translateY(-50%);font-size:var(--ah-font-size-label, 16px);font-weight:var(--ah-font-weight-label, 400);color:var(--ah-color-text-muted, #65676e);pointer-events:none;transition:all 0.15s ease-out;background-color:transparent;padding:0;z-index:1}.input-label.floating,.input-field:focus+.input-label,.input-field:not(:placeholder-shown)+.input-label,select.input-field+.input-label,input[type="date"].input-field+.input-label{top:-8px;transform:translateY(0);font-size:12px;background-color:var(--ah-color-bg, #ffffff);padding:0 4px;left:12px;color:var(--ah-color-text-muted, #65676e)}.input-field:focus+.input-label{color:var(--ah-color-primary, #635dff)}.required{color:var(--ah-color-error, #d03c38);margin-left:2px}.input-field{width:100%;padding:16px;font-size:16px;font-family:inherit;color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));background-color:var(--ah-color-input-bg, #ffffff);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-radius:var(--ah-input-radius, 3px);outline:none;transition:border-color 0.15s ease-out, box-shadow 0.15s ease-out;box-sizing:border-box}.input-field::placeholder{color:transparent}.input-field:hover{border-color:var(--ah-color-border-hover, #65676e)}.input-field:focus{border-color:var(--ah-color-primary, #635dff);box-shadow:inset 0 0 0 1px var(--ah-color-primary, #635dff)}.input-field.has-error{border-color:var(--ah-color-error, #d03c38)}.input-field.has-error:focus{box-shadow:inset 0 0 0 1px var(--ah-color-error, #d03c38)}.input-field:disabled{background-color:var(--ah-color-bg-disabled, #f5f5f5);border-color:var(--ah-color-border-disabled, #e0e1e3);cursor:not-allowed;opacity:0.7}.password-container{position:relative;display:flex;align-items:center}.password-container .input-field{padding-right:48px}.password-toggle{position:absolute;right:12px;top:50%;transform:translateY(-50%);background:none;border:none;cursor:pointer;padding:4px;display:flex;align-items:center;justify-content:center;color:var(--ah-color-icon, var(--ah-color-text-muted, #65676e));transition:color 0.15s ease}.password-toggle:hover{color:var(--ah-color-icon, var(--ah-color-text, #1e212a))}.password-toggle svg{width:20px;height:20px}.error-text{font-size:12px;color:var(--ah-color-error, #d03c38);margin-top:4px;line-height:1.4}.helper-text{font-size:12px;color:var(--ah-color-text-muted, #65676e);margin-top:4px;line-height:1.4}.field-link{display:block;text-align:left;margin-top:8px;margin-bottom:16px}.field-link a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);font-size:var(--ah-font-size-link, 14px);font-weight:var(--ah-font-weight-link, 400)}.field-link a:hover{text-decoration:underline}.checkbox-wrapper{display:flex;align-items:flex-start;gap:10px;cursor:pointer;margin-bottom:16px}.checkbox-wrapper input[type="checkbox"]{width:18px;height:18px;margin:0;accent-color:var(--ah-color-primary, #635dff);cursor:pointer;flex-shrink:0}.checkbox-label{font-size:var(--ah-font-size-body, 14px);font-weight:var(--ah-font-weight-body, 400);color:var(--ah-color-text, #1e212a);line-height:1.5}.btn{display:inline-flex;align-items:center;justify-content:center;gap:10px;width:100%;padding:14px 20px;font-size:var(--ah-font-size-btn, 16px);font-weight:var(--ah-font-weight-btn, 400);font-family:inherit;line-height:1.25;text-align:center;text-decoration:none;border:none;border-radius:var(--ah-btn-radius, 3px);cursor:pointer;transition:background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;box-sizing:border-box}.btn:disabled{opacity:0.6;cursor:not-allowed}.btn:not(:disabled):active{transform:scale(0.98)}.btn:focus-visible{outline:2px solid var(--ah-color-focus-ring, var(--ah-color-primary, #635dff));outline-offset:2px}.btn-primary{background-color:var(--ah-color-primary, #635dff);color:var(--ah-color-text-on-primary, #ffffff);margin-top:12px}.btn-primary:not(:disabled):hover{background-color:var( --ah-color-primary-hover, color-mix(in srgb, var(--ah-color-primary, #635dff) 85%, black) )}.btn-secondary{background-color:var(--ah-color-bg, #ffffff);color:var(--ah-btn-secondary-text, var(--ah-color-text, #1e212a));border:var(--ah-btn-border-width, 1px) solid var(--ah-btn-secondary-border, var(--ah-color-border, #c9cace))}.btn-secondary:not(:disabled):hover{background-color:var(--ah-color-bg-hover, #f5f5f5);border-color:var(--ah-color-border-hover, #65676e)}.btn-link{background:none;border:none;color:var(--ah-color-link, #635dff);padding:8px 0;font-weight:var(--ah-font-weight-link, 400);text-decoration:none}.btn-link:hover{text-decoration:underline}.phone-input-wrapper{display:flex;align-items:stretch;gap:0;width:100%}.country-select{flex-shrink:0;width:auto;padding:12px 8px;font-size:var(--ah-font-size-body, 16px);font-family:var(--ah-font-family, inherit);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-right:none;border-radius:var(--ah-input-radius, 4px) 0 0 var(--ah-input-radius, 4px);background-color:var(--ah-color-input-bg, var(--ah-color-surface, #fff));color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));cursor:pointer;appearance:none;-webkit-appearance:none;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 6px center;padding-right:22px}.country-select:focus{outline:none;border-color:var(--ah-color-primary, #635dff);box-shadow:0 0 0 1px var(--ah-color-primary, #635dff)}.country-select:disabled{opacity:0.5;cursor:not-allowed}.phone-input-wrapper .input-container{flex:1;min-width:0}.phone-input-wrapper .input-field{border-radius:0 var(--ah-input-radius, 4px) var(--ah-input-radius, 4px) 0}.phone-input-wrapper .input-label.floating,.phone-input-wrapper .input-field:focus+.input-label,.phone-input-wrapper .input-field:not(:placeholder-shown)+.input-label{left:8px}.social-buttons{display:flex;flex-direction:column;gap:12px}.btn-social{display:flex;align-items:center;justify-content:center;gap:12px;position:relative}.btn-social-badge{position:absolute;right:12px;top:0;transform:translateY(-50%);font-size:11px;font-weight:500;line-height:1;padding:4px 9px;border-radius:999px;background:var(--ah-color-last-used, var(--ah-color-primary, #635dff));color:var(--ah-color-last-used-text, var(--ah-color-text-on-primary, #fff));white-space:nowrap;pointer-events:none}.btn-social.btn-social-last-used{border-color:var(--ah-color-last-used, var(--ah-color-primary, #635dff));box-shadow:inset 0 0 0 1px var(--ah-color-last-used, var(--ah-color-primary, #635dff))}.input-badge{position:absolute;right:12px;top:0;transform:translateY(-50%);font-size:11px;font-weight:500;line-height:1;padding:4px 9px;border-radius:999px;background:var(--ah-color-last-used, var(--ah-color-primary, #635dff));color:var(--ah-color-last-used-text, var(--ah-color-text-on-primary, #fff));white-space:nowrap;pointer-events:none;z-index:2}.btn-social-content{display:flex;flex-direction:column;align-items:center;text-align:center}.btn-social-subtitle{font-size:12px;font-style:italic;opacity:0.8;margin-top:2px}.btn-social-subtitle:empty{display:none}.social-icon{width:20px;height:20px;flex-shrink:0}@media (max-width: 480px){.social-buttons:has(.btn-social:nth-child(3)){flex-direction:row;flex-wrap:nowrap;justify-content:stretch;gap:8px}.social-buttons:has(.btn-social:nth-child(3)) .btn-social{width:auto;min-width:0;padding:12px;flex:1 1 0}.social-buttons:has(.btn-social:nth-child(3)) .btn-social span{display:none}.social-buttons:has(.btn-social:nth-child(3)) .social-icon{width:24px;height:24px}}.btn-icon{width:20px;height:20px;flex-shrink:0}.btn-icon img{width:100%;height:100%;object-fit:contain}.text-title{font-size:var(--ah-font-size-title, 20px);font-weight:var(--ah-font-weight-title, 400);color:var(--ah-color-text-header, var(--ah-color-header, #1e212a));margin:8px 0;line-height:1.3}.text-title.text-success{color:var(--ah-color-success, #13a769)}.text-description{font-size:var(--ah-font-size-subtitle, 14px);font-weight:var(--ah-font-weight-subtitle, 400);color:var(--ah-color-text-muted, #65676e);margin:4px 0;line-height:1.5}.image{display:block;max-width:100%;height:auto;border-radius:4px}.image-centered{margin:0 auto 16px;width:52px;height:52px;object-fit:contain}.link{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);font-size:var(--ah-font-size-link, 14px);transition:color 0.15s ease}.link:hover{text-decoration:underline}.link:focus-visible{outline:2px solid var(--ah-color-focus-ring, var(--ah-color-link, #635dff));outline-offset:2px;border-radius:2px}.node-error{padding:12px 16px;background-color:var(--ah-color-error-bg, #ffeaea);color:var(--ah-color-error, #d03c38);border-left:3px solid var(--ah-color-error, #d03c38);border-radius:0;font-size:14px;margin-bottom:16px}.node-success{padding:12px 16px;background-color:var(--ah-color-success-bg, #e6f9f1);color:var(--ah-color-success, #13a769);border-left:3px solid var(--ah-color-success, #13a769);border-radius:0;font-size:14px;margin-bottom:16px}.divider{display:flex;align-items:center;text-align:center;margin:16px 0}.divider::before,.divider::after{content:"";flex:1;border-bottom:1px solid var(--ah-color-border-muted, #c9cace)}.divider-text{padding:0 10px;font-size:12px;font-weight:400;color:var(--ah-color-text-muted, #65676e);text-transform:uppercase;letter-spacing:0.5px}.rich-text{font-size:var(--ah-font-size-body, 14px);font-weight:var(--ah-font-weight-body, 400);line-height:1.5;color:var(--ah-color-text, #1e212a)}.rich-text a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);transition:color 0.15s ease}.rich-text a:hover{text-decoration:underline}.rich-text .terms-text{margin-top:16px;text-align:center;font-size:12px;color:var(--ah-color-text-muted, #65676e)}.rich-text .terms-text a{font-size:12px}.rich-text .forgot-password-link{text-align:right;font-size:13px;margin-top:4px}.rich-text .forgot-password-link a{font-size:13px;color:var(--ah-color-link, #635dff)}.rich-text .passwordless-link{margin-top:16px;text-align:center;font-size:14px}.rich-text .passwordless-link a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none)}.rich-text .passwordless-link a:hover{text-decoration:underline}.rich-text .signup-link{margin-top:16px;text-align:center;font-size:14px;color:var(--ah-color-text, #1e212a)}.code-field{position:relative}.code-input{position:absolute;inset:0;width:100%;height:100%;margin:0;padding:0;border:none;background:transparent;color:transparent;caret-color:transparent;font-family:inherit;letter-spacing:0;outline:none;cursor:text;-webkit-text-fill-color:transparent}.code-boxes{display:flex;align-items:center;gap:var(--ah-code-group-gap, 12px);justify-content:center}.code-group{display:flex;gap:0}.code-separator{color:var(--ah-color-text-muted, #65676e);font-size:var(--ah-code-font-size, 24px);user-select:none}.code-box-placeholder{color:var(--ah-color-text-muted, #65676e);opacity:0.4}.code-box{position:relative;flex:0 0 auto;width:var(--ah-code-box-width, 48px);height:var(--ah-code-box-height, 56px);display:flex;align-items:center;justify-content:center;font-size:var(--ah-code-font-size, 24px);font-family:inherit;color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));background-color:var(--ah-color-input-bg, #ffffff);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-radius:0;transition:border-color 0.15s ease-out, box-shadow 0.15s ease-out;box-sizing:border-box}.code-box+.code-box{margin-left:calc(-1 * var(--ah-input-border-width, 1px))}.code-group .code-box:first-child{border-top-left-radius:var(--ah-input-radius, 3px);border-bottom-left-radius:var(--ah-input-radius, 3px)}.code-group .code-box:last-child{border-top-right-radius:var(--ah-input-radius, 3px);border-bottom-right-radius:var(--ah-input-radius, 3px)}.code-field:focus-within .code-box.is-active{z-index:1;border-color:var(--ah-color-primary, #635dff);box-shadow:inset 0 0 0 1px var(--ah-color-primary, #635dff)}.code-field.has-error .code-box{border-color:var(--ah-color-error, #d03c38)}.code-input:disabled{cursor:not-allowed}.code-input:disabled~.code-boxes .code-box{background-color:var(--ah-color-bg-disabled, #f5f5f5);border-color:var(--ah-color-border-disabled, #e0e1e3)}`;
|
|
5503
|
+
/**
|
|
5504
|
+
* Locale-aware layout for the segmented DATE input.
|
|
5505
|
+
*
|
|
5506
|
+
* The segment order is resolved from a static table rather than from
|
|
5507
|
+
* `Intl.DateTimeFormat`, deliberately: the widget is server-rendered and then
|
|
5508
|
+
* hydrated in the browser, and the two runtimes do not ship the same ICU data
|
|
5509
|
+
* (a Workers runtime commonly falls back to en-US ordering). A static table
|
|
5510
|
+
* gives the server and the client the same answer, so the hydrated DOM matches
|
|
5511
|
+
* the rendered one.
|
|
5512
|
+
*/
|
|
5513
|
+
/** Languages that write dates big-endian: year, month, day. */
|
|
5514
|
+
const YEAR_FIRST_LANGUAGES = new Set([
|
|
5515
|
+
"bo",
|
|
5516
|
+
"dz",
|
|
5517
|
+
"hu",
|
|
5518
|
+
"ja",
|
|
5519
|
+
"ko",
|
|
5520
|
+
"lt",
|
|
5521
|
+
"mn",
|
|
5522
|
+
"sv",
|
|
5523
|
+
"ug",
|
|
5524
|
+
"zh",
|
|
5525
|
+
]);
|
|
5526
|
+
/**
|
|
5527
|
+
* Regions that write month before day. Month-first is essentially a US
|
|
5528
|
+
* convention plus the places that adopted it.
|
|
5529
|
+
*/
|
|
5530
|
+
const MONTH_FIRST_REGIONS = new Set(["us", "ph", "fm", "mh", "pw", "as", "gu"]);
|
|
5531
|
+
/**
|
|
5532
|
+
* Locales whose language is normally year-first but which write dates
|
|
5533
|
+
* day-first in a particular region — Finland-Swedish is d.m.yyyy, unlike
|
|
5534
|
+
* Sweden-Swedish.
|
|
5535
|
+
*/
|
|
5536
|
+
const DAY_FIRST_TAGS = new Set(["sv-fi"]);
|
|
5537
|
+
const DEFAULT_TOKENS = {
|
|
5538
|
+
day: "DD",
|
|
5539
|
+
month: "MM",
|
|
5540
|
+
year: "YYYY",
|
|
5541
|
+
};
|
|
5542
|
+
/**
|
|
5543
|
+
* Placeholder tokens in the language's own convention — a German field reads
|
|
5544
|
+
* TT.MM.JJJJ, a French one JJ/MM/AAAA. Languages without an entry fall back to
|
|
5545
|
+
* the English DD/MM/YYYY tokens.
|
|
5546
|
+
*/
|
|
5547
|
+
const TOKENS_BY_LANGUAGE = {
|
|
5548
|
+
cs: { day: "DD", month: "MM", year: "RRRR" },
|
|
5549
|
+
da: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
|
|
5550
|
+
de: { day: "TT", month: "MM", year: "JJJJ" },
|
|
5551
|
+
es: { day: "DD", month: "MM", year: "AAAA" },
|
|
5552
|
+
fi: { day: "PP", month: "KK", year: "VVVV" },
|
|
5553
|
+
fr: { day: "JJ", month: "MM", year: "AAAA" },
|
|
5554
|
+
hu: { day: "NN", month: "HH", year: "ÉÉÉÉ" },
|
|
5555
|
+
it: { day: "GG", month: "MM", year: "AAAA" },
|
|
5556
|
+
nb: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
|
|
5557
|
+
nl: { day: "DD", month: "MM", year: "JJJJ" },
|
|
5558
|
+
nn: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
|
|
5559
|
+
no: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
|
|
5560
|
+
pl: { day: "DD", month: "MM", year: "RRRR" },
|
|
5561
|
+
pt: { day: "DD", month: "MM", year: "AAAA" },
|
|
5562
|
+
ru: { day: "ДД", month: "ММ", year: "ГГГГ" },
|
|
5563
|
+
sk: { day: "DD", month: "MM", year: "RRRR" },
|
|
5564
|
+
sv: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
|
|
5565
|
+
tr: { day: "GG", month: "AA", year: "YYYY" },
|
|
5566
|
+
uk: { day: "ДД", month: "ММ", year: "РРРР" },
|
|
5567
|
+
};
|
|
5568
|
+
/**
|
|
5569
|
+
* Separator by language, for languages that do not use the defaults ("/" for
|
|
5570
|
+
* day- or month-first, "-" for year-first). Mostly the locales that write
|
|
5571
|
+
* 14.08.2026 with dots — German, the Nordics minus Sweden, and most of
|
|
5572
|
+
* Central/Eastern Europe.
|
|
5573
|
+
*/
|
|
5574
|
+
const SEPARATOR_BY_LANGUAGE = {
|
|
5575
|
+
bg: ".",
|
|
5576
|
+
cs: ".",
|
|
5577
|
+
da: ".",
|
|
5578
|
+
de: ".",
|
|
5579
|
+
et: ".",
|
|
5580
|
+
fi: ".",
|
|
5581
|
+
hr: ".",
|
|
5582
|
+
hu: ".",
|
|
5583
|
+
is: ".",
|
|
5584
|
+
ja: "/",
|
|
5585
|
+
ko: ".",
|
|
5586
|
+
lv: ".",
|
|
5587
|
+
mk: ".",
|
|
5588
|
+
nb: ".",
|
|
5589
|
+
nl: "-",
|
|
5590
|
+
nn: ".",
|
|
5591
|
+
no: ".",
|
|
5592
|
+
pl: ".",
|
|
5593
|
+
ro: ".",
|
|
5594
|
+
ru: ".",
|
|
5595
|
+
sk: ".",
|
|
5596
|
+
sl: ".",
|
|
5597
|
+
sr: ".",
|
|
5598
|
+
tr: ".",
|
|
5599
|
+
uk: ".",
|
|
5600
|
+
zh: "/",
|
|
5601
|
+
};
|
|
5602
|
+
/** Full-tag overrides — Finland-Swedish writes 14.8.2026 with dots. */
|
|
5603
|
+
const SEPARATOR_BY_TAG = {
|
|
5604
|
+
"sv-fi": ".",
|
|
5605
|
+
};
|
|
5606
|
+
/**
|
|
5607
|
+
* Split a BCP-47 tag into a lowercase language subtag and, when present, a
|
|
5608
|
+
* two-letter region subtag. Script and variant subtags are ignored.
|
|
5609
|
+
*/
|
|
5610
|
+
function parseTag(locale) {
|
|
5611
|
+
const tag = (locale || "").toLowerCase().replace(/_/g, "-");
|
|
5612
|
+
const parts = tag.split("-").filter(Boolean);
|
|
5613
|
+
const language = parts[0] || "";
|
|
5614
|
+
const region = parts.slice(1).find((part) => /^[a-z]{2}$/.test(part));
|
|
5615
|
+
return { language, region };
|
|
5616
|
+
}
|
|
5617
|
+
/**
|
|
5618
|
+
* Resolve the segment order for a locale. Falls back to day-month-year, which
|
|
5619
|
+
* is what most of the world writes.
|
|
5620
|
+
*/
|
|
5621
|
+
function getDateOrder(locale) {
|
|
5622
|
+
const { language, region } = parseTag(locale);
|
|
5623
|
+
if (region && MONTH_FIRST_REGIONS.has(region)) {
|
|
5624
|
+
return ["month", "day", "year"];
|
|
5625
|
+
}
|
|
5626
|
+
if (region && DAY_FIRST_TAGS.has(`${language}-${region}`)) {
|
|
5627
|
+
return ["day", "month", "year"];
|
|
5628
|
+
}
|
|
5629
|
+
if (YEAR_FIRST_LANGUAGES.has(language)) {
|
|
5630
|
+
return ["year", "month", "day"];
|
|
5631
|
+
}
|
|
5632
|
+
// A bare "en" carries no region — treat it the way Intl does and assume
|
|
5633
|
+
// en-US. Regional English (en-gb, en-au, …) falls through to day-first.
|
|
5634
|
+
if (language === "en" && !region) {
|
|
5635
|
+
return ["month", "day", "year"];
|
|
5636
|
+
}
|
|
5637
|
+
return ["day", "month", "year"];
|
|
5638
|
+
}
|
|
5639
|
+
/**
|
|
5640
|
+
* Parse an explicit format string from the component config, e.g.
|
|
5641
|
+
* "DD/MM/YYYY" or "YYYY-MM-DD". Returns null when the string does not name
|
|
5642
|
+
* all three segments.
|
|
5643
|
+
*/
|
|
5644
|
+
function parseFormat(format) {
|
|
5645
|
+
const matches = format.match(/y+|m+|d+/gi);
|
|
5646
|
+
if (!matches)
|
|
5647
|
+
return null;
|
|
5648
|
+
const order = [];
|
|
5649
|
+
const tokens = { ...DEFAULT_TOKENS };
|
|
5650
|
+
for (const match of matches) {
|
|
5651
|
+
const initial = match[0].toLowerCase();
|
|
5652
|
+
const segment = initial === "y" ? "year" : initial === "m" ? "month" : "day";
|
|
5653
|
+
if (order.includes(segment))
|
|
5654
|
+
continue;
|
|
5655
|
+
order.push(segment);
|
|
5656
|
+
// A "YY" format still collects a four-digit year — the segment holds four
|
|
5657
|
+
// characters and `toIsoDate` rejects anything shorter, with a two-digit
|
|
5658
|
+
// entry expanded on blur. Showing "YY" as the placeholder would promise an
|
|
5659
|
+
// input the field does not accept, so short year tokens are widened.
|
|
5660
|
+
tokens[segment] =
|
|
5661
|
+
segment === "year" && match.length < 4 ? DEFAULT_TOKENS.year : match;
|
|
5662
|
+
}
|
|
5663
|
+
if (order.length !== 3)
|
|
5664
|
+
return null;
|
|
5665
|
+
const separator = format.match(/[^a-z\s]/i)?.[0] ?? "/";
|
|
5666
|
+
return { order, tokens, separator };
|
|
5667
|
+
}
|
|
5668
|
+
/**
|
|
5669
|
+
* Resolve the full layout for a DATE field. An explicit `config.format` wins;
|
|
5670
|
+
* otherwise the locale decides the order.
|
|
5671
|
+
*/
|
|
5672
|
+
function getDateLayout(format, locale) {
|
|
5673
|
+
if (format) {
|
|
5674
|
+
const parsed = parseFormat(format);
|
|
5675
|
+
if (parsed)
|
|
5676
|
+
return parsed;
|
|
5677
|
+
}
|
|
5678
|
+
const { language, region } = parseTag(locale);
|
|
5679
|
+
const order = getDateOrder(locale);
|
|
5680
|
+
const separator = (region ? SEPARATOR_BY_TAG[`${language}-${region}`] : undefined) ??
|
|
5681
|
+
SEPARATOR_BY_LANGUAGE[language] ??
|
|
5682
|
+
(order[0] === "year" ? "-" : "/");
|
|
5683
|
+
return {
|
|
5684
|
+
order,
|
|
5685
|
+
tokens: TOKENS_BY_LANGUAGE[language] ?? DEFAULT_TOKENS,
|
|
5686
|
+
separator,
|
|
5687
|
+
};
|
|
5688
|
+
}
|
|
5689
|
+
/** Number of days in a given month, honouring leap years. */
|
|
5690
|
+
function daysInMonth(year, month) {
|
|
5691
|
+
if (month < 1 || month > 12)
|
|
5692
|
+
return 0;
|
|
5693
|
+
return new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
5694
|
+
}
|
|
5695
|
+
/** Split an ISO "YYYY-MM-DD" value into its segments. */
|
|
5696
|
+
function parseIsoDate(value) {
|
|
5697
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec((value || "").trim());
|
|
5698
|
+
if (!match)
|
|
5699
|
+
return null;
|
|
5700
|
+
return { year: match[1], month: match[2], day: match[3] };
|
|
5701
|
+
}
|
|
5702
|
+
/**
|
|
5703
|
+
* Build an ISO "YYYY-MM-DD" string from segment values. Returns "" unless all
|
|
5704
|
+
* three segments are complete and form a real calendar date — a half-filled or
|
|
5705
|
+
* impossible date (31 February) is not a value worth submitting.
|
|
5706
|
+
*/
|
|
5707
|
+
function toIsoDate(segments) {
|
|
5708
|
+
const { year, month, day } = segments;
|
|
5709
|
+
if (year.length !== 4 || month.length === 0 || day.length === 0)
|
|
5710
|
+
return "";
|
|
5711
|
+
const y = Number(year);
|
|
5712
|
+
const m = Number(month);
|
|
5713
|
+
const d = Number(day);
|
|
5714
|
+
if (!Number.isInteger(y) || !Number.isInteger(m) || !Number.isInteger(d)) {
|
|
5715
|
+
return "";
|
|
5716
|
+
}
|
|
5717
|
+
if (m < 1 || m > 12)
|
|
5718
|
+
return "";
|
|
5719
|
+
if (d < 1 || d > daysInMonth(y, m))
|
|
5720
|
+
return "";
|
|
5721
|
+
return `${String(y).padStart(4, "0")}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
|
|
5722
|
+
}
|
|
5723
|
+
/**
|
|
5724
|
+
* Expand a two-digit year into the most recent matching year at or before
|
|
5725
|
+
* `anchorYear` — "85" becomes 1985, "05" becomes 2005. Anything that is not
|
|
5726
|
+
* exactly two digits is returned unchanged, so a fully typed year is never
|
|
5727
|
+
* second-guessed.
|
|
5728
|
+
*/
|
|
5729
|
+
function expandTwoDigitYear(year, anchorYear) {
|
|
5730
|
+
if (!/^\d{2}$/.test(year))
|
|
5731
|
+
return year;
|
|
5732
|
+
const century = Math.floor(anchorYear / 100) * 100;
|
|
5733
|
+
const candidate = century + Number(year);
|
|
5734
|
+
return String(candidate > anchorYear ? candidate - 100 : candidate);
|
|
5735
|
+
}
|
|
5736
|
+
/**
|
|
5737
|
+
* The latest year a two-digit entry may expand to. `config.max` pins it when
|
|
5738
|
+
* the field has an upper bound; otherwise we assume a date in the past (the
|
|
5739
|
+
* birthdate case) and anchor on the current year.
|
|
5740
|
+
*/
|
|
5741
|
+
function resolveYearAnchor(max, today) {
|
|
5742
|
+
const parsed = parseIsoDate(max);
|
|
5743
|
+
if (parsed)
|
|
5744
|
+
return Number(parsed.year);
|
|
5745
|
+
return today.getUTCFullYear();
|
|
5746
|
+
}
|
|
5747
|
+
|
|
5748
|
+
const authheroNodeCss = () => `:host{display:block}.input-wrapper{display:flex;flex-direction:column;position:relative;margin-top:8px;margin-bottom:16px}.input-container{position:relative;width:100%}.input-label{position:absolute;left:16px;top:50%;transform:translateY(-50%);font-size:var(--ah-font-size-label, 16px);font-weight:var(--ah-font-weight-label, 400);color:var(--ah-color-text-muted, #65676e);pointer-events:none;transition:all 0.15s ease-out;background-color:transparent;padding:0;z-index:1}.input-label.floating,.input-field:focus+.input-label,.input-field:not(:placeholder-shown)+.input-label,select.input-field+.input-label,input[type="date"].input-field+.input-label{top:-8px;transform:translateY(0);font-size:12px;background-color:var(--ah-color-bg, #ffffff);padding:0 4px;left:12px;color:var(--ah-color-text-muted, #65676e)}.input-field:focus+.input-label{color:var(--ah-color-primary, #635dff)}.required{color:var(--ah-color-error, #d03c38);margin-left:2px}.input-field{width:100%;padding:16px;font-size:16px;font-family:inherit;color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));background-color:var(--ah-color-input-bg, #ffffff);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-radius:var(--ah-input-radius, 3px);outline:none;transition:border-color 0.15s ease-out, box-shadow 0.15s ease-out;box-sizing:border-box}.input-field::placeholder{color:transparent}.input-field:hover{border-color:var(--ah-color-border-hover, #65676e)}.input-field:focus{border-color:var(--ah-color-primary, #635dff);box-shadow:inset 0 0 0 1px var(--ah-color-primary, #635dff)}.input-field.has-error{border-color:var(--ah-color-error, #d03c38)}.input-field.has-error:focus{box-shadow:inset 0 0 0 1px var(--ah-color-error, #d03c38)}.input-field:disabled{background-color:var(--ah-color-bg-disabled, #f5f5f5);border-color:var(--ah-color-border-disabled, #e0e1e3);cursor:not-allowed;opacity:0.7}.password-container{position:relative;display:flex;align-items:center}.password-container .input-field{padding-right:48px}.password-toggle{position:absolute;right:12px;top:50%;transform:translateY(-50%);background:none;border:none;cursor:pointer;padding:4px;display:flex;align-items:center;justify-content:center;color:var(--ah-color-icon, var(--ah-color-text-muted, #65676e));transition:color 0.15s ease}.password-toggle:hover{color:var(--ah-color-icon, var(--ah-color-text, #1e212a))}.password-toggle svg{width:20px;height:20px}.error-text{font-size:12px;color:var(--ah-color-error, #d03c38);margin-top:4px;line-height:1.4}.helper-text{font-size:12px;color:var(--ah-color-text-muted, #65676e);margin-top:4px;line-height:1.4}.field-link{display:block;text-align:left;margin-top:8px;margin-bottom:16px}.field-link a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);font-size:var(--ah-font-size-link, 14px);font-weight:var(--ah-font-weight-link, 400)}.field-link a:hover{text-decoration:underline}.checkbox-wrapper{display:flex;align-items:flex-start;gap:10px;cursor:pointer;margin-bottom:16px}.checkbox-wrapper input[type="checkbox"]{width:18px;height:18px;margin:0;accent-color:var(--ah-color-primary, #635dff);cursor:pointer;flex-shrink:0}.checkbox-label{font-size:var(--ah-font-size-body, 14px);font-weight:var(--ah-font-weight-body, 400);color:var(--ah-color-text, #1e212a);line-height:1.5}.btn{display:inline-flex;align-items:center;justify-content:center;gap:10px;width:100%;padding:14px 20px;font-size:var(--ah-font-size-btn, 16px);font-weight:var(--ah-font-weight-btn, 400);font-family:inherit;line-height:1.25;text-align:center;text-decoration:none;border:none;border-radius:var(--ah-btn-radius, 3px);cursor:pointer;transition:background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;box-sizing:border-box}.btn:disabled{opacity:0.6;cursor:not-allowed}.btn:not(:disabled):active{transform:scale(0.98)}.btn:focus-visible{outline:2px solid var(--ah-color-focus-ring, var(--ah-color-primary, #635dff));outline-offset:2px}.btn-primary{background-color:var(--ah-color-primary, #635dff);color:var(--ah-color-text-on-primary, #ffffff);margin-top:12px}.btn-primary:not(:disabled):hover{background-color:var( --ah-color-primary-hover, color-mix(in srgb, var(--ah-color-primary, #635dff) 85%, black) )}.btn-secondary{background-color:var(--ah-color-bg, #ffffff);color:var(--ah-btn-secondary-text, var(--ah-color-text, #1e212a));border:var(--ah-btn-border-width, 1px) solid var(--ah-btn-secondary-border, var(--ah-color-border, #c9cace))}.btn-secondary:not(:disabled):hover{background-color:var(--ah-color-bg-hover, #f5f5f5);border-color:var(--ah-color-border-hover, #65676e)}.btn-link{background:none;border:none;color:var(--ah-color-link, #635dff);padding:8px 0;font-weight:var(--ah-font-weight-link, 400);text-decoration:none}.btn-link:hover{text-decoration:underline}.phone-input-wrapper{display:flex;align-items:stretch;gap:0;width:100%}.country-select{flex-shrink:0;width:auto;padding:12px 8px;font-size:var(--ah-font-size-body, 16px);font-family:var(--ah-font-family, inherit);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-right:none;border-radius:var(--ah-input-radius, 4px) 0 0 var(--ah-input-radius, 4px);background-color:var(--ah-color-input-bg, var(--ah-color-surface, #fff));color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));cursor:pointer;appearance:none;-webkit-appearance:none;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 6px center;padding-right:22px}.country-select:focus{outline:none;border-color:var(--ah-color-primary, #635dff);box-shadow:0 0 0 1px var(--ah-color-primary, #635dff)}.country-select:disabled{opacity:0.5;cursor:not-allowed}.phone-input-wrapper .input-container{flex:1;min-width:0}.phone-input-wrapper .input-field{border-radius:0 var(--ah-input-radius, 4px) var(--ah-input-radius, 4px) 0}.phone-input-wrapper .input-label.floating,.phone-input-wrapper .input-field:focus+.input-label,.phone-input-wrapper .input-field:not(:placeholder-shown)+.input-label{left:8px}.date-input{display:flex;align-items:center;width:100%;padding:16px;box-sizing:border-box;background-color:var(--ah-color-input-bg, #ffffff);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-radius:var(--ah-input-radius, 3px);transition:border-color 0.15s ease-out, box-shadow 0.15s ease-out}.date-input:hover{border-color:var(--ah-color-border-hover, #65676e)}.date-input:focus-within{border-color:var(--ah-color-primary, #635dff);box-shadow:inset 0 0 0 1px var(--ah-color-primary, #635dff)}.date-input.has-error{border-color:var(--ah-color-error, #d03c38)}.date-input.has-error:focus-within{box-shadow:inset 0 0 0 1px var(--ah-color-error, #d03c38)}@media (forced-colors: active){.date-input:focus-within,.date-input.has-error:focus-within{outline:2px solid Highlight;outline-offset:1px}}.date-segment{width:3.25ch;min-width:0;padding:0;font-size:16px;font-family:inherit;text-align:center;color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));background:transparent;border:none;outline:none}.date-segment[data-date-segment="year"]{width:5.5ch}.date-segment::placeholder{color:var(--ah-color-text-muted, #65676e);opacity:1}.date-segment:disabled{color:var(--ah-color-text-disabled, #a0a0a0);cursor:not-allowed}.date-input:has(.date-segment:disabled){background-color:var(--ah-color-bg-disabled, #f5f5f5)}.date-separator{padding:0 4px;font-size:16px;color:var(--ah-color-text-muted, #65676e);user-select:none}.social-buttons{display:flex;flex-direction:column;gap:12px}.btn-social{display:flex;align-items:center;justify-content:center;gap:12px;position:relative}.btn-social-badge{position:absolute;right:12px;top:0;transform:translateY(-50%);font-size:11px;font-weight:500;line-height:1;padding:4px 9px;border-radius:999px;background:var(--ah-color-last-used, var(--ah-color-primary, #635dff));color:var(--ah-color-last-used-text, var(--ah-color-text-on-primary, #fff));white-space:nowrap;pointer-events:none}.btn-social.btn-social-last-used{border-color:var(--ah-color-last-used, var(--ah-color-primary, #635dff));box-shadow:inset 0 0 0 1px var(--ah-color-last-used, var(--ah-color-primary, #635dff))}.input-badge{position:absolute;right:12px;top:0;transform:translateY(-50%);font-size:11px;font-weight:500;line-height:1;padding:4px 9px;border-radius:999px;background:var(--ah-color-last-used, var(--ah-color-primary, #635dff));color:var(--ah-color-last-used-text, var(--ah-color-text-on-primary, #fff));white-space:nowrap;pointer-events:none;z-index:2}.btn-social-content{display:flex;flex-direction:column;align-items:center;text-align:center}.btn-social-subtitle{font-size:12px;font-style:italic;opacity:0.8;margin-top:2px}.btn-social-subtitle:empty{display:none}.social-icon{width:20px;height:20px;flex-shrink:0}@media (max-width: 480px){.social-buttons:has(.btn-social:nth-child(3)){flex-direction:row;flex-wrap:nowrap;justify-content:stretch;gap:8px}.social-buttons:has(.btn-social:nth-child(3)) .btn-social{width:auto;min-width:0;padding:12px;flex:1 1 0}.social-buttons:has(.btn-social:nth-child(3)) .btn-social span{display:none}.social-buttons:has(.btn-social:nth-child(3)) .social-icon{width:24px;height:24px}}.btn-icon{width:20px;height:20px;flex-shrink:0}.btn-icon img{width:100%;height:100%;object-fit:contain}.text-title{font-size:var(--ah-font-size-title, 20px);font-weight:var(--ah-font-weight-title, 400);color:var(--ah-color-text-header, var(--ah-color-header, #1e212a));margin:8px 0;line-height:1.3}.text-title.text-success{color:var(--ah-color-success, #13a769)}.text-description{font-size:var(--ah-font-size-subtitle, 14px);font-weight:var(--ah-font-weight-subtitle, 400);color:var(--ah-color-text-muted, #65676e);margin:4px 0;line-height:1.5}.image{display:block;max-width:100%;height:auto;border-radius:4px}.image-centered{margin:0 auto 16px;width:52px;height:52px;object-fit:contain}.link{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);font-size:var(--ah-font-size-link, 14px);transition:color 0.15s ease}.link:hover{text-decoration:underline}.link:focus-visible{outline:2px solid var(--ah-color-focus-ring, var(--ah-color-link, #635dff));outline-offset:2px;border-radius:2px}.node-error{padding:12px 16px;background-color:var(--ah-color-error-bg, #ffeaea);color:var(--ah-color-error, #d03c38);border-left:3px solid var(--ah-color-error, #d03c38);border-radius:0;font-size:14px;margin-bottom:16px}.node-success{padding:12px 16px;background-color:var(--ah-color-success-bg, #e6f9f1);color:var(--ah-color-success, #13a769);border-left:3px solid var(--ah-color-success, #13a769);border-radius:0;font-size:14px;margin-bottom:16px}.divider{display:flex;align-items:center;text-align:center;margin:16px 0}.divider::before,.divider::after{content:"";flex:1;border-bottom:1px solid var(--ah-color-border-muted, #c9cace)}.divider-text{padding:0 10px;font-size:12px;font-weight:400;color:var(--ah-color-text-muted, #65676e);text-transform:uppercase;letter-spacing:0.5px}.rich-text{font-size:var(--ah-font-size-body, 14px);font-weight:var(--ah-font-weight-body, 400);line-height:1.5;color:var(--ah-color-text, #1e212a)}.rich-text a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none);transition:color 0.15s ease}.rich-text a:hover{text-decoration:underline}.rich-text .terms-text{margin-top:16px;text-align:center;font-size:12px;color:var(--ah-color-text-muted, #65676e)}.rich-text .terms-text a{font-size:12px}.rich-text .forgot-password-link{text-align:right;font-size:13px;margin-top:4px}.rich-text .forgot-password-link a{font-size:13px;color:var(--ah-color-link, #635dff)}.rich-text .passwordless-link{margin-top:16px;text-align:center;font-size:14px}.rich-text .passwordless-link a{color:var(--ah-color-link, #635dff);text-decoration:var(--ah-link-decoration, none)}.rich-text .passwordless-link a:hover{text-decoration:underline}.rich-text .signup-link{margin-top:16px;text-align:center;font-size:14px;color:var(--ah-color-text, #1e212a)}.code-field{position:relative}.code-input{position:absolute;inset:0;width:100%;height:100%;margin:0;padding:0;border:none;background:transparent;color:transparent;caret-color:transparent;font-family:inherit;letter-spacing:0;outline:none;cursor:text;-webkit-text-fill-color:transparent}.code-boxes{display:flex;align-items:center;gap:var(--ah-code-group-gap, 12px);justify-content:center}.code-group{display:flex;gap:0}.code-separator{color:var(--ah-color-text-muted, #65676e);font-size:var(--ah-code-font-size, 24px);user-select:none}.code-box-placeholder{color:var(--ah-color-text-muted, #65676e);opacity:0.4}.code-box{position:relative;flex:0 0 auto;width:var(--ah-code-box-width, 48px);height:var(--ah-code-box-height, 56px);display:flex;align-items:center;justify-content:center;font-size:var(--ah-code-font-size, 24px);font-family:inherit;color:var(--ah-color-input-text, var(--ah-color-text, #1e212a));background-color:var(--ah-color-input-bg, #ffffff);border:var(--ah-input-border-width, 1px) solid var(--ah-color-border, #c9cace);border-radius:0;transition:border-color 0.15s ease-out, box-shadow 0.15s ease-out;box-sizing:border-box}.code-box+.code-box{margin-left:calc(-1 * var(--ah-input-border-width, 1px))}.code-group .code-box:first-child{border-top-left-radius:var(--ah-input-radius, 3px);border-bottom-left-radius:var(--ah-input-radius, 3px)}.code-group .code-box:last-child{border-top-right-radius:var(--ah-input-radius, 3px);border-bottom-right-radius:var(--ah-input-radius, 3px)}.code-field:focus-within .code-box.is-active{z-index:1;border-color:var(--ah-color-primary, #635dff);box-shadow:inset 0 0 0 1px var(--ah-color-primary, #635dff)}.code-field.has-error .code-box{border-color:var(--ah-color-error, #d03c38)}.code-input:disabled{cursor:not-allowed}.code-input:disabled~.code-boxes .code-box{background-color:var(--ah-color-bg-disabled, #f5f5f5);border-color:var(--ah-color-border-disabled, #e0e1e3)}`;
|
|
5504
5749
|
|
|
5505
5750
|
class AuthheroNode {
|
|
5506
5751
|
constructor(hostRef) {
|
|
@@ -5518,6 +5763,12 @@ class AuthheroNode {
|
|
|
5518
5763
|
* Whether the component is disabled.
|
|
5519
5764
|
*/
|
|
5520
5765
|
disabled = false;
|
|
5766
|
+
/**
|
|
5767
|
+
* BCP-47 locale used for locale-dependent field layout (currently the
|
|
5768
|
+
* segment order of DATE fields). Resolved server-side so SSR and hydration
|
|
5769
|
+
* agree; falls back to day-month-year when absent.
|
|
5770
|
+
*/
|
|
5771
|
+
locale;
|
|
5521
5772
|
/**
|
|
5522
5773
|
* Whether the password field is visible.
|
|
5523
5774
|
*/
|
|
@@ -5539,6 +5790,15 @@ class AuthheroNode {
|
|
|
5539
5790
|
* When true, the value is emitted as-is without dial code prefix.
|
|
5540
5791
|
*/
|
|
5541
5792
|
telEmailMode = false;
|
|
5793
|
+
/**
|
|
5794
|
+
* Segment values for the DATE input, each held as typed (unpadded while the
|
|
5795
|
+
* user is mid-entry) and normalised on blur.
|
|
5796
|
+
*/
|
|
5797
|
+
dateSegments = {
|
|
5798
|
+
year: "",
|
|
5799
|
+
month: "",
|
|
5800
|
+
day: "",
|
|
5801
|
+
};
|
|
5542
5802
|
/**
|
|
5543
5803
|
* Emitted when a field value changes.
|
|
5544
5804
|
*/
|
|
@@ -5550,13 +5810,16 @@ class AuthheroNode {
|
|
|
5550
5810
|
componentChanged() {
|
|
5551
5811
|
this.initCountryFromConfig();
|
|
5552
5812
|
this.initTelValue();
|
|
5813
|
+
this.initDateValue();
|
|
5553
5814
|
}
|
|
5554
5815
|
valueChanged() {
|
|
5555
5816
|
this.initTelValue();
|
|
5817
|
+
this.initDateValue();
|
|
5556
5818
|
}
|
|
5557
5819
|
componentWillLoad() {
|
|
5558
5820
|
this.initCountryFromConfig();
|
|
5559
5821
|
this.initTelValue();
|
|
5822
|
+
this.initDateValue();
|
|
5560
5823
|
}
|
|
5561
5824
|
componentDidLoad() {
|
|
5562
5825
|
// Auto-focus a code field so the caret starts in the first (leftmost) box.
|
|
@@ -5582,6 +5845,20 @@ class AuthheroNode {
|
|
|
5582
5845
|
}
|
|
5583
5846
|
}
|
|
5584
5847
|
}
|
|
5848
|
+
/**
|
|
5849
|
+
* The last value this field emitted for a TEL component. The widget mirrors
|
|
5850
|
+
* every emitted value back onto the `value` prop, and that echo must not be
|
|
5851
|
+
* re-parsed: the wire format carries only a dial code, so a country picked
|
|
5852
|
+
* from the list would be replaced by the first entry sharing that code — a
|
|
5853
|
+
* user who chose Canada would be silently moved to the US on their next
|
|
5854
|
+
* keystroke.
|
|
5855
|
+
*/
|
|
5856
|
+
lastEmittedTel;
|
|
5857
|
+
/** Emit a TEL value and remember it, so the echo can be recognised. */
|
|
5858
|
+
emitTelValue(value) {
|
|
5859
|
+
this.lastEmittedTel = value;
|
|
5860
|
+
this.fieldChange.emit({ id: this.component.id, value });
|
|
5861
|
+
}
|
|
5585
5862
|
/**
|
|
5586
5863
|
* Hydrate localPhoneNumber (and selectedCountry) from the effective value
|
|
5587
5864
|
* for TEL fields. The full value is stored as `{dialCode}{localNumber}`,
|
|
@@ -5590,6 +5867,10 @@ class AuthheroNode {
|
|
|
5590
5867
|
initTelValue() {
|
|
5591
5868
|
if (this.component?.type !== "TEL")
|
|
5592
5869
|
return;
|
|
5870
|
+
if (this.lastEmittedTel !== undefined &&
|
|
5871
|
+
this.getEffectiveValue() === this.lastEmittedTel) {
|
|
5872
|
+
return;
|
|
5873
|
+
}
|
|
5593
5874
|
const config = this.component.config;
|
|
5594
5875
|
const allowEmail = config?.allow_email === true;
|
|
5595
5876
|
const fullValue = this.getEffectiveValue();
|
|
@@ -5624,11 +5905,16 @@ class AuthheroNode {
|
|
|
5624
5905
|
handleCountryChange = (e) => {
|
|
5625
5906
|
const target = e.target;
|
|
5626
5907
|
this.selectedCountry = getCountryByCode(target.value);
|
|
5908
|
+
// A half-typed "+xx" prefix is replaced by the picked country, not kept
|
|
5909
|
+
// as a local number (it would emit "+46+4").
|
|
5910
|
+
if (this.localPhoneNumber.startsWith("+")) {
|
|
5911
|
+
this.localPhoneNumber = "";
|
|
5912
|
+
}
|
|
5627
5913
|
// Re-emit the full phone number with new dial code
|
|
5628
5914
|
const fullNumber = this.localPhoneNumber
|
|
5629
5915
|
? `${this.selectedCountry.dialCode}${this.localPhoneNumber}`
|
|
5630
5916
|
: "";
|
|
5631
|
-
this.
|
|
5917
|
+
this.emitTelValue(fullNumber);
|
|
5632
5918
|
};
|
|
5633
5919
|
/**
|
|
5634
5920
|
* Try to detect a dial code prefix in the raw input (e.g. "+46", "0046")
|
|
@@ -5666,7 +5952,21 @@ class AuthheroNode {
|
|
|
5666
5952
|
target.value = cleanedLocal;
|
|
5667
5953
|
this.localPhoneNumber = cleanedLocal;
|
|
5668
5954
|
const fullNumber = `${this.selectedCountry.dialCode}${cleanedLocal}`;
|
|
5669
|
-
this.
|
|
5955
|
+
this.emitTelValue(fullNumber);
|
|
5956
|
+
}
|
|
5957
|
+
else if (value.startsWith("+")) {
|
|
5958
|
+
// A leading "+" is an international prefix the user is still typing.
|
|
5959
|
+
// Keep it in the field so the dial code can build up until it matches
|
|
5960
|
+
// a country — stripping it per keystroke means "+46" never resolves to
|
|
5961
|
+
// Sweden, since each character is discarded before the next arrives.
|
|
5962
|
+
const cleaned = `+${value.slice(1).replace(/[^\d\s\-()]/g, "")}`;
|
|
5963
|
+
if (cleaned !== value) {
|
|
5964
|
+
target.value = cleaned;
|
|
5965
|
+
}
|
|
5966
|
+
this.localPhoneNumber = cleaned;
|
|
5967
|
+
// Emit the partial prefix as-is; prefixing it with the (not yet chosen)
|
|
5968
|
+
// country's dial code would produce nonsense like "+1+4".
|
|
5969
|
+
this.emitTelValue(cleaned);
|
|
5670
5970
|
}
|
|
5671
5971
|
else {
|
|
5672
5972
|
const cleaned = allowPlus
|
|
@@ -5679,7 +5979,7 @@ class AuthheroNode {
|
|
|
5679
5979
|
const fullNumber = cleaned
|
|
5680
5980
|
? `${this.selectedCountry.dialCode}${cleaned}`
|
|
5681
5981
|
: "";
|
|
5682
|
-
this.
|
|
5982
|
+
this.emitTelValue(fullNumber);
|
|
5683
5983
|
}
|
|
5684
5984
|
}
|
|
5685
5985
|
handlePhoneInput = (e) => {
|
|
@@ -5699,7 +5999,7 @@ class AuthheroNode {
|
|
|
5699
5999
|
else {
|
|
5700
6000
|
// Email or text — emit as-is
|
|
5701
6001
|
this.localPhoneNumber = value;
|
|
5702
|
-
this.
|
|
6002
|
+
this.emitTelValue(value);
|
|
5703
6003
|
}
|
|
5704
6004
|
return;
|
|
5705
6005
|
}
|
|
@@ -5710,6 +6010,196 @@ class AuthheroNode {
|
|
|
5710
6010
|
const target = e.target;
|
|
5711
6011
|
this.fieldChange.emit({ id: this.component.id, value: target.value });
|
|
5712
6012
|
};
|
|
6013
|
+
// ===========================================================================
|
|
6014
|
+
// DATE segment handling
|
|
6015
|
+
// ===========================================================================
|
|
6016
|
+
/**
|
|
6017
|
+
* The last ISO value this field emitted. The widget mirrors every emitted
|
|
6018
|
+
* value back onto the `value` prop, and that echo must not be treated as an
|
|
6019
|
+
* external change: it would re-format the segments under the caret while
|
|
6020
|
+
* the user is still typing (a day of "3" comes back as "03", swallowing the
|
|
6021
|
+
* next digit).
|
|
6022
|
+
*/
|
|
6023
|
+
lastEmittedDate;
|
|
6024
|
+
/** Hydrate the day/month/year segments from the effective ISO value. */
|
|
6025
|
+
initDateValue() {
|
|
6026
|
+
if (this.component?.type !== "DATE")
|
|
6027
|
+
return;
|
|
6028
|
+
if (this.lastEmittedDate !== undefined &&
|
|
6029
|
+
this.getEffectiveValue() === this.lastEmittedDate) {
|
|
6030
|
+
return;
|
|
6031
|
+
}
|
|
6032
|
+
const parsed = parseIsoDate(this.getEffectiveValue());
|
|
6033
|
+
if (parsed) {
|
|
6034
|
+
this.dateSegments = parsed;
|
|
6035
|
+
return;
|
|
6036
|
+
}
|
|
6037
|
+
// No parseable value. Only clear when we currently hold a complete date,
|
|
6038
|
+
// i.e. this is a genuine external reset: a half-typed date emits "" and
|
|
6039
|
+
// the parent echoes that straight back as the value prop, which would
|
|
6040
|
+
// otherwise wipe the segment the user just typed into.
|
|
6041
|
+
if (toIsoDate(this.dateSegments) !== "") {
|
|
6042
|
+
this.dateSegments = { year: "", month: "", day: "" };
|
|
6043
|
+
}
|
|
6044
|
+
}
|
|
6045
|
+
dateConfig() {
|
|
6046
|
+
return this.component.config;
|
|
6047
|
+
}
|
|
6048
|
+
getDateLayoutForField() {
|
|
6049
|
+
const config = this.dateConfig();
|
|
6050
|
+
return getDateLayout(config?.format, this.locale);
|
|
6051
|
+
}
|
|
6052
|
+
static SEGMENT_LENGTH = {
|
|
6053
|
+
day: 2,
|
|
6054
|
+
month: 2,
|
|
6055
|
+
year: 4,
|
|
6056
|
+
};
|
|
6057
|
+
/** Birthdate autofill tokens — the common case for a typed date. */
|
|
6058
|
+
static SEGMENT_AUTOCOMPLETE = {
|
|
6059
|
+
day: "bday-day",
|
|
6060
|
+
month: "bday-month",
|
|
6061
|
+
year: "bday-year",
|
|
6062
|
+
};
|
|
6063
|
+
/**
|
|
6064
|
+
* The submittable value for the current segments: an ISO date, or "" when
|
|
6065
|
+
* it is incomplete, impossible, or outside the field's `min`/`max`. ISO
|
|
6066
|
+
* strings compare chronologically, so the bounds need no parsing.
|
|
6067
|
+
*/
|
|
6068
|
+
dateIsoValue(segments) {
|
|
6069
|
+
const iso = toIsoDate(segments);
|
|
6070
|
+
if (!iso)
|
|
6071
|
+
return "";
|
|
6072
|
+
const config = this.dateConfig();
|
|
6073
|
+
const min = config?.min;
|
|
6074
|
+
const max = config?.max;
|
|
6075
|
+
if (typeof min === "string" && parseIsoDate(min) && iso < min)
|
|
6076
|
+
return "";
|
|
6077
|
+
if (typeof max === "string" && parseIsoDate(max) && iso > max)
|
|
6078
|
+
return "";
|
|
6079
|
+
return iso;
|
|
6080
|
+
}
|
|
6081
|
+
setDateSegments(segments) {
|
|
6082
|
+
this.dateSegments = segments;
|
|
6083
|
+
this.lastEmittedDate = this.dateIsoValue(segments);
|
|
6084
|
+
this.fieldChange.emit({
|
|
6085
|
+
id: this.component.id,
|
|
6086
|
+
value: this.lastEmittedDate,
|
|
6087
|
+
});
|
|
6088
|
+
}
|
|
6089
|
+
focusDateSegment(segment) {
|
|
6090
|
+
const input = this.host.shadowRoot?.querySelector(`input[data-date-segment="${segment}"]`);
|
|
6091
|
+
input?.focus();
|
|
6092
|
+
input?.select();
|
|
6093
|
+
}
|
|
6094
|
+
/**
|
|
6095
|
+
* Whether typing this digit completes the segment. A segment is complete at
|
|
6096
|
+
* its full width, and also as soon as a further digit could not produce a
|
|
6097
|
+
* valid number — no day starts with 4 and no month starts with 2.
|
|
6098
|
+
*/
|
|
6099
|
+
isDateSegmentComplete(segment, value) {
|
|
6100
|
+
if (value.length >= AuthheroNode.SEGMENT_LENGTH[segment])
|
|
6101
|
+
return true;
|
|
6102
|
+
if (value.length !== 1)
|
|
6103
|
+
return false;
|
|
6104
|
+
if (segment === "day")
|
|
6105
|
+
return Number(value) > 3;
|
|
6106
|
+
if (segment === "month")
|
|
6107
|
+
return Number(value) > 1;
|
|
6108
|
+
return false;
|
|
6109
|
+
}
|
|
6110
|
+
handleDateSegmentInput = (segment) => (e) => {
|
|
6111
|
+
const target = e.target;
|
|
6112
|
+
const digits = target.value
|
|
6113
|
+
.replace(/\D/g, "")
|
|
6114
|
+
.slice(0, AuthheroNode.SEGMENT_LENGTH[segment]);
|
|
6115
|
+
if (digits !== target.value) {
|
|
6116
|
+
target.value = digits;
|
|
6117
|
+
}
|
|
6118
|
+
this.setDateSegments({ ...this.dateSegments, [segment]: digits });
|
|
6119
|
+
if (this.isDateSegmentComplete(segment, digits)) {
|
|
6120
|
+
const order = this.getDateLayoutForField().order;
|
|
6121
|
+
const next = order[order.indexOf(segment) + 1];
|
|
6122
|
+
if (next)
|
|
6123
|
+
this.focusDateSegment(next);
|
|
6124
|
+
}
|
|
6125
|
+
};
|
|
6126
|
+
/**
|
|
6127
|
+
* Pad a single digit ("5" -> "05") and expand a two-digit year against the
|
|
6128
|
+
* field's upper bound ("85" -> 1985). Shared by blur and paste so a pasted
|
|
6129
|
+
* date is read the same way as a typed one.
|
|
6130
|
+
*/
|
|
6131
|
+
normalizeDateSegment(segment, value) {
|
|
6132
|
+
if (segment !== "year")
|
|
6133
|
+
return value.padStart(2, "0");
|
|
6134
|
+
return expandTwoDigitYear(value, resolveYearAnchor(this.dateConfig()?.max, new Date()));
|
|
6135
|
+
}
|
|
6136
|
+
/**
|
|
6137
|
+
* Normalise on blur: pad a single digit ("5" -> "05") and expand a two-digit
|
|
6138
|
+
* year against the field's upper bound ("85" -> 1985).
|
|
6139
|
+
*/
|
|
6140
|
+
handleDateSegmentBlur = (segment) => (e) => {
|
|
6141
|
+
const target = e.target;
|
|
6142
|
+
const value = target.value.replace(/\D/g, "");
|
|
6143
|
+
if (!value)
|
|
6144
|
+
return;
|
|
6145
|
+
const normalized = this.normalizeDateSegment(segment, value);
|
|
6146
|
+
if (normalized === value)
|
|
6147
|
+
return;
|
|
6148
|
+
target.value = normalized;
|
|
6149
|
+
this.setDateSegments({ ...this.dateSegments, [segment]: normalized });
|
|
6150
|
+
};
|
|
6151
|
+
/**
|
|
6152
|
+
* Backspace at the start of an empty segment moves to the previous one, so
|
|
6153
|
+
* the whole date can be cleared without reaching for the mouse.
|
|
6154
|
+
*/
|
|
6155
|
+
handleDateSegmentKeyDown = (segment) => (e) => {
|
|
6156
|
+
if (e.key === "Enter") {
|
|
6157
|
+
e.preventDefault();
|
|
6158
|
+
this.buttonClick.emit({ id: "submit", type: "submit", value: "next" });
|
|
6159
|
+
return;
|
|
6160
|
+
}
|
|
6161
|
+
if (e.key !== "Backspace")
|
|
6162
|
+
return;
|
|
6163
|
+
const target = e.target;
|
|
6164
|
+
if (target.value.length > 0 || target.selectionStart !== 0)
|
|
6165
|
+
return;
|
|
6166
|
+
const order = this.getDateLayoutForField().order;
|
|
6167
|
+
const previous = order[order.indexOf(segment) - 1];
|
|
6168
|
+
if (previous) {
|
|
6169
|
+
e.preventDefault();
|
|
6170
|
+
this.focusDateSegment(previous);
|
|
6171
|
+
}
|
|
6172
|
+
};
|
|
6173
|
+
/**
|
|
6174
|
+
* Pasting a whole date into any segment fills all three. An ISO value is
|
|
6175
|
+
* read year-first; anything else follows the field's displayed order. A
|
|
6176
|
+
* two-digit year is expanded the same way a typed one is, so "15/03/85"
|
|
6177
|
+
* pastes as 1985 rather than falling through to the browser's own paste.
|
|
6178
|
+
*/
|
|
6179
|
+
handleDatePaste = (e) => {
|
|
6180
|
+
const text = e.clipboardData?.getData("text") ?? "";
|
|
6181
|
+
const groups = text.match(/\d+/g);
|
|
6182
|
+
if (!groups || groups.length < 3)
|
|
6183
|
+
return;
|
|
6184
|
+
const [first, second, third] = groups;
|
|
6185
|
+
const isoLike = first.length === 4;
|
|
6186
|
+
const order = isoLike
|
|
6187
|
+
? ["year", "month", "day"]
|
|
6188
|
+
: this.getDateLayoutForField().order;
|
|
6189
|
+
const segments = {
|
|
6190
|
+
year: "",
|
|
6191
|
+
month: "",
|
|
6192
|
+
day: "",
|
|
6193
|
+
};
|
|
6194
|
+
[first, second, third].forEach((group, index) => {
|
|
6195
|
+
const segment = order[index];
|
|
6196
|
+
segments[segment] = this.normalizeDateSegment(segment, group.slice(0, AuthheroNode.SEGMENT_LENGTH[segment]));
|
|
6197
|
+
});
|
|
6198
|
+
if (!toIsoDate(segments))
|
|
6199
|
+
return;
|
|
6200
|
+
e.preventDefault();
|
|
6201
|
+
this.setDateSegments(segments);
|
|
6202
|
+
};
|
|
5713
6203
|
handleKeyDown = (e) => {
|
|
5714
6204
|
if (e.key === "Enter") {
|
|
5715
6205
|
e.preventDefault();
|
|
@@ -5722,7 +6212,7 @@ class AuthheroNode {
|
|
|
5722
6212
|
if (config?.allow_email === true && target.value.length === 0) {
|
|
5723
6213
|
this.telEmailMode = true;
|
|
5724
6214
|
this.localPhoneNumber = "";
|
|
5725
|
-
this.
|
|
6215
|
+
this.emitTelValue("");
|
|
5726
6216
|
}
|
|
5727
6217
|
}
|
|
5728
6218
|
};
|
|
@@ -5997,17 +6487,40 @@ class AuthheroNode {
|
|
|
5997
6487
|
const effectiveValue = this.getEffectiveValue();
|
|
5998
6488
|
return (hAsync("div", { class: "input-wrapper", part: "input-wrapper" }, this.renderLabel(component.label, inputId, component.required), hAsync("input", { id: inputId, class: this.getInputFieldClass(errors.length > 0), part: "input", type: "url", name: component.id, value: effectiveValue ?? "", placeholder: component.config?.placeholder, required: component.required, disabled: this.disabled, onInput: this.handleInput, onKeyDown: this.handleKeyDown }), this.renderErrors(), errors.length === 0 && this.renderHint(component.hint)));
|
|
5999
6489
|
}
|
|
6490
|
+
/**
|
|
6491
|
+
* DATE is rendered as three numeric segments rather than `input type=date`.
|
|
6492
|
+
* A native date input renders differently in every browser (Safari adds a
|
|
6493
|
+
* stepper), keeps its dd/mm/yyyy hint visible while half-filled, and asks
|
|
6494
|
+
* for a calendar gesture to reach a year decades back — all wrong for a
|
|
6495
|
+
* date typed from memory, which is what these fields collect.
|
|
6496
|
+
*/
|
|
6000
6497
|
renderDateField(component) {
|
|
6001
|
-
const inputId = `input-${component.id}`;
|
|
6002
6498
|
const errors = this.getErrors();
|
|
6003
|
-
const {
|
|
6004
|
-
|
|
6005
|
-
const
|
|
6006
|
-
|
|
6007
|
-
|
|
6499
|
+
const { format } = component.config ?? {};
|
|
6500
|
+
const layout = getDateLayout(format, this.locale);
|
|
6501
|
+
const isoValue = this.dateIsoValue(this.dateSegments);
|
|
6502
|
+
// Every segment filled but no ISO value means the date does not exist
|
|
6503
|
+
// (31 February) or falls outside min/max. Flag it rather than silently
|
|
6504
|
+
// submitting nothing — the widget posts JSON, so the browser's own
|
|
6505
|
+
// constraint validation never runs.
|
|
6506
|
+
const isIncomplete = layout.order.some((segment) => this.dateSegments[segment].length === 0);
|
|
6507
|
+
const hasInvalidDate = !isoValue && !isIncomplete;
|
|
6508
|
+
const hasError = errors.length > 0 || hasInvalidDate;
|
|
6509
|
+
const firstInputId = `input-${component.id}`;
|
|
6510
|
+
const segmentInput = (segment) => (hAsync("input", { key: segment, id: segment === layout.order[0] ? firstInputId : undefined, class: "date-segment", part: `input date-segment date-segment-${segment}`, type: "text", inputmode: "numeric", autocomplete: AuthheroNode.SEGMENT_AUTOCOMPLETE[segment], "data-date-segment": segment, maxlength: AuthheroNode.SEGMENT_LENGTH[segment], size: AuthheroNode.SEGMENT_LENGTH[segment], value: this.dateSegments[segment], placeholder: layout.tokens[segment], "aria-label": layout.tokens[segment], "aria-invalid": hasError ? "true" : "false", required: component.required, disabled: this.disabled, onInput: this.handleDateSegmentInput(segment), onBlur: this.handleDateSegmentBlur(segment), onKeyDown: this.handleDateSegmentKeyDown(segment), onPaste: this.handleDatePaste }));
|
|
6511
|
+
return (hAsync("div", { class: "input-wrapper", part: "input-wrapper" }, hAsync("div", { class: "input-container" }, hAsync("div", { class: hasError ? "date-input has-error" : "date-input", part: "date-input", role: "group", "aria-label": component.label }, layout.order.map((segment, index) => [
|
|
6512
|
+
index > 0 && (hAsync("span", { key: `sep-${segment}`, class: "date-separator", part: "date-separator", "aria-hidden": "true" }, layout.separator)),
|
|
6513
|
+
segmentInput(segment),
|
|
6514
|
+
])), this.renderFloatingLabel(component.label, firstInputId, component.required, true)), hAsync("input", { type: "hidden", name: component.id, "data-input-name": component.id, value: isoValue }), this.renderErrors(), errors.length === 0 && this.renderHint(component.hint)));
|
|
6008
6515
|
}
|
|
6009
6516
|
renderBooleanField(component) {
|
|
6010
|
-
return (hAsync("label", { class: "checkbox-wrapper", part: "checkbox-wrapper" }, hAsync("input", { type: "checkbox", part: "checkbox", name: component.id, checked:
|
|
6517
|
+
return (hAsync("label", { class: "checkbox-wrapper", part: "checkbox-wrapper" }, hAsync("input", { type: "checkbox", part: "checkbox", name: component.id, checked:
|
|
6518
|
+
// Once the field has a value it is authoritative — falling back to
|
|
6519
|
+
// the default here would keep a ticked-by-default box ticked after
|
|
6520
|
+
// the user unticks it.
|
|
6521
|
+
this.value === undefined
|
|
6522
|
+
? component.config?.default_value === true
|
|
6523
|
+
: this.value === "true", required: component.required, disabled: this.disabled, onChange: this.handleCheckbox }), hAsync("span", { class: "checkbox-label", part: "checkbox-label" }, component.label)));
|
|
6011
6524
|
}
|
|
6012
6525
|
renderLegalField(component) {
|
|
6013
6526
|
const text = component.config?.text ?? component.label ?? "";
|
|
@@ -6187,11 +6700,13 @@ class AuthheroNode {
|
|
|
6187
6700
|
"component": [16],
|
|
6188
6701
|
"value": [1],
|
|
6189
6702
|
"disabled": [4],
|
|
6703
|
+
"locale": [1],
|
|
6190
6704
|
"passwordVisible": [32],
|
|
6191
6705
|
"selectedCountry": [32],
|
|
6192
6706
|
"localPhoneNumber": [32],
|
|
6193
6707
|
"countryDropdownOpen": [32],
|
|
6194
|
-
"telEmailMode": [32]
|
|
6708
|
+
"telEmailMode": [32],
|
|
6709
|
+
"dateSegments": [32]
|
|
6195
6710
|
},
|
|
6196
6711
|
"$listeners$": undefined,
|
|
6197
6712
|
"$lazyBundleId$": "-",
|
|
@@ -6722,6 +7237,27 @@ const authheroWidgetCss = () => `:host{display:block;font-family:var(--ah-font-f
|
|
|
6722
7237
|
* buttons. Used by long pick-one screens such as tenant selection.
|
|
6723
7238
|
*/
|
|
6724
7239
|
const CHOICE_LIST_SEARCH_THRESHOLD = 5;
|
|
7240
|
+
/**
|
|
7241
|
+
* Component types the widget renders as something the user can actually fill
|
|
7242
|
+
* in. Only these gate the primary action button: types that render nothing
|
|
7243
|
+
* (CARDS, FILE, RECAPTCHA, …) can carry `required` in the schema too, and
|
|
7244
|
+
* gating on them would leave Continue disabled with no way to satisfy it.
|
|
7245
|
+
*/
|
|
7246
|
+
const FILLABLE_FIELD_TYPES = new Set([
|
|
7247
|
+
"TEXT",
|
|
7248
|
+
"EMAIL",
|
|
7249
|
+
"CODE",
|
|
7250
|
+
"PASSWORD",
|
|
7251
|
+
"NUMBER",
|
|
7252
|
+
"TEL",
|
|
7253
|
+
"URL",
|
|
7254
|
+
"DATE",
|
|
7255
|
+
"BOOLEAN",
|
|
7256
|
+
"LEGAL",
|
|
7257
|
+
"COUNTRY",
|
|
7258
|
+
"DROPDOWN",
|
|
7259
|
+
"CHOICE",
|
|
7260
|
+
]);
|
|
6725
7261
|
class AuthheroWidget {
|
|
6726
7262
|
constructor(hostRef) {
|
|
6727
7263
|
registerInstance(this, hostRef);
|
|
@@ -6814,6 +7350,13 @@ class AuthheroWidget {
|
|
|
6814
7350
|
* @default false (same as autoSubmit when not specified)
|
|
6815
7351
|
*/
|
|
6816
7352
|
autoNavigate;
|
|
7353
|
+
/**
|
|
7354
|
+
* BCP-47 locale for locale-dependent field layout, e.g. whether a DATE
|
|
7355
|
+
* field reads DD/MM/YYYY, MM/DD/YYYY or YYYY-MM-DD. Resolve it server-side
|
|
7356
|
+
* and pass it in so the server-rendered markup and the hydrated one agree;
|
|
7357
|
+
* screen text itself is already localized by the server.
|
|
7358
|
+
*/
|
|
7359
|
+
locale;
|
|
6817
7360
|
/**
|
|
6818
7361
|
* Internal parsed screen state.
|
|
6819
7362
|
*/
|
|
@@ -6914,14 +7457,19 @@ class AuthheroWidget {
|
|
|
6914
7457
|
initFormDataFromDefaults(screen) {
|
|
6915
7458
|
const defaults = {};
|
|
6916
7459
|
for (const comp of screen.components || []) {
|
|
6917
|
-
if ("config" in comp
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
7460
|
+
if (!("config" in comp) || !comp.config)
|
|
7461
|
+
continue;
|
|
7462
|
+
if (!("default_value" in comp.config))
|
|
7463
|
+
continue;
|
|
7464
|
+
const val = comp.config.default_value;
|
|
7465
|
+
if (typeof val === "string" && val !== "") {
|
|
7466
|
+
defaults[comp.id] = val;
|
|
7467
|
+
}
|
|
7468
|
+
else if (typeof val === "boolean") {
|
|
7469
|
+
// A BOOLEAN's default decides whether the checkbox renders ticked, so
|
|
7470
|
+
// seed the matching value — otherwise a field the user never touches
|
|
7471
|
+
// submits nothing and the screen's state is lost.
|
|
7472
|
+
defaults[comp.id] = val ? "true" : "false";
|
|
6925
7473
|
}
|
|
6926
7474
|
}
|
|
6927
7475
|
if (Object.keys(defaults).length > 0) {
|
|
@@ -7922,6 +8470,11 @@ class AuthheroWidget {
|
|
|
7922
8470
|
handleButtonClick = (detail) => {
|
|
7923
8471
|
// If this is a submit button click, trigger form submission
|
|
7924
8472
|
if (detail.type === "submit") {
|
|
8473
|
+
// Enter in a text field submits too, so the required-field gate has to
|
|
8474
|
+
// live here and not only on the button's disabled state.
|
|
8475
|
+
if (this._screen && this.hasUnfilledRequiredFields(this._screen)) {
|
|
8476
|
+
return;
|
|
8477
|
+
}
|
|
7925
8478
|
// For GET screens (or missing method), navigate directly — no form submission needed
|
|
7926
8479
|
if ((!this._screen?.method ||
|
|
7927
8480
|
this._screen.method.toUpperCase() === "GET") &&
|
|
@@ -8110,6 +8663,32 @@ class AuthheroWidget {
|
|
|
8110
8663
|
isDividerComponent(component) {
|
|
8111
8664
|
return component.type === "DIVIDER";
|
|
8112
8665
|
}
|
|
8666
|
+
/**
|
|
8667
|
+
* Whether a required component holds a value the user has supplied.
|
|
8668
|
+
*/
|
|
8669
|
+
isRequiredFieldFilled(component) {
|
|
8670
|
+
const value = this.formData[component.id];
|
|
8671
|
+
// Checkboxes are only "filled" when ticked. A BOOLEAN's default_value is
|
|
8672
|
+
// seeded into formData, so it needs no separate handling here.
|
|
8673
|
+
if (component.type === "BOOLEAN" || component.type === "LEGAL") {
|
|
8674
|
+
return value === "true";
|
|
8675
|
+
}
|
|
8676
|
+
return typeof value === "string" && value.trim() !== "";
|
|
8677
|
+
}
|
|
8678
|
+
/**
|
|
8679
|
+
* Whether the screen still has required fields the user has not filled in.
|
|
8680
|
+
* Used to hold the primary action button disabled: the widget submits via
|
|
8681
|
+
* its own handler rather than a native form submit, so the browser's
|
|
8682
|
+
* constraint validation never runs and an empty required field would
|
|
8683
|
+
* otherwise only surface as a server error after a round trip.
|
|
8684
|
+
*/
|
|
8685
|
+
hasUnfilledRequiredFields(screen) {
|
|
8686
|
+
return (screen.components ?? []).some((component) => component.visible !== false &&
|
|
8687
|
+
"required" in component &&
|
|
8688
|
+
component.required === true &&
|
|
8689
|
+
FILLABLE_FIELD_TYPES.has(component.type) &&
|
|
8690
|
+
!this.isRequiredFieldFilled(component));
|
|
8691
|
+
}
|
|
8113
8692
|
/**
|
|
8114
8693
|
* Visible label of a choice button, used to filter searchable choice lists.
|
|
8115
8694
|
*/
|
|
@@ -8145,6 +8724,9 @@ class AuthheroWidget {
|
|
|
8145
8724
|
const choiceButtons = fieldComponents.filter((c) => c.type === "NEXT_BUTTON");
|
|
8146
8725
|
const isSearchableChoiceList = choiceButtons.length === fieldComponents.length &&
|
|
8147
8726
|
choiceButtons.length > CHOICE_LIST_SEARCH_THRESHOLD;
|
|
8727
|
+
// Hold the primary action button disabled until every required field has
|
|
8728
|
+
// a value.
|
|
8729
|
+
const requiredFieldsMissing = this.hasUnfilledRequiredFields(screen);
|
|
8148
8730
|
const filterQuery = this.listFilter.trim().toLowerCase();
|
|
8149
8731
|
const visibleChoiceButtons = isSearchableChoiceList && filterQuery
|
|
8150
8732
|
? choiceButtons.filter((c) => this.getChoiceButtonText(c).toLowerCase().includes(filterQuery))
|
|
@@ -8179,7 +8761,7 @@ class AuthheroWidget {
|
|
|
8179
8761
|
};
|
|
8180
8762
|
// Get logo URL from theme.widget (takes precedence) or branding
|
|
8181
8763
|
const logoUrl = this._theme?.widget?.logo_url || this._branding?.logo_url;
|
|
8182
|
-
return (hAsync("div", { class: "widget-container", part: "container", "data-authstack-container": true }, hAsync("header", { class: "widget-header", part: "header" }, logoUrl && (hAsync("div", { class: "logo-wrapper", part: "logo-wrapper" }, hAsync("img", { class: "logo", part: "logo", src: logoUrl, alt: "Logo" }))), screen.title && (hAsync("h1", { class: "title", part: "title", innerHTML: sanitizeHtml(screen.title) })), screen.description && (hAsync("p", { class: "description", part: "description", innerHTML: sanitizeHtml(screen.description) }))), hAsync("div", { class: "widget-body", part: "body" }, screenErrors.map((err) => (hAsync("div", { class: "message message-error", part: "message message-error", key: err.id ?? err.text }, err.text))), screenSuccesses.map((msg) => (hAsync("div", { class: "message message-success", part: "message message-success", key: msg.id ?? msg.text }, msg.text))), hAsync("form", { onSubmit: this.handleSubmit, action: screen.action, method: screen.method || "POST", part: "form" }, hiddenComponents.map((c) => (hAsync("input", { type: "hidden", name: c.id, id: c.id, key: c.id, value: this.formData[c.id] || "" }))), hAsync("div", { class: "form-content" }, socialComponents.length > 0 && (hAsync("div", { class: "social-section", part: "social-section" }, socialComponents.map((component) => (hAsync("authhero-node", { key: component.id, component: component, value: this.formData[component.id], onFieldChange: (e) => this.handleInputChange(e.detail.id, e.detail.value), onButtonClick: (e) => this.handleButtonClick(e.detail), disabled: this.loading, exportparts: getExportParts(component) }))))), socialComponents.length > 0 &&
|
|
8764
|
+
return (hAsync("div", { class: "widget-container", part: "container", "data-authstack-container": true }, hAsync("header", { class: "widget-header", part: "header" }, logoUrl && (hAsync("div", { class: "logo-wrapper", part: "logo-wrapper" }, hAsync("img", { class: "logo", part: "logo", src: logoUrl, alt: "Logo" }))), screen.title && (hAsync("h1", { class: "title", part: "title", innerHTML: sanitizeHtml(screen.title) })), screen.description && (hAsync("p", { class: "description", part: "description", innerHTML: sanitizeHtml(screen.description) }))), hAsync("div", { class: "widget-body", part: "body" }, screenErrors.map((err) => (hAsync("div", { class: "message message-error", part: "message message-error", key: err.id ?? err.text }, err.text))), screenSuccesses.map((msg) => (hAsync("div", { class: "message message-success", part: "message message-success", key: msg.id ?? msg.text }, msg.text))), hAsync("form", { onSubmit: this.handleSubmit, action: screen.action, method: screen.method || "POST", part: "form" }, hiddenComponents.map((c) => (hAsync("input", { type: "hidden", name: c.id, id: c.id, key: c.id, value: this.formData[c.id] || "" }))), hAsync("div", { class: "form-content" }, socialComponents.length > 0 && (hAsync("div", { class: "social-section", part: "social-section" }, socialComponents.map((component) => (hAsync("authhero-node", { key: component.id, component: component, locale: this.locale, value: this.formData[component.id], onFieldChange: (e) => this.handleInputChange(e.detail.id, e.detail.value), onButtonClick: (e) => this.handleButtonClick(e.detail), disabled: this.loading, exportparts: getExportParts(component) }))))), socialComponents.length > 0 &&
|
|
8183
8765
|
fieldComponents.length > 0 &&
|
|
8184
8766
|
hasDivider && (hAsync("div", { class: "divider", part: "divider" }, hAsync("span", { class: "divider-text" }, dividerText))), hAsync("div", { class: "fields-section", part: "fields-section" }, isSearchableChoiceList && (hAsync("input", { type: "text", class: "choice-list-search", part: "choice-list-search", placeholder: "Search", "aria-label": "Search", autocomplete: "off", value: this.listFilter, onInput: (e) => (this.listFilter = e.target.value), onKeyDown: (e) => {
|
|
8185
8767
|
// The search box lives inside the form; Enter would
|
|
@@ -8192,7 +8774,9 @@ class AuthheroWidget {
|
|
|
8192
8774
|
? "fields-list fields-list-scroll"
|
|
8193
8775
|
: "fields-list" }, (isSearchableChoiceList
|
|
8194
8776
|
? visibleChoiceButtons
|
|
8195
|
-
: fieldComponents).map((component) => (hAsync("authhero-node", { key: component.id, component: component, value: this.formData[component.id], onFieldChange: (e) => this.handleInputChange(e.detail.id, e.detail.value), onButtonClick: (e) => this.handleButtonClick(e.detail), disabled: this.loading
|
|
8777
|
+
: fieldComponents).map((component) => (hAsync("authhero-node", { key: component.id, component: component, locale: this.locale, value: this.formData[component.id], onFieldChange: (e) => this.handleInputChange(e.detail.id, e.detail.value), onButtonClick: (e) => this.handleButtonClick(e.detail), disabled: this.loading ||
|
|
8778
|
+
(component.type === "NEXT_BUTTON" &&
|
|
8779
|
+
requiredFieldsMissing) }))), isSearchableChoiceList &&
|
|
8196
8780
|
visibleChoiceButtons.length === 0 && (hAsync("div", { class: "choice-list-empty", part: "choice-list-empty" }, "No matches")))))), screen.links && screen.links.length > 0 && (hAsync("div", { class: "links", part: "links" }, screen.links.map((link) => (hAsync("span", { class: "link-wrapper", part: "link-wrapper", key: link.id ?? link.href }, link.linkText ? (hAsync("span", null, link.text, " ", hAsync("a", { href: link.href, class: "link", part: "link", onClick: (e) => this.handleLinkClick(e, {
|
|
8197
8781
|
id: link.id,
|
|
8198
8782
|
href: link.href,
|
|
@@ -8238,6 +8822,7 @@ class AuthheroWidget {
|
|
|
8238
8822
|
"loading": [1028],
|
|
8239
8823
|
"autoSubmit": [4, "auto-submit"],
|
|
8240
8824
|
"autoNavigate": [4, "auto-navigate"],
|
|
8825
|
+
"locale": [1],
|
|
8241
8826
|
"_screen": [32],
|
|
8242
8827
|
"_authParams": [32],
|
|
8243
8828
|
"_branding": [32],
|