@fecommunity/reactpress-toolkit 4.0.0-beta.0 → 4.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -107
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
1
|
# @fecommunity/reactpress-toolkit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript toolkit for ReactPress: OpenAPI/Swagger-generated API clients, site config types, Next.js theme SSR helpers, and admin plugin registry.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Package exports (`package.json` → `exports`)
|
|
6
6
|
|
|
7
|
-
|
|
|
7
|
+
| Subpath | Purpose |
|
|
8
8
|
|--------|------|
|
|
9
|
-
| `.` |
|
|
10
|
-
| `./api` |
|
|
11
|
-
| `./api/instance` |
|
|
12
|
-
| `./types` | Swagger
|
|
13
|
-
| `./utils` |
|
|
14
|
-
| `./config` |
|
|
15
|
-
| `./theme` |
|
|
9
|
+
| `.` | Root entry: `api`, `config`, `theme`, `ui`, `plugin` namespaces and common re-exports |
|
|
10
|
+
| `./api` | HTTP client classes per resource |
|
|
11
|
+
| `./api/instance` | Default `api` instance and `createApiInstance` |
|
|
12
|
+
| `./types` | Swagger-generated request/response types |
|
|
13
|
+
| `./utils` | Framework-agnostic utilities (see module table below) |
|
|
14
|
+
| `./config` | Env vars, global defaults, `i18n` strings (`config/locales/*.json`) |
|
|
15
|
+
| `./theme` | Visitor themes: SSR data fetch, runtime, extension config types; re-exports `./ui` |
|
|
16
16
|
| `./theme/next-config` | `createReactPressNextConfig()` |
|
|
17
|
-
| `./theme/node` | Node
|
|
18
|
-
| `./ui` |
|
|
19
|
-
| `./plugin` |
|
|
20
|
-
| `./plugin/admin` |
|
|
21
|
-
| `./plugin/client` | Web/Electron API
|
|
22
|
-
| `./plugin/react` |
|
|
23
|
-
| `./plugin/dev` | Vite
|
|
17
|
+
| `./theme/node` | Node-only helpers (e.g. read theme admin locale files) |
|
|
18
|
+
| `./ui` | Unstyled theme components and hooks |
|
|
19
|
+
| `./plugin` | Admin plugin aggregate entry |
|
|
20
|
+
| `./plugin/admin` | Menu registration, permission constants |
|
|
21
|
+
| `./plugin/client` | Web/Electron API client factory (recommended) |
|
|
22
|
+
| `./plugin/react` | Same as `./plugin/client` (legacy path) |
|
|
23
|
+
| `./plugin/dev` | Vite dev port redirect, etc. |
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
**Convention:** Only top-level directories under `src/` match the exports above; implementation details live in subdirectories with thin shims at the root (e.g. `theme/node.ts` → `theme/build/node.ts`).
|
|
26
26
|
|
|
27
|
-
##
|
|
27
|
+
## Source layout
|
|
28
28
|
|
|
29
29
|
```
|
|
30
30
|
src/
|
|
31
|
-
├── api/ # OpenAPI
|
|
32
|
-
├── config/ # env
|
|
33
|
-
├── types/ # Swagger
|
|
34
|
-
├── utils/ #
|
|
31
|
+
├── api/ # OpenAPI generated (do not hand-edit business logic)
|
|
32
|
+
├── config/ # env, global, i18n + locales/
|
|
33
|
+
├── types/ # Swagger generated types
|
|
34
|
+
├── utils/ # Pure utilities (shared by theme/plugin)
|
|
35
35
|
│ ├── api-envelope.ts # unpackList / unpackOne / unpackPaginated
|
|
36
36
|
│ ├── cookie.ts # readRequestCookie
|
|
37
|
-
│ ├── date.ts # formatDate
|
|
38
|
-
│ ├── email.ts #
|
|
39
|
-
│ ├── error.ts # ApiError
|
|
37
|
+
│ ├── date.ts # formatDate, formatPublishDate*
|
|
38
|
+
│ ├── email.ts # Comment email validation
|
|
39
|
+
│ ├── error.ts # ApiError, isApiError
|
|
40
40
|
│ ├── json.ts # safeJsonParse
|
|
41
|
-
│ ├── jsonp.ts #
|
|
42
|
-
│ ├── object.ts # deepMerge
|
|
41
|
+
│ ├── jsonp.ts # Browser JSONP
|
|
42
|
+
│ ├── object.ts # deepMerge, getByPath, deepClone
|
|
43
43
|
│ ├── setting.ts # pickSiteSettings
|
|
44
|
-
│ └── string.ts # stripHtml
|
|
44
|
+
│ └── string.ts # stripHtml, truncateWords
|
|
45
45
|
├── plugin/
|
|
46
|
-
│ ├── admin/ # AdminModule
|
|
47
|
-
│ ├── client/ # createClient
|
|
48
|
-
│ ├── dev/ # devPortRedirectPlugin
|
|
49
|
-
│ └── react/ #
|
|
46
|
+
│ ├── admin/ # AdminModule, menu registration, permissions
|
|
47
|
+
│ ├── client/ # createClient, resolveApiBaseUrl
|
|
48
|
+
│ ├── dev/ # devPortRedirectPlugin, etc.
|
|
49
|
+
│ └── react/ # Re-export client only (compat)
|
|
50
50
|
├── theme/
|
|
51
|
-
│ ├── api/ # themeApi
|
|
52
|
-
│ ├── ssr/ # fetch
|
|
53
|
-
│ ├── visitor/ #
|
|
54
|
-
│ ├── content/ # SEO
|
|
55
|
-
│ ├── preview/ #
|
|
56
|
-
│ ├── createCatalogApp.js #
|
|
57
|
-
│ ├── createApp.js # Next `_app`
|
|
58
|
-
│ ├── extension/ # theme.json
|
|
51
|
+
│ ├── api/ # themeApi, axios wrapper
|
|
52
|
+
│ ├── ssr/ # fetch, static props, site meta
|
|
53
|
+
│ ├── visitor/ # Language, session, colors, runtime mods
|
|
54
|
+
│ ├── content/ # SEO, nav paths, excerpts, static asset URLs
|
|
55
|
+
│ ├── preview/ # Preview token / mods / config query params
|
|
56
|
+
│ ├── createCatalogApp.js # Full theme _app factory (no UI framework)
|
|
57
|
+
│ ├── createApp.js # Next `_app` factory (allowJs, emitted to dist)
|
|
58
|
+
│ ├── extension/ # theme.json schema, site config, shared server types
|
|
59
59
|
│ ├── node.ts # → build/node
|
|
60
60
|
│ ├── next-config.ts
|
|
61
|
-
│ └── index.ts #
|
|
61
|
+
│ └── index.ts # Public barrel
|
|
62
62
|
└── ui/
|
|
63
|
-
├── components/ #
|
|
64
|
-
├── context/ # ReactPressProvider
|
|
65
|
-
└── hooks/ #
|
|
63
|
+
├── components/ # Unstyled React components
|
|
64
|
+
├── context/ # ReactPressProvider, locale, runtime
|
|
65
|
+
└── hooks/ # Generic React hooks
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
##
|
|
68
|
+
## Install
|
|
69
69
|
|
|
70
70
|
```bash
|
|
71
71
|
pnpm add @fecommunity/reactpress-toolkit
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
##
|
|
74
|
+
## Quick start
|
|
75
75
|
|
|
76
|
-
### API
|
|
76
|
+
### API client
|
|
77
77
|
|
|
78
78
|
```typescript
|
|
79
79
|
import { api } from '@fecommunity/reactpress-toolkit';
|
|
80
|
-
//
|
|
80
|
+
// or
|
|
81
81
|
import { api, createApiInstance } from '@fecommunity/reactpress-toolkit/api/instance';
|
|
82
82
|
|
|
83
83
|
const articles = await api.article.findAll();
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
Custom baseURL:
|
|
87
87
|
|
|
88
88
|
```typescript
|
|
89
89
|
import { createApiInstance } from '@fecommunity/reactpress-toolkit/api/instance';
|
|
@@ -91,9 +91,9 @@ import { createApiInstance } from '@fecommunity/reactpress-toolkit/api/instance'
|
|
|
91
91
|
const customApi = createApiInstance({ baseURL: 'https://api.example.com/api' });
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
###
|
|
94
|
+
### Utilities (`./utils`)
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
Framework-agnostic logic belongs in `utils`; `theme` re-exports for `@fecommunity/reactpress-toolkit/theme` compatibility:
|
|
97
97
|
|
|
98
98
|
```typescript
|
|
99
99
|
import {
|
|
@@ -107,49 +107,49 @@ import {
|
|
|
107
107
|
} from '@fecommunity/reactpress-toolkit/utils';
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
|
|
|
110
|
+
| Module | Typical use |
|
|
111
111
|
|------|----------|
|
|
112
|
-
| `json` |
|
|
113
|
-
| `api-envelope` |
|
|
114
|
-
| `date` |
|
|
115
|
-
| `string` |
|
|
116
|
-
| `object` | theme.json
|
|
117
|
-
| `setting` |
|
|
118
|
-
| `cookie` |
|
|
119
|
-
| `email` |
|
|
112
|
+
| `json` | Parse JSON strings in settings |
|
|
113
|
+
| `api-envelope` | Unwrap Nest `TransformInterceptor` `{ data }` |
|
|
114
|
+
| `date` | Article publish date display |
|
|
115
|
+
| `string` | Strip HTML for archive excerpts, truncate |
|
|
116
|
+
| `object` | Merge theme.json config, dot-path read/write |
|
|
117
|
+
| `setting` | Map settings rows to props |
|
|
118
|
+
| `cookie` | Read `Cookie` header in SSR |
|
|
119
|
+
| `email` | Visitor comment email format |
|
|
120
120
|
|
|
121
|
-
###
|
|
121
|
+
### Admin plugins
|
|
122
122
|
|
|
123
123
|
```typescript
|
|
124
124
|
import type { AdminModule } from '@fecommunity/reactpress-toolkit/plugin/admin';
|
|
125
125
|
import { permissionsForRole } from '@fecommunity/reactpress-toolkit/plugin/admin';
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
### Web / Electron
|
|
128
|
+
### Web / Electron client
|
|
129
129
|
|
|
130
130
|
```typescript
|
|
131
131
|
import { createClient, resolveApiBaseUrl } from '@fecommunity/reactpress-toolkit/plugin/client';
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
## App
|
|
134
|
+
## App factories (`./app`)
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
Entry factories for theme `_app.tsx`, UI-framework agnostic:
|
|
137
137
|
|
|
138
|
-
|
|
|
138
|
+
| Factory | Purpose |
|
|
139
139
|
|------|------|
|
|
140
|
-
| `createThemeApp` |
|
|
141
|
-
| `createReactPressApp` |
|
|
140
|
+
| `createThemeApp` | Minimal theme (hello-world): `ReactPressProvider` + `ThemeCssVars` |
|
|
141
|
+
| `createReactPressApp` | Full theme: SSR catalog, i18n, analytics, PV; inject Ant Design etc. via `wrapContent` |
|
|
142
142
|
|
|
143
143
|
```typescript
|
|
144
144
|
import { createThemeApp } from '@fecommunity/reactpress-toolkit/app';
|
|
145
145
|
import { createReactPressApp } from '@fecommunity/reactpress-toolkit/app';
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
Also re-exported from `./theme` (legacy paths).
|
|
149
149
|
|
|
150
|
-
##
|
|
150
|
+
## Theme development (`./theme`)
|
|
151
151
|
|
|
152
|
-
Next.js
|
|
152
|
+
Next.js visitor themes should use toolkit API and SSR helpers instead of copying `lib/api.ts` per theme.
|
|
153
153
|
|
|
154
154
|
```typescript
|
|
155
155
|
import {
|
|
@@ -175,7 +175,7 @@ import themeManifest from '../theme.json';
|
|
|
175
175
|
export default createThemeApp(themeManifest);
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
**Full-featured themes** — use `createReactPressApp` (UI-framework agnostic); keep Ant Design and heavy deps in the theme:
|
|
179
179
|
|
|
180
180
|
```typescript
|
|
181
181
|
import { createReactPressApp } from '@fecommunity/reactpress-toolkit/app';
|
|
@@ -193,9 +193,9 @@ export default createReactPressApp(themeManifest, {
|
|
|
193
193
|
});
|
|
194
194
|
```
|
|
195
195
|
|
|
196
|
-
`createReactPressApp`
|
|
196
|
+
`createReactPressApp` includes: SSR site data, preview mods, SiteCatalogProvider, route progress, analytics scripts, PV reporting. **Does not** include Ant Design / cssinjs.
|
|
197
197
|
|
|
198
|
-
**REST
|
|
198
|
+
**REST providers** — avoid copying 14 provider files per theme:
|
|
199
199
|
|
|
200
200
|
```typescript
|
|
201
201
|
import { createThemeAxiosClient, createThemeProviders } from '@fecommunity/reactpress-toolkit/theme';
|
|
@@ -204,68 +204,68 @@ export const httpProvider = createThemeAxiosClient({ onError, onUnauthorized });
|
|
|
204
204
|
export const { ArticleProvider, CategoryProvider, TagProvider } = createThemeProviders(httpProvider);
|
|
205
205
|
```
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
Env: `REACTPRESS_API_URL` (SSR), `NEXT_PUBLIC_REACTPRESS_API_URL` (browser), injected by `reactpress theme dev`.
|
|
208
208
|
|
|
209
|
-
###
|
|
209
|
+
### Headless UI (`./ui`)
|
|
210
210
|
|
|
211
|
-
|
|
211
|
+
Also importable from `./theme`:
|
|
212
212
|
|
|
213
213
|
```typescript
|
|
214
214
|
import { NavMenu, ArticleList, ReactPressProvider, useLocale } from '@fecommunity/reactpress-toolkit/ui';
|
|
215
215
|
```
|
|
216
216
|
|
|
217
|
-
|
|
|
217
|
+
| Symbol | Description |
|
|
218
218
|
|------|------|
|
|
219
|
-
| `ReactPressProvider` |
|
|
220
|
-
| `useLocale` / `useThemeRuntime` / `useThemeMod` |
|
|
221
|
-
| `useToggle` / `useAsyncLoading` |
|
|
222
|
-
| `usePagination` | `[items, total]`
|
|
223
|
-
| `useReportArticleView` / `useReportPageView` |
|
|
224
|
-
| `useRouteParam` / `useNavActive` |
|
|
225
|
-
| `useWarningOnExit` |
|
|
226
|
-
| `NavMenu` |
|
|
227
|
-
| `ArticleList` |
|
|
228
|
-
| `SiteCatalogProvider` / `useSiteSetting` / `useSiteUser` |
|
|
229
|
-
| `SiteSeo` / `RouteProgress` / `SiteAnalytics` | SEO meta
|
|
230
|
-
| `ArticleReader` / `HtmlContent` / `ArticleToc` |
|
|
231
|
-
| `ImageViewer` / `LocaleTime` |
|
|
232
|
-
| `createReactPressApp` |
|
|
233
|
-
| `fetchAppBootstrap` | `_app.getInitialProps` SSR
|
|
234
|
-
|
|
235
|
-
###
|
|
236
|
-
|
|
237
|
-
`theme/extension`
|
|
219
|
+
| `ReactPressProvider` | Inject site context in `_app` |
|
|
220
|
+
| `useLocale` / `useThemeRuntime` / `useThemeMod` | Language and theme mods |
|
|
221
|
+
| `useToggle` / `useAsyncLoading` | Boolean toggle, debounced loading |
|
|
222
|
+
| `usePagination` | `[items, total]` paginated lists |
|
|
223
|
+
| `useReportArticleView` / `useReportPageView` | Article views, site PV |
|
|
224
|
+
| `useRouteParam` / `useNavActive` | Dynamic route params, nav highlight |
|
|
225
|
+
| `useWarningOnExit` | Confirm before leaving page (Next Router) |
|
|
226
|
+
| `NavMenu` | Config-driven nav via `renderLink` + Next `Link` |
|
|
227
|
+
| `ArticleList` | List renderer via `renderArticle` |
|
|
228
|
+
| `SiteCatalogProvider` / `useSiteSetting` / `useSiteUser` | Site catalog + user session |
|
|
229
|
+
| `SiteSeo` / `RouteProgress` / `SiteAnalytics` | SEO meta, progress bar, GA/Baidu |
|
|
230
|
+
| `ArticleReader` / `HtmlContent` / `ArticleToc` | Article reading, HTML, TOC |
|
|
231
|
+
| `ImageViewer` / `LocaleTime` | Image preview, localized time |
|
|
232
|
+
| `createReactPressApp` | Full theme `_app` factory |
|
|
233
|
+
| `fetchAppBootstrap` | `_app.getInitialProps` SSR data |
|
|
234
|
+
|
|
235
|
+
### Extension config types
|
|
236
|
+
|
|
237
|
+
Types and validation in `theme/extension` are shared with **server** and **web appearance settings**, e.g. `ThemeConfigurationSchema`, `resolveSiteConfig`, `PUBLIC_SETTING_KEYS`. Server example:
|
|
238
238
|
|
|
239
239
|
```typescript
|
|
240
240
|
import { PUBLIC_SETTING_KEYS, systemGlobalSettingDefaults } from '@fecommunity/reactpress-toolkit/theme';
|
|
241
241
|
import { readThemeAdminLocaleFile } from '@fecommunity/reactpress-toolkit/theme/node';
|
|
242
242
|
```
|
|
243
243
|
|
|
244
|
-
##
|
|
244
|
+
## Regenerate API from Swagger
|
|
245
245
|
|
|
246
|
-
|
|
246
|
+
From monorepo root, ensure server builds:
|
|
247
247
|
|
|
248
248
|
```bash
|
|
249
249
|
cd toolkit && pnpm run generate
|
|
250
250
|
```
|
|
251
251
|
|
|
252
|
-
|
|
252
|
+
Updates `src/api/*` and `src/types/*`.
|
|
253
253
|
|
|
254
|
-
##
|
|
254
|
+
## Build
|
|
255
255
|
|
|
256
256
|
```bash
|
|
257
257
|
cd toolkit && pnpm run build
|
|
258
258
|
```
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
Output in `dist/`; `createApp.js` is emitted via `tsc` (`allowJs`) to `dist/theme/createApp.js`.
|
|
261
261
|
|
|
262
|
-
##
|
|
262
|
+
## Scripts
|
|
263
263
|
|
|
264
|
-
|
|
|
264
|
+
| Command | Description |
|
|
265
265
|
|------|------|
|
|
266
|
-
| `pnpm run generate` |
|
|
267
|
-
| `pnpm run build` | `tsc` +
|
|
268
|
-
| `pnpm run typecheck` |
|
|
266
|
+
| `pnpm run generate` | Generate API from server Swagger |
|
|
267
|
+
| `pnpm run build` | `tsc` + copy locales |
|
|
268
|
+
| `pnpm run typecheck` | Type check only |
|
|
269
269
|
|
|
270
270
|
## License
|
|
271
271
|
|