API Reference

November 30, 2025 ยท View on GitHub

Complete reference for all ArmorEditor methods, properties, and events.

Constructor

ArmorEditor(options)

Creates a new ArmorEditor instance.

const editor = new ArmorEditor({
  container: '#editor',
  height: '400px',
  // ... other options
});

Parameters:

  • options (Object) - Configuration options

Returns: ArmorEditor instance

Core Methods

Content Management

getContent()

Get the HTML content of the editor.

const content = editor.getContent();

Returns: String - HTML content

setContent(html)

Set the HTML content of the editor.

editor.setContent('<p>Hello world!</p>');

Parameters:

  • html (String) - HTML content to set

getText()

Get the plain text content (without HTML tags).

const text = editor.getText();

Returns: String - Plain text content

insertHTML(html)

Insert HTML at the current cursor position.

editor.insertHTML('<strong>Bold text</strong>');

Parameters:

  • html (String) - HTML to insert

clear()

Clear all content from the editor.

editor.clear();

Editor Control

focus()

Focus the editor.

editor.focus();

blur()

Remove focus from the editor.

editor.blur();

setReadOnly(readOnly)

Set the editor to read-only mode.

editor.setReadOnly(true);  // Enable read-only
editor.setReadOnly(false); // Enable editing

Parameters:

  • readOnly (Boolean) - Read-only state

isReadOnly()

Check if the editor is in read-only mode.

const readOnly = editor.isReadOnly();

Returns: Boolean - Read-only state

destroy()

Destroy the editor instance and clean up resources.

editor.destroy();

AI Methods

generateContent(prompt)

Generate content using AI.

const content = await editor.generateContent('Write a blog post about AI');

Parameters:

  • prompt (String) - AI prompt

Returns: Promise - Generated content

improveContent(text)

Improve existing content with AI.

const improved = await editor.improveContent('This is some text');

Parameters:

  • text (String) - Text to improve

Returns: Promise - Improved text

fixGrammar(text)

Fix grammar and spelling errors.

const corrected = await editor.fixGrammar('This are wrong');

Parameters:

  • text (String) - Text to correct

Returns: Promise - Corrected text

adjustTone(text, tone)

Adjust the tone of text.

const professional = await editor.adjustTone(text, 'professional');

Parameters:

  • text (String) - Text to adjust
  • tone (String) - Target tone ('professional', 'casual', 'friendly')

Returns: Promise - Adjusted text

Collaboration Methods

joinCollaboration(channelId, userId, userName)

Join a collaboration session.

editor.joinCollaboration('doc-123', 'user-456', 'John Doe');

Parameters:

  • channelId (String) - Document channel ID
  • userId (String) - User ID
  • userName (String) - Display name

leaveCollaboration()

Leave the current collaboration session.

editor.leaveCollaboration();

getActiveUsers()

Get list of active collaborators.

const users = editor.getActiveUsers();

Returns: Array - List of active users

setUserInfo(userInfo)

Set current user information.

editor.setUserInfo({
  userId: 'user-123',
  userName: 'Jane Smith',
  userColor: '#ff6b6b',
  avatar: 'https://example.com/avatar.jpg'
});

Parameters:

  • userInfo (Object) - User information

Security Methods

encryptContent(content)

Encrypt content using configured encryption.

const encrypted = await editor.encryptContent(sensitiveText);

Parameters:

  • content (String) - Content to encrypt

Returns: Promise - Encrypted content

decryptContent(encryptedContent)

Decrypt encrypted content.

const decrypted = await editor.decryptContent(encrypted);

Parameters:

  • encryptedContent (String) - Encrypted content

Returns: Promise - Decrypted content

getCurrentUser()

Get current authenticated user.

const user = editor.getCurrentUser();

Returns: Object - User information

hasPermission(action, resource)

Check if current user has permission.

const canEdit = editor.hasPermission('write', 'document');

Parameters:

  • action (String) - Action to check
  • resource (String) - Resource to check

Returns: Boolean - Permission status

Media Methods

startVoiceRecording()

Start recording voice comment.

editor.startVoiceRecording();

stopVoiceRecording()

Stop recording voice comment.

editor.stopVoiceRecording();

startVideoCall()

Start a video call session.

await editor.startVideoCall();

Returns: Promise - Video call session

endVideoCall()

End the current video call.

editor.endVideoCall();

editImage(imageUrl)

Open image editor for the specified image.

await editor.editImage('path/to/image.jpg');

Parameters:

  • imageUrl (String) - URL of image to edit

Returns: Promise - Edited image data

Workflow Methods

startWorkflow(workflowId, documentId, initiatedBy)

Start a workflow process.

const id = editor.startWorkflow('approval-process', 'doc-123', 'user-456');

Parameters:

  • workflowId (String) - Workflow template ID
  • documentId (String) - Document ID
  • initiatedBy (String) - User who started workflow

Returns: String - Workflow instance ID

submitForApproval(stage)

Submit document for approval at specified stage.

await editor.submitForApproval('review');

Parameters:

  • stage (String) - Approval stage

Returns: Promise - Submission result

createVersion(message, author)

Create a new document version.

const version = editor.createVersion('Added new section', {
  author: 'john@example.com',
  timestamp: new Date()
});

Parameters:

  • message (String) - Version message
  • author (Object) - Author information

Returns: Object - Version information

restoreVersion(versionId)

Restore a previous version.

const success = editor.restoreVersion('version-abc123');

Parameters:

  • versionId (String) - Version ID to restore

Returns: Boolean - Success status

Template Methods

useTemplate(templateId, variables)

Use a document template.

editor.useTemplate('project-proposal', {
  project_name: 'AI Integration',
  budget: 150000
});

Parameters:

  • templateId (String) - Template ID
  • variables (Object) - Template variables

createTemplate(template)

Create a new template.

editor.createTemplate({
  id: 'my-template',
  name: 'My Template',
  content: '<h1>{{title}}</h1><p>{{content}}</p>',
  variables: ['title', 'content']
});

Parameters:

  • template (Object) - Template definition

Performance Methods

getPerformanceMetrics()

Get current performance metrics.

const metrics = editor.getPerformanceMetrics();
console.log('FPS:', metrics.fps);
console.log('Memory:', metrics.memory);

Returns: Object - Performance metrics

cleanup()

Manually trigger cleanup of unused resources.

editor.cleanup();

enablePerformanceDebugging()

Enable performance debugging mode.

editor.enablePerformanceDebugging();

Event System

on(event, callback)

Add event listener.

editor.on('contentChanged', (content) => {
  console.log('Content changed:', content);
});

Parameters:

  • event (String) - Event name
  • callback (Function) - Event handler

off(event, callback)

Remove event listener.

editor.off('contentChanged', handler);

Parameters:

  • event (String) - Event name
  • callback (Function) - Event handler to remove

emit(event, data)

Emit custom event.

editor.emit('customEvent', { data: 'value' });

Parameters:

  • event (String) - Event name
  • data (Any) - Event data

Events

Content Events

contentChanged

Fired when content changes.

editor.on('contentChanged', (content) => {
  console.log('New content:', content);
});

Callback Parameters:

  • content (String) - New content

selectionChanged

Fired when text selection changes.

editor.on('selectionChanged', (selection) => {
  console.log('Selection:', selection);
});

Callback Parameters:

  • selection (Object) - Selection information

Collaboration Events

userJoined

Fired when a user joins collaboration.

editor.on('userJoined', (user) => {
  console.log(`${user.name} joined`);
});

Callback Parameters:

  • user (Object) - User information

userLeft

Fired when a user leaves collaboration.

editor.on('userLeft', (user) => {
  console.log(`${user.name} left`);
});

Callback Parameters:

  • user (Object) - User information

remoteChange

Fired when remote user makes changes.

editor.on('remoteChange', (change) => {
  console.log('Remote change:', change);
});

Callback Parameters:

  • change (Object) - Change information

AI Events

aiRequestStarted

Fired when AI request starts.

editor.on('aiRequestStarted', (request) => {
  console.log('AI request started:', request);
});

aiRequestCompleted

Fired when AI request completes.

editor.on('aiRequestCompleted', (result) => {
  console.log('AI result:', result);
});

aiError

Fired when AI request fails.

editor.on('aiError', (error) => {
  console.error('AI error:', error);
});

Performance Events

performanceMetric

Fired when performance metrics are updated.

editor.on('performanceMetric', (metric) => {
  console.log(`${metric.name}: ${metric.value}`);
});

performanceAlert

Fired when performance alert is triggered.

editor.on('performanceAlert', (alert) => {
  console.warn('Performance alert:', alert);
});

Configuration Options

Core Options

OptionTypeDefaultDescription
containerString/Element-Container selector or element
heightString'300px'Editor height
widthString'100%'Editor width
themeString'light'Editor theme
placeholderString''Placeholder text
readOnlyBooleanfalseRead-only mode
toolbarBoolean/ArraytrueToolbar configuration

AI Options

OptionTypeDefaultDescription
ai.enabledBooleanfalseEnable AI features
ai.providerString'openai'AI provider
ai.apiKeyString-API key
ai.modelString'gpt-3.5-turbo'AI model
ai.featuresObject{}AI feature settings

Collaboration Options

OptionTypeDefaultDescription
collaboration.enabledBooleanfalseEnable collaboration
collaboration.channelIdString-Document channel ID
collaboration.userIdString-User ID
collaboration.userNameString-Display name
collaboration.maxUsersNumber10Max concurrent users

Security Options

OptionTypeDefaultDescription
encryption.enabledBooleanfalseEnable encryption
encryption.algorithmString'AES-GCM'Encryption algorithm
encryption.keySizeNumber256Key size in bits
sso.enabledBooleanfalseEnable SSO
sso.providerString'saml'SSO provider

Performance Options

OptionTypeDefaultDescription
performance.virtualScrollingBooleanfalseVirtual scrolling
performance.lazyLoadingBooleanfalseLazy loading
performance.webWorkersBooleanfalseWeb workers
performance.memoryLimitString'100MB'Memory limit

TypeScript Types

EditorOptions

interface EditorOptions {
  container: HTMLElement | string;
  height?: string;
  width?: string;
  theme?: 'light' | 'dark';
  placeholder?: string;
  readOnly?: boolean;
  toolbar?: boolean | string[];
  ai?: AIConfig;
  collaboration?: CollaborationConfig;
  encryption?: EncryptionConfig;
  // ... other options
}

AIConfig

interface AIConfig {
  enabled: boolean;
  provider?: string;
  apiKey?: string;
  model?: string;
  features?: {
    smartSuggestions?: boolean;
    contentGeneration?: boolean;
    grammarCheck?: boolean;
  };
}

User

interface User {
  id: string;
  name: string;
  email?: string;
  avatar?: string;
  role?: string;
  permissions?: string[];
}

Error Handling

Common Errors

EditorNotInitializedError

Thrown when trying to use editor before initialization.

try {
  editor.getContent();
} catch (error) {
  if (error instanceof EditorNotInitializedError) {
    console.error('Editor not initialized');
  }
}

AIProviderError

Thrown when AI provider fails.

editor.on('aiError', (error) => {
  if (error.code === 'INVALID_API_KEY') {
    console.error('Invalid API key');
  }
});

CollaborationError

Thrown when collaboration fails.

editor.on('collaborationError', (error) => {
  if (error.code === 'CONNECTION_LOST') {
    console.error('Connection lost');
  }
});

Examples