UNPKG

strapi-plugin-country-select

Version:

A strapi custom field for selecting any country based on the ISO 3166-1 country code standard.

139 lines (135 loc) 4.85 kB
import { jsx } from "react/jsx-runtime"; import styled from "styled-components"; import { Flex } from "@strapi/design-system"; import { Globe } from "@strapi/icons"; import countries from "i18n-iso-countries"; const __variableDynamicImportRuntimeHelper = (glob, path, segs) => { const v = glob[path]; if (v) { return typeof v === "function" ? v() : Promise.resolve(v); } return new Promise((_, reject) => { (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)( reject.bind( null, new Error( "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "") ) ) ); }); }; const PLUGIN_ID = "country-select"; const prefixPluginTranslations = (trad) => { return Object.keys(trad).reduce((acc, current) => { acc[`${PLUGIN_ID}.${current}`] = trad[current]; return acc; }, {}); }; const IconBox = styled(Flex)` background-color: #f0f0ff; /* primary100 */ border: 1px solid #d9d8ff; /* primary200 */ svg > path { fill: #4945ff; /* primary600 */ } `; const CountrySelectIcon = () => { return /* @__PURE__ */ jsx(IconBox, { justifyContent: "center", alignItems: "center", width: 7, height: 6, hasRadius: true, "aria-hidden": true, children: /* @__PURE__ */ jsx(Globe, {}) }); }; const getTranslation = (id) => `${PLUGIN_ID}.${id}`; const index = { register(app) { app.customFields.register({ name: "country", pluginId: "country-select", type: "string", icon: CountrySelectIcon, intlLabel: { id: getTranslation("country-select.label"), defaultMessage: "Country" }, intlDescription: { id: getTranslation("country-select.description"), defaultMessage: "Select any country" }, components: { Input: async () => import("./index-ysgbVK4-.mjs") }, options: { advanced: [ { sectionTitle: { id: "global.settings", defaultMessage: "Settings" }, items: [ { name: "required", type: "checkbox", intlLabel: { id: "form.attribute.item.requiredField", defaultMessage: "Required field" }, description: { id: "form.attribute.item.requiredField.description", defaultMessage: "You won't be able to create an entry if this field is empty" } }, { name: "option.default", type: "text", intlLabel: { id: "form.attribute.item.defaultField", defaultMessage: "Required field" }, description: { id: "form.attribute.item.defaultField.description", defaultMessage: "You won't be able to create an entry if this field is empty" } } ] } ] } }); }, async registerTrads({ locales }) { const importedTrads = await Promise.all( locales.map((locale) => { console.log(locale); return Promise.all([ /* webpackChunkName: "[pluginId]-[request]" */ __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => import("./de-BifC-TEo.mjs"), "./translations/en.json": () => import("./en-GySpuZ50.mjs"), "./translations/fr.json": () => import("./fr-BH7sOUvt.mjs") }), `./translations/${locale}.json`, 3), /* import(`i18n-iso-countries/langs/${locale}.json`}) as long as vite is unable to import dynamic files from node_modules folder, we have to import a single language by default https://github.com/vitejs/vite/issues/14102 */ import("i18n-iso-countries/langs/en.json") ]).then(([pluginTranslations, countryTranslations]) => { countries.registerLocale(countryTranslations.default); return { data: { ...prefixPluginTranslations(pluginTranslations.default), [`${PLUGIN_ID}.countries`]: JSON.stringify(countries.getNames(locale)) }, locale }; }).catch((err) => { console.log("errrrr", err); return { data: {}, locale }; }); }) ); console.log(importedTrads); return Promise.resolve(importedTrads); } }; export { getTranslation as g, index as i }; //# sourceMappingURL=index-RJvmFeeZ.mjs.map