2022-11-08 11:15:21 +08:00
|
|
|
# Overview
|
2022-10-31 22:41:24 +08:00
|
|
|
|
2022-11-08 11:15:21 +08:00
|
|
|
Most of the extensions for the NocoBase client are provided as Providers.
|
2022-10-31 22:41:24 +08:00
|
|
|
|
2022-11-08 11:15:21 +08:00
|
|
|
## Built-in Providers
|
2022-10-31 22:41:24 +08:00
|
|
|
|
|
|
|
- APIClientProvider
|
|
|
|
- I18nextProvider
|
|
|
|
- AntdConfigProvider
|
|
|
|
- SystemSettingsProvider
|
|
|
|
- PluginManagerProvider
|
|
|
|
- SchemaComponentProvider
|
|
|
|
- BlockSchemaComponentProvider
|
|
|
|
- AntdSchemaComponentProvider
|
|
|
|
- DocumentTitleProvider
|
|
|
|
- ACLProvider
|
|
|
|
|
2022-11-08 11:15:21 +08:00
|
|
|
## Registration of client-side Provider modules
|
2022-10-31 22:41:24 +08:00
|
|
|
|
2022-11-08 11:15:21 +08:00
|
|
|
Static Providers are registered with app.use() and dynamic Providers are adapted with dynamicImport.
|
2022-10-31 22:41:24 +08:00
|
|
|
|
|
|
|
```tsx | pure
|
|
|
|
import React from 'react';
|
|
|
|
import { Application } from '@nocobase/client';
|
|
|
|
|
|
|
|
const app = new Application({
|
|
|
|
apiClient: {
|
|
|
|
baseURL: process.env.API_BASE_URL,
|
|
|
|
},
|
|
|
|
dynamicImport: (name: string) => {
|
2022-11-08 11:15:21 +08:00
|
|
|
return import(`... /plugins/${name}`);
|
2022-10-31 22:41:24 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-11-08 11:15:21 +08:00
|
|
|
// When visiting the /hello page, display Hello world!
|
2022-10-31 22:41:24 +08:00
|
|
|
const HelloProvider = React.memo((props) => {
|
|
|
|
const location = useLocation();
|
|
|
|
if (location.pathname === '/hello') {
|
|
|
|
return <div>Hello world!</div>
|
|
|
|
}
|
|
|
|
return <>{props.children}</>
|
|
|
|
});
|
2023-06-06 19:33:04 +08:00
|
|
|
HelloProvider.displayName = 'HelloProvider'
|
2022-10-31 22:41:24 +08:00
|
|
|
|
|
|
|
app.use(HelloProvider);
|
|
|
|
```
|
|
|
|
|
2022-11-08 11:15:21 +08:00
|
|
|
## Client-side of plugins
|
2022-10-31 22:41:24 +08:00
|
|
|
|
2022-11-08 11:15:21 +08:00
|
|
|
Directory structure of the client-side of an empty plugin is as follows
|
2022-10-31 22:41:24 +08:00
|
|
|
|
|
|
|
```bash
|
|
|
|
|- /my-plugin
|
|
|
|
|- /src
|
|
|
|
|- /client
|
|
|
|
|- index.tsx
|
|
|
|
|- client.d.ts
|
|
|
|
|- client.js
|
|
|
|
```
|
|
|
|
|
2022-11-08 11:15:21 +08:00
|
|
|
``client/index.tsx`` reads as follows.
|
2022-10-31 22:41:24 +08:00
|
|
|
|
|
|
|
```tsx | pure
|
|
|
|
import React from 'react';
|
|
|
|
|
2022-11-08 11:15:21 +08:00
|
|
|
// This is an empty Provider, only children are passed, no custom Context is provided
|
2022-10-31 22:41:24 +08:00
|
|
|
export default React.memo((props) => {
|
|
|
|
return <>{props.children}</>;
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-11-08 11:15:21 +08:00
|
|
|
After the plugin pm.add, it writes the `my-plugin.ts` file to the `packages/app/client/src/plugins` directory.
|