@nurielmeni/strapi-plugin-video-field
Version:
Add video field to your Strapi application.
120 lines (119 loc) • 3.77 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import styled from "styled-components";
import { Flex } from "@strapi/design-system";
import { Play } from "@strapi/icons";
import { useRef, useEffect } from "react";
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(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__ */ jsx(IconBox, { justifyContent: "center", alignItems: "center", width: 7, height: 6, hasRadius: true, "aria-hidden": true, children: /* @__PURE__ */ jsx(Play, {}) });
};
const Initializer = ({ setPlugin }) => {
const ref = useRef(setPlugin);
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 () => import(
/* webpackChunkName: "video-field-input-component" */
"./Input-Dw9DKFQ9.mjs"
)
}
});
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": () => import("./cs-wpd82YqC.mjs"), "./translations/en.json": () => import("./en-DqI4OZOl.mjs"), "./translations/sk.json": () => import("./sk-CPCV0DyM.mjs") }), `./translations/${locale}.json`, 3).then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, PLUGIN_ID),
locale
};
}).catch(() => {
return {
data: {},
locale
};
});
})
);
return importedTranslations;
}
};
export {
getTranslation as g,
index as i
};