@bomjan133/react-crud-ui 1.2.5 → 1.2.7

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 (78) hide show
  1. package/README.md +4630 -369
  2. package/bin/cli.js +387 -387
  3. package/dist/components/book-viewer/EpubViewer.d.ts +8 -0
  4. package/dist/components/book-viewer/PdfViewer.d.ts +9 -0
  5. package/dist/components/book-viewer/constants.d.ts +23 -0
  6. package/dist/components/book-viewer/hooks.d.ts +6 -0
  7. package/dist/components/book-viewer/index.d.ts +16 -0
  8. package/dist/components/book-viewer/ui.d.ts +16 -0
  9. package/dist/components/book-viewer/utils.d.ts +12 -0
  10. package/dist/components/crud/CrudDetail.d.ts +86 -0
  11. package/dist/components/crud/CrudForm.d.ts +33 -0
  12. package/dist/components/crud/CrudList.d.ts +105 -0
  13. package/dist/components/crud/DataTable.d.ts +64 -0
  14. package/dist/components/crud/EmptyState.d.ts +54 -0
  15. package/dist/components/crud/Loading.d.ts +32 -0
  16. package/dist/components/crud/Modal.d.ts +75 -0
  17. package/dist/components/crud/Pagination.d.ts +18 -0
  18. package/dist/components/crud/ServerErrorPage.d.ts +7 -0
  19. package/dist/components/layouts/AuthLayout.d.ts +32 -0
  20. package/dist/components/layouts/BreadcrumbContext.d.ts +4 -0
  21. package/dist/components/layouts/DashboardLayout.d.ts +41 -0
  22. package/dist/components/layouts/DetailView.d.ts +58 -0
  23. package/dist/components/layouts/Header.d.ts +13 -0
  24. package/dist/components/layouts/HeaderSlotContext.d.ts +4 -0
  25. package/dist/components/layouts/LoginPage.d.ts +50 -0
  26. package/dist/components/layouts/Sidebar.d.ts +38 -0
  27. package/dist/components/layouts/SidebarContext.d.ts +18 -0
  28. package/dist/components/layouts/index.d.ts +8 -0
  29. package/dist/components/toast/ToastContainer.d.ts +4 -0
  30. package/dist/components/toast/useUI.d.ts +33 -0
  31. package/dist/components/ui/CopyableField.d.ts +12 -0
  32. package/dist/components/ui/DownloadableButton.d.ts +15 -0
  33. package/dist/components/ui/alert-dialog.d.ts +26 -0
  34. package/dist/components/ui/alert.d.ts +8 -0
  35. package/dist/components/ui/avatar.d.ts +4 -0
  36. package/dist/components/ui/badge.d.ts +8 -0
  37. package/dist/components/ui/button.d.ts +6 -0
  38. package/dist/components/ui/calendar.d.ts +16 -0
  39. package/dist/components/ui/card.d.ts +7 -0
  40. package/dist/components/ui/checkbox.d.ts +2 -0
  41. package/dist/components/ui/collapsible.d.ts +3 -0
  42. package/dist/components/ui/date-picker.d.ts +2 -0
  43. package/dist/components/ui/date-range-picker.d.ts +2 -0
  44. package/dist/components/ui/dialog.d.ts +25 -0
  45. package/dist/components/ui/dropdown-menu.d.ts +23 -0
  46. package/dist/components/ui/form-fields.d.ts +19 -0
  47. package/dist/components/ui/input-group.d.ts +28 -0
  48. package/dist/components/ui/input.d.ts +2 -0
  49. package/dist/components/ui/label.d.ts +2 -0
  50. package/dist/components/ui/popover.d.ts +5 -0
  51. package/dist/components/ui/q-tabs.d.ts +18 -0
  52. package/dist/components/ui/rich-text-editor.d.ts +2 -0
  53. package/dist/components/ui/scroll-area.d.ts +3 -0
  54. package/dist/components/ui/search-select.d.ts +6 -0
  55. package/dist/components/ui/select.d.ts +12 -0
  56. package/dist/components/ui/separator.d.ts +2 -0
  57. package/dist/components/ui/skeleton.d.ts +4 -0
  58. package/dist/components/ui/switch.d.ts +2 -0
  59. package/dist/components/ui/table.d.ts +9 -0
  60. package/dist/components/ui/tabs.d.ts +6 -0
  61. package/dist/components/ui/textarea.d.ts +2 -0
  62. package/dist/components/ui/tiptap-editor.d.ts +2 -0
  63. package/dist/components/ui/tooltip.d.ts +6 -0
  64. package/dist/index.d.ts +42 -0
  65. package/dist/lib/utils.d.ts +61 -0
  66. package/dist/store/createCrudStore.d.ts +11 -0
  67. package/dist/store/useUIStore.d.ts +5 -0
  68. package/docs/1_GETTING_STARTED.md +333 -333
  69. package/docs/2_UI_COMPONENTS.md +586 -586
  70. package/docs/3_CRUD_COMPONENTS.md +974 -974
  71. package/docs/4_FORM_COMPONENTS.md +778 -778
  72. package/docs/5_LAYOUT_COMPONENTS.md +402 -402
  73. package/docs/6_STORE_FACTORY.md +456 -456
  74. package/docs/7_BOOK_VIEWER.md +365 -365
  75. package/docs/8_TOAST_NOTIFICATIONS.md +130 -130
  76. package/docs/9_UTILITIES.md +204 -204
  77. package/docs/README.md +83 -83
  78. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -1,387 +1,387 @@
1
- #!/usr/bin/env node
2
- /**
3
- * CRUD Module Generator CLI
4
- *
5
- * Usage: npx @sujanbomjan/react-crud-ui generate <module-name>
6
- * Example: npx @sujanbomjan/react-crud-ui generate blog
7
- *
8
- * This will create:
9
- * - src/pages/<module>/ModuleListPage.jsx
10
- * - src/pages/<module>/ModuleFormPage.jsx
11
- * - src/routes/modules/<module>Routes.js
12
- * - src/stores/use<Module>Store.js
13
- */
14
-
15
- import fs from "fs";
16
- import path from "path";
17
-
18
- const args = process.argv.slice(2);
19
- const command = args[0];
20
- const moduleName = args[1];
21
-
22
- // Show help if no command
23
- if (!command || command === "--help" || command === "-h") {
24
- console.log(`
25
- @sujanbomjan/react-crud-ui CLI
26
-
27
- Usage:
28
- npx @sujanbomjan/react-crud-ui generate <module-name>
29
- npx @sujanbomjan/react-crud-ui g <module-name>
30
-
31
- Commands:
32
- generate, g Generate a new CRUD module
33
-
34
- Options:
35
- --help, -h Show this help message
36
- --version, -v Show version number
37
-
38
- Examples:
39
- npx @sujanbomjan/react-crud-ui generate blog
40
- npx @sujanbomjan/react-crud-ui g product
41
- npx @sujanbomjan/react-crud-ui g user-profile
42
- `);
43
- process.exit(0);
44
- }
45
-
46
- // Show version
47
- if (command === "--version" || command === "-v") {
48
- try {
49
- const packageJson = JSON.parse(
50
- fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"),
51
- );
52
- console.log(packageJson.version);
53
- } catch {
54
- console.log("Unknown version");
55
- }
56
- process.exit(0);
57
- }
58
-
59
- // Handle generate command
60
- if (command === "generate" || command === "g") {
61
- if (!moduleName) {
62
- console.error("āŒ Please provide a module name");
63
- console.log(
64
- "Usage: npx @sujanbomjan/react-crud-ui generate <module-name>",
65
- );
66
- console.log("Example: npx @sujanbomjan/react-crud-ui generate blog");
67
- process.exit(1);
68
- }
69
-
70
- generateModule(moduleName);
71
- } else {
72
- console.error(`āŒ Unknown command: ${command}`);
73
- console.log("Run with --help to see available commands");
74
- process.exit(1);
75
- }
76
-
77
- function generateModule(name) {
78
- // Helper functions
79
- const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
80
- const kebabCase = (str) =>
81
- str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
82
- const pascalCase = (str) => str.split(/[-_]/).map(capitalize).join("");
83
- const camelCase = (str) => {
84
- const pascal = pascalCase(str);
85
- return pascal.charAt(0).toLowerCase() + pascal.slice(1);
86
- };
87
-
88
- const moduleNameLower = name.toLowerCase();
89
- const moduleNamePascal = pascalCase(name);
90
- const moduleNameCamel = camelCase(name);
91
- const moduleNameKebab = kebabCase(name);
92
-
93
- const cwd = process.cwd();
94
- const srcPath = path.join(cwd, "src");
95
-
96
- // Check if src folder exists
97
- if (!fs.existsSync(srcPath)) {
98
- console.error(
99
- "āŒ Could not find src folder. Make sure you are in the root of your React project.",
100
- );
101
- process.exit(1);
102
- }
103
-
104
- // Templates
105
- const listPageTemplate = `import { Badge, CrudList,TimeStampFormat } from '@sujanbomjan/react-crud-ui';
106
- import use${moduleNamePascal}Store from '@/stores/use${moduleNamePascal}Store';
107
-
108
- // Column definitions (actions column is auto-added by DataTable)
109
- const columns = [
110
- {
111
- key: 'name',
112
- label: 'Name',
113
- sortable: true,
114
- },
115
- {
116
- key: 'created_at',
117
- label: 'Created',
118
- render: (value) => TimeStampFormat(value),
119
- },
120
- {
121
- key: 'is_active',
122
- label: 'Status',
123
- render: (value) => (
124
- <Badge variant={value ? 'success' : 'secondary'}>
125
- {value ? 'Active' : 'Inactive'}
126
- </Badge>
127
- ),
128
- },
129
- ];
130
-
131
- export default function ${moduleNamePascal}ListPage() {
132
- const store = use${moduleNamePascal}Store();
133
-
134
- return (
135
- <CrudList
136
- title="${moduleNamePascal}s"
137
- description="Manage ${moduleNameLower}s"
138
- createPath="/${moduleNameLower}s/create"
139
- editPath="/${moduleNameLower}s"
140
- store={store}
141
- columns={columns}
142
- searchPlaceholder="Search ${moduleNameLower}s..."
143
- getDeleteItemName={(item) => item?.name}
144
- />
145
- );
146
- }
147
- `;
148
-
149
- const formPageTemplate = `import { Box } from 'lucide-react';
150
- import { CrudForm, QInput, QTextarea, QSwitch } from '@sujanbomjan/react-crud-ui';
151
- import use${moduleNamePascal}Store from '@/stores/use${moduleNamePascal}Store';
152
-
153
- export default function ${moduleNamePascal}FormPage() {
154
- const { form, setFormField } = use${moduleNamePascal}Store();
155
-
156
- return (
157
- <CrudForm
158
- title="${moduleNamePascal}"
159
- description="Enter the ${moduleNameLower} information below"
160
- icon={Box}
161
- listPath="/${moduleNameLower}s"
162
- useStore={use${moduleNamePascal}Store}
163
- >
164
- <div className="flex flex-col gap-4">
165
- <QInput
166
- name="name"
167
- label="Name"
168
- value={form.values.name || ''}
169
- onChange={(val) => setFormField('name', val)}
170
- error={form.errors.name}
171
- placeholder="Enter name"
172
- required
173
- />
174
-
175
- <QTextarea
176
- name="description"
177
- label="Description"
178
- value={form.values.description || ''}
179
- onChange={(val) => setFormField('description', val)}
180
- error={form.errors.description}
181
- placeholder="Enter description"
182
- rows={4}
183
- />
184
-
185
- <QSwitch
186
- label="Active"
187
- checked={form.values.is_active ?? true}
188
- onChange={(val) => setFormField('is_active', val)}
189
- />
190
- </div>
191
- </CrudForm>
192
- );
193
- }
194
- `;
195
-
196
- const detailPageTemplate = `import { CheckCircle2, FileText, XCircle, Activity, Box, ListOrdered } from 'lucide-react';
197
- import { CrudDetail } from '@sujanbomjan/react-crud-ui';
198
- import use${moduleNamePascal}Store from '@/stores/use${moduleNamePascal}Store';
199
- import DetailView from '@/components/features/DetailView';
200
-
201
- export default function ${moduleNamePascal}DetailPage() {
202
- return (
203
- <CrudDetail
204
- title="${moduleNamePascal} Details"
205
- description="View ${moduleNameLower} information"
206
- icon={Box}
207
- listPath="/${moduleNameLower}s"
208
- editPath="/${moduleNameLower}s"
209
- useStore={use${moduleNamePascal}Store}
210
- getItemName={(item) => item?.name}
211
- getBreadcrumbName={(item) => item?.name}
212
- >
213
- {(data) => {
214
- if (!data) return null;
215
-
216
- const mainSection = {
217
- title: '${moduleNamePascal}',
218
- description: '${moduleNamePascal} details',
219
- icon: FileText,
220
- columns: 2,
221
- fields: [
222
- {
223
- label: 'Name',
224
- value: data.name,
225
- icon: FileText,
226
- },
227
- {
228
- label: 'Description',
229
- value: data.description || '-',
230
- icon: Box,
231
- },
232
- {
233
- label: 'Status',
234
- value: data.is_active ? 'Active' : 'Inactive',
235
- type: 'badge',
236
- variant: data.is_active ? 'success' : 'destructive',
237
- icon: data.is_active ? CheckCircle2 : XCircle,
238
- },
239
- ],
240
- };
241
-
242
- const timelineConfig = {
243
- show: true,
244
- data: data,
245
- title: 'Timeline',
246
- description: 'Creation and modification history',
247
- showUserInfo: true,
248
- };
249
-
250
- const sidebarConfig = {
251
- statsTitle: 'Quick Info',
252
- statsIcon: Activity,
253
- stats: [
254
- {
255
- label: 'Status',
256
- value: data.is_active ? 'Active' : 'Inactive',
257
- type: 'badge',
258
- variant: data.is_active ? 'success' : 'secondary',
259
- icon: data.is_active ? CheckCircle2 : XCircle,
260
- },
261
- {
262
- label: 'ID',
263
- value: data.id ?? '-',
264
- icon: ListOrdered,
265
- },
266
- ],
267
- };
268
-
269
- return (
270
- <DetailView
271
- data={data}
272
- sections={[mainSection]}
273
- timeline={timelineConfig}
274
- sidebar={sidebarConfig}
275
- />
276
- );
277
- }}
278
- </CrudDetail>
279
- );
280
- }
281
- `;
282
-
283
- const routesTemplate = `import ${moduleNamePascal}ListPage from '@/pages/${moduleNameLower}s/${moduleNamePascal}ListPage';
284
- import ${moduleNamePascal}FormPage from '@/pages/${moduleNameLower}s/${moduleNamePascal}FormPage';
285
- import ${moduleNamePascal}DetailPage from '@/pages/${moduleNameLower}s/${moduleNamePascal}DetailPage';
286
-
287
- const ${moduleNameCamel}Routes = [
288
- { path: '/${moduleNameLower}s', element: <${moduleNamePascal}ListPage /> },
289
- { path: '/${moduleNameLower}s/create', element: <${moduleNamePascal}FormPage /> },
290
- { path: '/${moduleNameLower}s/:id', element: <${moduleNamePascal}DetailPage /> },
291
- { path: '/${moduleNameLower}s/:id/edit', element: <${moduleNamePascal}FormPage /> },
292
- ];
293
-
294
- export default ${moduleNameCamel}Routes;
295
- `;
296
-
297
- const storeTemplate = `import { createCrudStore } from './createCrudStore';
298
-
299
- // Default form values for ${moduleNameLower}s
300
- const defaultFormValues = {
301
- name: '',
302
- description: '',
303
- is_active: true,
304
- };
305
-
306
- // Create CRUD store for ${moduleNameLower}s
307
- const use${moduleNamePascal}Store = createCrudStore('${moduleNameLower}', '/${moduleNameLower}s/', defaultFormValues);
308
-
309
- export default use${moduleNamePascal}Store;
310
- `;
311
-
312
- // Create directories
313
- const pagesDir = path.join(srcPath, "pages", `${moduleNameLower}s`);
314
- const routesDir = path.join(srcPath, "routes", "modules");
315
- const storesDir = path.join(srcPath, "stores");
316
-
317
- if (!fs.existsSync(pagesDir)) {
318
- fs.mkdirSync(pagesDir, { recursive: true });
319
- }
320
-
321
- if (!fs.existsSync(routesDir)) {
322
- fs.mkdirSync(routesDir, { recursive: true });
323
- }
324
-
325
- // Write files
326
- const files = [
327
- {
328
- path: path.join(pagesDir, `${moduleNamePascal}ListPage.jsx`),
329
- content: listPageTemplate,
330
- },
331
- {
332
- path: path.join(pagesDir, `${moduleNamePascal}FormPage.jsx`),
333
- content: formPageTemplate,
334
- },
335
- {
336
- path: path.join(pagesDir, `${moduleNamePascal}DetailPage.jsx`),
337
- content: detailPageTemplate,
338
- },
339
- {
340
- path: path.join(routesDir, `${moduleNameCamel}Routes.jsx`),
341
- content: routesTemplate,
342
- },
343
- {
344
- path: path.join(storesDir, `use${moduleNamePascal}Store.jsx`),
345
- content: storeTemplate,
346
- },
347
- ];
348
-
349
- console.log(`\nšŸš€ Generating ${moduleNamePascal} module...\n`);
350
-
351
- files.forEach(({ path: filePath, content }) => {
352
- if (fs.existsSync(filePath)) {
353
- console.log(`āš ļø File already exists: ${path.relative(cwd, filePath)}`);
354
- } else {
355
- fs.writeFileSync(filePath, content);
356
- console.log(`āœ… Created: ${path.relative(cwd, filePath)}`);
357
- }
358
- });
359
-
360
- console.log(`
361
- šŸ“ Next steps:
362
-
363
- 1. Add route to src/routes/modules/index.js:
364
- export { default as ${moduleNameCamel}Routes } from './${moduleNameCamel}Routes';
365
-
366
- 2. Import in src/routes/index.jsx:
367
- import { ..., ${moduleNameCamel}Routes } from './modules';
368
-
369
- 3. Add to protected routes children:
370
- ...${moduleNameCamel}Routes,
371
-
372
- 4. Add sidebar menu item:
373
- {
374
- label: '${moduleNamePascal}s',
375
- path: '/${moduleNameLower}s',
376
- icon: Box,
377
- },
378
-
379
- 5. Customize the form fields in ${moduleNamePascal}FormPage.jsx
380
-
381
- 6. Customize the table columns in ${moduleNamePascal}ListPage.jsx
382
-
383
- 7. Update store default values in use${moduleNamePascal}Store.js
384
-
385
- 8. Update detail view fields in ${moduleNamePascal}DetailPage.jsx
386
- `);
387
- }
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CRUD Module Generator CLI
4
+ *
5
+ * Usage: npx @bomjan133/react-crud-ui generate <module-name>
6
+ * Example: npx @bomjan133/react-crud-ui generate blog
7
+ *
8
+ * This will create:
9
+ * - src/pages/<module>/ModuleListPage.jsx
10
+ * - src/pages/<module>/ModuleFormPage.jsx
11
+ * - src/routes/modules/<module>Routes.js
12
+ * - src/stores/use<Module>Store.js
13
+ */
14
+
15
+ import fs from "fs";
16
+ import path from "path";
17
+
18
+ const args = process.argv.slice(2);
19
+ const command = args[0];
20
+ const moduleName = args[1];
21
+
22
+ // Show help if no command
23
+ if (!command || command === "--help" || command === "-h") {
24
+ console.log(`
25
+ @bomjan133/react-crud-ui CLI
26
+
27
+ Usage:
28
+ npx @bomjan133/react-crud-ui generate <module-name>
29
+ npx @bomjan133/react-crud-ui g <module-name>
30
+
31
+ Commands:
32
+ generate, g Generate a new CRUD module
33
+
34
+ Options:
35
+ --help, -h Show this help message
36
+ --version, -v Show version number
37
+
38
+ Examples:
39
+ npx @bomjan133/react-crud-ui generate blog
40
+ npx @bomjan133/react-crud-ui g product
41
+ npx @bomjan133/react-crud-ui g user-profile
42
+ `);
43
+ process.exit(0);
44
+ }
45
+
46
+ // Show version
47
+ if (command === "--version" || command === "-v") {
48
+ try {
49
+ const packageJson = JSON.parse(
50
+ fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"),
51
+ );
52
+ console.log(packageJson.version);
53
+ } catch {
54
+ console.log("Unknown version");
55
+ }
56
+ process.exit(0);
57
+ }
58
+
59
+ // Handle generate command
60
+ if (command === "generate" || command === "g") {
61
+ if (!moduleName) {
62
+ console.error("āŒ Please provide a module name");
63
+ console.log(
64
+ "Usage: npx @bomjan133/react-crud-ui generate <module-name>",
65
+ );
66
+ console.log("Example: npx @bomjan133/react-crud-ui generate blog");
67
+ process.exit(1);
68
+ }
69
+
70
+ generateModule(moduleName);
71
+ } else {
72
+ console.error(`āŒ Unknown command: ${command}`);
73
+ console.log("Run with --help to see available commands");
74
+ process.exit(1);
75
+ }
76
+
77
+ function generateModule(name) {
78
+ // Helper functions
79
+ const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
80
+ const kebabCase = (str) =>
81
+ str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
82
+ const pascalCase = (str) => str.split(/[-_]/).map(capitalize).join("");
83
+ const camelCase = (str) => {
84
+ const pascal = pascalCase(str);
85
+ return pascal.charAt(0).toLowerCase() + pascal.slice(1);
86
+ };
87
+
88
+ const moduleNameLower = name.toLowerCase();
89
+ const moduleNamePascal = pascalCase(name);
90
+ const moduleNameCamel = camelCase(name);
91
+ const moduleNameKebab = kebabCase(name);
92
+
93
+ const cwd = process.cwd();
94
+ const srcPath = path.join(cwd, "src");
95
+
96
+ // Check if src folder exists
97
+ if (!fs.existsSync(srcPath)) {
98
+ console.error(
99
+ "āŒ Could not find src folder. Make sure you are in the root of your React project.",
100
+ );
101
+ process.exit(1);
102
+ }
103
+
104
+ // Templates
105
+ const listPageTemplate = `import { Badge, CrudList,TimeStampFormat } from '@bomjan133/react-crud-ui';
106
+ import use${moduleNamePascal}Store from '@/stores/use${moduleNamePascal}Store';
107
+
108
+ // Column definitions (actions column is auto-added by DataTable)
109
+ const columns = [
110
+ {
111
+ key: 'name',
112
+ label: 'Name',
113
+ sortable: true,
114
+ },
115
+ {
116
+ key: 'created_at',
117
+ label: 'Created',
118
+ render: (value) => TimeStampFormat(value),
119
+ },
120
+ {
121
+ key: 'is_active',
122
+ label: 'Status',
123
+ render: (value) => (
124
+ <Badge variant={value ? 'success' : 'secondary'}>
125
+ {value ? 'Active' : 'Inactive'}
126
+ </Badge>
127
+ ),
128
+ },
129
+ ];
130
+
131
+ export default function ${moduleNamePascal}ListPage() {
132
+ const store = use${moduleNamePascal}Store();
133
+
134
+ return (
135
+ <CrudList
136
+ title="${moduleNamePascal}s"
137
+ description="Manage ${moduleNameLower}s"
138
+ createPath="/${moduleNameLower}s/create"
139
+ editPath="/${moduleNameLower}s"
140
+ store={store}
141
+ columns={columns}
142
+ searchPlaceholder="Search ${moduleNameLower}s..."
143
+ getDeleteItemName={(item) => item?.name}
144
+ />
145
+ );
146
+ }
147
+ `;
148
+
149
+ const formPageTemplate = `import { Box } from 'lucide-react';
150
+ import { CrudForm, QInput, QTextarea, QSwitch } from '@bomjan133/react-crud-ui';
151
+ import use${moduleNamePascal}Store from '@/stores/use${moduleNamePascal}Store';
152
+
153
+ export default function ${moduleNamePascal}FormPage() {
154
+ const { form, setFormField } = use${moduleNamePascal}Store();
155
+
156
+ return (
157
+ <CrudForm
158
+ title="${moduleNamePascal}"
159
+ description="Enter the ${moduleNameLower} information below"
160
+ icon={Box}
161
+ listPath="/${moduleNameLower}s"
162
+ useStore={use${moduleNamePascal}Store}
163
+ >
164
+ <div className="flex flex-col gap-4">
165
+ <QInput
166
+ name="name"
167
+ label="Name"
168
+ value={form.values.name || ''}
169
+ onChange={(val) => setFormField('name', val)}
170
+ error={form.errors.name}
171
+ placeholder="Enter name"
172
+ required
173
+ />
174
+
175
+ <QTextarea
176
+ name="description"
177
+ label="Description"
178
+ value={form.values.description || ''}
179
+ onChange={(val) => setFormField('description', val)}
180
+ error={form.errors.description}
181
+ placeholder="Enter description"
182
+ rows={4}
183
+ />
184
+
185
+ <QSwitch
186
+ label="Active"
187
+ checked={form.values.is_active ?? true}
188
+ onChange={(val) => setFormField('is_active', val)}
189
+ />
190
+ </div>
191
+ </CrudForm>
192
+ );
193
+ }
194
+ `;
195
+
196
+ const detailPageTemplate = `import { CheckCircle2, FileText, XCircle, Activity, Box, ListOrdered } from 'lucide-react';
197
+ import { CrudDetail } from '@bomjan133/react-crud-ui';
198
+ import use${moduleNamePascal}Store from '@/stores/use${moduleNamePascal}Store';
199
+ import DetailView from '@/components/features/DetailView';
200
+
201
+ export default function ${moduleNamePascal}DetailPage() {
202
+ return (
203
+ <CrudDetail
204
+ title="${moduleNamePascal} Details"
205
+ description="View ${moduleNameLower} information"
206
+ icon={Box}
207
+ listPath="/${moduleNameLower}s"
208
+ editPath="/${moduleNameLower}s"
209
+ useStore={use${moduleNamePascal}Store}
210
+ getItemName={(item) => item?.name}
211
+ getBreadcrumbName={(item) => item?.name}
212
+ >
213
+ {(data) => {
214
+ if (!data) return null;
215
+
216
+ const mainSection = {
217
+ title: '${moduleNamePascal}',
218
+ description: '${moduleNamePascal} details',
219
+ icon: FileText,
220
+ columns: 2,
221
+ fields: [
222
+ {
223
+ label: 'Name',
224
+ value: data.name,
225
+ icon: FileText,
226
+ },
227
+ {
228
+ label: 'Description',
229
+ value: data.description || '-',
230
+ icon: Box,
231
+ },
232
+ {
233
+ label: 'Status',
234
+ value: data.is_active ? 'Active' : 'Inactive',
235
+ type: 'badge',
236
+ variant: data.is_active ? 'success' : 'destructive',
237
+ icon: data.is_active ? CheckCircle2 : XCircle,
238
+ },
239
+ ],
240
+ };
241
+
242
+ const timelineConfig = {
243
+ show: true,
244
+ data: data,
245
+ title: 'Timeline',
246
+ description: 'Creation and modification history',
247
+ showUserInfo: true,
248
+ };
249
+
250
+ const sidebarConfig = {
251
+ statsTitle: 'Quick Info',
252
+ statsIcon: Activity,
253
+ stats: [
254
+ {
255
+ label: 'Status',
256
+ value: data.is_active ? 'Active' : 'Inactive',
257
+ type: 'badge',
258
+ variant: data.is_active ? 'success' : 'secondary',
259
+ icon: data.is_active ? CheckCircle2 : XCircle,
260
+ },
261
+ {
262
+ label: 'ID',
263
+ value: data.id ?? '-',
264
+ icon: ListOrdered,
265
+ },
266
+ ],
267
+ };
268
+
269
+ return (
270
+ <DetailView
271
+ data={data}
272
+ sections={[mainSection]}
273
+ timeline={timelineConfig}
274
+ sidebar={sidebarConfig}
275
+ />
276
+ );
277
+ }}
278
+ </CrudDetail>
279
+ );
280
+ }
281
+ `;
282
+
283
+ const routesTemplate = `import ${moduleNamePascal}ListPage from '@/pages/${moduleNameLower}s/${moduleNamePascal}ListPage';
284
+ import ${moduleNamePascal}FormPage from '@/pages/${moduleNameLower}s/${moduleNamePascal}FormPage';
285
+ import ${moduleNamePascal}DetailPage from '@/pages/${moduleNameLower}s/${moduleNamePascal}DetailPage';
286
+
287
+ const ${moduleNameCamel}Routes = [
288
+ { path: '/${moduleNameLower}s', element: <${moduleNamePascal}ListPage /> },
289
+ { path: '/${moduleNameLower}s/create', element: <${moduleNamePascal}FormPage /> },
290
+ { path: '/${moduleNameLower}s/:id', element: <${moduleNamePascal}DetailPage /> },
291
+ { path: '/${moduleNameLower}s/:id/edit', element: <${moduleNamePascal}FormPage /> },
292
+ ];
293
+
294
+ export default ${moduleNameCamel}Routes;
295
+ `;
296
+
297
+ const storeTemplate = `import { createCrudStore } from './createCrudStore';
298
+
299
+ // Default form values for ${moduleNameLower}s
300
+ const defaultFormValues = {
301
+ name: '',
302
+ description: '',
303
+ is_active: true,
304
+ };
305
+
306
+ // Create CRUD store for ${moduleNameLower}s
307
+ const use${moduleNamePascal}Store = createCrudStore('${moduleNameLower}', '/${moduleNameLower}s/', defaultFormValues);
308
+
309
+ export default use${moduleNamePascal}Store;
310
+ `;
311
+
312
+ // Create directories
313
+ const pagesDir = path.join(srcPath, "pages", `${moduleNameLower}s`);
314
+ const routesDir = path.join(srcPath, "routes", "modules");
315
+ const storesDir = path.join(srcPath, "stores");
316
+
317
+ if (!fs.existsSync(pagesDir)) {
318
+ fs.mkdirSync(pagesDir, { recursive: true });
319
+ }
320
+
321
+ if (!fs.existsSync(routesDir)) {
322
+ fs.mkdirSync(routesDir, { recursive: true });
323
+ }
324
+
325
+ // Write files
326
+ const files = [
327
+ {
328
+ path: path.join(pagesDir, `${moduleNamePascal}ListPage.jsx`),
329
+ content: listPageTemplate,
330
+ },
331
+ {
332
+ path: path.join(pagesDir, `${moduleNamePascal}FormPage.jsx`),
333
+ content: formPageTemplate,
334
+ },
335
+ {
336
+ path: path.join(pagesDir, `${moduleNamePascal}DetailPage.jsx`),
337
+ content: detailPageTemplate,
338
+ },
339
+ {
340
+ path: path.join(routesDir, `${moduleNameCamel}Routes.jsx`),
341
+ content: routesTemplate,
342
+ },
343
+ {
344
+ path: path.join(storesDir, `use${moduleNamePascal}Store.jsx`),
345
+ content: storeTemplate,
346
+ },
347
+ ];
348
+
349
+ console.log(`\nšŸš€ Generating ${moduleNamePascal} module...\n`);
350
+
351
+ files.forEach(({ path: filePath, content }) => {
352
+ if (fs.existsSync(filePath)) {
353
+ console.log(`āš ļø File already exists: ${path.relative(cwd, filePath)}`);
354
+ } else {
355
+ fs.writeFileSync(filePath, content);
356
+ console.log(`āœ… Created: ${path.relative(cwd, filePath)}`);
357
+ }
358
+ });
359
+
360
+ console.log(`
361
+ šŸ“ Next steps:
362
+
363
+ 1. Add route to src/routes/modules/index.js:
364
+ export { default as ${moduleNameCamel}Routes } from './${moduleNameCamel}Routes';
365
+
366
+ 2. Import in src/routes/index.jsx:
367
+ import { ..., ${moduleNameCamel}Routes } from './modules';
368
+
369
+ 3. Add to protected routes children:
370
+ ...${moduleNameCamel}Routes,
371
+
372
+ 4. Add sidebar menu item:
373
+ {
374
+ label: '${moduleNamePascal}s',
375
+ path: '/${moduleNameLower}s',
376
+ icon: Box,
377
+ },
378
+
379
+ 5. Customize the form fields in ${moduleNamePascal}FormPage.jsx
380
+
381
+ 6. Customize the table columns in ${moduleNamePascal}ListPage.jsx
382
+
383
+ 7. Update store default values in use${moduleNamePascal}Store.js
384
+
385
+ 8. Update detail view fields in ${moduleNamePascal}DetailPage.jsx
386
+ `);
387
+ }