UNPKG

strapi-plugin-country-select

Version:

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

1 lines 7.94 kB
{"version":3,"file":"index-RJvmFeeZ.mjs","sources":["../../admin/src/pluginId.ts","../../admin/src/utils/prefixPluginTranslations.ts","../../admin/src/components/CountrySelectIcon/index.tsx","../../admin/src/utils/getTrad.ts","../../admin/src/index.ts"],"sourcesContent":["export const PLUGIN_ID = 'country-select';\n","import { PLUGIN_ID } from '../pluginId';\n\ntype TradOptions = Record<string, string>;\n\nexport const prefixPluginTranslations = (\n trad: TradOptions,\n): TradOptions => {\n return Object.keys(trad).reduce((acc, current) => {\n acc[`${PLUGIN_ID}.${current}`] = trad[current];\n return acc;\n }, {} as TradOptions);\n};","import styled from 'styled-components';\nimport { Flex, } from '@strapi/design-system';\nimport { Globe } from '@strapi/icons';\n\nconst IconBox = styled(Flex)`\n background-color: #f0f0ff; /* primary100 */\n border: 1px solid #d9d8ff; /* primary200 */\n \n svg > path {\n fill: #4945ff; /* primary600 */\n }\n`;\n\nconst CountrySelectIcon = () => {\n return (\n <IconBox justifyContent=\"center\" alignItems=\"center\" width={7} height={6} hasRadius aria-hidden>\n <Globe />\n </IconBox>\n );\n};\n\nexport default CountrySelectIcon;","import { PLUGIN_ID } from '../pluginId';\n\nconst getTranslation = (id: string) => `${PLUGIN_ID}.${id}`;\n\nexport { getTranslation };","import { prefixPluginTranslations } from './utils/prefixPluginTranslations';\nimport { PLUGIN_ID } from './pluginId';\nimport CountrySelectIcon from './components/CountrySelectIcon';\nimport { getTranslation } from './utils/getTrad';\nimport countries from 'i18n-iso-countries';\n\nexport default {\n register(app: any) {\n app.customFields.register({\n name: 'country',\n pluginId: 'country-select',\n type: 'string',\n icon: CountrySelectIcon,\n intlLabel: {\n id: getTranslation('country-select.label'),\n defaultMessage: 'Country',\n },\n intlDescription: {\n id: getTranslation('country-select.description'),\n defaultMessage: 'Select any country',\n },\n components: {\n Input: async () =>\n import('./components/CountrySelect'),\n },\n options: {\n advanced: [\n {\n sectionTitle: {\n id: 'global.settings',\n defaultMessage: 'Settings',\n },\n items: [\n {\n name: 'required',\n type: 'checkbox',\n intlLabel: {\n id: 'form.attribute.item.requiredField',\n defaultMessage: 'Required field',\n },\n description: {\n id: 'form.attribute.item.requiredField.description',\n defaultMessage: \"You won't be able to create an entry if this field is empty\",\n },\n },\n {\n name: 'option.default',\n type: 'text',\n intlLabel: {\n id: 'form.attribute.item.defaultField',\n defaultMessage: 'Required field',\n },\n description: {\n id: 'form.attribute.item.defaultField.description',\n defaultMessage: \"You won't be able to create an entry if this field is empty\",\n },\n },\n ],\n },\n ],\n },\n });\n },\n\n async registerTrads({ locales }: { locales: string[] }) {\n const importedTrads = await Promise.all(\n locales.map((locale) => {\n console.log(locale);\n \n return Promise.all([\n /* webpackChunkName: \"[pluginId]-[request]\" */ import(`./translations/${locale}.json`),\n /* import(`i18n-iso-countries/langs/${locale}.json`})\n \n as long as vite is unable to import dynamic files from node_modules folder, \n we have to import a single language by default\n\n https://github.com/vitejs/vite/issues/14102\n */\n import(`i18n-iso-countries/langs/en.json`)\n ])\n .then(([pluginTranslations, countryTranslations]) => {\n countries.registerLocale(countryTranslations.default);\n\n return {\n data: {\n ...prefixPluginTranslations(pluginTranslations.default),\n [`${PLUGIN_ID}.countries`]: JSON.stringify(countries.getNames(locale)) \n },\n locale,\n };\n })\n .catch((err) => {\n console.log('errrrr', err);\n \n return {\n data: {},\n locale,\n };\n });\n })\n );\n console.log(importedTrads);\n \n return Promise.resolve(importedTrads);\n },\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAO,MAAM,YAAY;ACIZ,MAAA,2BAA2B,CACpC,SACc;AACd,SAAO,OAAO,KAAK,IAAI,EAAE,OAAO,CAAC,KAAK,YAAY;AAC9C,QAAI,GAAG,SAAS,IAAI,OAAO,EAAE,IAAI,KAAK,OAAO;AACtC,WAAA;AAAA,EACX,GAAG,EAAiB;AACxB;ACPA,MAAM,UAAU,OAAO,IAAI;AAA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