@sklinet/strapi-plugin-tinymce
Version:
Strapi custom field with a customized build of TinyMCE richtext editor.
166 lines (164 loc) • 4.92 kB
JavaScript
import { useRef, useEffect } from "react";
import { jsx } from "react/jsx-runtime";
import styled from "styled-components";
import { Flex } from "@strapi/design-system";
import { Paragraph } 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 name$1 = "@sklinet/strapi-plugin-tinymce";
const strapi = {
name: "tinymce"
};
const pluginPkg = {
name: name$1,
strapi
};
const PLUGIN_ID = pluginPkg.name.replace(/^(@sklinet\/strapi-)plugin-/i, "");
const getTranslation = (id) => `${PLUGIN_ID}.${id}`;
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 pluginPermissions = {
settings: [{ action: "plugin::tinymce.settings.read", subject: null }]
};
const IconBox = styled(Flex)`
background-color: #f0f0ff; /* primary100 */
border: 1px solid #d9d8ff; /* primary200 */
svg > path {
fill: #4945ff; /* primary600 */
}
`;
const PluginIcon = () => {
return /* @__PURE__ */ jsx(IconBox, { justifyContent: "center", alignItems: "center", width: 7, height: 6, hasRadius: true, "aria-hidden": true, children: /* @__PURE__ */ jsx(Paragraph, {}) });
};
const name = pluginPkg.strapi.name;
const index = {
register(app) {
app.customFields.register({
name: "tinymce",
pluginId: PLUGIN_ID,
type: "richtext",
icon: PluginIcon,
intlLabel: {
id: getTranslation("settings.title"),
defaultMessage: "TinyMCE"
},
intlDescription: {
id: getTranslation("settings.description"),
defaultMessage: "TinyMCE rich text editor"
},
isResizable: false,
default: 12,
options: {
advanced: [
{
type: "checkbox",
name: "required",
intlLabel: {
id: getTranslation("settings.required-field"),
defaultMessage: "Required field"
},
description: "You won't be able to create an entry if this field is empty"
},
{
type: "checkbox",
name: "options.disableMediaLibrary",
intlLabel: {
id: getTranslation("settings.disable-media-library"),
defaultMessage: "Disable Media Library"
},
description: "Disable Media Library integration and prevent uploading images through the editor"
}
]
},
components: {
Input: async () => import(
/* webpackChunkName: "video-field-input-component" */
"./Wysiwyg-XdlHkP3y.mjs"
)
}
});
app.createSettingSection(
{
id: PLUGIN_ID,
intlLabel: {
id: `${PLUGIN_ID}.plugin.name`,
defaultMessage: "TinyMCE"
}
},
[
{
intlLabel: {
id: getTranslation("settings.page-title"),
defaultMessage: "Configuration"
},
id: "settings",
to: `/settings/${PLUGIN_ID}`,
Component: async () => {
return import("./Settings-CBEqe0_f.mjs");
},
permissions: pluginPermissions["settings"]
}
]
);
app.registerPlugin({
id: PLUGIN_ID,
initializer: Initializer,
isReady: false,
name
});
},
bootstrap(app) {
},
async registerTrads(app) {
const { locales } = app;
const importedTranslations = await Promise.all(
locales.map((locale) => {
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/cs.json": () => import("./cs-Dxi1JUpg.mjs"), "./translations/en.json": () => import("./en-JHeBS1Yy.mjs"), "./translations/sk.json": () => import("./sk-Cqi7_cNY.mjs") }), `./translations/${locale}.json`, 3).then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, PLUGIN_ID),
locale
};
}).catch(() => {
return {
data: {},
locale
};
});
})
);
return importedTranslations;
}
};
export {
PLUGIN_ID as P,
getTranslation as g,
index as i
};