Initial Strapi plugin project

This commit is contained in:
2026-02-05 10:19:56 +00:00
parent f6de861195
commit efa89313fa
100 changed files with 48612 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
import { useEffect, useRef } from 'react';
import { PLUGIN_ID } from '../pluginId';
type InitializerProps = {
setPlugin: (id: string) => void;
};
const Initializer = ({ setPlugin }: InitializerProps) => {
const ref = useRef(setPlugin);
useEffect(() => {
ref.current(PLUGIN_ID);
}, []);
return null;
};
export { Initializer };

View File

@@ -0,0 +1,5 @@
import { PuzzlePiece } from '@strapi/icons';
const PluginIcon = () => <PuzzlePiece />;
export { PluginIcon };

43
admin/src/index.ts Normal file
View File

@@ -0,0 +1,43 @@
import { getTranslation } from './utils/getTranslation';
import { PLUGIN_ID } from './pluginId';
import { Initializer } from './components/Initializer';
import { PluginIcon } from './components/PluginIcon';
export default {
register(app: any) {
app.addMenuLink({
to: `plugins/${PLUGIN_ID}`,
icon: PluginIcon,
intlLabel: {
id: `${PLUGIN_ID}.plugin.name`,
defaultMessage: PLUGIN_ID,
},
Component: async () => {
const { App } = await import('./pages/App');
return App;
},
});
app.registerPlugin({
id: PLUGIN_ID,
initializer: Initializer,
isReady: false,
name: PLUGIN_ID,
});
},
async registerTrads({ locales }: { locales: string[] }) {
return Promise.all(
locales.map(async (locale) => {
try {
const { default: data } = await import(`./translations/${locale}.json`);
return { data, locale };
} catch {
return { data: {}, locale };
}
})
);
},
};

15
admin/src/pages/App.tsx Normal file
View File

@@ -0,0 +1,15 @@
import { Page } from '@strapi/strapi/admin';
import { Routes, Route } from 'react-router-dom';
import { HomePage } from './HomePage';
const App = () => {
return (
<Routes>
<Route index element={<HomePage />} />
<Route path="*" element={<Page.Error />} />
</Routes>
);
};
export { App };

View File

@@ -0,0 +1,16 @@
import { Main } from '@strapi/design-system';
import { useIntl } from 'react-intl';
import { getTranslation } from '../utils/getTranslation';
const HomePage = () => {
const { formatMessage } = useIntl();
return (
<Main>
<h1>Welcome to {formatMessage({ id: getTranslation('plugin.name') })}</h1>
</Main>
);
};
export { HomePage };

1
admin/src/pluginId.ts Normal file
View File

@@ -0,0 +1 @@
export const PLUGIN_ID = 'checkbox-list';

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,5 @@
import { PLUGIN_ID } from '../pluginId';
const getTranslation = (id: string) => `${PLUGIN_ID}.${id}`;
export { getTranslation };