|
| 1 | +import { prefixPluginTranslations } from '@strapi/helper-plugin'; |
| 2 | +import pluginPkg from '../../package.json'; |
| 3 | +import pluginId from './pluginId'; |
| 4 | +import Initializer from './components/Initializer'; |
| 5 | +import PluginIcon from './components/PluginIcon'; |
| 6 | +import AITextIcon from './components/PluginIcon'; |
| 7 | + |
| 8 | + |
| 9 | +const name = pluginPkg.strapi.name; |
| 10 | + |
| 11 | +export default { |
| 12 | + register(app) { |
| 13 | + // app.addMenuLink({ |
| 14 | + // to: `/plugins/${pluginId}`, |
| 15 | + // icon: PluginIcon, |
| 16 | + // intlLabel: { |
| 17 | + // id: `${pluginId}.plugin.name`, |
| 18 | + // defaultMessage: name, |
| 19 | + // }, |
| 20 | + // Component: async () => { |
| 21 | + // const component = await import(/* webpackChunkName: "[request]" */ './pages/App'); |
| 22 | + |
| 23 | + // return component; |
| 24 | + // }, |
| 25 | + // permissions: [ |
| 26 | + // // Uncomment to set the permissions of the plugin here |
| 27 | + // // { |
| 28 | + // // action: '', // the action name should be plugin::plugin-name.actionType |
| 29 | + // // subject: null, |
| 30 | + // // }, |
| 31 | + // ], |
| 32 | + // }); |
| 33 | + // app.registerPlugin({ |
| 34 | + // id: pluginId, |
| 35 | + // initializer: Initializer, |
| 36 | + // isReady: false, |
| 37 | + // name, |
| 38 | + // }); |
| 39 | + app.customFields.register({ |
| 40 | + name: "text-ai", |
| 41 | + pluginId: "ai-text-generation", // the custom field is created by a color-picker plugin |
| 42 | + type: "string", // the color will be stored as a string |
| 43 | + intlLabel: { |
| 44 | + id: "ai-text-generation.text-ai.label", |
| 45 | + defaultMessage: "Text AI", |
| 46 | + }, |
| 47 | + intlDescription: { |
| 48 | + id: "ai-text-generation.text-ai.description", |
| 49 | + defaultMessage: "Let AI do your writing!", |
| 50 | + }, |
| 51 | + icon: AITextIcon, // don't forget to create/import your icon component |
| 52 | + components: { |
| 53 | + Input: async () => import(/* webpackChunkName: "input-component" */ "./components/Input"), |
| 54 | + }, |
| 55 | + options: { |
| 56 | + base: [ |
| 57 | + /* |
| 58 | + Declare settings to be added to the "Base settings" section |
| 59 | + of the field in the Content-Type Builder |
| 60 | + */ |
| 61 | + { |
| 62 | + sectionTitle: { // Add a "Format" settings section |
| 63 | + id: 'ai-text-generation.text-ai.api.details', |
| 64 | + defaultMessage: 'API Details', |
| 65 | + }, |
| 66 | + items: [ // Add settings items to the section |
| 67 | + { |
| 68 | + /* |
| 69 | + Add a "Color format" dropdown |
| 70 | + to choose between 2 different format options |
| 71 | + for the color value: hexadecimal or RGBA |
| 72 | + */ |
| 73 | + intlLabel: { |
| 74 | + id: 'ai-text-generation.text-ai.key', |
| 75 | + defaultMessage: 'Key', |
| 76 | + }, |
| 77 | + name: 'options.key', |
| 78 | + type: 'input', |
| 79 | + value: '', // option selected by default |
| 80 | + }, |
| 81 | + ], |
| 82 | + }, |
| 83 | + ], |
| 84 | + }, |
| 85 | + }); |
| 86 | + }, |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + bootstrap(app) {}, |
| 91 | + async registerTrads({ locales }) { |
| 92 | + const importedTrads = await Promise.all( |
| 93 | + locales.map((locale) => { |
| 94 | + return import( |
| 95 | + /* webpackChunkName: "translation-[request]" */ `./translations/${locale}.json` |
| 96 | + ) |
| 97 | + .then(({ default: data }) => { |
| 98 | + return { |
| 99 | + data: prefixPluginTranslations(data, pluginId), |
| 100 | + locale, |
| 101 | + }; |
| 102 | + }) |
| 103 | + .catch(() => { |
| 104 | + return { |
| 105 | + data: {}, |
| 106 | + locale, |
| 107 | + }; |
| 108 | + }); |
| 109 | + }) |
| 110 | + ); |
| 111 | + |
| 112 | + return Promise.resolve(importedTrads); |
| 113 | + }, |
| 114 | +}; |
0 commit comments