@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
|
@@ -238,7 +238,252 @@ function getCountryByCode(code) {
|
|
|
238
238
|
countries.find((c) => c.code === "US"));
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
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)}`;
|
|
241
|
+
/**
|
|
242
|
+
* Locale-aware layout for the segmented DATE input.
|
|
243
|
+
*
|
|
244
|
+
* The segment order is resolved from a static table rather than from
|
|
245
|
+
* `Intl.DateTimeFormat`, deliberately: the widget is server-rendered and then
|
|
246
|
+
* hydrated in the browser, and the two runtimes do not ship the same ICU data
|
|
247
|
+
* (a Workers runtime commonly falls back to en-US ordering). A static table
|
|
248
|
+
* gives the server and the client the same answer, so the hydrated DOM matches
|
|
249
|
+
* the rendered one.
|
|
250
|
+
*/
|
|
251
|
+
/** Languages that write dates big-endian: year, month, day. */
|
|
252
|
+
const YEAR_FIRST_LANGUAGES = new Set([
|
|
253
|
+
"bo",
|
|
254
|
+
"dz",
|
|
255
|
+
"hu",
|
|
256
|
+
"ja",
|
|
257
|
+
"ko",
|
|
258
|
+
"lt",
|
|
259
|
+
"mn",
|
|
260
|
+
"sv",
|
|
261
|
+
"ug",
|
|
262
|
+
"zh",
|
|
263
|
+
]);
|
|
264
|
+
/**
|
|
265
|
+
* Regions that write month before day. Month-first is essentially a US
|
|
266
|
+
* convention plus the places that adopted it.
|
|
267
|
+
*/
|
|
268
|
+
const MONTH_FIRST_REGIONS = new Set(["us", "ph", "fm", "mh", "pw", "as", "gu"]);
|
|
269
|
+
/**
|
|
270
|
+
* Locales whose language is normally year-first but which write dates
|
|
271
|
+
* day-first in a particular region — Finland-Swedish is d.m.yyyy, unlike
|
|
272
|
+
* Sweden-Swedish.
|
|
273
|
+
*/
|
|
274
|
+
const DAY_FIRST_TAGS = new Set(["sv-fi"]);
|
|
275
|
+
const DEFAULT_TOKENS = {
|
|
276
|
+
day: "DD",
|
|
277
|
+
month: "MM",
|
|
278
|
+
year: "YYYY",
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* Placeholder tokens in the language's own convention — a German field reads
|
|
282
|
+
* TT.MM.JJJJ, a French one JJ/MM/AAAA. Languages without an entry fall back to
|
|
283
|
+
* the English DD/MM/YYYY tokens.
|
|
284
|
+
*/
|
|
285
|
+
const TOKENS_BY_LANGUAGE = {
|
|
286
|
+
cs: { day: "DD", month: "MM", year: "RRRR" },
|
|
287
|
+
da: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
|
|
288
|
+
de: { day: "TT", month: "MM", year: "JJJJ" },
|
|
289
|
+
es: { day: "DD", month: "MM", year: "AAAA" },
|
|
290
|
+
fi: { day: "PP", month: "KK", year: "VVVV" },
|
|
291
|
+
fr: { day: "JJ", month: "MM", year: "AAAA" },
|
|
292
|
+
hu: { day: "NN", month: "HH", year: "ÉÉÉÉ" },
|
|
293
|
+
it: { day: "GG", month: "MM", year: "AAAA" },
|
|
294
|
+
nb: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
|
|
295
|
+
nl: { day: "DD", month: "MM", year: "JJJJ" },
|
|
296
|
+
nn: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
|
|
297
|
+
no: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
|
|
298
|
+
pl: { day: "DD", month: "MM", year: "RRRR" },
|
|
299
|
+
pt: { day: "DD", month: "MM", year: "AAAA" },
|
|
300
|
+
ru: { day: "ДД", month: "ММ", year: "ГГГГ" },
|
|
301
|
+
sk: { day: "DD", month: "MM", year: "RRRR" },
|
|
302
|
+
sv: { day: "DD", month: "MM", year: "ÅÅÅÅ" },
|
|
303
|
+
tr: { day: "GG", month: "AA", year: "YYYY" },
|
|
304
|
+
uk: { day: "ДД", month: "ММ", year: "РРРР" },
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* Separator by language, for languages that do not use the defaults ("/" for
|
|
308
|
+
* day- or month-first, "-" for year-first). Mostly the locales that write
|
|
309
|
+
* 14.08.2026 with dots — German, the Nordics minus Sweden, and most of
|
|
310
|
+
* Central/Eastern Europe.
|
|
311
|
+
*/
|
|
312
|
+
const SEPARATOR_BY_LANGUAGE = {
|
|
313
|
+
bg: ".",
|
|
314
|
+
cs: ".",
|
|
315
|
+
da: ".",
|
|
316
|
+
de: ".",
|
|
317
|
+
et: ".",
|
|
318
|
+
fi: ".",
|
|
319
|
+
hr: ".",
|
|
320
|
+
hu: ".",
|
|
321
|
+
is: ".",
|
|
322
|
+
ja: "/",
|
|
323
|
+
ko: ".",
|
|
324
|
+
lv: ".",
|
|
325
|
+
mk: ".",
|
|
326
|
+
nb: ".",
|
|
327
|
+
nl: "-",
|
|
328
|
+
nn: ".",
|
|
329
|
+
no: ".",
|
|
330
|
+
pl: ".",
|
|
331
|
+
ro: ".",
|
|
332
|
+
ru: ".",
|
|
333
|
+
sk: ".",
|
|
334
|
+
sl: ".",
|
|
335
|
+
sr: ".",
|
|
336
|
+
tr: ".",
|
|
337
|
+
uk: ".",
|
|
338
|
+
zh: "/",
|
|
339
|
+
};
|
|
340
|
+
/** Full-tag overrides — Finland-Swedish writes 14.8.2026 with dots. */
|
|
341
|
+
const SEPARATOR_BY_TAG = {
|
|
342
|
+
"sv-fi": ".",
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* Split a BCP-47 tag into a lowercase language subtag and, when present, a
|
|
346
|
+
* two-letter region subtag. Script and variant subtags are ignored.
|
|
347
|
+
*/
|
|
348
|
+
function parseTag(locale) {
|
|
349
|
+
const tag = (locale || "").toLowerCase().replace(/_/g, "-");
|
|
350
|
+
const parts = tag.split("-").filter(Boolean);
|
|
351
|
+
const language = parts[0] || "";
|
|
352
|
+
const region = parts.slice(1).find((part) => /^[a-z]{2}$/.test(part));
|
|
353
|
+
return { language, region };
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Resolve the segment order for a locale. Falls back to day-month-year, which
|
|
357
|
+
* is what most of the world writes.
|
|
358
|
+
*/
|
|
359
|
+
function getDateOrder(locale) {
|
|
360
|
+
const { language, region } = parseTag(locale);
|
|
361
|
+
if (region && MONTH_FIRST_REGIONS.has(region)) {
|
|
362
|
+
return ["month", "day", "year"];
|
|
363
|
+
}
|
|
364
|
+
if (region && DAY_FIRST_TAGS.has(`${language}-${region}`)) {
|
|
365
|
+
return ["day", "month", "year"];
|
|
366
|
+
}
|
|
367
|
+
if (YEAR_FIRST_LANGUAGES.has(language)) {
|
|
368
|
+
return ["year", "month", "day"];
|
|
369
|
+
}
|
|
370
|
+
// A bare "en" carries no region — treat it the way Intl does and assume
|
|
371
|
+
// en-US. Regional English (en-gb, en-au, …) falls through to day-first.
|
|
372
|
+
if (language === "en" && !region) {
|
|
373
|
+
return ["month", "day", "year"];
|
|
374
|
+
}
|
|
375
|
+
return ["day", "month", "year"];
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Parse an explicit format string from the component config, e.g.
|
|
379
|
+
* "DD/MM/YYYY" or "YYYY-MM-DD". Returns null when the string does not name
|
|
380
|
+
* all three segments.
|
|
381
|
+
*/
|
|
382
|
+
function parseFormat(format) {
|
|
383
|
+
const matches = format.match(/y+|m+|d+/gi);
|
|
384
|
+
if (!matches)
|
|
385
|
+
return null;
|
|
386
|
+
const order = [];
|
|
387
|
+
const tokens = { ...DEFAULT_TOKENS };
|
|
388
|
+
for (const match of matches) {
|
|
389
|
+
const initial = match[0].toLowerCase();
|
|
390
|
+
const segment = initial === "y" ? "year" : initial === "m" ? "month" : "day";
|
|
391
|
+
if (order.includes(segment))
|
|
392
|
+
continue;
|
|
393
|
+
order.push(segment);
|
|
394
|
+
// A "YY" format still collects a four-digit year — the segment holds four
|
|
395
|
+
// characters and `toIsoDate` rejects anything shorter, with a two-digit
|
|
396
|
+
// entry expanded on blur. Showing "YY" as the placeholder would promise an
|
|
397
|
+
// input the field does not accept, so short year tokens are widened.
|
|
398
|
+
tokens[segment] =
|
|
399
|
+
segment === "year" && match.length < 4 ? DEFAULT_TOKENS.year : match;
|
|
400
|
+
}
|
|
401
|
+
if (order.length !== 3)
|
|
402
|
+
return null;
|
|
403
|
+
const separator = format.match(/[^a-z\s]/i)?.[0] ?? "/";
|
|
404
|
+
return { order, tokens, separator };
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Resolve the full layout for a DATE field. An explicit `config.format` wins;
|
|
408
|
+
* otherwise the locale decides the order.
|
|
409
|
+
*/
|
|
410
|
+
function getDateLayout(format, locale) {
|
|
411
|
+
if (format) {
|
|
412
|
+
const parsed = parseFormat(format);
|
|
413
|
+
if (parsed)
|
|
414
|
+
return parsed;
|
|
415
|
+
}
|
|
416
|
+
const { language, region } = parseTag(locale);
|
|
417
|
+
const order = getDateOrder(locale);
|
|
418
|
+
const separator = (region ? SEPARATOR_BY_TAG[`${language}-${region}`] : undefined) ??
|
|
419
|
+
SEPARATOR_BY_LANGUAGE[language] ??
|
|
420
|
+
(order[0] === "year" ? "-" : "/");
|
|
421
|
+
return {
|
|
422
|
+
order,
|
|
423
|
+
tokens: TOKENS_BY_LANGUAGE[language] ?? DEFAULT_TOKENS,
|
|
424
|
+
separator,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
/** Number of days in a given month, honouring leap years. */
|
|
428
|
+
function daysInMonth(year, month) {
|
|
429
|
+
if (month < 1 || month > 12)
|
|
430
|
+
return 0;
|
|
431
|
+
return new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
432
|
+
}
|
|
433
|
+
/** Split an ISO "YYYY-MM-DD" value into its segments. */
|
|
434
|
+
function parseIsoDate(value) {
|
|
435
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec((value || "").trim());
|
|
436
|
+
if (!match)
|
|
437
|
+
return null;
|
|
438
|
+
return { year: match[1], month: match[2], day: match[3] };
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Build an ISO "YYYY-MM-DD" string from segment values. Returns "" unless all
|
|
442
|
+
* three segments are complete and form a real calendar date — a half-filled or
|
|
443
|
+
* impossible date (31 February) is not a value worth submitting.
|
|
444
|
+
*/
|
|
445
|
+
function toIsoDate(segments) {
|
|
446
|
+
const { year, month, day } = segments;
|
|
447
|
+
if (year.length !== 4 || month.length === 0 || day.length === 0)
|
|
448
|
+
return "";
|
|
449
|
+
const y = Number(year);
|
|
450
|
+
const m = Number(month);
|
|
451
|
+
const d = Number(day);
|
|
452
|
+
if (!Number.isInteger(y) || !Number.isInteger(m) || !Number.isInteger(d)) {
|
|
453
|
+
return "";
|
|
454
|
+
}
|
|
455
|
+
if (m < 1 || m > 12)
|
|
456
|
+
return "";
|
|
457
|
+
if (d < 1 || d > daysInMonth(y, m))
|
|
458
|
+
return "";
|
|
459
|
+
return `${String(y).padStart(4, "0")}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Expand a two-digit year into the most recent matching year at or before
|
|
463
|
+
* `anchorYear` — "85" becomes 1985, "05" becomes 2005. Anything that is not
|
|
464
|
+
* exactly two digits is returned unchanged, so a fully typed year is never
|
|
465
|
+
* second-guessed.
|
|
466
|
+
*/
|
|
467
|
+
function expandTwoDigitYear(year, anchorYear) {
|
|
468
|
+
if (!/^\d{2}$/.test(year))
|
|
469
|
+
return year;
|
|
470
|
+
const century = Math.floor(anchorYear / 100) * 100;
|
|
471
|
+
const candidate = century + Number(year);
|
|
472
|
+
return String(candidate > anchorYear ? candidate - 100 : candidate);
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* The latest year a two-digit entry may expand to. `config.max` pins it when
|
|
476
|
+
* the field has an upper bound; otherwise we assume a date in the past (the
|
|
477
|
+
* birthdate case) and anchor on the current year.
|
|
478
|
+
*/
|
|
479
|
+
function resolveYearAnchor(max, today) {
|
|
480
|
+
const parsed = parseIsoDate(max);
|
|
481
|
+
if (parsed)
|
|
482
|
+
return Number(parsed.year);
|
|
483
|
+
return today.getUTCFullYear();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
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)}`;
|
|
242
487
|
|
|
243
488
|
const AuthheroNode = class {
|
|
244
489
|
constructor(hostRef) {
|
|
@@ -256,6 +501,12 @@ const AuthheroNode = class {
|
|
|
256
501
|
* Whether the component is disabled.
|
|
257
502
|
*/
|
|
258
503
|
disabled = false;
|
|
504
|
+
/**
|
|
505
|
+
* BCP-47 locale used for locale-dependent field layout (currently the
|
|
506
|
+
* segment order of DATE fields). Resolved server-side so SSR and hydration
|
|
507
|
+
* agree; falls back to day-month-year when absent.
|
|
508
|
+
*/
|
|
509
|
+
locale;
|
|
259
510
|
/**
|
|
260
511
|
* Whether the password field is visible.
|
|
261
512
|
*/
|
|
@@ -277,6 +528,15 @@ const AuthheroNode = class {
|
|
|
277
528
|
* When true, the value is emitted as-is without dial code prefix.
|
|
278
529
|
*/
|
|
279
530
|
telEmailMode = false;
|
|
531
|
+
/**
|
|
532
|
+
* Segment values for the DATE input, each held as typed (unpadded while the
|
|
533
|
+
* user is mid-entry) and normalised on blur.
|
|
534
|
+
*/
|
|
535
|
+
dateSegments = {
|
|
536
|
+
year: "",
|
|
537
|
+
month: "",
|
|
538
|
+
day: "",
|
|
539
|
+
};
|
|
280
540
|
/**
|
|
281
541
|
* Emitted when a field value changes.
|
|
282
542
|
*/
|
|
@@ -288,13 +548,16 @@ const AuthheroNode = class {
|
|
|
288
548
|
componentChanged() {
|
|
289
549
|
this.initCountryFromConfig();
|
|
290
550
|
this.initTelValue();
|
|
551
|
+
this.initDateValue();
|
|
291
552
|
}
|
|
292
553
|
valueChanged() {
|
|
293
554
|
this.initTelValue();
|
|
555
|
+
this.initDateValue();
|
|
294
556
|
}
|
|
295
557
|
componentWillLoad() {
|
|
296
558
|
this.initCountryFromConfig();
|
|
297
559
|
this.initTelValue();
|
|
560
|
+
this.initDateValue();
|
|
298
561
|
}
|
|
299
562
|
componentDidLoad() {
|
|
300
563
|
// Auto-focus a code field so the caret starts in the first (leftmost) box.
|
|
@@ -320,6 +583,20 @@ const AuthheroNode = class {
|
|
|
320
583
|
}
|
|
321
584
|
}
|
|
322
585
|
}
|
|
586
|
+
/**
|
|
587
|
+
* The last value this field emitted for a TEL component. The widget mirrors
|
|
588
|
+
* every emitted value back onto the `value` prop, and that echo must not be
|
|
589
|
+
* re-parsed: the wire format carries only a dial code, so a country picked
|
|
590
|
+
* from the list would be replaced by the first entry sharing that code — a
|
|
591
|
+
* user who chose Canada would be silently moved to the US on their next
|
|
592
|
+
* keystroke.
|
|
593
|
+
*/
|
|
594
|
+
lastEmittedTel;
|
|
595
|
+
/** Emit a TEL value and remember it, so the echo can be recognised. */
|
|
596
|
+
emitTelValue(value) {
|
|
597
|
+
this.lastEmittedTel = value;
|
|
598
|
+
this.fieldChange.emit({ id: this.component.id, value });
|
|
599
|
+
}
|
|
323
600
|
/**
|
|
324
601
|
* Hydrate localPhoneNumber (and selectedCountry) from the effective value
|
|
325
602
|
* for TEL fields. The full value is stored as `{dialCode}{localNumber}`,
|
|
@@ -328,6 +605,10 @@ const AuthheroNode = class {
|
|
|
328
605
|
initTelValue() {
|
|
329
606
|
if (this.component?.type !== "TEL")
|
|
330
607
|
return;
|
|
608
|
+
if (this.lastEmittedTel !== undefined &&
|
|
609
|
+
this.getEffectiveValue() === this.lastEmittedTel) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
331
612
|
const config = this.component.config;
|
|
332
613
|
const allowEmail = config?.allow_email === true;
|
|
333
614
|
const fullValue = this.getEffectiveValue();
|
|
@@ -362,11 +643,16 @@ const AuthheroNode = class {
|
|
|
362
643
|
handleCountryChange = (e) => {
|
|
363
644
|
const target = e.target;
|
|
364
645
|
this.selectedCountry = getCountryByCode(target.value);
|
|
646
|
+
// A half-typed "+xx" prefix is replaced by the picked country, not kept
|
|
647
|
+
// as a local number (it would emit "+46+4").
|
|
648
|
+
if (this.localPhoneNumber.startsWith("+")) {
|
|
649
|
+
this.localPhoneNumber = "";
|
|
650
|
+
}
|
|
365
651
|
// Re-emit the full phone number with new dial code
|
|
366
652
|
const fullNumber = this.localPhoneNumber
|
|
367
653
|
? `${this.selectedCountry.dialCode}${this.localPhoneNumber}`
|
|
368
654
|
: "";
|
|
369
|
-
this.
|
|
655
|
+
this.emitTelValue(fullNumber);
|
|
370
656
|
};
|
|
371
657
|
/**
|
|
372
658
|
* Try to detect a dial code prefix in the raw input (e.g. "+46", "0046")
|
|
@@ -404,7 +690,21 @@ const AuthheroNode = class {
|
|
|
404
690
|
target.value = cleanedLocal;
|
|
405
691
|
this.localPhoneNumber = cleanedLocal;
|
|
406
692
|
const fullNumber = `${this.selectedCountry.dialCode}${cleanedLocal}`;
|
|
407
|
-
this.
|
|
693
|
+
this.emitTelValue(fullNumber);
|
|
694
|
+
}
|
|
695
|
+
else if (value.startsWith("+")) {
|
|
696
|
+
// A leading "+" is an international prefix the user is still typing.
|
|
697
|
+
// Keep it in the field so the dial code can build up until it matches
|
|
698
|
+
// a country — stripping it per keystroke means "+46" never resolves to
|
|
699
|
+
// Sweden, since each character is discarded before the next arrives.
|
|
700
|
+
const cleaned = `+${value.slice(1).replace(/[^\d\s\-()]/g, "")}`;
|
|
701
|
+
if (cleaned !== value) {
|
|
702
|
+
target.value = cleaned;
|
|
703
|
+
}
|
|
704
|
+
this.localPhoneNumber = cleaned;
|
|
705
|
+
// Emit the partial prefix as-is; prefixing it with the (not yet chosen)
|
|
706
|
+
// country's dial code would produce nonsense like "+1+4".
|
|
707
|
+
this.emitTelValue(cleaned);
|
|
408
708
|
}
|
|
409
709
|
else {
|
|
410
710
|
const cleaned = allowPlus
|
|
@@ -417,7 +717,7 @@ const AuthheroNode = class {
|
|
|
417
717
|
const fullNumber = cleaned
|
|
418
718
|
? `${this.selectedCountry.dialCode}${cleaned}`
|
|
419
719
|
: "";
|
|
420
|
-
this.
|
|
720
|
+
this.emitTelValue(fullNumber);
|
|
421
721
|
}
|
|
422
722
|
}
|
|
423
723
|
handlePhoneInput = (e) => {
|
|
@@ -437,7 +737,7 @@ const AuthheroNode = class {
|
|
|
437
737
|
else {
|
|
438
738
|
// Email or text — emit as-is
|
|
439
739
|
this.localPhoneNumber = value;
|
|
440
|
-
this.
|
|
740
|
+
this.emitTelValue(value);
|
|
441
741
|
}
|
|
442
742
|
return;
|
|
443
743
|
}
|
|
@@ -448,6 +748,196 @@ const AuthheroNode = class {
|
|
|
448
748
|
const target = e.target;
|
|
449
749
|
this.fieldChange.emit({ id: this.component.id, value: target.value });
|
|
450
750
|
};
|
|
751
|
+
// ===========================================================================
|
|
752
|
+
// DATE segment handling
|
|
753
|
+
// ===========================================================================
|
|
754
|
+
/**
|
|
755
|
+
* The last ISO value this field emitted. The widget mirrors every emitted
|
|
756
|
+
* value back onto the `value` prop, and that echo must not be treated as an
|
|
757
|
+
* external change: it would re-format the segments under the caret while
|
|
758
|
+
* the user is still typing (a day of "3" comes back as "03", swallowing the
|
|
759
|
+
* next digit).
|
|
760
|
+
*/
|
|
761
|
+
lastEmittedDate;
|
|
762
|
+
/** Hydrate the day/month/year segments from the effective ISO value. */
|
|
763
|
+
initDateValue() {
|
|
764
|
+
if (this.component?.type !== "DATE")
|
|
765
|
+
return;
|
|
766
|
+
if (this.lastEmittedDate !== undefined &&
|
|
767
|
+
this.getEffectiveValue() === this.lastEmittedDate) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
const parsed = parseIsoDate(this.getEffectiveValue());
|
|
771
|
+
if (parsed) {
|
|
772
|
+
this.dateSegments = parsed;
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
// No parseable value. Only clear when we currently hold a complete date,
|
|
776
|
+
// i.e. this is a genuine external reset: a half-typed date emits "" and
|
|
777
|
+
// the parent echoes that straight back as the value prop, which would
|
|
778
|
+
// otherwise wipe the segment the user just typed into.
|
|
779
|
+
if (toIsoDate(this.dateSegments) !== "") {
|
|
780
|
+
this.dateSegments = { year: "", month: "", day: "" };
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
dateConfig() {
|
|
784
|
+
return this.component.config;
|
|
785
|
+
}
|
|
786
|
+
getDateLayoutForField() {
|
|
787
|
+
const config = this.dateConfig();
|
|
788
|
+
return getDateLayout(config?.format, this.locale);
|
|
789
|
+
}
|
|
790
|
+
static SEGMENT_LENGTH = {
|
|
791
|
+
day: 2,
|
|
792
|
+
month: 2,
|
|
793
|
+
year: 4,
|
|
794
|
+
};
|
|
795
|
+
/** Birthdate autofill tokens — the common case for a typed date. */
|
|
796
|
+
static SEGMENT_AUTOCOMPLETE = {
|
|
797
|
+
day: "bday-day",
|
|
798
|
+
month: "bday-month",
|
|
799
|
+
year: "bday-year",
|
|
800
|
+
};
|
|
801
|
+
/**
|
|
802
|
+
* The submittable value for the current segments: an ISO date, or "" when
|
|
803
|
+
* it is incomplete, impossible, or outside the field's `min`/`max`. ISO
|
|
804
|
+
* strings compare chronologically, so the bounds need no parsing.
|
|
805
|
+
*/
|
|
806
|
+
dateIsoValue(segments) {
|
|
807
|
+
const iso = toIsoDate(segments);
|
|
808
|
+
if (!iso)
|
|
809
|
+
return "";
|
|
810
|
+
const config = this.dateConfig();
|
|
811
|
+
const min = config?.min;
|
|
812
|
+
const max = config?.max;
|
|
813
|
+
if (typeof min === "string" && parseIsoDate(min) && iso < min)
|
|
814
|
+
return "";
|
|
815
|
+
if (typeof max === "string" && parseIsoDate(max) && iso > max)
|
|
816
|
+
return "";
|
|
817
|
+
return iso;
|
|
818
|
+
}
|
|
819
|
+
setDateSegments(segments) {
|
|
820
|
+
this.dateSegments = segments;
|
|
821
|
+
this.lastEmittedDate = this.dateIsoValue(segments);
|
|
822
|
+
this.fieldChange.emit({
|
|
823
|
+
id: this.component.id,
|
|
824
|
+
value: this.lastEmittedDate,
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
focusDateSegment(segment) {
|
|
828
|
+
const input = this.host.shadowRoot?.querySelector(`input[data-date-segment="${segment}"]`);
|
|
829
|
+
input?.focus();
|
|
830
|
+
input?.select();
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Whether typing this digit completes the segment. A segment is complete at
|
|
834
|
+
* its full width, and also as soon as a further digit could not produce a
|
|
835
|
+
* valid number — no day starts with 4 and no month starts with 2.
|
|
836
|
+
*/
|
|
837
|
+
isDateSegmentComplete(segment, value) {
|
|
838
|
+
if (value.length >= AuthheroNode.SEGMENT_LENGTH[segment])
|
|
839
|
+
return true;
|
|
840
|
+
if (value.length !== 1)
|
|
841
|
+
return false;
|
|
842
|
+
if (segment === "day")
|
|
843
|
+
return Number(value) > 3;
|
|
844
|
+
if (segment === "month")
|
|
845
|
+
return Number(value) > 1;
|
|
846
|
+
return false;
|
|
847
|
+
}
|
|
848
|
+
handleDateSegmentInput = (segment) => (e) => {
|
|
849
|
+
const target = e.target;
|
|
850
|
+
const digits = target.value
|
|
851
|
+
.replace(/\D/g, "")
|
|
852
|
+
.slice(0, AuthheroNode.SEGMENT_LENGTH[segment]);
|
|
853
|
+
if (digits !== target.value) {
|
|
854
|
+
target.value = digits;
|
|
855
|
+
}
|
|
856
|
+
this.setDateSegments({ ...this.dateSegments, [segment]: digits });
|
|
857
|
+
if (this.isDateSegmentComplete(segment, digits)) {
|
|
858
|
+
const order = this.getDateLayoutForField().order;
|
|
859
|
+
const next = order[order.indexOf(segment) + 1];
|
|
860
|
+
if (next)
|
|
861
|
+
this.focusDateSegment(next);
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
/**
|
|
865
|
+
* Pad a single digit ("5" -> "05") and expand a two-digit year against the
|
|
866
|
+
* field's upper bound ("85" -> 1985). Shared by blur and paste so a pasted
|
|
867
|
+
* date is read the same way as a typed one.
|
|
868
|
+
*/
|
|
869
|
+
normalizeDateSegment(segment, value) {
|
|
870
|
+
if (segment !== "year")
|
|
871
|
+
return value.padStart(2, "0");
|
|
872
|
+
return expandTwoDigitYear(value, resolveYearAnchor(this.dateConfig()?.max, new Date()));
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Normalise on blur: pad a single digit ("5" -> "05") and expand a two-digit
|
|
876
|
+
* year against the field's upper bound ("85" -> 1985).
|
|
877
|
+
*/
|
|
878
|
+
handleDateSegmentBlur = (segment) => (e) => {
|
|
879
|
+
const target = e.target;
|
|
880
|
+
const value = target.value.replace(/\D/g, "");
|
|
881
|
+
if (!value)
|
|
882
|
+
return;
|
|
883
|
+
const normalized = this.normalizeDateSegment(segment, value);
|
|
884
|
+
if (normalized === value)
|
|
885
|
+
return;
|
|
886
|
+
target.value = normalized;
|
|
887
|
+
this.setDateSegments({ ...this.dateSegments, [segment]: normalized });
|
|
888
|
+
};
|
|
889
|
+
/**
|
|
890
|
+
* Backspace at the start of an empty segment moves to the previous one, so
|
|
891
|
+
* the whole date can be cleared without reaching for the mouse.
|
|
892
|
+
*/
|
|
893
|
+
handleDateSegmentKeyDown = (segment) => (e) => {
|
|
894
|
+
if (e.key === "Enter") {
|
|
895
|
+
e.preventDefault();
|
|
896
|
+
this.buttonClick.emit({ id: "submit", type: "submit", value: "next" });
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
if (e.key !== "Backspace")
|
|
900
|
+
return;
|
|
901
|
+
const target = e.target;
|
|
902
|
+
if (target.value.length > 0 || target.selectionStart !== 0)
|
|
903
|
+
return;
|
|
904
|
+
const order = this.getDateLayoutForField().order;
|
|
905
|
+
const previous = order[order.indexOf(segment) - 1];
|
|
906
|
+
if (previous) {
|
|
907
|
+
e.preventDefault();
|
|
908
|
+
this.focusDateSegment(previous);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
/**
|
|
912
|
+
* Pasting a whole date into any segment fills all three. An ISO value is
|
|
913
|
+
* read year-first; anything else follows the field's displayed order. A
|
|
914
|
+
* two-digit year is expanded the same way a typed one is, so "15/03/85"
|
|
915
|
+
* pastes as 1985 rather than falling through to the browser's own paste.
|
|
916
|
+
*/
|
|
917
|
+
handleDatePaste = (e) => {
|
|
918
|
+
const text = e.clipboardData?.getData("text") ?? "";
|
|
919
|
+
const groups = text.match(/\d+/g);
|
|
920
|
+
if (!groups || groups.length < 3)
|
|
921
|
+
return;
|
|
922
|
+
const [first, second, third] = groups;
|
|
923
|
+
const isoLike = first.length === 4;
|
|
924
|
+
const order = isoLike
|
|
925
|
+
? ["year", "month", "day"]
|
|
926
|
+
: this.getDateLayoutForField().order;
|
|
927
|
+
const segments = {
|
|
928
|
+
year: "",
|
|
929
|
+
month: "",
|
|
930
|
+
day: "",
|
|
931
|
+
};
|
|
932
|
+
[first, second, third].forEach((group, index) => {
|
|
933
|
+
const segment = order[index];
|
|
934
|
+
segments[segment] = this.normalizeDateSegment(segment, group.slice(0, AuthheroNode.SEGMENT_LENGTH[segment]));
|
|
935
|
+
});
|
|
936
|
+
if (!toIsoDate(segments))
|
|
937
|
+
return;
|
|
938
|
+
e.preventDefault();
|
|
939
|
+
this.setDateSegments(segments);
|
|
940
|
+
};
|
|
451
941
|
handleKeyDown = (e) => {
|
|
452
942
|
if (e.key === "Enter") {
|
|
453
943
|
e.preventDefault();
|
|
@@ -460,7 +950,7 @@ const AuthheroNode = class {
|
|
|
460
950
|
if (config?.allow_email === true && target.value.length === 0) {
|
|
461
951
|
this.telEmailMode = true;
|
|
462
952
|
this.localPhoneNumber = "";
|
|
463
|
-
this.
|
|
953
|
+
this.emitTelValue("");
|
|
464
954
|
}
|
|
465
955
|
}
|
|
466
956
|
};
|
|
@@ -735,17 +1225,40 @@ const AuthheroNode = class {
|
|
|
735
1225
|
const effectiveValue = this.getEffectiveValue();
|
|
736
1226
|
return (index.h("div", { class: "input-wrapper", part: "input-wrapper" }, this.renderLabel(component.label, inputId, component.required), index.h("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)));
|
|
737
1227
|
}
|
|
1228
|
+
/**
|
|
1229
|
+
* DATE is rendered as three numeric segments rather than `input type=date`.
|
|
1230
|
+
* A native date input renders differently in every browser (Safari adds a
|
|
1231
|
+
* stepper), keeps its dd/mm/yyyy hint visible while half-filled, and asks
|
|
1232
|
+
* for a calendar gesture to reach a year decades back — all wrong for a
|
|
1233
|
+
* date typed from memory, which is what these fields collect.
|
|
1234
|
+
*/
|
|
738
1235
|
renderDateField(component) {
|
|
739
|
-
const inputId = `input-${component.id}`;
|
|
740
1236
|
const errors = this.getErrors();
|
|
741
|
-
const {
|
|
742
|
-
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
|
|
1237
|
+
const { format } = component.config ?? {};
|
|
1238
|
+
const layout = getDateLayout(format, this.locale);
|
|
1239
|
+
const isoValue = this.dateIsoValue(this.dateSegments);
|
|
1240
|
+
// Every segment filled but no ISO value means the date does not exist
|
|
1241
|
+
// (31 February) or falls outside min/max. Flag it rather than silently
|
|
1242
|
+
// submitting nothing — the widget posts JSON, so the browser's own
|
|
1243
|
+
// constraint validation never runs.
|
|
1244
|
+
const isIncomplete = layout.order.some((segment) => this.dateSegments[segment].length === 0);
|
|
1245
|
+
const hasInvalidDate = !isoValue && !isIncomplete;
|
|
1246
|
+
const hasError = errors.length > 0 || hasInvalidDate;
|
|
1247
|
+
const firstInputId = `input-${component.id}`;
|
|
1248
|
+
const segmentInput = (segment) => (index.h("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 }));
|
|
1249
|
+
return (index.h("div", { class: "input-wrapper", part: "input-wrapper" }, index.h("div", { class: "input-container" }, index.h("div", { class: hasError ? "date-input has-error" : "date-input", part: "date-input", role: "group", "aria-label": component.label }, layout.order.map((segment, index$1) => [
|
|
1250
|
+
index$1 > 0 && (index.h("span", { key: `sep-${segment}`, class: "date-separator", part: "date-separator", "aria-hidden": "true" }, layout.separator)),
|
|
1251
|
+
segmentInput(segment),
|
|
1252
|
+
])), this.renderFloatingLabel(component.label, firstInputId, component.required, true)), index.h("input", { type: "hidden", name: component.id, "data-input-name": component.id, value: isoValue }), this.renderErrors(), errors.length === 0 && this.renderHint(component.hint)));
|
|
746
1253
|
}
|
|
747
1254
|
renderBooleanField(component) {
|
|
748
|
-
return (index.h("label", { class: "checkbox-wrapper", part: "checkbox-wrapper" }, index.h("input", { type: "checkbox", part: "checkbox", name: component.id, checked:
|
|
1255
|
+
return (index.h("label", { class: "checkbox-wrapper", part: "checkbox-wrapper" }, index.h("input", { type: "checkbox", part: "checkbox", name: component.id, checked:
|
|
1256
|
+
// Once the field has a value it is authoritative — falling back to
|
|
1257
|
+
// the default here would keep a ticked-by-default box ticked after
|
|
1258
|
+
// the user unticks it.
|
|
1259
|
+
this.value === undefined
|
|
1260
|
+
? component.config?.default_value === true
|
|
1261
|
+
: this.value === "true", required: component.required, disabled: this.disabled, onChange: this.handleCheckbox }), index.h("span", { class: "checkbox-label", part: "checkbox-label" }, component.label)));
|
|
749
1262
|
}
|
|
750
1263
|
renderLegalField(component) {
|
|
751
1264
|
const text = component.config?.text ?? component.label ?? "";
|