UNPKG

strapi-plugin-link-custom-field

Version:
111 lines (110 loc) 3.3 kB
import { useRef, useEffect } from "react"; import { jsx } from "react/jsx-runtime"; import { Earth } from "@strapi/icons"; 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 = "link-custom-field"; const getTranslation = (id) => `${PLUGIN_ID}.${id}`; const Initializer = ({ setPlugin }) => { const ref = useRef(setPlugin); useEffect(() => { ref.current(PLUGIN_ID); }, []); return null; }; const PluginIcon = () => /* @__PURE__ */ jsx(Earth, {}); const prefixPluginTranslations = (trad, pluginId) => { return Object.keys(trad).reduce((acc, current) => { acc[`${pluginId}.${current}`] = trad[current]; return acc; }, {}); }; const index = { register(app) { app.customFields.register({ name: "link", plugin: PLUGIN_ID, type: "string", intlLabel: { id: getTranslation("field.name"), defaultMessage: "Link" }, intlDescription: { id: getTranslation("field.description"), defaultMessage: "Select a link from the list" }, icon: PluginIcon, components: { Input: async () => import("./Providers-BurbEGcp.mjs").then((module) => ({ default: module.LinkField })) }, options: { advanced: [ { sectionTitle: { id: "global.settings", defaultMessage: "Settings" }, items: [ { name: "required", type: "checkbox", intlLabel: { id: getTranslation("options.advanced.requiredField"), defaultMessage: "Required field" }, description: { id: getTranslation("options.advanced.requiredField.description"), defaultMessage: "You won't be able to create an entry if this field is empty" } } ] } ] } }); app.registerPlugin({ id: PLUGIN_ID, initializer: Initializer, isReady: false, name: PLUGIN_ID }); }, async registerTrads({ locales }) { const importedTrads = await Promise.all( locales.map((locale) => { return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => import("./de-DqTMLSwC.mjs"), "./translations/en.json": () => import("./en-DIwLb1hp.mjs") }), `./translations/${locale}.json`, 3).then(({ default: data }) => { return { data: prefixPluginTranslations(data, PLUGIN_ID), locale }; }).catch(() => { return { data: {}, locale }; }); }) ); return Promise.resolve(importedTrads); } }; export { getTranslation as g, index as i };