OnCodemerge Docs
A WYSIWYG editor for on-codemerge
A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product. This intuitive tool for developers of all skill levels.
Welcome to the documentation for On-Codemerge, a versatile web editor designed for seamless integration and functionality.
Start by installing On-Codemerge in your project.
To install on-codemerge
, run one of the following commands in your project directory, depending on your preferred package manager:
npm install --save on-codemerge
yarn add on-codemerge
pnpm add on-codemerge
bun add on-codemerge
Here's a basic example of integrating On-Codemerge into a vanilla JavaScript project:
import 'on-codemerge/index.css';
import 'on-codemerge/plugins/ToolbarPlugin/style.css';
import 'on-codemerge/plugins/AlignmentPlugin/public.css';
import 'on-codemerge/plugins/AlignmentPlugin/style.css';
import {HTMLEditor, ToolbarPlugin, AlignmentPlugin } from 'on-codemerge';
document.addEventListener('DOMContentLoaded', async () => {
const appElement = document.getElementById('app');
if (appElement) {
const editor = new HTMLEditor(editorElement);
await editor.setLocale('ru');
editor.use(new ToolbarPlugin());
editor.use(new AlignmentPlugin());
// ... register other modules
editor.subscribeToContentChange((newContent?: string) => {
console.log(newContent)
});
// Optional: Set initial content
editor.setHtml('Your initial content here');
console.log(editor.getHtml());
}
});
Each plugin adds unique functionality to the On-Codemerge editor, making it a powerful tool for web content creation and editing.
On-Codemerge supports multiple locales to cater to a global audience. Below is the list of available locales:
Locale Code | Language | File Name |
---|---|---|
ar | Arabic | ar.json |
cs | Czech | cs.json |
de | German | de.json |
en | English | en.json |
es | Spanish | es.json |
fr | French | fr.json |
hi | Hindi | hi.json |
id | Indonesian | id.json |
it | Italian | it.json |
ja | Japanese | ja.json |
ko | Korean | ko.json |
nl | Dutch | nl.json |
pl | Polish | pl.json |
pt | Portuguese | pt.json |
ru | Russian | ru.json |
th | Thai | th.json |
tr | Turkish | tr.json |
vi | Vietnamese | vi.json |
zh | Chinese (Simplified) | zh.json |
To set a locale in On-Codemerge, use the setLocale
method:
await editor.setLocale('ru'); // Set locale to Russian
You can use placeholders in your translations to dynamically insert values. For example:
{
"File size exceeds {{max}} limit": "File size exceeds {{max}} limit"
}
In your code, you can pass the max
parameter when translating:
editor.t('File size exceeds {{max}} limit', { max: '10MB' });
This will output: File size exceeds 10MB limit
.
If a translation key is missing in the current locale, On-Codemerge will fall back to the default locale (en
by default). You can change the fallback locale using the setFallbackLocale
method:
editor.setFallbackLocale('en'); // Set fallback locale to English
To retrieve the currently active locale, use the getCurrentLocale
method:
const currentLocale = editor.getCurrentLocale();
console.log(currentLocale); // Outputs: 'ru' (if Russian is set)
To get a list of all loaded locales, use the getLoadedLocales
method:
const loadedLocales = editor.getLoadedLocales();
console.log(loadedLocales); // Outputs: ['en', 'ru', 'es']
Below is a list of all available plugins for On-Codemerge and their functionalities:
Plugin | Description |
---|---|
ToolbarPlugin | Adds a customizable toolbar for quick access to editor features. |
AlignmentPlugin | Allows alignment of text (left, center, right, justify). |
ToolbarDividerPlugin | Adds a visual divider in the toolbar for better organization. |
FontPlugin | Provides options to change font family, size, and style. |
TablePlugin | Enables creation and editing of tables. |
ImagePlugin | Allows inserting and managing images in the editor. |
BlockPlugin | Adds support for block-level elements like paragraphs, headings, etc. |
HTMLViewerPlugin | Displays the raw HTML content of the editor. |
CodeBlockPlugin | Adds syntax-highlighted code blocks for programming languages. |
TemplatesPlugin | Provides pre-designed templates for quick content creation. |
ExportPlugin | Enables exporting editor content to various formats (e.g., HTML, PDF). |
HistoryPlugin | Adds undo/redo functionality for tracking changes. |
ChartsPlugin | Allows embedding and editing charts in the editor. |
ShortcutsPlugin | Adds keyboard shortcuts for faster editing. |
ColorPlugin | Provides options to change text and background colors. |
TypographyPlugin | Adds advanced typography options like line height, letter spacing, etc. |
ListsPlugin | Enables creation of ordered and unordered lists. |
CommentsPlugin | Adds support for comments and annotations in the editor. |
FootnotesPlugin | Allows adding footnotes to the content. |
FooterPlugin | Adds a footer section to the editor. |
ResponsivePlugin | Ensures the editor content is responsive across devices. |
LinkPlugin | Allows inserting and managing hyperlinks. |
VideoPlugin | Enables embedding and managing video files. |
YouTubeVideoPlugin | Allows embedding YouTube videos directly into the editor. |
FileUploadPlugin | Provides functionality to upload and manage files. |
CollaborationPlugin | Enables real-time collaborative editing with multiple users. |
FormBuilderPlugin | Form builder plugin |
SpellCheckerPlugin | Spell Checker plugin |
BlockStylePlugin | Class and style editor |
MathPlugin | Math Plugin |
AIAssistantPlugin | AI Assistant Plugin |
Parameter | Type | Default Value | Description |
---|---|---|---|
endpoints | UploadEndpoints | undefined | Optional endpoints for file upload and download. Includes: |
- upload | string | Endpoint for uploading files. | |
- download | string | Endpoint for downloading files. | |
maxFileSize | number | 10 * 1024 * 1024 (10MB) | Maximum allowed file size in bytes. |
allowedTypes | string[] | ['*/*'] | Array of MIME types or wildcards (*/* ) to specify allowed file types. |
useEmulation | boolean | true | Enables file upload emulation for testing purposes. |
editor.use(
new FileUploadPlugin({
endpoints: {
upload: '/api/upload',
download: '/api/download',
},
maxFileSize: 20 * 1024 * 1024, // 20MB
allowedTypes: ['image/jpeg', 'image/png', 'application/pdf'],
useEmulation: false,
})
);
The SpellCheckerPlugin
provides spell-checking functionality for the On-Codemerge editor. It relies on WebAssembly (WASM) to perform efficient spell-checking operations. To use this plugin, you need to configure your build system to handle WASM files properly.
To use the SpellCheckerPlugin
, you need to configure your build system (e.g., Vite) to handle WASM files. Below is an example configuration for Vite:
import { defineConfig } from 'vite';
import wasm from 'vite-plugin-wasm';
export default defineConfig({
plugins: [
// ...
wasm(), // Enable WASM support
],
optimizeDeps: {
exclude: ['spellchecker-wasm'], // Exclude WASM library from dependency optimization
},
});
To use the SpellCheckerPlugin
, follow these steps:
Install the Plugin: Ensure the plugin is installed in your project.
Register the Plugin: Register the plugin with the On-Codemerge editor.
Configure the Plugin: Provide the necessary configuration options, such as the language dictionary.
The CollaborationPlugin
enables real-time collaborative editing of documents by multiple users. It uses WebSocket to synchronize changes between clients.
Parameter | Type | Default Value | Description |
---|---|---|---|
serverUrl | string | 'ws://localhost:8080' | URL of the WebSocket server for change synchronization. |
autoStart | boolean | true | Automatically start collaboration when the plugin is initialized. |
import { CollaborationPlugin } from 'on-codemerge';
// Initialize the plugin
const collaborationPlugin = new CollaborationPlugin({
serverUrl: 'ws://your-websocket-server.com',
autoStart: true,
});
// Register the plugin with the editor
editor.use(collaborationPlugin);
// Start collaboration
collaborationPlugin.startCollaboration();
// Disconnect from the server
collaborationPlugin.disconnect();
// Reconnect to the server
collaborationPlugin.reconnect();
To use the CollaborationPlugin
, a WebSocket server is required to handle the following events:
An example implementation of a WebSocket server is provided in the collaboration-server
folder of the project. This example demonstrates how to set up a basic server for real-time collaboration.
The collaboration-server
folder contains a Node.js implementation of a WebSocket server. Here’s how to use it:
Navigate to the collaboration-server
folder:
cd collaboration-server
Install dependencies:
npm install
Start the server:
npm start
The server will run on ws://localhost:8080
by default. You can modify the configuration as needed.