UNPKG

@nurielmeni/strapi-plugin-video-field

Version:
121 lines (120 loc) 4.14 kB
"use strict"; const jsxRuntime = require("react/jsx-runtime"); const styled = require("styled-components"); const designSystem = require("@strapi/design-system"); const icons = require("@strapi/icons"); const react = require("react"); const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; const styled__default = /* @__PURE__ */ _interopDefault(styled); 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 name = "@nurielmeni/strapi-plugin-video-field"; const pluginPkg = { name }; const PLUGIN_ID = pluginPkg.name.replace(/^(@nurielmeni\/strapi-)plugin-/i, ""); const getTranslation = (id) => `${PLUGIN_ID}.${id}`; const IconBox = styled__default.default(designSystem.Flex)` /* Hard code color values */ /* to stay consistent between themes */ background-color: #f0f0ff; /* primary100 */ border: 1px solid #d9d8ff; /* primary200 */ svg > path { fill: #4945ff; /* primary600 */ } `; const FieldIcon = () => { return /* @__PURE__ */ jsxRuntime.jsx(IconBox, { justifyContent: "center", alignItems: "center", width: 7, height: 6, hasRadius: true, "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx(icons.Play, {}) }); }; const Initializer = ({ setPlugin }) => { const ref = react.useRef(setPlugin); react.useEffect(() => { ref.current(PLUGIN_ID); }, []); return null; }; const prefixPluginTranslations = (trad, pluginId) => { if (!pluginId) { throw new TypeError("pluginId can't be empty"); } return Object.keys(trad).reduce((acc, current) => { acc[`${pluginId}.${current}`] = trad[current]; return acc; }, {}); }; const index = { register(app) { app.customFields.register({ name: "video", pluginId: PLUGIN_ID, type: "json", icon: FieldIcon, intlLabel: { id: getTranslation("video-field.label"), defaultMessage: "Video" }, intlDescription: { id: getTranslation("video-field.description"), defaultMessage: "Video field for YouTube or Vimeo." }, components: { Input: async () => Promise.resolve().then(() => require( /* webpackChunkName: "video-field-input-component" */ "./Input-Cfkvveq4.js" )) } }); app.registerPlugin({ id: PLUGIN_ID, initializer: Initializer, isReady: false, name: PLUGIN_ID }); }, bootstrap(app) { console.log(`[${PLUGIN_ID}] Bootstrap started`); const plugin = app.getPlugin(PLUGIN_ID); if (plugin) { console.log(`[${PLUGIN_ID}] Setting plugin as ready`); plugin.isReady = true; } else { console.warn(`[${PLUGIN_ID}] Plugin not found during bootstrap`); } console.log(`[${PLUGIN_ID}] Bootstrap completed`); }, async registerTrads(app) { const { locales } = app; const importedTranslations = await Promise.all( locales.map((locale) => { return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/cs.json": () => Promise.resolve().then(() => require("./cs-pJ7Pxvy7.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-BN8PZ6vT.js")), "./translations/sk.json": () => Promise.resolve().then(() => require("./sk-4btYe2BM.js")) }), `./translations/${locale}.json`, 3).then(({ default: data }) => { return { data: prefixPluginTranslations(data, PLUGIN_ID), locale }; }).catch(() => { return { data: {}, locale }; }); }) ); return importedTranslations; } }; exports.getTranslation = getTranslation; exports.index = index;