Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/angular-integration-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Angular + Formeo Integration Example

This directory contains a complete Angular v20 project demonstrating Formeo integration.

## Quick Start

```bash
# Navigate to the Angular example
cd docs/angular-integration-example

# Install dependencies
npm install

# Run the development server
ng serve

# Open http://localhost:4200
```

## Project Structure

```
angular-integration-example/
├── src/
│ ├── app/
│ │ ├── form-builder/
│ │ │ ├── form-builder.component.ts
│ │ │ ├── form-builder.component.html
│ │ │ └── form-builder.component.scss
│ │ ├── app.component.ts
│ │ └── app.module.ts
│ └── main.ts
├── angular.json
├── package.json
└── tsconfig.json
```

## Integration Guide

See the `form-builder.component.ts` for a complete working example of Formeo integration in Angular.
145 changes: 145 additions & 0 deletions docs/angular-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Angular + Formeo Integration Guide

## Why the Demo Doesn't Load Real Angular v20

The current Angular demo in `src/demo/js/frameworks/angular.js` simulates Angular patterns rather than loading the actual Angular framework for several technical reasons:

### Technical Limitations

1. **Dynamic ES Module Loading Complexity**
- Angular v20 requires complex module resolution
- Dependencies between @angular/core, @angular/common, @angular/platform-browser
- Browser ES module loading limitations

2. **Bundle Size Impact**
- Angular v20 with dependencies is ~200KB+ minified
- Would significantly slow down demo loading
- Not suitable for quick demonstrations

3. **Build Tool Requirements**
- Angular typically requires compilation (TypeScript → JavaScript)
- Template compilation and bundling
- Zone.js and other runtime dependencies

4. **Runtime Environment Mismatch**
- Demo runs in vanilla browser environment
- Angular expects Node.js tooling ecosystem

## Recommended Alternatives

### Option 1: Complete Angular Project Example (Recommended)

Create a separate Angular project that demonstrates real integration:

```bash
# Create new Angular project
ng new formeo-angular-example --routing --style=scss
cd formeo-angular-example

# Install Formeo
npm install formeo

# Run development server
ng serve
```

**Benefits:**
- Real Angular v20 environment
- Proper TypeScript support
- Full Angular CLI tooling
- Production-ready patterns

### Option 2: Improved CDN Loading (Experimental)

Update the demo to use Angular's standalone CDN bundles:

```javascript
// Load Angular via CDN (Angular v20 standalone)
async function loadAngularFromCDN() {
const scripts = [
'https://unpkg.com/@angular/core@20/bundles/core.umd.js',
'https://unpkg.com/@angular/common@20/bundles/common.umd.js',
'https://unpkg.com/@angular/platform-browser@20/bundles/platform-browser.umd.js'
];

for (const src of scripts) {
await loadScript(src);
}
}
```

**Limitations:**
- Still complex dependency management
- Large download size
- Limited TypeScript support
- Not recommended for production

### Option 3: Web Components Approach

Use Angular Elements to create a web component:

```typescript
// Create Angular Element
import { createCustomElement } from '@angular/elements';
import { FormBuilderComponent } from './form-builder.component';

const FormBuilderElement = createCustomElement(FormBuilderComponent, { injector });
customElements.define('formeo-angular-builder', FormBuilderElement);
```

**Benefits:**
- Can be loaded in any environment
- Encapsulated Angular functionality
- Framework-agnostic usage

### Option 4: Stackblitz/CodeSandbox Integration

Embed live Angular examples using online IDEs:

```html
<iframe src="https://stackblitz.com/edit/formeo-angular-v20?embed=1"
width="100%" height="600px"></iframe>
```

## Current Demo Value

The current simulated demo is still valuable because it:

1. **Shows Integration Patterns**: Demonstrates proper Angular component structure
2. **Provides Copy-Paste Code**: Complete, working examples for real projects
3. **Educational Value**: Teaches Angular + Formeo integration concepts
4. **Performance**: Loads quickly without framework overhead

## Implementation Recommendation

For your use case, I recommend:

1. **Keep the current demo** for quick pattern demonstration
2. **Add a complete Angular project** in `/docs/angular-integration-example/`
3. **Update the demo documentation** to clearly explain the simulation
4. **Add links to the full project** for developers who want real integration

This approach provides both quick learning (demo) and complete implementation (separate project).

## Migration Path

If you want to enhance the current demo:

```javascript
// Enhanced demo with better Angular simulation
export async function loadAngularDemo(container) {
// 1. Show comprehensive setup instructions
// 2. Provide modern Angular v20 code examples
// 3. Demonstrate advanced patterns (signals, standalone components)
// 4. Include service-based architecture examples
// 5. Add TypeScript type definitions
}
```

The updated demo now includes:
- Modern Angular v20 patterns
- Standalone components
- Angular signals
- Service-based architecture
- Better TypeScript examples
- Comprehensive integration guide
File renamed without changes.
89 changes: 89 additions & 0 deletions docs/editor/editor-clear-method.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# FormeoEditor.clear() Method

## Overview

The `clear()` method has been added to the FormeoEditor class to provide a clean way to reset the editor to its initial state, as if no form data was ever provided.

## Method Signature

```typescript
editor.clear(): void
```

## Description

The `clear()` method:
- Resets the internal `userFormData` to the default form structure using `DEFAULT_FORMDATA()`
- Maintains the proper form structure with at least one empty stage
- Reloads the Components with the default form data
- Re-renders the editor to show the clean, initial state
- Effectively returns the editor to its initial state while preserving the required stage structure

## Usage Examples

### Basic Usage
```javascript
import { FormeoEditor } from 'formeo';

const editor = new FormeoEditor({
editorContainer: '#my-editor'
});

// ... user builds a form ...

// Clear the form back to empty state
editor.clear();
```

### React Hook Example
```javascript
const clearForm = useCallback(() => {
if (editorRef.current) {
editorRef.current.clear();
setFormData(null);
}
}, []);
```

### Angular Component Example
```typescript
clearForm() {
if (this.editor) {
this.editor.clear();
}
if (this.renderer && this.renderContainer) {
this.renderContainer.nativeElement.innerHTML = '';
}
}
```

## When to Use

Use the `clear()` method when you need to:
- Reset the form builder to a blank state
- Start over with a new form
- Clear all form stages and fields
- Return to the initial editor state

## Comparison with formData Setter

| Method | Purpose | Result |
|--------|---------|---------|
| `editor.clear()` | Reset to initial state with proper structure | Clean editor with one empty stage |
| `editor.formData = {}` | Set specific form data | May break editor structure |

The `clear()` method is more reliable as it uses the proper default form structure and maintains at least one stage.

## Integration with Framework Demos

Both React and Angular demos now use the `clear()` method:
- **Interactive Demo**: Clear button uses `editor.clear()`
- **Code Examples**: All framework patterns updated to use the new method
- **Error-Free**: No more "clear is not a function" errors

## Benefits

1. **Official API**: Now part of the FormeoEditor public API
2. **Consistent**: Same behavior across all framework integrations
3. **Complete Reset**: Thoroughly clears all editor state
4. **Future-Proof**: Will work with future Formeo updates
97 changes: 97 additions & 0 deletions docs/react-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# React + Formeo Integration Guide

## Overview

The React integration demo showcases modern React patterns for integrating Formeo into React applications. It includes examples of hooks, functional components, context patterns, and TypeScript integration.

## Key Features

### 🎣 **Custom React Hooks**
- `useFormeoEditor`: Manages Formeo editor instances with React lifecycle
- `useFormeoRenderer`: Handles form rendering with proper cleanup
- Automatic memory management and cleanup

### ⚛️ **Modern React Patterns**
- Functional components with hooks
- React Context for global state management
- TypeScript support with proper typing
- Error boundaries and error handling

### 🎨 **Enhanced User Experience**
- Syntax highlighting for all code examples
- Interactive demo with React-like behavior
- Export functionality for form data
- Real-time form state management

## Code Examples Included

### 1. Custom Hooks
- Complete implementation of `useFormeoEditor` and `useFormeoRenderer`
- Proper dependency management and cleanup
- React lifecycle integration

### 2. Functional Components
- Modern React component with hooks
- Event handling and state management
- Form persistence and export features

### 3. Context Provider
- Global state management for multiple forms
- Reducer pattern for complex state
- Provider/Consumer pattern

### 4. TypeScript Integration
- Complete type definitions
- Interface declarations
- Proper typing for all components

## Installation Guide

```bash
# Create new React project
npx create-react-app my-formeo-app
cd my-formeo-app

# Install Formeo
npm install formeo

# Optional: Add TypeScript support
npm install --save-dev @types/react @types/react-dom typescript
```

## Best Practices Demonstrated

- **Memory Management**: Proper cleanup of Formeo instances
- **State Management**: Using React hooks and context effectively
- **TypeScript**: Complete type safety and IntelliSense support
- **Performance**: Efficient re-rendering and memoization
- **Error Handling**: Graceful error boundaries and fallbacks

## Integration Patterns

The demo shows three main integration approaches:

1. **Basic Hook Integration**: Simple useEffect-based setup
2. **Advanced Hook Pattern**: Custom hooks with complete lifecycle management
3. **Context-Based Architecture**: Global state management for complex applications

Each pattern is suitable for different use cases and complexity levels.

## Demo Structure

The React demo includes:
- **Interactive Editor**: Full Formeo editor with React integration
- **Live Renderer**: Real-time form rendering
- **Code Examples**: Copy-paste ready implementations
- **Syntax Highlighting**: Enhanced code readability
- **Export Features**: JSON export and form persistence

## Next Steps

For a complete React project with Formeo:
1. Follow the installation guide above
2. Copy the hook implementations from the demo
3. Integrate the components into your application
4. Customize styling and behavior as needed

The demo provides production-ready code that can be directly used in React applications.
Loading
Loading