one
Version:
One is a React framework for web, iOS, and Android apps.
72 lines (71 loc) • 2.28 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var contacts_exports = {};
__export(contacts_exports, { Contacts: () => Contacts });
module.exports = __toCommonJS(contacts_exports);
var import_unavailable = require("./unavailable.cjs");
function picker() {
return typeof window === "undefined" ? void 0 : navigator.contacts;
}
let busy = false;
const Contacts = Object.freeze({
...import_unavailable.Contacts,
pickContact: async () => {
const contacts = picker();
if (!contacts) return import_unavailable.Contacts.pickContact();
if (busy) throw new Error("Contacts.pickContact: a picker is already open");
busy = true;
try {
const supported = await contacts.getProperties();
const fields = [
"name",
"tel",
"email",
"address"
].filter((field) => supported.includes(field));
const [contact] = await contacts.select(fields, { multiple: false });
if (!contact) return void 0;
return {
identifier: "",
givenName: contact.name?.[0] ?? "",
familyName: "",
phoneNumbers: contact.tel ?? [],
emailAddresses: contact.email ?? [],
postalAddresses: (contact.address ?? []).map((address) => ({
label: "",
street: address.addressLine.join("\n"),
subLocality: "",
city: address.city,
subAdministrativeArea: "",
state: address.region,
postalCode: address.postalCode,
country: "",
isoCountryCode: address.country
}))
};
} catch (error) {
if (error.name === "AbortError") return void 0;
throw error;
} finally {
busy = false;
}
}
});