修复问题
This commit is contained in:
+134
-1
@@ -1139,6 +1139,12 @@ async function fillSignupEmailAndContinue(email, step) {
|
||||
}
|
||||
|
||||
function normalizePhoneDigits(value) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.normalizePhoneDigits === 'function') {
|
||||
return phoneCountryUtils.normalizePhoneDigits(value);
|
||||
}
|
||||
let digits = String(value || '').replace(/\D+/g, '');
|
||||
if (digits.startsWith('00')) {
|
||||
digits = digits.slice(2);
|
||||
@@ -1147,6 +1153,12 @@ function normalizePhoneDigits(value) {
|
||||
}
|
||||
|
||||
function extractDialCodeFromText(value) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.extractDialCodeFromText === 'function') {
|
||||
return phoneCountryUtils.extractDialCodeFromText(value);
|
||||
}
|
||||
const match = String(value || '').match(/\(\+\s*(\d{1,4})\s*\)|\+\s*\(\s*(\d{1,4})\s*\)|\+\s*(\d{1,4})\b/);
|
||||
return String(match?.[1] || match?.[2] || match?.[3] || '').trim();
|
||||
}
|
||||
@@ -1158,6 +1170,12 @@ function dispatchSignupPhoneFieldEvents(element) {
|
||||
}
|
||||
|
||||
function normalizeSignupCountryLabel(value) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.normalizeCountryLabel === 'function') {
|
||||
return phoneCountryUtils.normalizeCountryLabel(value);
|
||||
}
|
||||
return String(value || '')
|
||||
.normalize('NFKD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
@@ -1169,6 +1187,12 @@ function normalizeSignupCountryLabel(value) {
|
||||
}
|
||||
|
||||
function getSignupCountryLabelAliases(value) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.getCountryLabelAliases === 'function') {
|
||||
return phoneCountryUtils.getCountryLabelAliases(value);
|
||||
}
|
||||
const aliases = new Set();
|
||||
const addAlias = (alias) => {
|
||||
const normalized = normalizeSignupCountryLabel(alias);
|
||||
@@ -1205,16 +1229,34 @@ function getSignupCountryLabelAliases(value) {
|
||||
}
|
||||
|
||||
function getSignupPhoneOptionLabel(option) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.getOptionLabel === 'function') {
|
||||
return phoneCountryUtils.getOptionLabel(option);
|
||||
}
|
||||
return String(option?.textContent || option?.label || '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
}
|
||||
|
||||
function normalizeSignupCountryOptionValue(value) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.normalizeCountryOptionValue === 'function') {
|
||||
return phoneCountryUtils.normalizeCountryOptionValue(value);
|
||||
}
|
||||
return String(value || '').trim().toUpperCase();
|
||||
}
|
||||
|
||||
function getSignupRegionDisplayName(regionCode, locale) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.getRegionDisplayName === 'function') {
|
||||
return phoneCountryUtils.getRegionDisplayName(regionCode, locale);
|
||||
}
|
||||
const normalizedRegionCode = normalizeSignupCountryOptionValue(regionCode);
|
||||
const normalizedLocale = String(locale || '').trim();
|
||||
if (!/^[A-Z]{2}$/.test(normalizedRegionCode) || !normalizedLocale || typeof Intl?.DisplayNames !== 'function') {
|
||||
@@ -1230,6 +1272,18 @@ function getSignupRegionDisplayName(regionCode, locale) {
|
||||
}
|
||||
|
||||
function getSignupPhoneCountryMatchLabels(option) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.getOptionMatchLabels === 'function') {
|
||||
const rootScope = typeof self !== 'undefined' ? self : globalThis;
|
||||
return phoneCountryUtils.getOptionMatchLabels(option, {
|
||||
document: typeof document !== 'undefined' ? document : null,
|
||||
navigator: rootScope?.navigator || globalThis?.navigator || null,
|
||||
getOptionLabel: getSignupPhoneOptionLabel,
|
||||
});
|
||||
}
|
||||
|
||||
const labels = new Set();
|
||||
const pushLabel = (value) => {
|
||||
const label = String(value || '').replace(/\s+/g, ' ').trim();
|
||||
@@ -1408,6 +1462,12 @@ function getSignupPhoneHiddenNumberInput(phoneInput = getSignupPhoneInput()) {
|
||||
}
|
||||
|
||||
function resolveSignupPhoneDialCodeFromNumber(phoneNumber = '', texts = []) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.resolveDialCodeFromPhoneNumber === 'function') {
|
||||
return phoneCountryUtils.resolveDialCodeFromPhoneNumber(phoneNumber, texts);
|
||||
}
|
||||
const digits = normalizePhoneDigits(phoneNumber);
|
||||
if (!digits) {
|
||||
return '';
|
||||
@@ -1517,6 +1577,16 @@ function findSignupPhoneCountryOptionByLabel(phoneInput, countryLabel) {
|
||||
if (!select) {
|
||||
return null;
|
||||
}
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.findOptionByCountryLabel === 'function') {
|
||||
return phoneCountryUtils.findOptionByCountryLabel(select.options, countryLabel, {
|
||||
document: typeof document !== 'undefined' ? document : null,
|
||||
navigator: (typeof self !== 'undefined' ? self : globalThis)?.navigator || globalThis?.navigator || null,
|
||||
getOptionLabel: getSignupPhoneOptionLabel,
|
||||
});
|
||||
}
|
||||
const normalizedTargets = getSignupCountryLabelAliases(countryLabel);
|
||||
if (normalizedTargets.length === 0) {
|
||||
return null;
|
||||
@@ -1544,6 +1614,14 @@ function findSignupPhoneCountryOptionByPhoneNumber(phoneInput, phoneNumber) {
|
||||
if (!select) {
|
||||
return null;
|
||||
}
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.findOptionByPhoneNumber === 'function') {
|
||||
return phoneCountryUtils.findOptionByPhoneNumber(select.options, phoneNumber, {
|
||||
getOptionLabel: getSignupPhoneOptionLabel,
|
||||
});
|
||||
}
|
||||
const digits = normalizePhoneDigits(phoneNumber);
|
||||
if (!digits) {
|
||||
return null;
|
||||
@@ -1601,6 +1679,18 @@ function findSignupPhoneCountryListboxOption(targetOption, options = {}) {
|
||||
return byLabel;
|
||||
}
|
||||
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.findElementByDialCode === 'function') {
|
||||
const byPhoneNumber = phoneCountryUtils.findElementByDialCode(candidates, options.phoneNumber, {
|
||||
getText: getActionText,
|
||||
});
|
||||
if (byPhoneNumber) {
|
||||
return byPhoneNumber;
|
||||
}
|
||||
}
|
||||
|
||||
const targetDialCode = resolveSignupPhoneTargetDialCode(options, targetOption);
|
||||
if (!targetDialCode) {
|
||||
const digits = normalizePhoneDigits(options.phoneNumber);
|
||||
@@ -2819,11 +2909,17 @@ function getLoginSubmitButton({ allowDisabled = false } = {}) {
|
||||
}
|
||||
|
||||
function normalizeCountryLabel(value) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.normalizeCountryLabel === 'function') {
|
||||
return phoneCountryUtils.normalizeCountryLabel(value);
|
||||
}
|
||||
return String(value || '')
|
||||
.normalize('NFKD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.replace(/&/g, ' and ')
|
||||
.replace(/[^\w\s]/g, ' ')
|
||||
.replace(/[^\p{L}\p{N}\s]/gu, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
@@ -2836,12 +2932,30 @@ function getLoginPhoneCountrySelect(phoneInput) {
|
||||
}
|
||||
|
||||
function getLoginPhoneCountryOptionLabel(option) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.getOptionLabel === 'function') {
|
||||
return phoneCountryUtils.getOptionLabel(option);
|
||||
}
|
||||
return String(option?.textContent || option?.label || '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
}
|
||||
|
||||
function getLoginPhoneCountryOptionMatchLabels(option) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.getOptionMatchLabels === 'function') {
|
||||
const rootScope = typeof self !== 'undefined' ? self : globalThis;
|
||||
return phoneCountryUtils.getOptionMatchLabels(option, {
|
||||
document: typeof document !== 'undefined' ? document : null,
|
||||
navigator: rootScope?.navigator || globalThis?.navigator || null,
|
||||
getOptionLabel: getLoginPhoneCountryOptionLabel,
|
||||
});
|
||||
}
|
||||
|
||||
const labels = new Set();
|
||||
const pushLabel = (value) => {
|
||||
const label = String(value || '').replace(/\s+/g, ' ').trim();
|
||||
@@ -2856,6 +2970,17 @@ function getLoginPhoneCountryOptionMatchLabels(option) {
|
||||
}
|
||||
|
||||
function findLoginPhoneCountryOptionByLabel(select, countryLabel) {
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (select && typeof phoneCountryUtils.findOptionByCountryLabel === 'function') {
|
||||
return phoneCountryUtils.findOptionByCountryLabel(select.options, countryLabel, {
|
||||
document: typeof document !== 'undefined' ? document : null,
|
||||
navigator: (typeof self !== 'undefined' ? self : globalThis)?.navigator || globalThis?.navigator || null,
|
||||
getOptionLabel: getLoginPhoneCountryOptionLabel,
|
||||
});
|
||||
}
|
||||
|
||||
const normalizedTarget = normalizeCountryLabel(countryLabel);
|
||||
if (!select || !normalizedTarget) {
|
||||
return null;
|
||||
@@ -2881,6 +3006,14 @@ function findLoginPhoneCountryOptionByNumber(select, phoneNumber) {
|
||||
if (!select) {
|
||||
return null;
|
||||
}
|
||||
const phoneCountryUtils = (typeof self !== 'undefined' ? self : globalThis)?.MultiPagePhoneCountryUtils
|
||||
|| globalThis?.MultiPagePhoneCountryUtils
|
||||
|| {};
|
||||
if (typeof phoneCountryUtils.findOptionByPhoneNumber === 'function') {
|
||||
return phoneCountryUtils.findOptionByPhoneNumber(select.options, phoneNumber, {
|
||||
getOptionLabel: getLoginPhoneCountryOptionLabel,
|
||||
});
|
||||
}
|
||||
const digits = normalizePhoneDigits(phoneNumber);
|
||||
if (!digits) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user