create-questpie 2.0.0 → 2.0.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.
Files changed (45) hide show
  1. package/README.md +10 -6
  2. package/dist/index.mjs +140 -25
  3. package/package.json +5 -3
  4. package/skills/questpie/AGENTS.md +2664 -0
  5. package/skills/questpie/SKILL.md +181 -0
  6. package/skills/questpie/references/auth.md +121 -0
  7. package/skills/questpie/references/business-logic.md +550 -0
  8. package/skills/questpie/references/codegen-plugin-api.md +382 -0
  9. package/skills/questpie/references/crud-api.md +378 -0
  10. package/skills/questpie/references/data-modeling.md +489 -0
  11. package/skills/questpie/references/extend.md +493 -0
  12. package/skills/questpie/references/field-types.md +386 -0
  13. package/skills/questpie/references/infrastructure-adapters.md +545 -0
  14. package/skills/questpie/references/multi-tenancy.md +364 -0
  15. package/skills/questpie/references/production.md +475 -0
  16. package/skills/questpie/references/query-operators.md +125 -0
  17. package/skills/questpie/references/quickstart.md +549 -0
  18. package/skills/questpie/references/rules.md +327 -0
  19. package/skills/questpie/references/tanstack-query.md +520 -0
  20. package/skills/questpie-admin/AGENTS.md +1442 -0
  21. package/skills/questpie-admin/SKILL.md +410 -0
  22. package/skills/questpie-admin/references/blocks.md +307 -0
  23. package/skills/questpie-admin/references/custom-ui.md +305 -0
  24. package/skills/questpie-admin/references/views.md +433 -0
  25. package/templates/tanstack-start/AGENTS.md +71 -62
  26. package/templates/tanstack-start/CLAUDE.md +26 -23
  27. package/templates/tanstack-start/README.md +32 -20
  28. package/templates/tanstack-start/env.example +1 -1
  29. package/templates/tanstack-start/package.json +20 -6
  30. package/templates/tanstack-start/src/lib/client.ts +2 -2
  31. package/templates/tanstack-start/src/lib/env.ts +1 -1
  32. package/templates/tanstack-start/src/questpie/admin/.generated/client.ts +13 -0
  33. package/templates/tanstack-start/src/questpie/admin/modules.ts +1 -0
  34. package/templates/tanstack-start/src/questpie/server/.generated/factories.ts +117 -241
  35. package/templates/tanstack-start/src/questpie/server/.generated/index.ts +129 -81
  36. package/templates/tanstack-start/src/questpie/server/app.ts +1 -1
  37. package/templates/tanstack-start/src/questpie/server/config/admin.ts +27 -30
  38. package/templates/tanstack-start/src/questpie/server/globals/site-settings.global.ts +1 -1
  39. package/templates/tanstack-start/src/questpie/server/questpie.config.ts +1 -1
  40. package/templates/tanstack-start/src/routeTree.gen.ts +138 -0
  41. package/templates/tanstack-start/src/routes/__root.tsx +0 -2
  42. package/templates/tanstack-start/src/routes/admin.tsx +8 -1
  43. package/templates/tanstack-start/src/tanstack-start.d.ts +1 -0
  44. package/templates/tanstack-start/src/vite-env.d.ts +1 -0
  45. package/templates/tanstack-start/vite.config.ts +1 -3
@@ -0,0 +1,433 @@
1
+ ---
2
+ name: questpie-admin/views
3
+ description: QUESTPIE admin views list-view table form-view sections sidebar dashboard widgets filters bulk-actions visibility history versioning sorting search
4
+ ---
5
+
6
+ # QUESTPIE Admin Views
7
+
8
+ This skill builds on questpie-admin.
9
+
10
+ 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.
11
+
12
+ ```text
13
+ Server Config Admin UI
14
+ .list(({ v }) => v.collectionTable({})) -> Table with columns, sort, search
15
+ .form(({ v, f }) => v.collectionForm({})) -> Form with sections, sidebar, tabs
16
+ sidebar({...}) -> Navigation sidebar
17
+ dashboard({...}) -> Dashboard with widgets
18
+ ```
19
+
20
+ ## List Views
21
+
22
+ Configure table views with `.list()` on a collection.
23
+
24
+ ### Basic Table
25
+
26
+ ```ts
27
+ .list(({ v }) => v.collectionTable({}))
28
+ ```
29
+
30
+ Shows all fields as columns with default rendering.
31
+
32
+ ### Custom Columns and Search
33
+
34
+ ```ts
35
+ .list(({ v, f }) =>
36
+ v.collectionTable({
37
+ columns: [f.name, f.email, f.isActive, f.createdAt],
38
+ searchableFields: [f.name, f.email],
39
+ defaultSort: { field: f.createdAt, direction: "desc" },
40
+ }),
41
+ )
42
+ ```
43
+
44
+ | Option | Type | Description |
45
+ | ------------------ | ---------------------- | ------------------------------ |
46
+ | `columns` | `Field[]` | Fields to show as columns |
47
+ | `searchableFields` | `Field[]` | Fields included in text search |
48
+ | `defaultSort` | `{ field, direction }` | Default sort order |
49
+
50
+ ## Form Views
51
+
52
+ Configure edit forms with `.form()`.
53
+
54
+ ### Basic Form
55
+
56
+ ```ts
57
+ .form(({ v, f }) => v.collectionForm({}))
58
+ ```
59
+
60
+ Renders all fields in a single column.
61
+
62
+ ### Sections
63
+
64
+ Group fields into labeled sections with optional grid layout:
65
+
66
+ ```ts
67
+ .form(({ v, f }) =>
68
+ v.collectionForm({
69
+ fields: [
70
+ {
71
+ type: "section",
72
+ label: { en: "Contact Information" },
73
+ layout: "grid",
74
+ columns: 2,
75
+ fields: [f.name, f.email, f.phone],
76
+ },
77
+ {
78
+ type: "section",
79
+ label: { en: "Profile" },
80
+ fields: [f.bio],
81
+ },
82
+ ],
83
+ }),
84
+ )
85
+ ```
86
+
87
+ | Option | Type | Description |
88
+ | ------------- | ------------------- | ------------------------------------ |
89
+ | `type` | `"section"` | Required |
90
+ | `label` | `string \| i18n` | Section heading |
91
+ | `description` | `string \| i18n` | Section description |
92
+ | `layout` | `"grid" \| "stack"` | Field layout |
93
+ | `columns` | `number` | Grid columns (with `layout: "grid"`) |
94
+ | `fields` | `Field[]` | Fields in this section |
95
+
96
+ ### Form Sidebar
97
+
98
+ Place fields in a right sidebar panel:
99
+
100
+ ```ts
101
+ .form(({ v, f }) =>
102
+ v.collectionForm({
103
+ sidebar: {
104
+ position: "right",
105
+ fields: [f.isActive, f.avatar, f.status],
106
+ },
107
+ fields: [ /* main content sections */ ],
108
+ }),
109
+ )
110
+ ```
111
+
112
+ ### Computed Fields
113
+
114
+ Auto-compute values from other fields:
115
+
116
+ ```ts
117
+ {
118
+ field: f.slug,
119
+ compute: {
120
+ handler: ({ data }) => {
121
+ if (data.name && !data.slug?.trim()) {
122
+ return slugify(data.name);
123
+ }
124
+ return undefined;
125
+ },
126
+ deps: ({ data }) => [data.name, data.slug],
127
+ debounce: 300,
128
+ },
129
+ }
130
+ ```
131
+
132
+ | Option | Type | Description |
133
+ | ---------- | ---------------- | ------------------------ |
134
+ | `handler` | `(ctx) => value` | Compute function |
135
+ | `deps` | `(ctx) => any[]` | Reactive dependencies |
136
+ | `debounce` | `number` | Debounce in milliseconds |
137
+
138
+ ### Conditional Visibility
139
+
140
+ Show or hide fields based on other field values:
141
+
142
+ ```ts
143
+ {
144
+ field: f.cancellationReason,
145
+ hidden: ({ data }) => data.status !== "cancelled",
146
+ }
147
+ ```
148
+
149
+ Read-only fields:
150
+
151
+ ```ts
152
+ {
153
+ field: f.customerName,
154
+ readOnly: ({ data }) => !!data.customer,
155
+ }
156
+ ```
157
+
158
+ Section-level visibility:
159
+
160
+ ```ts
161
+ {
162
+ type: "section",
163
+ label: { en: "SEO" },
164
+ hidden: ({ data }) => !data.isPublished,
165
+ fields: [f.metaTitle, f.metaDescription],
166
+ }
167
+ ```
168
+
169
+ ## Dashboard
170
+
171
+ Configure in `config/admin.ts` under the `dashboard` key:
172
+
173
+ ```ts title="config/admin.ts"
174
+ import { adminConfig } from "#questpie/factories";
175
+
176
+ export default adminConfig({
177
+ dashboard: {
178
+ title: { en: "Dashboard" },
179
+ description: { en: "Overview of your app" },
180
+ columns: 4,
181
+ actions: [
182
+ {
183
+ id: "new-post",
184
+ href: "/admin/collections/posts?create=true",
185
+ label: { en: "New Post" },
186
+ icon: { type: "icon", props: { name: "ph:plus" } },
187
+ variant: "primary",
188
+ },
189
+ ],
190
+ sections: [
191
+ { id: "today", label: { en: "Today" }, layout: "grid", columns: 4 },
192
+ { id: "business", label: { en: "Business" }, layout: "grid", columns: 4 },
193
+ ],
194
+ items: [
195
+ /* widget items — see widget types below */
196
+ ],
197
+ },
198
+ });
199
+ ```
200
+
201
+ ### Widget Types
202
+
203
+ **Stats** — count records with optional filter:
204
+
205
+ ```ts
206
+ {
207
+ sectionId: "today",
208
+ id: "pending",
209
+ type: "stats",
210
+ collection: "appointments",
211
+ label: { en: "Pending" },
212
+ filter: { status: "pending" },
213
+ span: 1,
214
+ }
215
+ ```
216
+
217
+ **Value** — custom-loaded value with trend:
218
+
219
+ ```ts
220
+ {
221
+ sectionId: "business",
222
+ id: "revenue",
223
+ type: "value",
224
+ span: 2,
225
+ refreshInterval: 1000 * 60 * 5,
226
+ loader: async ({ app }) => ({
227
+ value: 42000,
228
+ formatted: "42,000 EUR",
229
+ label: { en: "Monthly Revenue" },
230
+ trend: { value: "+12%" },
231
+ }),
232
+ }
233
+ ```
234
+
235
+ **Progress** — progress bar toward a goal:
236
+
237
+ ```ts
238
+ {
239
+ sectionId: "business",
240
+ id: "goal",
241
+ type: "progress",
242
+ span: 1,
243
+ showPercentage: true,
244
+ label: { en: "Monthly Goal" },
245
+ loader: async ({ app }) => ({ current: 350, target: 500 }),
246
+ }
247
+ ```
248
+
249
+ **Chart** — chart from field values:
250
+
251
+ ```ts
252
+ {
253
+ sectionId: "business",
254
+ id: "by-status",
255
+ type: "chart",
256
+ collection: "appointments",
257
+ field: "status",
258
+ chartType: "pie",
259
+ label: { en: "By Status" },
260
+ span: 1,
261
+ }
262
+ ```
263
+
264
+ **Recent Items** — list recent records:
265
+
266
+ ```ts
267
+ {
268
+ sectionId: "ops",
269
+ id: "recent",
270
+ type: "recentItems",
271
+ collection: "appointments",
272
+ label: { en: "Recent" },
273
+ limit: 6,
274
+ dateField: "scheduledAt",
275
+ span: 2,
276
+ }
277
+ ```
278
+
279
+ **Timeline** — activity stream:
280
+
281
+ ```ts
282
+ {
283
+ sectionId: "ops",
284
+ id: "activity",
285
+ type: "timeline",
286
+ label: { en: "Activity" },
287
+ maxItems: 8,
288
+ showTimestamps: true,
289
+ timestampFormat: "relative",
290
+ loader: async ({ app }) => {
291
+ const res = await app.collections.appointments.find({
292
+ limit: 8,
293
+ orderBy: { updatedAt: "desc" },
294
+ });
295
+ return res.docs.map((apt) => ({
296
+ id: apt.id,
297
+ title: apt.displayTitle,
298
+ description: `Status: ${apt.status}`,
299
+ timestamp: apt.updatedAt,
300
+ variant: apt.status === "completed" ? "success" : "warning",
301
+ href: `/admin/collections/appointments/${apt.id}`,
302
+ }));
303
+ },
304
+ span: 2,
305
+ }
306
+ ```
307
+
308
+ ## Sidebar
309
+
310
+ Configure in `config/admin.ts` under the `sidebar` key:
311
+
312
+ ```ts title="config/admin.ts"
313
+ import { adminConfig } from "#questpie/factories";
314
+
315
+ export default adminConfig({
316
+ sidebar: {
317
+ sections: [
318
+ { id: "overview", title: { en: "Overview" } },
319
+ { id: "content", title: { en: "Content" } },
320
+ { id: "external", title: { en: "External" } },
321
+ ],
322
+ items: [
323
+ {
324
+ sectionId: "overview",
325
+ type: "link",
326
+ label: { en: "Dashboard" },
327
+ href: "/admin",
328
+ icon: { type: "icon", props: { name: "ph:house" } },
329
+ },
330
+ { sectionId: "overview", type: "global", global: "siteSettings" },
331
+ { sectionId: "content", type: "collection", collection: "posts" },
332
+ {
333
+ sectionId: "external",
334
+ type: "link",
335
+ label: { en: "Open Website" },
336
+ href: "/",
337
+ external: true,
338
+ icon: { type: "icon", props: { name: "ph:arrow-square-out" } },
339
+ },
340
+ ],
341
+ },
342
+ });
343
+ ```
344
+
345
+ Items appear in definition order within their section.
346
+
347
+ Modules contribute sidebar items automatically. `adminModule` adds "Administration" with user management. `auditModule` adds an audit log item.
348
+
349
+ ## Filters & Saved Views
350
+
351
+ Filters are auto-generated from field definitions:
352
+
353
+ | Field Type | Filter Operators |
354
+ | ------------------- | ---------------------------------------- |
355
+ | `text` | Contains, equals, starts with, ends with |
356
+ | `number` | Equals, greater than, less than, between |
357
+ | `boolean` | Is true, is false |
358
+ | `select` | Is, is not, in |
359
+ | `date` / `datetime` | Before, after, between |
360
+ | `relation` | Is (picker) |
361
+
362
+ Users can save filter + sort + column combinations as named views.
363
+
364
+ ## Bulk Actions
365
+
366
+ 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.
367
+
368
+ ## History & Versions
369
+
370
+ Click the clock icon in the form toolbar. Two tabs:
371
+
372
+ | Tab | Shows | Requires |
373
+ | ------------ | ---------------------------------------------- | ----------------------------- |
374
+ | **Activity** | Audit log (create, update, delete, transition) | `auditModule` |
375
+ | **Versions** | Full document snapshots with restore | `.versioning()` on collection |
376
+
377
+ Enable versioning:
378
+
379
+ ```ts
380
+ export const pages = collection("pages")
381
+ .fields(({ f }) => ({ ... }))
382
+ .options({ versioning: true });
383
+ ```
384
+
385
+ Disable audit for a specific collection:
386
+
387
+ ```ts
388
+ export const logs = collection("logs")
389
+ .admin(() => ({ audit: false }))
390
+ .fields(({ f }) => ({ ... }));
391
+ ```
392
+
393
+ ## Common Mistakes
394
+
395
+ 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.
396
+
397
+ 2. **MEDIUM: Not specifying `searchableFields`** — table search bar won't work unless you explicitly list which fields to search.
398
+
399
+ 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.
400
+
401
+ 4. **MEDIUM: Missing `sectionId` on sidebar items** — every item must reference an existing section ID.
402
+
403
+ 5. **LOW: Not setting `defaultSort`** — records appear in database insertion order which is usually not what users expect.
404
+
405
+ ## Form Views and Live Preview
406
+
407
+ Form views connect to the Live Preview V2 system when the collection has `.preview()` configured. The form editor becomes the source of `postMessage` patches — every field change emits a patch through the bus, giving the preview iframe instant updates.
408
+
409
+ ### Enabling Preview on a Collection
410
+
411
+ Add `.preview()` to the collection definition:
412
+
413
+ ```ts
414
+ export const pages = collection("pages")
415
+ .fields(({ f }) => ({
416
+ title: f.text().required().localized(),
417
+ slug: f.text().required(),
418
+ content: f.blocks().localized(),
419
+ }))
420
+ .preview({
421
+ enabled: true,
422
+ position: "right",
423
+ defaultWidth: 50,
424
+ url: ({ record }) => `/${record.slug}?preview=true`,
425
+ });
426
+ ```
427
+
428
+ ### How It Works
429
+
430
+ 1. The form view detects `.preview()` config and opens a split-screen layout
431
+ 2. Save/autosave sends a `PREVIEW_REFRESH` message to the preview iframe
432
+ 3. The preview page handles refreshes through `useCollectionPreview({ initialData, onRefresh })`
433
+ 4. `PreviewProvider` and `PreviewField` wire field focus and click-to-focus messages