create-questpie 2.0.1 → 2.0.3
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 +10 -6
- package/dist/index.mjs +139 -24
- package/package.json +5 -3
- package/skills/questpie/AGENTS.md +2670 -0
- package/skills/questpie/SKILL.md +260 -0
- package/skills/questpie/references/auth.md +121 -0
- package/skills/questpie/references/business-logic.md +550 -0
- package/skills/questpie/references/codegen-plugin-api.md +382 -0
- package/skills/questpie/references/crud-api.md +378 -0
- package/skills/questpie/references/data-modeling.md +493 -0
- package/skills/questpie/references/extend.md +557 -0
- package/skills/questpie/references/field-types.md +386 -0
- package/skills/questpie/references/infrastructure-adapters.md +545 -0
- package/skills/questpie/references/multi-tenancy.md +364 -0
- package/skills/questpie/references/production.md +475 -0
- package/skills/questpie/references/query-operators.md +125 -0
- package/skills/questpie/references/quickstart.md +564 -0
- package/skills/questpie/references/rules.md +389 -0
- package/skills/questpie/references/tanstack-query.md +520 -0
- package/skills/questpie-admin/AGENTS.md +1508 -0
- package/skills/questpie-admin/SKILL.md +436 -0
- package/skills/questpie-admin/references/blocks.md +331 -0
- package/skills/questpie-admin/references/custom-ui.md +305 -0
- package/skills/questpie-admin/references/views.md +449 -0
- package/templates/tanstack-start/AGENTS.md +17 -13
- package/templates/tanstack-start/CLAUDE.md +15 -12
- package/templates/tanstack-start/README.md +19 -13
- package/templates/tanstack-start/env.example +1 -1
- package/templates/tanstack-start/package.json +20 -6
- package/templates/tanstack-start/src/lib/env.ts +1 -1
- package/templates/tanstack-start/src/lib/query-client.ts +10 -1
- package/templates/tanstack-start/src/questpie/server/config/admin.ts +27 -30
- package/templates/tanstack-start/src/routeTree.gen.ts +138 -0
- package/templates/tanstack-start/src/routes/__root.tsx +0 -2
- package/templates/tanstack-start/src/routes/admin/$.tsx +12 -1
- package/templates/tanstack-start/src/routes/admin/index.tsx +12 -5
- package/templates/tanstack-start/src/routes/admin.tsx +8 -1
- package/templates/tanstack-start/src/tanstack-start.d.ts +1 -0
- package/templates/tanstack-start/src/vite-env.d.ts +1 -0
- package/templates/tanstack-start/vite.config.ts +1 -3
|
@@ -0,0 +1,1508 @@
|
|
|
1
|
+
# QUESTPIE Admin Panel
|
|
2
|
+
|
|
3
|
+
The QUESTPIE admin panel is a **projection of your server schema** — not the framework itself. It reads collections, globals, and config via introspection and generates a full admin interface. Your backend works without it.
|
|
4
|
+
|
|
5
|
+
## Reference Topics
|
|
6
|
+
|
|
7
|
+
| Topic | File | Covers |
|
|
8
|
+
| --------- | ------------------------- | -------------------------------------------------------------------------------------- |
|
|
9
|
+
| Views | `references/views.md` | List views, form views, dashboard, sidebar, filters, bulk actions, visibility, history |
|
|
10
|
+
| Blocks | `references/blocks.md` | Block definitions, fields, prefetch, renderers, block picker |
|
|
11
|
+
| Custom UI | `references/custom-ui.md` | Custom fields, custom views, registries, reactive fields, widgets |
|
|
12
|
+
|
|
13
|
+
## Full Compiled Document
|
|
14
|
+
|
|
15
|
+
For the complete admin reference with all topics expanded: `AGENTS.md`
|
|
16
|
+
|
|
17
|
+
## Tech Stack
|
|
18
|
+
|
|
19
|
+
- **React** + **Tailwind CSS v4** + **shadcn** components
|
|
20
|
+
- **@base-ui/react** primitives (NOT @radix-ui)
|
|
21
|
+
- **@iconify/react** with Phosphor icon set (`ph:icon-name`)
|
|
22
|
+
- **sonner** for toasts — `toast.error()`, `toast.success()`
|
|
23
|
+
- Brutalist flat design: `--radius: 0px`, no shadows
|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
### 1. Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bun add @questpie/admin
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Runtime Config
|
|
34
|
+
|
|
35
|
+
```ts title="questpie.config.ts"
|
|
36
|
+
import { runtimeConfig } from "questpie";
|
|
37
|
+
|
|
38
|
+
export default runtimeConfig({
|
|
39
|
+
app: { url: process.env.APP_URL || "http://localhost:3000" },
|
|
40
|
+
db: { url: process.env.DATABASE_URL },
|
|
41
|
+
secret: process.env.APP_SECRET,
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The admin module contributes the codegen plugin automatically. It discovers `config/admin.ts`, `blocks/`, views, components, and admin client modules.
|
|
46
|
+
|
|
47
|
+
### 3. Modules
|
|
48
|
+
|
|
49
|
+
```ts title="modules.ts"
|
|
50
|
+
import { adminModule, auditModule } from "@questpie/admin/server";
|
|
51
|
+
|
|
52
|
+
export default [adminModule, auditModule] as const;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
| Module | Provides |
|
|
56
|
+
| ------------- | ------------------------------------- |
|
|
57
|
+
| `adminModule` | User collection, auth pages, admin UI |
|
|
58
|
+
| `auditModule` | Audit log collection, timeline widget |
|
|
59
|
+
|
|
60
|
+
### 4. Admin Config
|
|
61
|
+
|
|
62
|
+
```ts title="config/admin.ts"
|
|
63
|
+
import { adminConfig } from "#questpie/factories";
|
|
64
|
+
|
|
65
|
+
export default adminConfig({
|
|
66
|
+
branding: {
|
|
67
|
+
name: { en: "My App Admin" },
|
|
68
|
+
},
|
|
69
|
+
sidebar: {
|
|
70
|
+
sections: [
|
|
71
|
+
{ id: "overview", title: { en: "Overview" } },
|
|
72
|
+
{ id: "content", title: { en: "Content" } },
|
|
73
|
+
],
|
|
74
|
+
items: [
|
|
75
|
+
{
|
|
76
|
+
sectionId: "overview",
|
|
77
|
+
type: "link",
|
|
78
|
+
label: { en: "Dashboard" },
|
|
79
|
+
href: "/admin",
|
|
80
|
+
icon: { type: "icon", props: { name: "ph:house" } },
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
sectionId: "content",
|
|
84
|
+
type: "collection",
|
|
85
|
+
collection: "posts",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 5. Codegen
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
bunx questpie generate
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 6. Mount the Admin
|
|
99
|
+
|
|
100
|
+
```ts title="routes/admin/$.tsx"
|
|
101
|
+
import { AdminRouter } from "@questpie/admin/client";
|
|
102
|
+
import { admin } from "@/questpie/admin/admin";
|
|
103
|
+
|
|
104
|
+
export default function AdminPage() {
|
|
105
|
+
return <AdminRouter admin={admin} />;
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The admin client config is auto-generated by codegen at `admin/.generated/client.ts`. No manual builder setup needed.
|
|
110
|
+
|
|
111
|
+
## Branding
|
|
112
|
+
|
|
113
|
+
```ts title="config/admin.ts"
|
|
114
|
+
import { adminConfig } from "#questpie/factories";
|
|
115
|
+
|
|
116
|
+
export default adminConfig({
|
|
117
|
+
branding: {
|
|
118
|
+
name: { en: "Barbershop Control", sk: "Riadenie barbershopu" },
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
| Option | Type | Description |
|
|
124
|
+
| ------ | ---------------- | -------------------------------- |
|
|
125
|
+
| `name` | `string \| i18n` | App name shown in sidebar header |
|
|
126
|
+
| `logo` | `string` | Logo URL or path |
|
|
127
|
+
|
|
128
|
+
## Theming (CSS Variables)
|
|
129
|
+
|
|
130
|
+
The admin uses CSS variables for all theming. Override them in your own CSS file.
|
|
131
|
+
|
|
132
|
+
### Light Theme (`:root`)
|
|
133
|
+
|
|
134
|
+
| Variable | Default | Purpose |
|
|
135
|
+
| ---------------------- | --------- | -------------------------------- |
|
|
136
|
+
| `--background` | `#FFFFFF` | Page background |
|
|
137
|
+
| `--foreground` | `#0A0A0A` | Primary text |
|
|
138
|
+
| `--card` | `#F8F8F8` | Cards, panels, sidebar |
|
|
139
|
+
| `--popover` | `#FFFFFF` | Dropdowns, tooltips, dialogs |
|
|
140
|
+
| `--muted` | `#F0F0F0` | Hover states, table headers |
|
|
141
|
+
| `--muted-foreground` | `#666666` | Secondary text, placeholders |
|
|
142
|
+
| `--primary` | `#B700FF` | Brand accent (CTAs, focus rings) |
|
|
143
|
+
| `--primary-foreground` | `#FFFFFF` | Text on primary backgrounds |
|
|
144
|
+
| `--destructive` | `#FF3D57` | Errors, delete actions |
|
|
145
|
+
| `--success` | `#00E676` | Positive states |
|
|
146
|
+
| `--warning` | `#FFB300` | Caution states |
|
|
147
|
+
| `--info` | `#40C4FF` | Informational emphasis |
|
|
148
|
+
| `--border` | `#E0E0E0` | All structural borders |
|
|
149
|
+
| `--ring` | `#B700FF` | Focus ring color |
|
|
150
|
+
| `--radius` | `0px` | Border radius (0 = brutalist) |
|
|
151
|
+
|
|
152
|
+
### Dark Theme (`.dark` class)
|
|
153
|
+
|
|
154
|
+
Dark mode uses the `.dark` class on the root element. Key overrides:
|
|
155
|
+
|
|
156
|
+
| Variable | Dark Value |
|
|
157
|
+
| -------------- | ---------- |
|
|
158
|
+
| `--background` | `#0A0A0A` |
|
|
159
|
+
| `--foreground` | `#FFFFFF` |
|
|
160
|
+
| `--card` | `#111111` |
|
|
161
|
+
| `--border` | `#333333` |
|
|
162
|
+
| `--muted` | `#1A1A1A` |
|
|
163
|
+
|
|
164
|
+
### Typography
|
|
165
|
+
|
|
166
|
+
| Variable | Value |
|
|
167
|
+
| ------------- | ------------------------------------------------------------------- |
|
|
168
|
+
| `--font-sans` | `"Geist Variable"` — body text, descriptions |
|
|
169
|
+
| `--font-mono` | `"JetBrains Mono Variable"` — UI chrome: nav, buttons, tabs, badges |
|
|
170
|
+
|
|
171
|
+
### Sidebar Variables
|
|
172
|
+
|
|
173
|
+
Separate tokens for independent sidebar theming: `--sidebar`, `--sidebar-foreground`, `--sidebar-primary`, `--sidebar-accent`, `--sidebar-border`, `--sidebar-ring`.
|
|
174
|
+
|
|
175
|
+
### Custom Theme
|
|
176
|
+
|
|
177
|
+
1. Copy the admin CSS file
|
|
178
|
+
2. Change variable values
|
|
179
|
+
3. Import your copy instead
|
|
180
|
+
4. Zero component changes needed
|
|
181
|
+
|
|
182
|
+
## Content Localization
|
|
183
|
+
|
|
184
|
+
When collections have `.localized()` fields, the admin shows a locale switcher:
|
|
185
|
+
|
|
186
|
+
```ts title="config/app.ts"
|
|
187
|
+
import { appConfig } from "questpie";
|
|
188
|
+
|
|
189
|
+
export default appConfig({
|
|
190
|
+
locale: {
|
|
191
|
+
locales: [
|
|
192
|
+
{ code: "en", label: { en: "English" }, flagCountryCode: "gb" },
|
|
193
|
+
{ code: "sk", label: { en: "Slovak" } },
|
|
194
|
+
],
|
|
195
|
+
defaultLocale: "en",
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
The admin tracks content locale separately from UI locale. Only localized field values change when switching.
|
|
201
|
+
|
|
202
|
+
## Media & Uploads
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
avatar: f.upload({
|
|
206
|
+
to: "assets",
|
|
207
|
+
mimeTypes: ["image/*"],
|
|
208
|
+
maxSize: 5_000_000,
|
|
209
|
+
}),
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
The admin renders drag-and-drop upload, image preview, file info, and remove button.
|
|
213
|
+
|
|
214
|
+
## Live Preview
|
|
215
|
+
|
|
216
|
+
Live Preview is one system: the existing collection `FormView`, Preview button, `LivePreviewMode`, and frontend iframe. Preserve the normal form lifecycle. Do not introduce a separate visual-edit form API, a second default form view, or a parallel preview surface.
|
|
217
|
+
|
|
218
|
+
The admin form is authoritative. The iframe mirrors form state through `postMessage`, supports field/block focus, and may request inline scalar edits. Persistence still goes through existing save, autosave, Cmd+S, history, workflow, locks, and actions.
|
|
219
|
+
|
|
220
|
+
### Server Config
|
|
221
|
+
|
|
222
|
+
Add `.preview()` to a collection to enable split-screen editing:
|
|
223
|
+
|
|
224
|
+
```ts title="collections/pages.ts"
|
|
225
|
+
export const pages = collection("pages")
|
|
226
|
+
.fields(({ f }) => ({
|
|
227
|
+
title: f.text().required().localized(),
|
|
228
|
+
slug: f.text().required(),
|
|
229
|
+
content: f.blocks().localized(),
|
|
230
|
+
}))
|
|
231
|
+
.preview({
|
|
232
|
+
enabled: true,
|
|
233
|
+
position: "right",
|
|
234
|
+
defaultWidth: 50,
|
|
235
|
+
url: ({ record }) => {
|
|
236
|
+
const slug = record.slug as string;
|
|
237
|
+
return slug === "home" ? "/?preview=true" : `/${slug}?preview=true`;
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Preview opens the existing split-screen editor. Patches and refresh/resync messages update the iframe mirror; save/autosave still writes through the form.
|
|
243
|
+
|
|
244
|
+
### Prepare a Frontend Page
|
|
245
|
+
|
|
246
|
+
Use exported APIs only: `useCollectionPreview`, `PreviewProvider`, `PreviewField`, and `BlockRenderer`.
|
|
247
|
+
|
|
248
|
+
Checklist:
|
|
249
|
+
|
|
250
|
+
1. Configure `.preview({ url })` on the collection.
|
|
251
|
+
2. Load the same record shape the page normally renders.
|
|
252
|
+
3. For workflow-published pages, public reads use `stage: "published"`; if the public client/HTTP API is exposed, anonymous read access also checks `input?.stage === "published"`. Authorized preview/draft reads can load the working record.
|
|
253
|
+
4. Call `useCollectionPreview({ initialData, onRefresh })` in the page renderer.
|
|
254
|
+
5. Wrap the visual output in `PreviewProvider`.
|
|
255
|
+
6. Render from `preview.data`, not the original loader object.
|
|
256
|
+
7. Wrap editable scalar text with `PreviewField field="..." editable="text" | "textarea"`.
|
|
257
|
+
8. Render block content with `BlockRenderer`; pass `selectedBlockId` and `onBlockClick`.
|
|
258
|
+
9. Keep add/remove/reorder/nesting block operations in the existing block editor.
|
|
259
|
+
|
|
260
|
+
```tsx
|
|
261
|
+
import {
|
|
262
|
+
BlockRenderer,
|
|
263
|
+
PreviewField,
|
|
264
|
+
PreviewProvider,
|
|
265
|
+
useCollectionPreview,
|
|
266
|
+
} from "@questpie/admin/client";
|
|
267
|
+
import admin from "@/questpie/admin/.generated/client";
|
|
268
|
+
|
|
269
|
+
function PagePreview({ page }) {
|
|
270
|
+
const router = useRouter();
|
|
271
|
+
const preview = useCollectionPreview({
|
|
272
|
+
initialData: page,
|
|
273
|
+
onRefresh: () => router.invalidate(),
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
return (
|
|
277
|
+
<PreviewProvider preview={preview}>
|
|
278
|
+
<main className={preview.isPreviewMode ? "questpie-preview" : undefined}>
|
|
279
|
+
<PreviewField field="title" editable="text" as="h1">
|
|
280
|
+
{preview.data.title}
|
|
281
|
+
</PreviewField>
|
|
282
|
+
|
|
283
|
+
<BlockRenderer
|
|
284
|
+
content={preview.data.content}
|
|
285
|
+
data={preview.data.content?._data}
|
|
286
|
+
renderers={admin.blocks}
|
|
287
|
+
selectedBlockId={preview.selectedBlockId}
|
|
288
|
+
onBlockClick={
|
|
289
|
+
preview.isPreviewMode ? preview.handleBlockClick : undefined
|
|
290
|
+
}
|
|
291
|
+
/>
|
|
292
|
+
</main>
|
|
293
|
+
</PreviewProvider>
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Key Principles
|
|
299
|
+
|
|
300
|
+
- Keep `FormView`, the Preview button, and `LivePreviewMode`
|
|
301
|
+
- Never add a separate visual-edit form API, a second default form view, or parallel preview API names
|
|
302
|
+
- Preserve save/autosave/Cmd+S/history/workflow/locks/actions
|
|
303
|
+
- `useCollectionPreview` handles preview mode, mirrored data, refresh/resync, and focus state
|
|
304
|
+
- `PreviewProvider` supplies preview context to `PreviewField`
|
|
305
|
+
- `PreviewField` annotates scalar fields and can opt into inline editing with `editable`
|
|
306
|
+
- `BlockRenderer` preserves block IDs and block scopes for block annotations
|
|
307
|
+
- Use `BlockScopeProvider` only for custom/manual block rendering outside `BlockRenderer`
|
|
308
|
+
- Validate all iframe messages before updating form state
|
|
309
|
+
|
|
310
|
+
## History & Versions
|
|
311
|
+
|
|
312
|
+
Enable `auditModule` for activity timeline. Enable versioning on collections for snapshot restore:
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
export const pages = collection("pages")
|
|
316
|
+
.fields(({ f }) => ({ ... }))
|
|
317
|
+
.options({ versioning: true });
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Scope (Multi-Tenancy)
|
|
321
|
+
|
|
322
|
+
The admin provides scope primitives for multi-tenant applications. Import from `@questpie/admin/client`.
|
|
323
|
+
|
|
324
|
+
### ScopeProvider
|
|
325
|
+
|
|
326
|
+
Wraps the admin to enable scope selection. Manages scope ID in React state and persists to localStorage.
|
|
327
|
+
|
|
328
|
+
```tsx
|
|
329
|
+
import { ScopeProvider } from "@questpie/admin/client";
|
|
330
|
+
|
|
331
|
+
<ScopeProvider
|
|
332
|
+
headerName="x-selected-workspace" // HTTP header for scope ID
|
|
333
|
+
storageKey="admin-workspace" // localStorage key
|
|
334
|
+
defaultScope={null} // default value
|
|
335
|
+
>
|
|
336
|
+
<AdminLayout>...</AdminLayout>
|
|
337
|
+
</ScopeProvider>;
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### ScopePicker
|
|
341
|
+
|
|
342
|
+
Dropdown for selecting the current scope. Place in sidebar via `slots.afterBrand`:
|
|
343
|
+
|
|
344
|
+
```tsx
|
|
345
|
+
import { ScopePicker } from "@questpie/admin/client";
|
|
346
|
+
|
|
347
|
+
<AdminLayout
|
|
348
|
+
admin={admin}
|
|
349
|
+
basePath="/admin"
|
|
350
|
+
slots={{
|
|
351
|
+
afterBrand: (
|
|
352
|
+
<div className="px-3 py-2 border-b">
|
|
353
|
+
<ScopePicker
|
|
354
|
+
collection="workspaces"
|
|
355
|
+
labelField="name"
|
|
356
|
+
allowClear
|
|
357
|
+
compact
|
|
358
|
+
/>
|
|
359
|
+
</div>
|
|
360
|
+
),
|
|
361
|
+
}}
|
|
362
|
+
/>;
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
Three data sources: `collection` (queries a collection), `options` (static array), `loadOptions` (async function).
|
|
366
|
+
|
|
367
|
+
### useScopedFetch / createScopedFetch
|
|
368
|
+
|
|
369
|
+
Inject scope header into all API calls:
|
|
370
|
+
|
|
371
|
+
```tsx
|
|
372
|
+
import { useScopedFetch, createScopedFetch } from "@questpie/admin/client";
|
|
373
|
+
|
|
374
|
+
// React hook
|
|
375
|
+
const scopedFetch = useScopedFetch();
|
|
376
|
+
const client = useMemo(
|
|
377
|
+
() => createClient({ baseURL: "/api", fetch: scopedFetch }),
|
|
378
|
+
[scopedFetch],
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
// Non-React
|
|
382
|
+
const scopedFetch = createScopedFetch("x-selected-workspace", () =>
|
|
383
|
+
getScopeId(),
|
|
384
|
+
);
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### useScope / useScopeSafe
|
|
388
|
+
|
|
389
|
+
Access current scope state in any component:
|
|
390
|
+
|
|
391
|
+
```tsx
|
|
392
|
+
import { useScope, useScopeSafe } from "@questpie/admin/client";
|
|
393
|
+
|
|
394
|
+
const { scopeId, setScope, clearScope, headerName } = useScope(); // throws outside ScopeProvider
|
|
395
|
+
const scope = useScopeSafe(); // returns null outside ScopeProvider
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
For the full server-side setup (context resolver, type augmentation, access rules), see the `questpie` skill's `references/multi-tenancy.md`.
|
|
399
|
+
|
|
400
|
+
## Common Mistakes
|
|
401
|
+
|
|
402
|
+
1. **CRITICAL: Using `asChild` prop** — QUESTPIE admin uses `@base-ui/react`, which uses the `render` prop. `asChild` is a Radix pattern and does NOT work here.
|
|
403
|
+
|
|
404
|
+
```tsx
|
|
405
|
+
// WRONG
|
|
406
|
+
<DialogTrigger asChild><Button>Open</Button></DialogTrigger>
|
|
407
|
+
// CORRECT
|
|
408
|
+
<DialogTrigger render={<Button>Open</Button>} />
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
2. **CRITICAL: Importing from `@radix-ui/*`** — use `@base-ui/react` instead.
|
|
412
|
+
|
|
413
|
+
3. **HIGH: Using `@phosphor-icons/react`** — use `@iconify/react` with `ph:` prefix.
|
|
414
|
+
|
|
415
|
+
```tsx
|
|
416
|
+
// WRONG
|
|
417
|
+
import { CaretDown } from "@phosphor-icons/react";
|
|
418
|
+
// CORRECT
|
|
419
|
+
import { Icon } from "@iconify/react";
|
|
420
|
+
<Icon icon="ph:caret-down" width={16} height={16} />;
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
4. **HIGH: Using lucide-react icons** — use `@iconify/react` with Phosphor icon set.
|
|
424
|
+
|
|
425
|
+
5. **MEDIUM: Custom `<button>` or `<div>` instead of shadcn components** — use `<Button>`, `<Card>`, etc.
|
|
426
|
+
|
|
427
|
+
6. **MEDIUM: `console.error` for user errors** — use `toast.error()` from `sonner`.
|
|
428
|
+
|
|
429
|
+
---
|
|
430
|
+
|
|
431
|
+
# QUESTPIE Admin Views
|
|
432
|
+
|
|
433
|
+
This skill builds on questpie-admin.
|
|
434
|
+
|
|
435
|
+
Views control how data appears in the QUESTPIE admin panel. They are configured **server-side** on collections and globals, then rendered by the admin client via registries.
|
|
436
|
+
|
|
437
|
+
```text
|
|
438
|
+
Server Config Admin UI
|
|
439
|
+
.list(({ v }) => v.collectionTable({})) -> Table with columns, sort, search
|
|
440
|
+
.form(({ v, f }) => v.collectionForm({})) -> Form with sections, sidebar, tabs
|
|
441
|
+
sidebar({...}) -> Navigation sidebar
|
|
442
|
+
dashboard({...}) -> Dashboard with widgets
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
## List Views
|
|
446
|
+
|
|
447
|
+
Configure table views with `.list()` on a collection.
|
|
448
|
+
|
|
449
|
+
### Basic Table
|
|
450
|
+
|
|
451
|
+
```ts
|
|
452
|
+
.list(({ v }) => v.collectionTable({}))
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
Shows all fields as columns with default rendering.
|
|
456
|
+
|
|
457
|
+
### Custom Columns and Search
|
|
458
|
+
|
|
459
|
+
```ts
|
|
460
|
+
.list(({ v, f }) =>
|
|
461
|
+
v.collectionTable({
|
|
462
|
+
columns: [f.name, f.email, f.isActive, f.createdAt],
|
|
463
|
+
searchableFields: [f.name, f.email],
|
|
464
|
+
defaultSort: { field: f.createdAt, direction: "desc" },
|
|
465
|
+
}),
|
|
466
|
+
)
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
| Option | Type | Description |
|
|
470
|
+
| ------------------ | ---------------------- | ------------------------------ |
|
|
471
|
+
| `columns` | `Field[]` | Fields to show as columns |
|
|
472
|
+
| `searchableFields` | `Field[]` | Fields included in text search |
|
|
473
|
+
| `defaultSort` | `{ field, direction }` | Default sort order |
|
|
474
|
+
|
|
475
|
+
## Form Views
|
|
476
|
+
|
|
477
|
+
Configure edit forms with `.form()`.
|
|
478
|
+
|
|
479
|
+
### Basic Form
|
|
480
|
+
|
|
481
|
+
```ts
|
|
482
|
+
.form(({ v, f }) => v.collectionForm({}))
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
Renders all fields in a single column.
|
|
486
|
+
|
|
487
|
+
### Sections
|
|
488
|
+
|
|
489
|
+
Group fields into labeled sections with optional grid layout:
|
|
490
|
+
|
|
491
|
+
```ts
|
|
492
|
+
.form(({ v, f }) =>
|
|
493
|
+
v.collectionForm({
|
|
494
|
+
fields: [
|
|
495
|
+
{
|
|
496
|
+
type: "section",
|
|
497
|
+
label: { en: "Contact Information" },
|
|
498
|
+
layout: "grid",
|
|
499
|
+
columns: 2,
|
|
500
|
+
fields: [f.name, f.email, f.phone],
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
type: "section",
|
|
504
|
+
label: { en: "Profile" },
|
|
505
|
+
fields: [f.bio],
|
|
506
|
+
},
|
|
507
|
+
],
|
|
508
|
+
}),
|
|
509
|
+
)
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
| Option | Type | Description |
|
|
513
|
+
| ------------- | ------------------- | ------------------------------------ |
|
|
514
|
+
| `type` | `"section"` | Required |
|
|
515
|
+
| `label` | `string \| i18n` | Section heading |
|
|
516
|
+
| `description` | `string \| i18n` | Section description |
|
|
517
|
+
| `layout` | `"grid" \| "stack"` | Field layout |
|
|
518
|
+
| `columns` | `number` | Grid columns (with `layout: "grid"`) |
|
|
519
|
+
| `fields` | `Field[]` | Fields in this section |
|
|
520
|
+
|
|
521
|
+
### Form Sidebar
|
|
522
|
+
|
|
523
|
+
Place fields in a right sidebar panel:
|
|
524
|
+
|
|
525
|
+
```ts
|
|
526
|
+
.form(({ v, f }) =>
|
|
527
|
+
v.collectionForm({
|
|
528
|
+
sidebar: {
|
|
529
|
+
position: "right",
|
|
530
|
+
fields: [f.isActive, f.avatar, f.status],
|
|
531
|
+
},
|
|
532
|
+
fields: [ /* main content sections */ ],
|
|
533
|
+
}),
|
|
534
|
+
)
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### Computed Fields
|
|
538
|
+
|
|
539
|
+
Auto-compute values from other fields:
|
|
540
|
+
|
|
541
|
+
```ts
|
|
542
|
+
{
|
|
543
|
+
field: f.slug,
|
|
544
|
+
compute: {
|
|
545
|
+
handler: ({ data }) => {
|
|
546
|
+
if (data.name && !data.slug?.trim()) {
|
|
547
|
+
return slugify(data.name);
|
|
548
|
+
}
|
|
549
|
+
return undefined;
|
|
550
|
+
},
|
|
551
|
+
deps: ({ data }) => [data.name, data.slug],
|
|
552
|
+
debounce: 300,
|
|
553
|
+
},
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
| Option | Type | Description |
|
|
558
|
+
| ---------- | ---------------- | ------------------------ |
|
|
559
|
+
| `handler` | `(ctx) => value` | Compute function |
|
|
560
|
+
| `deps` | `(ctx) => any[]` | Reactive dependencies |
|
|
561
|
+
| `debounce` | `number` | Debounce in milliseconds |
|
|
562
|
+
|
|
563
|
+
### Conditional Visibility
|
|
564
|
+
|
|
565
|
+
Show or hide fields based on other field values:
|
|
566
|
+
|
|
567
|
+
```ts
|
|
568
|
+
{
|
|
569
|
+
field: f.cancellationReason,
|
|
570
|
+
hidden: ({ data }) => data.status !== "cancelled",
|
|
571
|
+
}
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
Read-only fields:
|
|
575
|
+
|
|
576
|
+
```ts
|
|
577
|
+
{
|
|
578
|
+
field: f.customerName,
|
|
579
|
+
readOnly: ({ data }) => !!data.customer,
|
|
580
|
+
}
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
Section-level visibility:
|
|
584
|
+
|
|
585
|
+
```ts
|
|
586
|
+
{
|
|
587
|
+
type: "section",
|
|
588
|
+
label: { en: "SEO" },
|
|
589
|
+
hidden: ({ data }) => !data.showSeo,
|
|
590
|
+
fields: [f.metaTitle, f.metaDescription],
|
|
591
|
+
}
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
## Dashboard
|
|
595
|
+
|
|
596
|
+
Configure in `config/admin.ts` under the `dashboard` key:
|
|
597
|
+
|
|
598
|
+
```ts title="config/admin.ts"
|
|
599
|
+
import { adminConfig } from "#questpie/factories";
|
|
600
|
+
|
|
601
|
+
export default adminConfig({
|
|
602
|
+
dashboard: {
|
|
603
|
+
title: { en: "Dashboard" },
|
|
604
|
+
description: { en: "Overview of your app" },
|
|
605
|
+
columns: 4,
|
|
606
|
+
actions: [
|
|
607
|
+
{
|
|
608
|
+
id: "new-post",
|
|
609
|
+
href: "/admin/collections/posts?create=true",
|
|
610
|
+
label: { en: "New Post" },
|
|
611
|
+
icon: { type: "icon", props: { name: "ph:plus" } },
|
|
612
|
+
variant: "primary",
|
|
613
|
+
},
|
|
614
|
+
],
|
|
615
|
+
sections: [
|
|
616
|
+
{ id: "today", label: { en: "Today" }, layout: "grid", columns: 4 },
|
|
617
|
+
{ id: "business", label: { en: "Business" }, layout: "grid", columns: 4 },
|
|
618
|
+
],
|
|
619
|
+
items: [
|
|
620
|
+
/* widget items — see widget types below */
|
|
621
|
+
],
|
|
622
|
+
},
|
|
623
|
+
});
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
### Widget Types
|
|
627
|
+
|
|
628
|
+
**Stats** — count records with optional filter:
|
|
629
|
+
|
|
630
|
+
```ts
|
|
631
|
+
{
|
|
632
|
+
sectionId: "today",
|
|
633
|
+
id: "pending",
|
|
634
|
+
type: "stats",
|
|
635
|
+
collection: "appointments",
|
|
636
|
+
label: { en: "Pending" },
|
|
637
|
+
filter: { status: "pending" },
|
|
638
|
+
span: 1,
|
|
639
|
+
}
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
**Value** — custom-loaded value with trend:
|
|
643
|
+
|
|
644
|
+
```ts
|
|
645
|
+
{
|
|
646
|
+
sectionId: "business",
|
|
647
|
+
id: "revenue",
|
|
648
|
+
type: "value",
|
|
649
|
+
span: 2,
|
|
650
|
+
refreshInterval: 1000 * 60 * 5,
|
|
651
|
+
loader: async ({ app }) => ({
|
|
652
|
+
value: 42000,
|
|
653
|
+
formatted: "42,000 EUR",
|
|
654
|
+
label: { en: "Monthly Revenue" },
|
|
655
|
+
trend: { value: "+12%" },
|
|
656
|
+
}),
|
|
657
|
+
}
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
**Progress** — progress bar toward a goal:
|
|
661
|
+
|
|
662
|
+
```ts
|
|
663
|
+
{
|
|
664
|
+
sectionId: "business",
|
|
665
|
+
id: "goal",
|
|
666
|
+
type: "progress",
|
|
667
|
+
span: 1,
|
|
668
|
+
showPercentage: true,
|
|
669
|
+
label: { en: "Monthly Goal" },
|
|
670
|
+
loader: async ({ app }) => ({ current: 350, target: 500 }),
|
|
671
|
+
}
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
**Chart** — chart from field values:
|
|
675
|
+
|
|
676
|
+
```ts
|
|
677
|
+
{
|
|
678
|
+
sectionId: "business",
|
|
679
|
+
id: "by-status",
|
|
680
|
+
type: "chart",
|
|
681
|
+
collection: "appointments",
|
|
682
|
+
field: "status",
|
|
683
|
+
chartType: "pie",
|
|
684
|
+
label: { en: "By Status" },
|
|
685
|
+
span: 1,
|
|
686
|
+
}
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
**Recent Items** — list recent records:
|
|
690
|
+
|
|
691
|
+
```ts
|
|
692
|
+
{
|
|
693
|
+
sectionId: "ops",
|
|
694
|
+
id: "recent",
|
|
695
|
+
type: "recentItems",
|
|
696
|
+
collection: "appointments",
|
|
697
|
+
label: { en: "Recent" },
|
|
698
|
+
limit: 6,
|
|
699
|
+
dateField: "scheduledAt",
|
|
700
|
+
span: 2,
|
|
701
|
+
}
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
**Timeline** — activity stream:
|
|
705
|
+
|
|
706
|
+
```ts
|
|
707
|
+
{
|
|
708
|
+
sectionId: "ops",
|
|
709
|
+
id: "activity",
|
|
710
|
+
type: "timeline",
|
|
711
|
+
label: { en: "Activity" },
|
|
712
|
+
maxItems: 8,
|
|
713
|
+
showTimestamps: true,
|
|
714
|
+
timestampFormat: "relative",
|
|
715
|
+
loader: async ({ app }) => {
|
|
716
|
+
const res = await app.collections.appointments.find({
|
|
717
|
+
limit: 8,
|
|
718
|
+
orderBy: { updatedAt: "desc" },
|
|
719
|
+
});
|
|
720
|
+
return res.docs.map((apt) => ({
|
|
721
|
+
id: apt.id,
|
|
722
|
+
title: apt.displayTitle,
|
|
723
|
+
description: `Status: ${apt.status}`,
|
|
724
|
+
timestamp: apt.updatedAt,
|
|
725
|
+
variant: apt.status === "completed" ? "success" : "warning",
|
|
726
|
+
href: `/admin/collections/appointments/${apt.id}`,
|
|
727
|
+
}));
|
|
728
|
+
},
|
|
729
|
+
span: 2,
|
|
730
|
+
}
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
## Sidebar
|
|
734
|
+
|
|
735
|
+
Configure in `config/admin.ts` under the `sidebar` key:
|
|
736
|
+
|
|
737
|
+
```ts title="config/admin.ts"
|
|
738
|
+
import { adminConfig } from "#questpie/factories";
|
|
739
|
+
|
|
740
|
+
export default adminConfig({
|
|
741
|
+
sidebar: {
|
|
742
|
+
sections: [
|
|
743
|
+
{ id: "overview", title: { en: "Overview" } },
|
|
744
|
+
{ id: "content", title: { en: "Content" } },
|
|
745
|
+
{ id: "external", title: { en: "External" } },
|
|
746
|
+
],
|
|
747
|
+
items: [
|
|
748
|
+
{
|
|
749
|
+
sectionId: "overview",
|
|
750
|
+
type: "link",
|
|
751
|
+
label: { en: "Dashboard" },
|
|
752
|
+
href: "/admin",
|
|
753
|
+
icon: { type: "icon", props: { name: "ph:house" } },
|
|
754
|
+
},
|
|
755
|
+
{ sectionId: "overview", type: "global", global: "siteSettings" },
|
|
756
|
+
{ sectionId: "content", type: "collection", collection: "posts" },
|
|
757
|
+
{
|
|
758
|
+
sectionId: "external",
|
|
759
|
+
type: "link",
|
|
760
|
+
label: { en: "Open Website" },
|
|
761
|
+
href: "/",
|
|
762
|
+
external: true,
|
|
763
|
+
icon: { type: "icon", props: { name: "ph:arrow-square-out" } },
|
|
764
|
+
},
|
|
765
|
+
],
|
|
766
|
+
},
|
|
767
|
+
});
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
Items appear in definition order within their section.
|
|
771
|
+
|
|
772
|
+
Modules contribute sidebar items automatically. `adminModule` adds "Administration" with user management. `auditModule` adds an audit log item.
|
|
773
|
+
|
|
774
|
+
## Filters & Saved Views
|
|
775
|
+
|
|
776
|
+
Filters are auto-generated from field definitions:
|
|
777
|
+
|
|
778
|
+
| Field Type | Filter Operators |
|
|
779
|
+
| ------------------- | ---------------------------------------- |
|
|
780
|
+
| `text` | Contains, equals, starts with, ends with |
|
|
781
|
+
| `number` | Equals, greater than, less than, between |
|
|
782
|
+
| `boolean` | Is true, is false |
|
|
783
|
+
| `select` | Is, is not, in |
|
|
784
|
+
| `date` / `datetime` | Before, after, between |
|
|
785
|
+
| `relation` | Is (picker) |
|
|
786
|
+
|
|
787
|
+
Users can save filter + sort + column combinations as named views.
|
|
788
|
+
|
|
789
|
+
## Bulk Actions
|
|
790
|
+
|
|
791
|
+
List views support multi-select. Check rows, then use the floating toolbar. Built-in: **Delete** (with confirmation). Soft-delete collections soft-delete instead of permanent removal.
|
|
792
|
+
|
|
793
|
+
## History & Versions
|
|
794
|
+
|
|
795
|
+
Click the clock icon in the form toolbar. Two tabs:
|
|
796
|
+
|
|
797
|
+
| Tab | Shows | Requires |
|
|
798
|
+
| ------------ | ---------------------------------------------- | ----------------------------- |
|
|
799
|
+
| **Activity** | Audit log (create, update, delete, transition) | `auditModule` |
|
|
800
|
+
| **Versions** | Full document snapshots with restore | `.versioning()` on collection |
|
|
801
|
+
|
|
802
|
+
Enable versioning:
|
|
803
|
+
|
|
804
|
+
```ts
|
|
805
|
+
export const pages = collection("pages")
|
|
806
|
+
.fields(({ f }) => ({ ... }))
|
|
807
|
+
.options({ versioning: true });
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
Disable audit for a specific collection:
|
|
811
|
+
|
|
812
|
+
```ts
|
|
813
|
+
export const logs = collection("logs")
|
|
814
|
+
.admin(() => ({ audit: false }))
|
|
815
|
+
.fields(({ f }) => ({ ... }));
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
## Common Mistakes
|
|
819
|
+
|
|
820
|
+
1. **HIGH: Defining columns that don't match field names** — `columns: [f.name]` requires a `name` field in the collection's `.fields()`. Mismatches cause empty columns.
|
|
821
|
+
|
|
822
|
+
2. **MEDIUM: Not specifying `searchableFields`** — table search bar won't work unless you explicitly list which fields to search.
|
|
823
|
+
|
|
824
|
+
3. **MEDIUM: Forgetting sidebar section ordering** — items appear in definition order. If you want "Dashboard" at the top, define it first in the `items` array.
|
|
825
|
+
|
|
826
|
+
4. **MEDIUM: Missing `sectionId` on sidebar items** — every item must reference an existing section ID.
|
|
827
|
+
|
|
828
|
+
5. **LOW: Not setting `defaultSort`** — records appear in database insertion order which is usually not what users expect.
|
|
829
|
+
|
|
830
|
+
## Form Views and Live Preview
|
|
831
|
+
|
|
832
|
+
Form views connect to the existing Live Preview system when the collection has `.preview()` configured. Keep `v.collectionForm()` as the form surface; do not introduce a separate visual-edit form API, a second default form view, or parallel preview API names. The form editor remains the source of patches, refreshes, commits, and resyncs.
|
|
833
|
+
|
|
834
|
+
### Enabling Preview on a Collection
|
|
835
|
+
|
|
836
|
+
Add `.preview()` to the collection definition:
|
|
837
|
+
|
|
838
|
+
```ts
|
|
839
|
+
export const pages = collection("pages")
|
|
840
|
+
.fields(({ f }) => ({
|
|
841
|
+
title: f.text().required().localized(),
|
|
842
|
+
slug: f.text().required(),
|
|
843
|
+
content: f.blocks().localized(),
|
|
844
|
+
}))
|
|
845
|
+
.preview({
|
|
846
|
+
enabled: true,
|
|
847
|
+
position: "right",
|
|
848
|
+
defaultWidth: 50,
|
|
849
|
+
url: ({ record }) => `/${record.slug}?preview=true`,
|
|
850
|
+
});
|
|
851
|
+
```
|
|
852
|
+
|
|
853
|
+
### How It Works
|
|
854
|
+
|
|
855
|
+
1. The form view detects `.preview()` config and opens a split-screen layout
|
|
856
|
+
2. The preview iframe mirrors form state with snapshot, patch, refresh, commit, and resync messages
|
|
857
|
+
3. Save/autosave/Cmd+S/history/workflow/locks/actions stay in the form lifecycle
|
|
858
|
+
4. The preview page uses `useCollectionPreview({ initialData, onRefresh })`
|
|
859
|
+
5. `PreviewProvider`, `PreviewField`, and `BlockRenderer` wire field and block annotations
|
|
860
|
+
|
|
861
|
+
### Frontend Preparation Checklist
|
|
862
|
+
|
|
863
|
+
Use this checklist before expecting visual editing to work:
|
|
864
|
+
|
|
865
|
+
1. The collection has `.preview({ url })`.
|
|
866
|
+
2. The page loader returns the complete rendered record shape.
|
|
867
|
+
3. Public workflow reads use `stage: "published"`; if public client/HTTP access is enabled, anonymous read access also requires `input?.stage === "published"`. Preview/draft-mode reads load the working record for authorized editors.
|
|
868
|
+
4. The page renderer calls `useCollectionPreview({ initialData, onRefresh })`.
|
|
869
|
+
5. The rendered page is wrapped in `PreviewProvider preview={preview}`.
|
|
870
|
+
6. UI reads from `preview.data`, not directly from loader data.
|
|
871
|
+
7. Scalar text uses `PreviewField field="..." editable="text" | "textarea"` when inline editing is expected.
|
|
872
|
+
8. Blocks render through `BlockRenderer` with `selectedBlockId` and `onBlockClick`.
|
|
873
|
+
9. `BlockScopeProvider` is only needed for custom/manual block rendering outside `BlockRenderer`.
|
|
874
|
+
10. Add/remove/reorder/nesting block operations stay in the existing block editor.
|
|
875
|
+
|
|
876
|
+
---
|
|
877
|
+
|
|
878
|
+
# QUESTPIE Blocks
|
|
879
|
+
|
|
880
|
+
This skill builds on questpie-admin.
|
|
881
|
+
|
|
882
|
+
Blocks are reusable content components for page builders. Define them server-side with fields and admin metadata, then render them client-side with React components.
|
|
883
|
+
|
|
884
|
+
```text
|
|
885
|
+
Server: block("hero") Client: HeroRenderer
|
|
886
|
+
.fields({ title, image }) -> Receives { values, data }
|
|
887
|
+
.admin({ label, icon }) Returns JSX
|
|
888
|
+
.prefetch({ with: {...} })
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
## Defining Blocks
|
|
892
|
+
|
|
893
|
+
Blocks are defined in `blocks/` using the `block()` factory:
|
|
894
|
+
|
|
895
|
+
```ts title="blocks/hero.ts"
|
|
896
|
+
import { block } from "#questpie/factories";
|
|
897
|
+
|
|
898
|
+
export const heroBlock = block("hero")
|
|
899
|
+
.admin(({ c }) => ({
|
|
900
|
+
label: { en: "Hero Section", sk: "Hero sekcia" },
|
|
901
|
+
icon: c.icon("ph:image"),
|
|
902
|
+
category: "sections",
|
|
903
|
+
}))
|
|
904
|
+
.fields(({ f }) => ({
|
|
905
|
+
title: f.text().localized().required(),
|
|
906
|
+
subtitle: f.textarea().localized(),
|
|
907
|
+
backgroundImage: f.upload({ to: "assets" }),
|
|
908
|
+
overlayOpacity: f.number().default(60),
|
|
909
|
+
alignment: f
|
|
910
|
+
.select([
|
|
911
|
+
{ value: "left", label: "Left" },
|
|
912
|
+
{ value: "center", label: "Center" },
|
|
913
|
+
{ value: "right", label: "Right" },
|
|
914
|
+
])
|
|
915
|
+
.default("center"),
|
|
916
|
+
ctaText: f.text().localized(),
|
|
917
|
+
ctaLink: f.text(),
|
|
918
|
+
}))
|
|
919
|
+
.prefetch({ with: { backgroundImage: true } });
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
### Admin Metadata
|
|
923
|
+
|
|
924
|
+
```ts
|
|
925
|
+
.admin(({ c }) => ({
|
|
926
|
+
label: { en: "Hero Section" }, // Display name in block picker
|
|
927
|
+
icon: c.icon("ph:image"), // Icon in block picker (Phosphor set)
|
|
928
|
+
category: "sections", // Group in block picker
|
|
929
|
+
}))
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
### Multiple Blocks Per File
|
|
933
|
+
|
|
934
|
+
Export multiple named blocks from one file:
|
|
935
|
+
|
|
936
|
+
```ts title="blocks/layout.ts"
|
|
937
|
+
import { block } from "#questpie/factories";
|
|
938
|
+
|
|
939
|
+
export const twoColumnBlock = block("twoColumn")
|
|
940
|
+
.admin(({ c }) => ({
|
|
941
|
+
label: { en: "Two Columns" },
|
|
942
|
+
icon: c.icon("ph:columns"),
|
|
943
|
+
category: "layout",
|
|
944
|
+
}))
|
|
945
|
+
.fields(({ f }) => ({
|
|
946
|
+
left: f.blocks(),
|
|
947
|
+
right: f.blocks(),
|
|
948
|
+
}));
|
|
949
|
+
|
|
950
|
+
export const spacerBlock = block("spacer")
|
|
951
|
+
.admin(({ c }) => ({
|
|
952
|
+
label: { en: "Spacer" },
|
|
953
|
+
icon: c.icon("ph:arrows-out-line-vertical"),
|
|
954
|
+
category: "layout",
|
|
955
|
+
}))
|
|
956
|
+
.fields(({ f }) => ({
|
|
957
|
+
height: f
|
|
958
|
+
.select([
|
|
959
|
+
{ value: "sm", label: "Small" },
|
|
960
|
+
{ value: "md", label: "Medium" },
|
|
961
|
+
{ value: "lg", label: "Large" },
|
|
962
|
+
{ value: "xl", label: "Extra Large" },
|
|
963
|
+
])
|
|
964
|
+
.default("md"),
|
|
965
|
+
}));
|
|
966
|
+
```
|
|
967
|
+
|
|
968
|
+
## Using Blocks in Collections
|
|
969
|
+
|
|
970
|
+
Add a `blocks` field to any collection:
|
|
971
|
+
|
|
972
|
+
```ts title="collections/pages.ts"
|
|
973
|
+
import { collection } from "#questpie/factories";
|
|
974
|
+
|
|
975
|
+
export const pages = collection("pages").fields(({ f }) => ({
|
|
976
|
+
title: f.text().required().localized(),
|
|
977
|
+
slug: f.text().required(),
|
|
978
|
+
content: f.blocks().localized(),
|
|
979
|
+
}));
|
|
980
|
+
```
|
|
981
|
+
|
|
982
|
+
The admin renders a visual block editor for this field.
|
|
983
|
+
|
|
984
|
+
## Prefetch
|
|
985
|
+
|
|
986
|
+
Blocks often reference related data (images, linked records). Use `.prefetch()` to load them alongside block values.
|
|
987
|
+
|
|
988
|
+
### Declarative Prefetch
|
|
989
|
+
|
|
990
|
+
```ts
|
|
991
|
+
.prefetch({
|
|
992
|
+
with: {
|
|
993
|
+
backgroundImage: true, // Load the full image record
|
|
994
|
+
},
|
|
995
|
+
})
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
### Nested Prefetch
|
|
999
|
+
|
|
1000
|
+
```ts
|
|
1001
|
+
.prefetch({
|
|
1002
|
+
with: {
|
|
1003
|
+
featuredBarber: {
|
|
1004
|
+
with: {
|
|
1005
|
+
avatar: true,
|
|
1006
|
+
services: true,
|
|
1007
|
+
},
|
|
1008
|
+
},
|
|
1009
|
+
},
|
|
1010
|
+
})
|
|
1011
|
+
```
|
|
1012
|
+
|
|
1013
|
+
### Functional Prefetch
|
|
1014
|
+
|
|
1015
|
+
For complex queries, use a function. The `ctx` parameter provides fully typed `collections` and `globals` via `AppContext` augmentation — no imports needed:
|
|
1016
|
+
|
|
1017
|
+
```ts title="blocks/featured.ts"
|
|
1018
|
+
import { block } from "#questpie/factories";
|
|
1019
|
+
|
|
1020
|
+
export const featuredBlock = block("featured")
|
|
1021
|
+
.fields(({ f }) => ({
|
|
1022
|
+
heading: f.text().required(),
|
|
1023
|
+
}))
|
|
1024
|
+
.prefetch(async ({ values, ctx }) => {
|
|
1025
|
+
return {
|
|
1026
|
+
posts: (await ctx.collections.posts.find({ limit: 5 })).docs,
|
|
1027
|
+
};
|
|
1028
|
+
});
|
|
1029
|
+
```
|
|
1030
|
+
|
|
1031
|
+
### Using Prefetched Data in Renderers
|
|
1032
|
+
|
|
1033
|
+
```tsx
|
|
1034
|
+
function HeroRenderer({ values, data }: BlockProps<"hero">) {
|
|
1035
|
+
// values.backgroundImage = "asset-id-123" (just the ID)
|
|
1036
|
+
// data.backgroundImage = { url: "/api/assets/...", filename: "hero.jpg", ... }
|
|
1037
|
+
|
|
1038
|
+
return (
|
|
1039
|
+
<section>
|
|
1040
|
+
{data?.backgroundImage?.url && (
|
|
1041
|
+
<img src={data.backgroundImage.url} alt="" />
|
|
1042
|
+
)}
|
|
1043
|
+
<h1>{values.title}</h1>
|
|
1044
|
+
</section>
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
## Block Renderers
|
|
1050
|
+
|
|
1051
|
+
React components that receive block data and return JSX.
|
|
1052
|
+
|
|
1053
|
+
### Defining a Renderer
|
|
1054
|
+
|
|
1055
|
+
```tsx title="admin/blocks/hero.tsx"
|
|
1056
|
+
import type { BlockProps } from "../.generated/client";
|
|
1057
|
+
|
|
1058
|
+
export function HeroRenderer({ values, data }: BlockProps<"hero">) {
|
|
1059
|
+
return (
|
|
1060
|
+
<section
|
|
1061
|
+
className="relative flex items-center justify-center"
|
|
1062
|
+
style={{ minHeight: "60vh" }}
|
|
1063
|
+
>
|
|
1064
|
+
{data?.backgroundImage?.url && (
|
|
1065
|
+
<img
|
|
1066
|
+
src={data.backgroundImage.url}
|
|
1067
|
+
alt=""
|
|
1068
|
+
className="absolute inset-0 w-full h-full object-cover"
|
|
1069
|
+
/>
|
|
1070
|
+
)}
|
|
1071
|
+
<div className="relative text-center">
|
|
1072
|
+
<h1 className="text-5xl font-bold">{values.title}</h1>
|
|
1073
|
+
{values.subtitle && <p className="text-xl mt-4">{values.subtitle}</p>}
|
|
1074
|
+
{values.ctaText && (
|
|
1075
|
+
<a href={values.ctaLink} className="mt-6 inline-block btn">
|
|
1076
|
+
{values.ctaText}
|
|
1077
|
+
</a>
|
|
1078
|
+
)}
|
|
1079
|
+
</div>
|
|
1080
|
+
</section>
|
|
1081
|
+
);
|
|
1082
|
+
}
|
|
1083
|
+
```
|
|
1084
|
+
|
|
1085
|
+
### BlockProps
|
|
1086
|
+
|
|
1087
|
+
| Property | Type | Description |
|
|
1088
|
+
| ---------- | ----------- | -------------------------------------------------- |
|
|
1089
|
+
| `values` | `object` | Block field values (title, subtitle, etc.) |
|
|
1090
|
+
| `data` | `object` | Prefetched relation data (images, related records) |
|
|
1091
|
+
| `children` | `ReactNode` | Nested block content |
|
|
1092
|
+
|
|
1093
|
+
### Registering Renderers
|
|
1094
|
+
|
|
1095
|
+
```tsx title="admin/blocks/index.tsx"
|
|
1096
|
+
import { HeroRenderer } from "./hero";
|
|
1097
|
+
import { GalleryRenderer } from "./gallery";
|
|
1098
|
+
import { CTARenderer } from "./cta";
|
|
1099
|
+
|
|
1100
|
+
export const renderers = {
|
|
1101
|
+
hero: HeroRenderer,
|
|
1102
|
+
gallery: GalleryRenderer,
|
|
1103
|
+
cta: CTARenderer,
|
|
1104
|
+
};
|
|
1105
|
+
```
|
|
1106
|
+
|
|
1107
|
+
### Frontend Rendering
|
|
1108
|
+
|
|
1109
|
+
Use block renderers on the public frontend:
|
|
1110
|
+
|
|
1111
|
+
```tsx title="components/page-renderer.tsx"
|
|
1112
|
+
import { renderers } from "@/questpie/admin/blocks";
|
|
1113
|
+
|
|
1114
|
+
function PageRenderer({ page }) {
|
|
1115
|
+
return (
|
|
1116
|
+
<div>
|
|
1117
|
+
{page.content?.map((block, i) => {
|
|
1118
|
+
const Renderer = renderers[block.type];
|
|
1119
|
+
if (!Renderer) return null;
|
|
1120
|
+
return <Renderer key={i} values={block.values} data={block.data} />;
|
|
1121
|
+
})}
|
|
1122
|
+
</div>
|
|
1123
|
+
);
|
|
1124
|
+
}
|
|
1125
|
+
```
|
|
1126
|
+
|
|
1127
|
+
## Common Mistakes
|
|
1128
|
+
|
|
1129
|
+
1. **HIGH: Not using `ctx.collections.*` in functional prefetch** — use the context-injected collections directly. Do NOT import `app` from `#questpie` inside block files (causes circular dependencies).
|
|
1130
|
+
|
|
1131
|
+
```ts
|
|
1132
|
+
// WRONG — importing app creates circular dependency
|
|
1133
|
+
import { app } from "#questpie";
|
|
1134
|
+
.prefetch(async ({ values, ctx }) => {
|
|
1135
|
+
const posts = await app.collections.posts.find({});
|
|
1136
|
+
})
|
|
1137
|
+
|
|
1138
|
+
// CORRECT — use ctx.collections directly
|
|
1139
|
+
.prefetch(async ({ values, ctx }) => {
|
|
1140
|
+
const posts = await ctx.collections.posts.find({});
|
|
1141
|
+
})
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
2. **HIGH: Importing from `.generated/` inside block files** — block files are imported BY `.generated/index.ts`, so importing from it back creates circular dependencies. Use the `ctx` parameter instead.
|
|
1145
|
+
|
|
1146
|
+
3. **MEDIUM: Block renderer not exported as default or named export** — codegen discovers named exports from block renderer files. Ensure the component is exported.
|
|
1147
|
+
|
|
1148
|
+
4. **MEDIUM: Using `{ with: { field: true } }` prefetch for complex queries** — declarative prefetch only loads related records by ID. For filtered/sorted/limited queries, use functional prefetch instead.
|
|
1149
|
+
|
|
1150
|
+
5. **MEDIUM: Forgetting `.prefetch()` for upload fields** — without prefetch, `values.backgroundImage` is just an ID string. Add `{ with: { backgroundImage: true } }` to get the full asset record with `url`.
|
|
1151
|
+
|
|
1152
|
+
6. **LOW: Missing `category` in `.admin()`** — blocks without a category won't be grouped in the block picker, making it harder to find them.
|
|
1153
|
+
|
|
1154
|
+
## Blocks in Live Preview
|
|
1155
|
+
|
|
1156
|
+
When a collection has `.preview()` configured, blocks participate in the existing Live Preview system through `BlockRenderer` and `PreviewField`. The form remains authoritative; block annotations only mirror values, focus fields, select blocks, or request inline scalar edits.
|
|
1157
|
+
|
|
1158
|
+
### Preferred: BlockRenderer
|
|
1159
|
+
|
|
1160
|
+
Use `BlockRenderer` for normal frontend page rendering. It preserves `data-block-id`, routes block selection, and scopes nested `PreviewField` paths automatically.
|
|
1161
|
+
|
|
1162
|
+
```tsx
|
|
1163
|
+
<BlockRenderer
|
|
1164
|
+
content={preview.data.content}
|
|
1165
|
+
data={preview.data.content?._data}
|
|
1166
|
+
renderers={admin.blocks}
|
|
1167
|
+
selectedBlockId={preview.selectedBlockId}
|
|
1168
|
+
onBlockClick={preview.isPreviewMode ? preview.handleBlockClick : undefined}
|
|
1169
|
+
/>
|
|
1170
|
+
```
|
|
1171
|
+
|
|
1172
|
+
Inside custom block renderers, annotate scalar values with `PreviewField`:
|
|
1173
|
+
|
|
1174
|
+
```tsx
|
|
1175
|
+
<PreviewField field="title" editable="text" as="h2">
|
|
1176
|
+
{values.title}
|
|
1177
|
+
</PreviewField>
|
|
1178
|
+
```
|
|
1179
|
+
|
|
1180
|
+
This resolves to `content._values.{blockId}.title` when rendered inside `BlockRenderer`.
|
|
1181
|
+
|
|
1182
|
+
### Manual BlockScopeProvider Wrapper
|
|
1183
|
+
|
|
1184
|
+
Use `BlockScopeProvider` only when you manually render blocks outside `BlockRenderer`:
|
|
1185
|
+
|
|
1186
|
+
```tsx
|
|
1187
|
+
import { BlockScopeProvider } from "@questpie/admin/client";
|
|
1188
|
+
|
|
1189
|
+
function PageRenderer({ blocks, previewData }) {
|
|
1190
|
+
return blocks.map((block) => {
|
|
1191
|
+
const Renderer = renderers[block.type];
|
|
1192
|
+
return (
|
|
1193
|
+
<BlockScopeProvider key={block.id} blockId={block.id}>
|
|
1194
|
+
<Renderer values={block.values} data={block.data} />
|
|
1195
|
+
</BlockScopeProvider>
|
|
1196
|
+
);
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
```
|
|
1200
|
+
|
|
1201
|
+
`PreviewField` components inside the provider resolve paths like `content._values.{blockId}.title`.
|
|
1202
|
+
|
|
1203
|
+
Inline block edits target `_values`, for example `content._values.<blockId>.title`. Tree edits such as add, remove, reorder, and nesting stay in the existing block editor and should trigger refresh or resync when patching is not safe.
|
|
1204
|
+
|
|
1205
|
+
---
|
|
1206
|
+
|
|
1207
|
+
# QUESTPIE Custom UI
|
|
1208
|
+
|
|
1209
|
+
This skill builds on questpie-admin.
|
|
1210
|
+
|
|
1211
|
+
Extend the QUESTPIE admin with custom field types, custom view types, custom components, and reactive field behaviors.
|
|
1212
|
+
|
|
1213
|
+
## Registries
|
|
1214
|
+
|
|
1215
|
+
Registries connect server-side schema to client-side rendering. When the admin encounters a field type, it looks up the renderer in the field registry.
|
|
1216
|
+
|
|
1217
|
+
```text
|
|
1218
|
+
Server: f.text().required()
|
|
1219
|
+
|
|
|
1220
|
+
Generated: { type: "text", options: {...} }
|
|
1221
|
+
|
|
|
1222
|
+
Admin Client: fieldRegistry.get("text")
|
|
1223
|
+
|
|
|
1224
|
+
React: <TextFieldRenderer value={...} onChange={...} />
|
|
1225
|
+
```
|
|
1226
|
+
|
|
1227
|
+
### Built-in Field Registry
|
|
1228
|
+
|
|
1229
|
+
```
|
|
1230
|
+
text -> TextInput
|
|
1231
|
+
textarea -> TextareaInput
|
|
1232
|
+
richText -> RichTextEditor (TipTap)
|
|
1233
|
+
number -> NumberInput
|
|
1234
|
+
boolean -> Checkbox / Switch
|
|
1235
|
+
date -> DatePicker
|
|
1236
|
+
datetime -> DateTimePicker
|
|
1237
|
+
select -> SelectDropdown
|
|
1238
|
+
relation -> RelationPicker
|
|
1239
|
+
upload -> FileUpload
|
|
1240
|
+
object -> NestedForm
|
|
1241
|
+
array -> RepeatableItems
|
|
1242
|
+
blocks -> BlockEditor
|
|
1243
|
+
json -> JSONEditor
|
|
1244
|
+
```
|
|
1245
|
+
|
|
1246
|
+
### Extending Registries
|
|
1247
|
+
|
|
1248
|
+
Place files in the admin directory. Codegen discovers them automatically:
|
|
1249
|
+
|
|
1250
|
+
```
|
|
1251
|
+
questpie/admin/
|
|
1252
|
+
fields/
|
|
1253
|
+
color.tsx # Custom color field renderer
|
|
1254
|
+
currency.tsx # Custom currency field renderer
|
|
1255
|
+
views/
|
|
1256
|
+
kanban.tsx # Custom kanban list view
|
|
1257
|
+
```
|
|
1258
|
+
|
|
1259
|
+
These are merged with built-in defaults during codegen and exported in `.generated/client.ts`.
|
|
1260
|
+
|
|
1261
|
+
## Custom Fields
|
|
1262
|
+
|
|
1263
|
+
### Server-Side Registration
|
|
1264
|
+
|
|
1265
|
+
Register custom fields through modules:
|
|
1266
|
+
|
|
1267
|
+
```ts
|
|
1268
|
+
const myModule = module({
|
|
1269
|
+
name: "custom-fields",
|
|
1270
|
+
fields: {
|
|
1271
|
+
color: colorField,
|
|
1272
|
+
currency: currencyField,
|
|
1273
|
+
phone: phoneField,
|
|
1274
|
+
},
|
|
1275
|
+
});
|
|
1276
|
+
```
|
|
1277
|
+
|
|
1278
|
+
Once registered and codegen runs, the field becomes available on the `f` builder:
|
|
1279
|
+
|
|
1280
|
+
```ts
|
|
1281
|
+
.fields(({ f }) => ({
|
|
1282
|
+
brandColor: f.color().default("#000000"),
|
|
1283
|
+
price: f.currency({ currency: "USD" }),
|
|
1284
|
+
}))
|
|
1285
|
+
```
|
|
1286
|
+
|
|
1287
|
+
### Admin Field Renderer
|
|
1288
|
+
|
|
1289
|
+
Create a React component for the field's edit form:
|
|
1290
|
+
|
|
1291
|
+
```tsx title="admin/fields/color.tsx"
|
|
1292
|
+
import { Icon } from "@iconify/react";
|
|
1293
|
+
|
|
1294
|
+
function ColorFieldRenderer({ value, onChange }) {
|
|
1295
|
+
return (
|
|
1296
|
+
<div className="flex items-center gap-2">
|
|
1297
|
+
<input
|
|
1298
|
+
type="color"
|
|
1299
|
+
value={value || "#000000"}
|
|
1300
|
+
onChange={(e) => onChange(e.target.value)}
|
|
1301
|
+
className="w-10 h-10 border border-border cursor-pointer"
|
|
1302
|
+
/>
|
|
1303
|
+
<span className="font-mono text-sm text-muted-foreground">
|
|
1304
|
+
{value || "#000000"}
|
|
1305
|
+
</span>
|
|
1306
|
+
</div>
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
1309
|
+
```
|
|
1310
|
+
|
|
1311
|
+
### Cell Renderer
|
|
1312
|
+
|
|
1313
|
+
For custom table column rendering, provide a `cell` component alongside the field renderer:
|
|
1314
|
+
|
|
1315
|
+
```tsx title="admin/fields/color.tsx"
|
|
1316
|
+
// Cell component for list view table
|
|
1317
|
+
export function ColorCell({ value }) {
|
|
1318
|
+
return (
|
|
1319
|
+
<div className="flex items-center gap-2">
|
|
1320
|
+
<div
|
|
1321
|
+
className="w-4 h-4 border border-border"
|
|
1322
|
+
style={{ backgroundColor: value || "transparent" }}
|
|
1323
|
+
/>
|
|
1324
|
+
<span className="text-xs font-mono">{value}</span>
|
|
1325
|
+
</div>
|
|
1326
|
+
);
|
|
1327
|
+
}
|
|
1328
|
+
```
|
|
1329
|
+
|
|
1330
|
+
## Custom Views
|
|
1331
|
+
|
|
1332
|
+
Create view types beyond built-in table and form — kanban boards, calendars, galleries.
|
|
1333
|
+
|
|
1334
|
+
### Server-Side Declaration
|
|
1335
|
+
|
|
1336
|
+
```ts
|
|
1337
|
+
const myModule = module({
|
|
1338
|
+
name: "custom-views",
|
|
1339
|
+
views: {
|
|
1340
|
+
kanban: kanbanViewDefinition,
|
|
1341
|
+
calendar: calendarViewDefinition,
|
|
1342
|
+
},
|
|
1343
|
+
});
|
|
1344
|
+
```
|
|
1345
|
+
|
|
1346
|
+
### Usage in Collections
|
|
1347
|
+
|
|
1348
|
+
```ts
|
|
1349
|
+
.list(({ v }) => v.kanban({
|
|
1350
|
+
columns: "status",
|
|
1351
|
+
cardTitle: "title",
|
|
1352
|
+
}))
|
|
1353
|
+
```
|
|
1354
|
+
|
|
1355
|
+
### Client Rendering
|
|
1356
|
+
|
|
1357
|
+
```tsx title="admin/views/kanban.tsx"
|
|
1358
|
+
function KanbanView({ data, columns, onDrop }) {
|
|
1359
|
+
return (
|
|
1360
|
+
<div className="flex gap-4">
|
|
1361
|
+
{columns.map((col) => (
|
|
1362
|
+
<div key={col.id} className="flex-1">
|
|
1363
|
+
<h3 className="font-mono text-sm font-semibold mb-2">{col.label}</h3>
|
|
1364
|
+
{data
|
|
1365
|
+
.filter((item) => item.status === col.id)
|
|
1366
|
+
.map((item) => (
|
|
1367
|
+
<div
|
|
1368
|
+
key={item.id}
|
|
1369
|
+
className="border border-border bg-card p-3 mb-2"
|
|
1370
|
+
>
|
|
1371
|
+
{item.title}
|
|
1372
|
+
</div>
|
|
1373
|
+
))}
|
|
1374
|
+
</div>
|
|
1375
|
+
))}
|
|
1376
|
+
</div>
|
|
1377
|
+
);
|
|
1378
|
+
}
|
|
1379
|
+
```
|
|
1380
|
+
|
|
1381
|
+
## Reactive Field System
|
|
1382
|
+
|
|
1383
|
+
Fields support reactive behaviors configured in the collection's `.form()` view or on the field definition itself.
|
|
1384
|
+
|
|
1385
|
+
### Conditional Visibility
|
|
1386
|
+
|
|
1387
|
+
```ts
|
|
1388
|
+
{
|
|
1389
|
+
field: f.cancellationReason,
|
|
1390
|
+
hidden: ({ data }) => data.status !== "cancelled",
|
|
1391
|
+
}
|
|
1392
|
+
```
|
|
1393
|
+
|
|
1394
|
+
### Read-Only
|
|
1395
|
+
|
|
1396
|
+
```ts
|
|
1397
|
+
{
|
|
1398
|
+
field: f.customerName,
|
|
1399
|
+
readOnly: ({ data }) => !!data.customer,
|
|
1400
|
+
}
|
|
1401
|
+
```
|
|
1402
|
+
|
|
1403
|
+
### Computed Values
|
|
1404
|
+
|
|
1405
|
+
```ts
|
|
1406
|
+
{
|
|
1407
|
+
field: f.slug,
|
|
1408
|
+
compute: {
|
|
1409
|
+
handler: ({ data }) => {
|
|
1410
|
+
if (data.name && !data.slug?.trim()) {
|
|
1411
|
+
return slugify(data.name);
|
|
1412
|
+
}
|
|
1413
|
+
return undefined;
|
|
1414
|
+
},
|
|
1415
|
+
deps: ({ data }) => [data.name, data.slug],
|
|
1416
|
+
debounce: 300,
|
|
1417
|
+
},
|
|
1418
|
+
}
|
|
1419
|
+
```
|
|
1420
|
+
|
|
1421
|
+
### Dynamic Options (Server-Side)
|
|
1422
|
+
|
|
1423
|
+
For select/relation fields with options that depend on other field values:
|
|
1424
|
+
|
|
1425
|
+
```ts
|
|
1426
|
+
city: f.relation("cities").admin({
|
|
1427
|
+
options: {
|
|
1428
|
+
handler: async ({ data, search, ctx }) => {
|
|
1429
|
+
const cities = await ctx.db.query.cities.findMany({
|
|
1430
|
+
where: { countryId: data.country },
|
|
1431
|
+
});
|
|
1432
|
+
return {
|
|
1433
|
+
options: cities.map((c) => ({ value: c.id, label: c.name })),
|
|
1434
|
+
};
|
|
1435
|
+
},
|
|
1436
|
+
deps: ({ data }) => [data.country],
|
|
1437
|
+
},
|
|
1438
|
+
}),
|
|
1439
|
+
```
|
|
1440
|
+
|
|
1441
|
+
The `handler` runs **server-side** with full access to `ctx.db`, `ctx.user`, `ctx.req`. It re-executes when any value in `deps` changes.
|
|
1442
|
+
|
|
1443
|
+
## UI Component Reference
|
|
1444
|
+
|
|
1445
|
+
When building custom admin UI, use these patterns:
|
|
1446
|
+
|
|
1447
|
+
### Icons
|
|
1448
|
+
|
|
1449
|
+
```tsx
|
|
1450
|
+
import { Icon } from "@iconify/react";
|
|
1451
|
+
|
|
1452
|
+
// Phosphor icon set with ph: prefix
|
|
1453
|
+
<Icon icon="ph:house" width={20} height={20} />
|
|
1454
|
+
<Icon icon="ph:caret-down-bold" width={16} height={16} /> // bold weight
|
|
1455
|
+
<Icon icon="ph:heart-fill" width={16} height={16} /> // fill weight
|
|
1456
|
+
```
|
|
1457
|
+
|
|
1458
|
+
### Toasts
|
|
1459
|
+
|
|
1460
|
+
```tsx
|
|
1461
|
+
import { toast } from "sonner";
|
|
1462
|
+
|
|
1463
|
+
toast.success("Record saved");
|
|
1464
|
+
toast.error("Failed to save");
|
|
1465
|
+
```
|
|
1466
|
+
|
|
1467
|
+
### Primitives (base-ui)
|
|
1468
|
+
|
|
1469
|
+
```tsx
|
|
1470
|
+
// CORRECT — render prop
|
|
1471
|
+
<DialogTrigger render={<Button>Open</Button>} />
|
|
1472
|
+
|
|
1473
|
+
// WRONG — asChild is Radix, not base-ui
|
|
1474
|
+
<DialogTrigger asChild><Button>Open</Button></DialogTrigger>
|
|
1475
|
+
```
|
|
1476
|
+
|
|
1477
|
+
### Responsive Components
|
|
1478
|
+
|
|
1479
|
+
- `ResponsivePopover` — Popover on desktop, Drawer on mobile
|
|
1480
|
+
- `ResponsiveDialog` — Dialog on desktop, fullscreen Drawer on mobile
|
|
1481
|
+
- Hooks: `useIsMobile()`, `useIsDesktop()`, `useMediaQuery()`
|
|
1482
|
+
|
|
1483
|
+
## Common Mistakes
|
|
1484
|
+
|
|
1485
|
+
1. **HIGH: Not registering custom field in the field registry** — if codegen doesn't discover the field renderer file, the admin will render nothing for that field type. Place it in `questpie/admin/fields/<name>.tsx`.
|
|
1486
|
+
|
|
1487
|
+
2. **HIGH: Missing `cell` component for custom fields** — without a cell component, the list view table shows raw values for your custom field instead of a formatted display.
|
|
1488
|
+
|
|
1489
|
+
3. **MEDIUM: Reactive field handlers running client-side** — `options.handler`, `compute.handler`, and other reactive handlers run **SERVER-SIDE** with access to `ctx.db`, `ctx.user`. Do not import client-side modules or use browser APIs in them.
|
|
1490
|
+
|
|
1491
|
+
4. **MEDIUM: Using `onChange` wrong in field components** — the field renderer receives `onChange` that expects the **value directly**, not a DOM event.
|
|
1492
|
+
|
|
1493
|
+
```tsx
|
|
1494
|
+
// WRONG
|
|
1495
|
+
onChange={(e) => onChange(e)}
|
|
1496
|
+
// CORRECT
|
|
1497
|
+
onChange={(e) => onChange(e.target.value)}
|
|
1498
|
+
// Or for non-DOM values:
|
|
1499
|
+
onChange={newValue}
|
|
1500
|
+
```
|
|
1501
|
+
|
|
1502
|
+
5. **MEDIUM: Importing from `@radix-ui/*`** — QUESTPIE admin uses `@base-ui/react`. Never import Radix primitives.
|
|
1503
|
+
|
|
1504
|
+
6. **MEDIUM: Using `@phosphor-icons/react` or `lucide-react`** — use `@iconify/react` with `ph:` prefix for all icons.
|
|
1505
|
+
|
|
1506
|
+
7. **LOW: Not using shadcn components** — prefer `<Button>`, `<Card>`, `<Input>` from the shadcn component library instead of raw HTML elements. The admin has a consistent brutalist design system.
|
|
1507
|
+
|
|
1508
|
+
---
|