Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/euclidesseg/euclides-workspace/llms.txt

Use this file to discover all available pages before exploring further.

Your First Editor

This guide will walk you through creating a functional rich text editor with all the core features in just a few minutes.
1

Create a new component

Create a component that will host the editor:
ng generate component editor-demo --standalone
Or create a file manually:
src/app/editor-demo/editor-demo.component.ts
import { Component } from '@angular/core';
import { EuclidesRichEditorComponent } from 'euclides-rich-editor';

@Component({
  selector: 'app-editor-demo',
  standalone: true,
  imports: [EuclidesRichEditorComponent],
  templateUrl: './editor-demo.component.html',
  styleUrls: ['./editor-demo.component.css']
})
export class EditorDemoComponent {}
2

Add the editor to your template

The simplest way to use the editor is to add it directly to your template:
src/app/editor-demo/editor-demo.component.html
<div class="editor-container">
  <h1>My Rich Text Editor</h1>
  <euclides-rich-editor />
</div>
The editor component includes a built-in toolbar with all formatting options.
3

Add basic styling

Style the editor container for a better appearance:
src/app/editor-demo/editor-demo.component.css
.editor-container {
  max-width: 900px;
  margin: 2rem auto;
  padding: 1rem;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

h1 {
  margin-bottom: 1rem;
  color: #333;
}
4

Try the editor

Start your development server and test the editor:
ng serve
Navigate to your component and try these features:
  • Bold: Click the B button or press Ctrl/Cmd + B
  • Italic: Click the I button or press Ctrl/Cmd + I
  • Lists: Click the bullet or numbered list buttons
  • Links: Select text and click the link button
  • Text Alignment: Use the alignment buttons (left, center, right, justify)
  • Undo/Redo: Use the arrow buttons or Ctrl/Cmd + Z and Ctrl/Cmd + Shift + Z

Understanding the Editor Component

Let’s explore what’s happening inside the EuclidesRichEditorComponent:

Component Structure

The editor consists of two main parts:
import { Component, ElementRef, ViewChild, AfterViewInit, OnDestroy } from '@angular/core';
import { EditorView } from 'prosemirror-view';
import { EditorEngine } from '../../engine/editor-engine';
import { EditorCommandsService } from '../../core/editor-commands.service';
import { EditorStateService } from '../../core/editor-state.service';

@Component({
  selector: 'euclides-rich-editor',
  standalone: true,
  templateUrl: './euclides-editor.component.html'
})
export class EuclidesRichEditorComponent implements AfterViewInit, OnDestroy {
  @ViewChild('editor', { static: true })
  editorRef!: ElementRef<HTMLDivElement>;
  
  view!: EditorView;
  
  ngAfterViewInit() {
    // Initialize the ProseMirror view
    this.view = EditorEngine.create(
      this.editorRef.nativeElement,
      this.editorStateService
    );
  }
  
  ngOnDestroy() {
    this.view.destroy();
  }
}

Key Features Explained

Text formatting is handled through the EditorCommandsService:
toggleBold() {
  if (this.editorCommandsService.toggleBold(this.view)) {
    this.view.focus();
  }
}

toggleItalic() {
  if (this.editorCommandsService.toggleItalic(this.view)) {
    this.view.focus();
  }
}

toggleStrike() {
  if (this.editorCommandsService.toggleStrike(this.view)) {
    this.view.focus();
  }
}
The service uses ProseMirror’s toggleMark command:
src/lib/core/editor-commands.service.ts
toggleBold(view: EditorView): boolean {
  const command = toggleMark(EuclidesEditorSchema.marks['strong']);
  return command(view.state, view.dispatch);
}

Advanced Example

Here’s a more complete example showing how to integrate the editor into a form:
src/app/document-editor/document-editor.component.ts
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { EuclidesRichEditorComponent } from 'euclides-rich-editor';

@Component({
  selector: 'app-document-editor',
  standalone: true,
  imports: [EuclidesRichEditorComponent, FormsModule],
  template: `
    <div class="document-form">
      <div class="form-group">
        <label for="title">Document Title</label>
        <input 
          id="title" 
          type="text" 
          [(ngModel)]="title"
          placeholder="Enter document title"
        />
      </div>
      
      <div class="form-group">
        <label>Content</label>
        <euclides-rich-editor />
      </div>
      
      <div class="form-actions">
        <button (click)="save()">Save Document</button>
        <button (click)="cancel()">Cancel</button>
      </div>
    </div>
  `,
  styles: [`
    .document-form {
      max-width: 1000px;
      margin: 2rem auto;
      padding: 2rem;
    }
    
    .form-group {
      margin-bottom: 1.5rem;
    }
    
    label {
      display: block;
      margin-bottom: 0.5rem;
      font-weight: 600;
      color: #333;
    }
    
    input[type="text"] {
      width: 100%;
      padding: 0.75rem;
      border: 1px solid #ddd;
      border-radius: 4px;
      font-size: 1rem;
    }
    
    .form-actions {
      display: flex;
      gap: 1rem;
      margin-top: 2rem;
    }
    
    button {
      padding: 0.75rem 1.5rem;
      border: none;
      border-radius: 4px;
      font-size: 1rem;
      cursor: pointer;
    }
    
    button:first-child {
      background: #007bff;
      color: white;
    }
    
    button:last-child {
      background: #6c757d;
      color: white;
    }
  `]
})
export class DocumentEditorComponent {
  title: string = '';
  
  save() {
    console.log('Saving document:', this.title);
    // Implement save logic
  }
  
  cancel() {
    console.log('Cancelling edit');
    // Implement cancel logic
  }
}

Keyboard Shortcuts

The editor supports standard keyboard shortcuts:
ShortcutAction
Ctrl/Cmd + BToggle bold
Ctrl/Cmd + IToggle italic
Ctrl/Cmd + ZUndo
Ctrl/Cmd + Shift + ZRedo
Ctrl/Cmd + YRedo (alternative)
EnterCreate new paragraph or list item
Shift + EnterHard line break
Tab (in list)Increase indentation
Shift + Tab (in list)Decrease indentation
The keyboard shortcuts are defined in src/lib/engine/keymaps/euclides-keymaps.ts and can be customized if needed.

What’s Next?

Now that you have a working editor, explore these topics:
  • Customization - Learn how to customize the editor’s appearance and behavior
  • Schema Extension - Add custom nodes and marks to the editor
  • Content Management - Extract and load editor content
  • Plugins - Extend functionality with custom plugins
  • API Reference - Explore all available methods and properties

Build docs developers (and LLMs) love