strapi-plugin-link-custom-field
Version:
Grab Slugs and url paths from other content types
110 lines (109 loc) • 3.45 kB
JavaScript
const React = require("react");
const jsxRuntime = require("react/jsx-runtime");
const icons = require("@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 = React.useRef(setPlugin);
React.useEffect(() => {
ref.current(PLUGIN_ID);
}, []);
return null;
};
const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.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 () => Promise.resolve().then(() => require("./Providers-DB50WJKh.js")).then((module2) => ({
default: module2.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": () => Promise.resolve().then(() => require("./de-BXqb7SKa.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-DhzMjc_B.js")) }), `./translations/${locale}.json`, 3).then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, PLUGIN_ID),
locale
};
}).catch(() => {
return {
data: {},
locale
};
});
})
);
return Promise.resolve(importedTrads);
}
};
exports.getTranslation = getTranslation;
exports.index = index;
;