strapi-plugin-country-select
Version:
A strapi custom field for selecting any country based on the ISO 3166-1 country code standard.
161 lines (157 loc) • 6.42 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
const jsxRuntime = require("react/jsx-runtime");
const styled = require("styled-components");
const designSystem = require("@strapi/design-system");
const icons = require("@strapi/icons");
const countries = require("i18n-iso-countries");
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
const styled__default = /* @__PURE__ */ _interopDefault(styled);
const countries__default = /* @__PURE__ */ _interopDefault(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__default.default(designSystem.Flex)`
background-color: #f0f0ff; /* primary100 */
border: 1px solid #d9d8ff; /* primary200 */
svg > path {
fill: #4945ff; /* primary600 */
}
`;
const CountrySelectIcon = () => {
return /* @__PURE__ */ jsxRuntime.jsx(IconBox, { justifyContent: "center", alignItems: "center", width: 7, height: 6, hasRadius: true, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx(icons.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 () => Promise.resolve().then(() => require("./index-C8U3bTFQ.js"))
},
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: "options.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) => {
return Promise.all([
/* webpackChunkName: "[pluginId]-[request]" */
__variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => Promise.resolve().then(() => require("./de-BD1XJS6t.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-DiloOMJM.js")), "./translations/fr.json": () => Promise.resolve().then(() => require("./fr-Cs3chGYF.js")) }), `./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__default.default.registerLocale(countryTranslations.default);
return {
data: {
...prefixPluginTranslations(pluginTranslations.default),
[`${PLUGIN_ID}.countries`]: JSON.stringify(countries__default.default.getNames(locale))
},
locale
};
}).catch((err) => {
console.log(err);
return {
data: {},
locale
};
});
})
);
return Promise.resolve(importedTrads);
}
};
exports.getTranslation = getTranslation;
exports.index = index;
//# sourceMappingURL=index-aIbMpT-h.js.map