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