### Install Form Builder Dependencies
Source: https://github.com/hasanharman/form-builder/blob/main/README.md
Installs the necessary Node.js dependencies for the Form Builder project. This command should be run after cloning the repository and navigating into the project directory.
```bash
npm install
```
--------------------------------
### Install Credit Card Component with shadcn-ui
Source: https://github.com/hasanharman/form-builder/blob/main/components/ui/credit-card.md
This command installs the Credit Card component using the shadcn-ui CLI. Ensure you have shadcn-ui set up in your project before running this command. It manages dependencies and component files.
```bash
npx shadcn-ui@latest add credit-card
```
--------------------------------
### Start Form Builder Development Server
Source: https://github.com/hasanharman/form-builder/blob/main/README.md
Starts the development server for the Form Builder application. This allows you to view and interact with the form builder in your local environment, typically accessible at http://localhost:3000.
```bash
npm run dev
```
--------------------------------
### GET /api/file/:filename
Source: https://context7.com/hasanharman/form-builder/llms.txt
Securely retrieves the content of a specified template file. Includes validation to prevent directory traversal attacks.
```APIDOC
## GET /api/file/:filename
### Description
Securely retrieves template file contents with validation to prevent directory traversal attacks.
### Method
GET
### Endpoint
/api/file/:filename
### Parameters
#### Path Parameters
- **filename** (string) - Required - The name of the template file to retrieve. Must contain only alphanumeric characters and hyphens.
#### Query Parameters
None
### Request Example
```javascript
fetch('/api/file/login')
.then(res => {
if (!res.ok) throw new Error('File not found');
return res.json();
})
.then(data => {
console.log('Template content:', data.content);
// Use the content in code editor or preview
})
.catch(error => {
console.error('Error loading template:', error);
});
```
### Response
#### Success Response (200)
- **content** (string) - The content of the requested template file.
#### Response Example
```json
{
"content": "..."
}
```
### Error Handling
- **404 Not Found**: If the specified file does not exist or is not accessible.
- **400 Bad Request**: If the filename is invalid (e.g., contains malicious path characters).
```
--------------------------------
### GET /api/sponsors
Source: https://context7.com/hasanharman/form-builder/llms.txt
Retrieves GitHub sponsors data including active sponsors categorized by support tiers (header, project, community) and historical sponsor information.
```APIDOC
## GET /api/sponsors
### Description
Retrieves GitHub sponsors data with tiered support levels (header, project, community) and historical sponsor information.
### Method
GET
### Endpoint
/api/sponsors
### Parameters
#### Query Parameters
None
### Request Example
```javascript
fetch('/api/sponsors')
.then(res => res.json())
.then(data => {
console.log('Header sponsors:', data.active.header);
console.log('Project supporters:', data.active.project);
console.log('Community supporters:', data.active.community);
console.log('Past sponsors:', data.past);
})
.catch(error => {
console.error('Failed to fetch sponsors:', error);
});
```
### Response
#### Success Response (200)
- **active** (object) - Contains active sponsors categorized into header, project, and community.
- **past** (array) - Contains a list of past sponsors.
#### Response Example
```json
{
"active": {
"header": [
{
"id": "sponsor-id-123",
"name": "Example Company",
"image": "https://avatars.githubusercontent.com/u/123456",
"url": "https://example.com",
"tierName": "Header Sponsor",
"monthly": 100,
"isActive": true
}
],
"project": [],
"community": []
},
"past": []
}
```
```
--------------------------------
### Basic Credit Card Component Usage in React (TSX)
Source: https://github.com/hasanharman/form-builder/blob/main/components/ui/credit-card.md
This example demonstrates the basic integration of the CreditCard component in a React application using TypeScript. It utilizes the useState hook to manage the credit card data and passes it along with an onChange handler to the CreditCard component.
```tsx
import { useState } from 'react'
import { CreditCard } from '@/components/ui/credit-card'
export default function PaymentPage() {
const [cardData, setCardData] = useState({
cardholderName: '',
cardNumber: '',
expiryMonth: '',
expiryYear: '',
cvv: '',
cvvLabel: 'CVC' as const
})
return (
Payment Information
)
}
```
--------------------------------
### Secure File Content API Endpoint (TypeScript)
Source: https://context7.com/hasanharman/form-builder/llms.txt
Securely retrieves template file contents using a GET request to '/api/file/{filename}'. It includes validation to prevent directory traversal attacks, ensuring only intended files are accessed. Valid filenames consist of alphanumeric characters and hyphens.
```typescript
fetch('/api/file/login')
.then(res => {
if (!res.ok) throw new Error('File not found');
return res.json();
})
.then(data => {
console.log('Template content:', data.content);
// Use the content in code editor or preview
})
.catch(error => {
console.error('Error loading template:', error);
});
```
--------------------------------
### Credit Card Component Usage with Form Validation in React (TSX)
Source: https://github.com/hasanharman/form-builder/blob/main/components/ui/credit-card.md
This example shows how to use the CreditCard component within a form and implement basic client-side validation. It checks if all required fields are filled before enabling a 'Process Payment' button. The state management and validation logic are handled using React hooks.
```tsx
import { useState } from 'react'
import { CreditCard } from '@/components/ui/credit-card'
import { Button } from '@/components/ui/button'
export default function CheckoutForm() {
const [cardData, setCardData] = useState({
cardholderName: '',
cardNumber: '',
expiryMonth: '',
expiryYear: '',
cvv: '',
cvvLabel: 'CVC' as const
})
const isValid = cardData.cardholderName.trim() &&
cardData.cardNumber.trim() &&
cardData.expiryMonth.trim() &&
cardData.expiryYear.trim() &&
cardData.cvv.trim()
const handleSubmit = () => {
if (isValid) {
console.log('Processing payment...', cardData)
}
}
return (
)
}
```
--------------------------------
### Fetch GitHub Sponsors Data API (TypeScript)
Source: https://context7.com/hasanharman/form-builder/llms.txt
Retrieves GitHub sponsors data including tiered support levels (header, project, community) and historical sponsor information. This API endpoint is designed for fetching and displaying sponsor contributions.
```typescript
fetch('/api/sponsors')
.then(res => res.json())
.then(data => {
console.log('Header sponsors:', data.active.header);
console.log('Project supporters:', data.active.project);
console.log('Community supporters:', data.active.community);
console.log('Past sponsors:', data.past);
})
.catch(error => {
console.error('Failed to fetch sponsors:', error);
});
```
--------------------------------
### JSON Schema Generation Utilities
Source: https://context7.com/hasanharman/form-builder/llms.txt
Utilities for converting Zod schemas into JSON Schema format. Supports generation from Zod objects and arrays of form fields, and includes functionality to download the generated schema.
```APIDOC
## JSON Schema Generation Utilities
### Description
Converts Zod schemas to JSON Schema format for API documentation, validation, and integration with external tools. Includes functions to generate schema from Zod objects or form field definitions, and to download the schema as a JSON file.
### Method
Utility Functions (Not API Endpoints)
### Functions
- **`generateJsonSchema(schema, config)`**: Generates JSON Schema from a Zod schema.
- **`generateFormJsonSchema(fields, config)`**: Generates JSON Schema from an array of form field definitions.
- **`downloadJsonSchema(schema, filename)`**: Downloads the generated schema as a JSON file.
### Usage Example
```typescript
import { z } from 'zod';
import { generateJsonSchema, generateFormJsonSchema, downloadJsonSchema } from '@/lib/json-schema-generator';
// Generate from Zod schema
const userSchema = z.object({
name: z.string().min(2),
email: z.string().email(),
age: z.number().min(18),
newsletter: z.boolean().optional()
});
const jsonSchema = generateJsonSchema(userSchema, {
title: 'User Registration Schema',
description: 'Schema for user registration form'
});
// Generate from form fields array
const formFields = [
{ name: 'email', variant: 'Input', type: 'email', required: true },
{ name: 'age', variant: 'Number', required: true },
{ name: 'subscribe', variant: 'Checkbox', required: false }
];
const formJsonSchema = generateFormJsonSchema(formFields, {
title: 'Dynamic Form Schema'
});
// Download schema as JSON file
downloadJsonSchema(jsonSchema, 'user-registration-schema.json');
console.log('Generated JSON Schema:', jsonSchema);
console.log('Generated Form JSON Schema:', formJsonSchema);
```
### Parameters
- **`schema`** (ZodSchema): The Zod schema object to convert.
- **`fields`** (Array