@structcms/admin 0.1.0
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/LICENSE +21 -0
- package/README.md +180 -0
- package/dist/index.cjs +2761 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +736 -0
- package/dist/index.d.ts +736 -0
- package/dist/index.js +2686 -0
- package/dist/index.js.map +1 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 skrischer-mw
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# @structcms/admin
|
|
2
|
+
|
|
3
|
+
Admin UI components for StructCMS. Provides dynamic form generation from Zod schemas, section/page editors, media browser, navigation editor, and a layout shell for the admin interface.
|
|
4
|
+
|
|
5
|
+
For architectural context, see [ARCHITECTURE.md](../../ARCHITECTURE.md) (Layer 6: Admin UI).
|
|
6
|
+
|
|
7
|
+
**[← Back to main README](../../README.md)**
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @structcms/admin
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { AdminProvider, AdminLayout } from '@structcms/admin';
|
|
19
|
+
import { registry } from './lib/registry'; // Your section registry
|
|
20
|
+
|
|
21
|
+
export default function AdminLayoutRoot({ children }) {
|
|
22
|
+
return (
|
|
23
|
+
<AdminProvider registry={registry} apiBaseUrl="/api/cms">
|
|
24
|
+
<AdminLayout>{children}</AdminLayout>
|
|
25
|
+
</AdminProvider>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Tailwind Configuration:** Add `./node_modules/@structcms/admin/dist/**/*.{js,mjs}` to your `tailwind.config.ts` content array.
|
|
31
|
+
|
|
32
|
+
See [examples/test-app/app/admin/](../../examples/test-app/app/admin/) for complete admin view implementations.
|
|
33
|
+
|
|
34
|
+
## File Structure
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
packages/admin/
|
|
38
|
+
├── src/
|
|
39
|
+
│ ├── index.ts # Public exports
|
|
40
|
+
│ ├── components/
|
|
41
|
+
│ │ ├── dashboard/
|
|
42
|
+
│ │ │ ├── dashboard-page.tsx # Main dashboard with KPIs, recent pages, quick actions
|
|
43
|
+
│ │ │ ├── kpi-cards.tsx # KPI overview cards
|
|
44
|
+
│ │ │ ├── recent-pages.tsx # Recently updated pages list
|
|
45
|
+
│ │ │ └── quick-actions.tsx # Quick action buttons
|
|
46
|
+
│ │ ├── editors/
|
|
47
|
+
│ │ │ ├── page-editor.tsx # Page editor with section management
|
|
48
|
+
│ │ │ └── section-editor.tsx # Section form from Zod schema
|
|
49
|
+
│ │ ├── inputs/
|
|
50
|
+
│ │ │ ├── string-input.tsx # Single-line text input
|
|
51
|
+
│ │ │ ├── text-input.tsx # Textarea input
|
|
52
|
+
│ │ │ ├── rich-text-editor.tsx # WYSIWYG editor (Tiptap)
|
|
53
|
+
│ │ │ ├── image-picker.tsx # Media browser integration
|
|
54
|
+
│ │ │ ├── array-field.tsx # Add/remove/reorder items
|
|
55
|
+
│ │ │ └── object-field.tsx # Nested object form
|
|
56
|
+
│ │ ├── content/
|
|
57
|
+
│ │ │ ├── page-list.tsx # Page listing with search/filter
|
|
58
|
+
│ │ │ └── navigation-editor.tsx # Navigation item editor
|
|
59
|
+
│ │ ├── media/
|
|
60
|
+
│ │ │ └── media-browser.tsx # Browse, upload, select media
|
|
61
|
+
│ │ ├── layout/
|
|
62
|
+
│ │ │ └── admin-layout.tsx # Admin shell with sidebar
|
|
63
|
+
│ │ └── ui/ # Base UI primitives
|
|
64
|
+
│ ├── context/
|
|
65
|
+
│ │ └── admin-context.tsx # AdminProvider (registry, API base URL)
|
|
66
|
+
│ ├── hooks/
|
|
67
|
+
│ │ ├── use-admin.ts # Access admin context
|
|
68
|
+
│ │ └── use-api-client.ts # HTTP client for CMS API
|
|
69
|
+
│ ├── lib/
|
|
70
|
+
│ │ ├── form-generator.tsx # Zod schema → React Hook Form mapping
|
|
71
|
+
│ │ └── utils.ts # cn() utility (clsx + tailwind-merge)
|
|
72
|
+
│ └── test/ # Test setup (jsdom, testing-library)
|
|
73
|
+
├── package.json
|
|
74
|
+
├── tsconfig.json
|
|
75
|
+
├── vitest.config.ts
|
|
76
|
+
└── tsup.config.ts
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Key Concepts
|
|
80
|
+
|
|
81
|
+
### Form Generation
|
|
82
|
+
|
|
83
|
+
The `FormGenerator` component reads a Zod schema and renders the appropriate input component for each field based on its `FieldType` metadata (set by `fields.*` helpers from `@structcms/core`).
|
|
84
|
+
|
|
85
|
+
### AdminProvider
|
|
86
|
+
|
|
87
|
+
Wraps the admin UI with context providing the `registry` (from `@structcms/core`) and `apiBaseUrl`. All admin components access this via the `useAdmin()` hook.
|
|
88
|
+
|
|
89
|
+
### API Client
|
|
90
|
+
|
|
91
|
+
The `useApiClient()` hook provides typed HTTP methods (`get`, `post`, `put`, `del`) for communicating with the CMS API routes in the host project.
|
|
92
|
+
|
|
93
|
+
## API Reference
|
|
94
|
+
|
|
95
|
+
### Context & Providers
|
|
96
|
+
|
|
97
|
+
- **`AdminProvider`** — Context provider with `registry` and `apiBaseUrl` props. Wraps all admin components.
|
|
98
|
+
|
|
99
|
+
### Hooks
|
|
100
|
+
|
|
101
|
+
- **`useAdmin()`** — Access admin context (registry, apiBaseUrl)
|
|
102
|
+
- **`useApiClient()`** — HTTP client for CMS API with methods: `get`, `post`, `put`, `del`
|
|
103
|
+
|
|
104
|
+
### Dashboard Components
|
|
105
|
+
|
|
106
|
+
- **`DashboardPage`** — Main dashboard container with KPIs, recent pages, and quick actions
|
|
107
|
+
- **`KpiCards`** — Metrics display (total pages, media files, navigation sets, sections)
|
|
108
|
+
- **`RecentPages`** — Paginated list of recently updated pages
|
|
109
|
+
- **`QuickActions`** — Action buttons for creating pages and uploading media
|
|
110
|
+
|
|
111
|
+
### Editor Components
|
|
112
|
+
|
|
113
|
+
- **`PageEditor`** — Edit page title and sections (add, remove, reorder)
|
|
114
|
+
- **`SectionEditor`** — Renders a form for a single section based on its Zod schema
|
|
115
|
+
|
|
116
|
+
### Field Input Components
|
|
117
|
+
|
|
118
|
+
- **`StringInput`** — Single-line text input for `fields.string()`
|
|
119
|
+
- **`TextInput`** — Textarea for `fields.text()`
|
|
120
|
+
- **`RichTextEditor`** — WYSIWYG editor using Tiptap for `fields.richtext()`
|
|
121
|
+
- **`ImagePicker`** — Media browser integration for `fields.image()`
|
|
122
|
+
- **`ArrayField`** — Dynamic list with add/remove/reorder for `fields.array()`
|
|
123
|
+
- **`ObjectField`** — Nested form for `fields.object()`
|
|
124
|
+
|
|
125
|
+
### Content Components
|
|
126
|
+
|
|
127
|
+
- **`PageList`** — List pages with search and filter
|
|
128
|
+
- **`NavigationEditor`** — Edit navigation items with nested children
|
|
129
|
+
|
|
130
|
+
### Media Components
|
|
131
|
+
|
|
132
|
+
- **`MediaBrowser`** — Browse, upload, and select media files
|
|
133
|
+
|
|
134
|
+
### Layout Components
|
|
135
|
+
|
|
136
|
+
- **`AdminLayout`** — Admin shell with sidebar navigation and dashboard
|
|
137
|
+
|
|
138
|
+
### UI Primitives
|
|
139
|
+
|
|
140
|
+
Base components in `src/components/ui/`: `Button`, `Input`, `Textarea`, `Label`, `Skeleton`, `Toast`, `ErrorBoundary`
|
|
141
|
+
|
|
142
|
+
### Utilities
|
|
143
|
+
|
|
144
|
+
- **`FormGenerator`** — Maps Zod schemas to React Hook Form inputs with field type detection
|
|
145
|
+
|
|
146
|
+
## Dependencies
|
|
147
|
+
|
|
148
|
+
| Package | Purpose |
|
|
149
|
+
|---------|---------|
|
|
150
|
+
| `@structcms/core` | Registry, field type metadata |
|
|
151
|
+
| `react-hook-form` | Form state management |
|
|
152
|
+
| `@hookform/resolvers` | Zod resolver for react-hook-form |
|
|
153
|
+
| `@tiptap/react` | Rich text editor |
|
|
154
|
+
| `@tiptap/starter-kit` | TipTap base extensions (bold, italic, lists, headings) |
|
|
155
|
+
| `@tiptap/extension-link` | TipTap link extension |
|
|
156
|
+
| `class-variance-authority` | Component variant styling |
|
|
157
|
+
| `tailwind-merge` + `clsx` | Conditional class merging |
|
|
158
|
+
| `zod` | Schema validation |
|
|
159
|
+
|
|
160
|
+
**Peer dependencies:** `react ^19.0.0`, `react-dom ^19.0.0`
|
|
161
|
+
|
|
162
|
+
## Development
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
# Run tests (watch mode)
|
|
166
|
+
pnpm test
|
|
167
|
+
|
|
168
|
+
# Run tests once
|
|
169
|
+
pnpm test run
|
|
170
|
+
|
|
171
|
+
# Build
|
|
172
|
+
pnpm build
|
|
173
|
+
|
|
174
|
+
# Type check
|
|
175
|
+
pnpm typecheck
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Tests use `@testing-library/react` with `jsdom`.
|
|
179
|
+
|
|
180
|
+
**[← Back to main README](../../README.md)**
|