@donotdev/cli 0.1.0 → 0.1.1

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 (93) hide show
  1. package/dependencies-matrix.json +100 -50
  2. package/dist/bin/commands/agent-setup.js +245 -12
  3. package/dist/bin/commands/build.js +3339 -208
  4. package/dist/bin/commands/bump.js +245 -12
  5. package/dist/bin/commands/cacheout.js +245 -12
  6. package/dist/bin/commands/coach.js +361 -60
  7. package/dist/bin/commands/create-app.js +245 -12
  8. package/dist/bin/commands/create-project.js +253 -12
  9. package/dist/bin/commands/db.js +9114 -2327
  10. package/dist/bin/commands/deploy.js +4074 -694
  11. package/dist/bin/commands/dev.js +347 -33
  12. package/dist/bin/commands/doctor.js +408 -107
  13. package/dist/bin/commands/emu.js +386 -52
  14. package/dist/bin/commands/format.js +245 -12
  15. package/dist/bin/commands/get-demo.js +245 -12
  16. package/dist/bin/commands/make-admin.js +8356 -1516
  17. package/dist/bin/commands/preview.js +347 -33
  18. package/dist/bin/commands/seed.js +9114 -2327
  19. package/dist/bin/commands/setup-cicd.js +452 -132
  20. package/dist/bin/commands/setup.js +407 -107
  21. package/dist/bin/commands/staging.js +4074 -694
  22. package/dist/bin/commands/sync-secrets.js +246 -13
  23. package/dist/bin/commands/type-check.js +245 -12
  24. package/dist/bin/commands/wai.js +245 -12
  25. package/dist/bin/dndev.js +13 -4
  26. package/dist/bin/donotdev.js +13 -4
  27. package/dist/index.js +4169 -812
  28. package/{templates/root-consumer/guides/dndev/advanced/VERSION_CONTROL.md.example → guidelines/VERSION_CONTROL.md} +7 -11
  29. package/package.json +2 -1
  30. package/templates/app-demo/src/themes.css.example +21 -0
  31. package/templates/app-dndev/index.html.example +0 -3
  32. package/templates/app-dndev/src/themes.css.example +21 -0
  33. package/templates/app-next/src/app/layout.tsx.example +13 -4
  34. package/templates/app-next/src/themes.css.example +21 -0
  35. package/templates/app-vite/csp.example.json +44 -0
  36. package/templates/app-vite/index.html.example +0 -3
  37. package/templates/app-vite/src/themes.css.example +21 -0
  38. package/templates/functions-supabase/supabase/migrations/20250101000000_idempotency.sql +3 -0
  39. package/templates/functions-supabase/supabase/migrations/20250101000001_rate_limits.sql +3 -0
  40. package/templates/functions-supabase/supabase/migrations/20250101000003_operation_metrics.sql +3 -0
  41. package/templates/root-consumer/.claude/hooks/framework-compliance.sh.example +56 -0
  42. package/templates/root-consumer/.claude/hooks/guard-bash.sh.example +61 -0
  43. package/templates/root-consumer/.claude/hooks/guard-files.sh.example +46 -0
  44. package/templates/root-consumer/.claude/hooks/guard-mcp.sh.example +91 -0
  45. package/templates/root-consumer/.claude/hooks/guard-secrets.sh.example +67 -0
  46. package/templates/root-consumer/.claude/hooks/guard-write.sh.example +89 -0
  47. package/templates/root-consumer/.claude/hooks/session-start.sh.example +50 -0
  48. package/templates/root-consumer/.claude/hooks/track-mcp-lookup.sh.example +20 -0
  49. package/templates/root-consumer/.claude/hooks/typecheck-stop.sh.example +18 -0
  50. package/templates/root-consumer/.claude/rules/consumer-ux.md.example +32 -0
  51. package/templates/root-consumer/.claude/rules/definition-of-done.md.example +32 -0
  52. package/templates/root-consumer/.claude/rules/framework.md.example +39 -0
  53. package/templates/root-consumer/.claude/rules/git.md.example +14 -0
  54. package/templates/root-consumer/.claude/rules/security.md.example +13 -0
  55. package/templates/root-consumer/.claude/settings.json.example +123 -1
  56. package/templates/root-consumer/.claude/skills/build/SKILL.md.example +103 -25
  57. package/templates/root-consumer/.claude/skills/grill/SKILL.md.example +26 -15
  58. package/templates/root-consumer/.claude/skills/polish/SKILL.md.example +50 -37
  59. package/templates/root-consumer/AI.md.example +2 -2
  60. package/templates/root-consumer/CLAUDE.md.example +33 -1
  61. package/templates/root-consumer/guides/dndev/INDEX.md.example +23 -27
  62. package/templates/root-consumer/guides/dndev/SETUP_AUTH.md.example +3 -2
  63. package/templates/root-consumer/guides/dndev/SETUP_OAUTH.md.example +10 -5
  64. package/templates/root-consumer/guides/dndev/SETUP_SUPABASE.md.example +50 -3
  65. package/templates/root-consumer/guides/wai-way/blueprints/3_compose.md.example +13 -15
  66. package/templates/app-demo/public/manifest.json.example +0 -10
  67. package/templates/app-dndev/public/manifest.json.example +0 -10
  68. package/templates/root-consumer/.claude/commands/brainstorm.md.example +0 -175
  69. package/templates/root-consumer/.claude/commands/build.md.example +0 -131
  70. package/templates/root-consumer/.claude/commands/design.md.example +0 -184
  71. package/templates/root-consumer/.claude/commands/grill.md.example +0 -135
  72. package/templates/root-consumer/.claude/commands/polish.md.example +0 -146
  73. package/templates/root-consumer/.claude/commands/techdebt.md.example +0 -28
  74. package/templates/root-consumer/guides/dndev/COMPONENTS_ATOMIC.md.example +0 -180
  75. package/templates/root-consumer/guides/dndev/COMPONENTS_CRUD.md.example +0 -234
  76. package/templates/root-consumer/guides/dndev/COMPONENTS_UI.md.example +0 -136
  77. package/templates/root-consumer/guides/dndev/COMPONENT_API.md.example +0 -195
  78. package/templates/root-consumer/guides/dndev/ENV_SETUP.md.example +0 -219
  79. package/templates/root-consumer/guides/dndev/GOTCHAS.md.example +0 -197
  80. package/templates/root-consumer/guides/dndev/SETUP_APP_CONFIG.md.example +0 -132
  81. package/templates/root-consumer/guides/dndev/SETUP_BLOG.md.example +0 -280
  82. package/templates/root-consumer/guides/dndev/SETUP_CICD.md.example +0 -115
  83. package/templates/root-consumer/guides/dndev/SETUP_CRUD.md.example +0 -334
  84. package/templates/root-consumer/guides/dndev/SETUP_FUNCTIONS.md.example +0 -9
  85. package/templates/root-consumer/guides/dndev/SETUP_I18N.md.example +0 -233
  86. package/templates/root-consumer/guides/dndev/SETUP_LAYOUTS.md.example +0 -158
  87. package/templates/root-consumer/guides/dndev/SETUP_PAGES.md.example +0 -205
  88. package/templates/root-consumer/guides/dndev/SETUP_PWA.md.example +0 -213
  89. package/templates/root-consumer/guides/dndev/SETUP_TESTING.md.example +0 -184
  90. package/templates/root-consumer/guides/dndev/SETUP_THEMES.md.example +0 -111
  91. package/templates/root-consumer/guides/dndev/SETUP_VERCEL.md.example +0 -260
  92. package/templates/root-consumer/guides/dndev/USE_ROUTING.md.example +0 -499
  93. package/templates/root-consumer/guides/dndev/essences_reference.css.example +0 -288
@@ -1,146 +0,0 @@
1
- ---
2
- description: Generate tests, firestore rules, CI/CD, config, fix bugs, i18n (Phase 4) - AFTER /build
3
- ---
4
-
5
- # Polish Command - Production-Ready App
6
-
7
- **⚠️ MODE CHECK:** This command is for **Consumer App Development** only.
8
-
9
- **If you're in the framework monorepo (this repo):**
10
- - ❌ **DO NOT use `/polish`** - framework dev doesn't use this workflow
11
- - ✅ See [Modes Guide](https://github.com/donotdev/framework/blob/main/docs/development/MODES.md) for framework dev workflow
12
-
13
- **If you're in a consumer repo:**
14
- - ✅ Use `/polish` after `/build` is complete
15
- - ✅ Use `/polish` to generate tests, firestore rules, CI/CD
16
- - ✅ Use `/polish` to fix bugs, add styling, add i18n
17
- - ✅ Use `/polish` to finalize configuration
18
-
19
- **WORKFLOW ORDER:**
20
- 1. `/brainstorm` → Extract requirements, generate spec
21
- 2. `/design` → Create technical plan
22
- 3. `/build` → Implement code using framework defaults
23
- 4. `/polish` → Generate tests, config, CI/CD, fix bugs (THIS COMMAND)
24
-
25
- ---
26
-
27
- ## Usage
28
-
29
- ```
30
- /polish [task]
31
- ```
32
-
33
- **Examples:**
34
- ```
35
- /polish Generate all tests and firestore rules
36
- /polish Fix bug: Projects list is empty
37
- /polish Add French and Spanish translations
38
- /polish Complete configuration and deploy
39
- ```
40
-
41
- ---
42
-
43
- ## Process
44
-
45
- ### Step 0: Start Phase (MANDATORY — DO THIS FIRST)
46
-
47
- **BEFORE any polish work**, call:
48
- ```
49
- start_phase(4)
50
- ```
51
- This activates Phase 4: CONFIGURE and loads the blueprint, persona, context, and lessons. **Do NOT proceed without this call.**
52
-
53
- ### Step 1: Activate Polisher Agent
54
-
55
- **Deploy:** `/agents polisher` (Phase 4 Polisher persona)
56
-
57
- **READ first:**
58
- - `guides/wai-way/spec_template.md` — validated spec (your test plan)
59
- - `entities/index.ts` — all entity definitions
60
- - `src/pages/` — all page files
61
- - `guides/dndev/SETUP_TESTING.md` — testing patterns
62
-
63
- ### Step 2: Generate Tests
64
-
65
- Call `get_guide("TESTING")` for patterns.
66
-
67
- 1. **Entity tests** — one per entity in `tests/entities/[Entity].test.ts`
68
- 2. **Page tests** — one per page in `tests/pages/[Page].test.tsx`
69
- 3. **Access control tests** — `tests/access/access-rules.test.ts`
70
-
71
- ### Step 3: Generate Firestore Rules
72
-
73
- Create `firestore.rules` from entity access definitions.
74
-
75
- ### Step 4: Generate CI/CD
76
-
77
- Create `.github/workflows/ci.yml` — type-check → test → build → deploy.
78
-
79
- ### Step 5: Configure
80
-
81
- - `src/config/app.ts` — APP_NAME, preset, footer
82
- - `src/config/legal.ts` — company, contacts, jurisdiction
83
- - `.env` — Firebase config, license key
84
-
85
- ### Step 6: Run Tests
86
-
87
- ```bash
88
- bun test
89
- ```
90
-
91
- All tests must pass.
92
-
93
- ### Step 7: Fix Bugs (if any)
94
-
95
- - Understand → Diagnose → Fix (minimal) → Verify → Check regressions
96
-
97
- ### Step 8: Mobile Check
98
-
99
- DevTools → 375px → navigation, forms, text, buttons (44px)
100
-
101
- ### Step 9: i18n (Optional)
102
-
103
- Extract strings to `src/locales/`, replace with `useTranslation()`.
104
-
105
- ---
106
-
107
- ## What Polisher Does
108
-
109
- | Task | Description |
110
- |------|-------------|
111
- | **Test Generation** | Entity tests, page tests, access tests from spec |
112
- | **Firestore Rules** | Security rules from entity access definitions |
113
- | **CI/CD** | GitHub Actions workflow (test → build → deploy) |
114
- | **Configuration** | app.ts, legal.ts, .env, Firebase setup |
115
- | **Bug Fixes** | Diagnose and fix bugs with minimal changes |
116
- | **i18n** | Extract strings, create translation files (optional) |
117
-
118
- ---
119
-
120
- ## Ship Readiness
121
-
122
- App is ready to ship when:
123
- - ✅ `dndev tc` passes
124
- - ✅ `bun test` passes
125
- - ✅ `firestore.rules` generated
126
- - ✅ `.github/workflows/ci.yml` created
127
- - ✅ No critical bugs
128
- - ✅ Auth is secure
129
- - ✅ Mobile works at 375px
130
- - ✅ Configuration complete
131
- - ✅ (Optional) i18n added
132
-
133
- ## Phase Completion (MANDATORY)
134
-
135
- When all ship readiness checks pass, call:
136
- ```
137
- complete_phase({ files: ["...all test/config files..."], summary: "Tests passing, config complete, ready to ship" })
138
- ```
139
- Wait for user to call `approve_phase()`.
140
-
141
- ---
142
-
143
- ## Next Step
144
-
145
- Once app is production-ready:
146
- → `dndev deploy`
@@ -1,28 +0,0 @@
1
- ---
2
- description: End-of-session tech debt sweep — surfaces cleanup items, does NOT fix
3
- ---
4
-
5
- **Phase gate: only use after Phase 3 (COMPOSE) is complete.**
6
-
7
- Scan files modified in this session for tech debt.
8
-
9
- Check for:
10
- - Duplicate logic (same pattern implemented 2+ places)
11
- - Dead exports (exported symbols with no consumers)
12
- - Missing JSDoc on public API functions/types
13
- - Broken or missing imports (type-only imports used as values, etc.)
14
- - Unused dependencies in package.json vs actual imports
15
- - Hardcoded strings that should be in config or i18n
16
-
17
- Output: prioritized list, grouped by area. Format:
18
- ```
19
- ## <area>
20
- - [HIGH] <description> — <file>:<line>
21
- - [MED] <description> — <file>:<line>
22
- - [LOW] <description> — <file>:<line>
23
- ```
24
-
25
- Rules:
26
- - DO NOT fix anything. Report only.
27
- - Skip node_modules, dist, .d.ts files.
28
- - Skip items already in .dndev/implementation.md as known TODOs.
@@ -1,180 +0,0 @@
1
- # Component Reference
2
-
3
- **Check JSDoc in your IDE** - Hover over any component import to see props, types, and examples.
4
-
5
- **Import from:** `@donotdev/components` (atomic UI)
6
-
7
- **This is your GOTO Semantic React package**
8
-
9
- ---
10
-
11
- ## Layout Components
12
-
13
- These are the only ways one should handle layout to get to quick results functionality wide.
14
- - **Section** - Layout section with title, grid, tone system, and `bleed` prop for full-viewport-width content (images, maps, galleries).
15
- - **Grid** - CSS Grid layout primitive with responsive column control.
16
- - **Stack** - Flexbox layout for arranging items in rows or columns.
17
- - **HeroSection** - Hero banner with title, subtitle, gradient backgrounds, `bleed` for full-width, and `backgroundImage` for cover images with overlay.
18
- - **CallToAction** - Conversion-focused section with actions, `bleed` for full-width, and `backgroundImage` for cover images with overlay.
19
-
20
- ---
21
-
22
- ## Content Components
23
-
24
- - **Card** - Premium card component with title, content, footer, and elevation variants.
25
- - **Navigation with middle-click support:** Wrap Card in Link component for navigation that supports middle-click (opens in new tab). See navigation section below.
26
- - **DualCard** - Side-by-side card layout for comparison or feature showcases.
27
- - **Text** - Typography component with semantic text variants.
28
- - **Blockquote** - Styled blockquote for citations and testimonials.
29
- - **List** - Bullet points, numbered lists, and feature lists with zero CSS. Use `icon` prop for custom icons, `icon={null}` for plain bullets.
30
- - **DescriptionList** - Key-value pairs and metadata using semantic HTML (dl, dt, dd).
31
- - **Separator** - Visual separator with semantic styling variants.
32
-
33
- ---
34
-
35
- ## Action Components
36
-
37
- - **Button** - Accessible button with variants, icons, tooltips, and render prop composition.
38
- - **ActionButton** - Button with async action handling and loading states.
39
- - **FileButton** - Button that triggers file input selection.
40
- - **PortalButton** - Button that opens content in a portal overlay.
41
- - **ButtonGroup** - Visual grouping of buttons with joined borders. Supports horizontal/vertical orientation, variant propagation, and items-based API.
42
-
43
- ---
44
-
45
- ## Form Components
46
-
47
- - **Input** - Accessible input with mobile-friendly touch targets and key state styling.
48
- - **PasswordInput** - Password field with show/hide toggle functionality.
49
- - **Textarea** - Multi-line text input component.
50
- - **Label** - Accessible label with icon support and various positions.
51
- - **Checkbox** - Accessible checkbox with custom styling.
52
- - **RadioGroup** - Accessible radio group with multiple visual variants.
53
- - **Select** - Accessible select dropdown with search and multi-select support.
54
- - **Combobox** - Searchable combobox with autocomplete functionality.
55
- - **Switch** - Toggle switch component.
56
- - **Slider** - Range slider for numeric input.
57
- - **ColorPicker** - Color selection with preset swatch grid, native color input, and ARIA radiogroup pattern. Built-in palettes: basic, material, pastel.
58
-
59
- ---
60
-
61
- ## Feedback Components
62
-
63
- - **Alert** - Attention-grabbing alert with semantic variants and icons.
64
- - **AlertDialog** - Modal dialog that interrupts with important content expecting a response.
65
- - **Dialog** - Accessible modal dialog with custom content sizes and actions.
66
- - **Toast** - Toast notifications via Toaster component with ToastProvider.
67
- - **Skeleton** - Loading state skeleton with multiple animation variants.
68
- - **Spinner** - Loading spinner with multiple sizes and theme-aware colors.
69
- - **Progress** - Progress bar component for task completion.
70
-
71
- ---
72
-
73
- ## Navigation Components
74
-
75
- - **Tabs** - Tabbed interface with props-based API and full keyboard navigation.
76
- - **Accordion** - Vertically stacked headings that reveal content sections.
77
- - **NavigationMenu** - Props-based navigation menu with nested menus and rich content.
78
- - **Pagination** - Accessible pagination with page number generation and ellipsis.
79
- - **Command** - Command palette component for keyboard navigation and search.
80
- - **CommandDialog** - Command palette dialog optimized for Cmd+K navigation.
81
- - **TreeView** - Hierarchical tree component with WAI-ARIA TreeView pattern. Supports expand/collapse, single/multi selection, keyboard navigation, type-ahead search, and connector lines.
82
-
83
- ---
84
-
85
- ## Overlay Components
86
-
87
- - **Popover** - Accessible popover displaying rich content in a portal.
88
- - **Tooltip** - Tooltip component with positioning and delay controls.
89
- - **HoverCard** - Card that appears on hover with rich content.
90
- - **Sheet** - Slide-out panel for sidebars, mobile navigation, or editing panels.
91
- - **ContextMenu** - Right-click context menu with nested submenus.
92
- - **DropdownMenu** - Professional dropdown menu with props-based API.
93
-
94
- ---
95
-
96
- ## Data Display Components
97
-
98
- - **Table** - Accessible table component with sorting and selection.
99
- - **DataTable** - High-level table with built-in sorting, filtering, search, and pagination.
100
- - **Avatar** - Accessible avatar with image and fallback support.
101
- - **Badge** - Status indicator with semantic variants (polymorphic: div, span, mark).
102
- - **Tag** - Tag component for labels and categories.
103
- - **Calendar** - Accessible date picker built on react-day-picker.
104
-
105
- ---
106
-
107
- ## Utility Components
108
-
109
- - **Collapsible** - Collapsible content component.
110
- - **Toggle** - Toggle button component.
111
- - **ToggleGroup** - Group of toggle buttons.
112
- - **ScrollArea** - Scrollable area with custom scrollbars.
113
- - **Portal** - Portal component for rendering outside DOM hierarchy.
114
- - **VisuallyHidden** - Screen reader-only content component.
115
- - **Slot** - Slot component for composition patterns.
116
- - **SkipLink** - Accessibility skip-to-content links, visible only on keyboard focus. Supports multiple targets with smooth scroll and focus management.
117
-
118
- ---
119
-
120
- ## Advanced Components
121
-
122
- - **InfiniteScroll** - Infinite scroll component with load more functionality.
123
- - **Stepper** - Step-by-step workflow component with navigation controls.
124
- - **CopyToClipboard** - Copy to clipboard with visual feedback.
125
- - **VideoPlayer** - Video player component with controls.
126
- - **FeatureFallback** - Fallback UI when features are unavailable.
127
-
128
- ---
129
-
130
- ## Icons
131
-
132
- - **Icons** - Icon components from lucide-react and custom partner icons.
133
-
134
- ---
135
-
136
- **See also:** [COMPONENTS_UI.md](./COMPONENTS_UI.md) for layout/composition components | [COMPONENTS_CRUD.md](./COMPONENTS_CRUD.md) for CRUD operations and entity forms
137
-
138
- ---
139
-
140
- ## Navigation with Card Component
141
-
142
- **For clickable cards with navigation support (including middle-click):**
143
-
144
- Wrap Card in Link component from `@donotdev/ui`:
145
-
146
- ```tsx
147
- import { Card } from '@donotdev/components';
148
- import { Link } from '@donotdev/ui';
149
-
150
- // Card with navigation (supports middle-click)
151
- <Link
152
- path="/about"
153
- style={{ display: 'block', textDecoration: 'none', height: '100%' }}
154
- aria-label="Learn more about About"
155
- >
156
- <Card
157
- title="About"
158
- subtitle="Learn more about us"
159
- content="Click to navigate"
160
- />
161
- </Link>
162
-
163
- // Card with onClick only (no middle-click support)
164
- <Card
165
- title="Action Card"
166
- onClick={() => handleAction()}
167
- />
168
- ```
169
-
170
- **Why wrap in Link?**
171
- - Card component is standalone and not routing-aware
172
- - Link wrapper provides framework navigation (SPA routing, keeps outlet context)
173
- - Native browser middle-click support (opens in new tab)
174
- - CSR/SSR safe
175
-
176
- **Alternative:** Use FeatureCard from `@donotdev/ui` which handles this automatically when `href` prop is provided.
177
-
178
- ---
179
-
180
- **All props documented in JSDoc** - Hover in IDE for complete reference.
@@ -1,234 +0,0 @@
1
- # CRUD Package Reference
2
-
3
- **Import:** `@donotdev/crud`
4
-
5
- ---
6
-
7
- ## Hooks
8
-
9
- ### useCrud
10
- Single document CRUD actions (add, update, delete, get, subscribe).
11
-
12
- ```tsx
13
- const { add, update, delete: remove, get, data, loading, error } = useCrud(carEntity);
14
- await add({ name: 'Tesla', year: 2024 });
15
- await remove('doc-id');
16
- ```
17
-
18
- ### useCrudList
19
- Paginated list with automatic loading. For data tables.
20
-
21
- ```tsx
22
- const { items, loading, refresh } = useCrudList(productEntity);
23
- ```
24
-
25
- ### useCrudCardList
26
- Card-based list with infinite scroll.
27
-
28
- ```tsx
29
- const { items, loading, refresh } = useCrudCardList(articleEntity);
30
- ```
31
-
32
- ---
33
-
34
- ## Form Components
35
-
36
- ### EntityFormRenderer
37
- Auto-render full entity form from definition.
38
-
39
- ```tsx
40
- <EntityFormRenderer
41
- entity={productEntity}
42
- operation="create"
43
- onSubmit={handleSubmit}
44
- />
45
- ```
46
-
47
- ### FormFieldRenderer
48
- Render single field. Used inside custom forms.
49
-
50
- ```tsx
51
- <FormFieldRenderer field={field} control={form.control} />
52
- ```
53
-
54
- ### EntityList
55
- Data table for entity collection.
56
-
57
- ```tsx
58
- <EntityList entity={userEntity} onRowClick={(user) => edit(user.id)} />
59
- ```
60
-
61
- ### EntityCardList
62
- Card grid for entity collection.
63
-
64
- ```tsx
65
- <EntityCardList entity={productEntity} renderCard={(item) => <ProductCard {...item} />} />
66
- ```
67
-
68
- ---
69
-
70
- ## Form Building Blocks
71
-
72
- For custom forms, use these low-level utilities:
73
-
74
- ```tsx
75
- import { useEntityForm, getFieldsForOperation, validateEntity } from '@donotdev/crud';
76
-
77
- const { register, handleSubmit, fields, formState } = useEntityForm(productEntity, {
78
- operation: 'create'
79
- });
80
- ```
81
-
82
- | Export | Purpose |
83
- |--------|---------|
84
- | `useEntityForm` | React Hook Form wrapper for entities |
85
- | `useEntityField` | Single field hook |
86
- | `getFieldsForOperation` | Get editable fields for create/edit |
87
- | `validateEntity` | Validate data against entity schema |
88
- | `isFieldEditable` | Check if field is editable |
89
-
90
- ---
91
-
92
- ## Field Types (Built-in)
93
-
94
- Field components are auto-rendered by `FormFieldRenderer`. You don't import them directly.
95
-
96
- ### Text Inputs
97
- - `text` - Single-line text input
98
- - `email` - Email input with validation
99
- - `tel` - Phone number input
100
- - `url` - URL input
101
- - `color` - Color picker
102
- - `password` - Password input (masked)
103
- - `textarea` - Multi-line text input
104
- - `richtext` - Rich text editor
105
-
106
- ### Numbers
107
- - `number` - Numeric input
108
- - `range` - Slider input
109
- - `rating` - Star rating input (1–5, configurable max)
110
-
111
- **Rating + comment (e.g. reviews):** Use two fields on the same entity — `rating` (type `rating`) for stars and `comment` (type `textarea`) for the text. The form renders them as separate rows; no composite field type needed.
112
-
113
- ### Boolean
114
- - `checkbox` - Checkbox input
115
- - `boolean` - Alias for checkbox
116
- - `switch` - Toggle switch
117
-
118
- ### Dates & Time
119
- - `date` - Date picker
120
- - `datetime-local` - Date and time picker
121
- - `time` - Time picker
122
- - `week` - Week picker
123
- - `month` - Month picker
124
- - `timestamp` - Timestamp (Firestore Timestamp)
125
-
126
- ### Selection
127
- - `select` - Dropdown select
128
- - `combobox` - Searchable dropdown
129
- - `multiselect` - Multiple selection dropdown
130
- - `radio` - Radio button group
131
-
132
- ### Files & Media
133
- - `file` - Single file upload
134
- - `files` - Multiple file uploads
135
- - `document` - Document upload (PDF, etc.)
136
- - `documents` - Multiple document uploads
137
- - `image` - Single image upload
138
- - `images` - Multiple image uploads
139
-
140
- ### Complex Types
141
- - `geopoint` - Geographic coordinates (lat/lng)
142
- - `address` - Address input with autocomplete
143
- - `map` - Map picker
144
- - `array` - Array of text inputs
145
-
146
- ### Special
147
- - `avatar` - Avatar image upload
148
- - `badge` - Badge display
149
- - `hidden` - Hidden field (not displayed)
150
- - `submit` - Submit button (uncontrolled)
151
- - `reset` - Reset button (uncontrolled)
152
-
153
- To add custom field types:
154
- ```tsx
155
- import { useController, registerFieldType } from '@donotdev/crud';
156
- import type { ControlledFieldProps } from '@donotdev/crud';
157
-
158
- // Custom controlled component MUST use framework's useController (not react-hook-form's)
159
- function ScoreField({
160
- fieldConfig,
161
- control,
162
- errors,
163
- t,
164
- onChange
165
- }: ControlledFieldProps) {
166
- // REQUIRED: Use framework's useController - ensures type compatibility
167
- const { field, fieldState } = useController({
168
- name: fieldConfig.name,
169
- control: control,
170
- });
171
-
172
- return (
173
- <div>
174
- <label>{t(fieldConfig.label)}</label>
175
- {/* Use field.value and field.onChange */}
176
- <input
177
- type="number"
178
- value={field.value ?? 0}
179
- onChange={(e) => {
180
- const value = Number(e.target.value);
181
- field.onChange(value);
182
- onChange?.(value);
183
- }}
184
- min={0}
185
- max={10}
186
- />
187
- {fieldState?.error && (
188
- <span className="error">{fieldState.error.message}</span>
189
- )}
190
- </div>
191
- );
192
- }
193
-
194
- registerFieldType({
195
- type: 'score',
196
- controlledComponent: ScoreField,
197
- });
198
- ```
199
-
200
- **Important:**
201
- - Custom controlled components receive `control` prop, NOT `field` prop
202
- - You must use **framework's `useController`** (from `@donotdev/crud`), NOT `react-hook-form`'s useController
203
- - This ensures type compatibility - no type assertions needed
204
-
205
- ---
206
-
207
- ## Service & Store
208
-
209
- Direct access (rarely needed):
210
-
211
- ```tsx
212
- import { getCrudService, useCrudStore } from '@donotdev/crud';
213
-
214
- const service = getCrudService();
215
- await service.query('products', { where: [['active', '==', true]] });
216
- ```
217
-
218
- ---
219
-
220
- ## Collection Utilities
221
-
222
- ```tsx
223
- import { loadDeterministicRange, upsertDeterministic, appendToCollection } from '@donotdev/crud';
224
- ```
225
-
226
- | Utility | Purpose |
227
- |---------|---------|
228
- | `loadDeterministicRange` | Paginated loading with deterministic IDs |
229
- | `upsertDeterministic` | Insert or update with deterministic ID |
230
- | `appendToCollection` | Add to collection end |
231
-
232
- ---
233
-
234
- **JSDoc in IDE** - Hover over any import for full props and examples.