@object-ui/plugin-editor
v3.0.3
Published
Rich text editor plugin for Object UI, powered by Monaco Editor
Readme
Plugin Editor - Lazy-Loaded Monaco Editor
A lazy-loaded code editor component for Object UI based on Monaco Editor.
Features
- Internal Lazy Loading: The Monaco Editor is loaded on-demand using
React.lazy()andSuspense - Zero Configuration: Just import the package and use
type: 'code-editor'in your schema - Automatic Registration: Components auto-register with the ComponentRegistry
- Skeleton Loading: Shows a skeleton while Monaco loads
Installation
pnpm add @object-ui/plugin-editorUsage
Automatic Registration (Side-Effect Import)
// In your app entry point (e.g., App.tsx or main.tsx)
import '@object-ui/plugin-editor';
// Now you can use code-editor type in your schemas
const schema = {
type: 'code-editor',
value: 'console.log("Hello, World!");',
language: 'javascript',
theme: 'vs-dark',
height: '400px'
};Manual Integration
import { editorComponents } from '@object-ui/plugin-editor';
import { ComponentRegistry } from '@object-ui/core';
// Manually register if needed
Object.entries(editorComponents).forEach(([type, component]) => {
ComponentRegistry.register(type, component);
});TypeScript Support
The plugin exports TypeScript types for full type safety:
import type { CodeEditorSchema } from '@object-ui/plugin-editor';
const schema: CodeEditorSchema = {
type: 'code-editor',
value: 'console.log("Hello, World!");',
language: 'javascript',
theme: 'vs-dark',
height: '400px'
};Schema API
{
type: 'code-editor',
value?: string, // Code content
language?: string, // 'javascript' | 'typescript' | 'python' | 'json' | 'html' | 'css'
theme?: 'vs-dark' | 'light', // Editor theme
height?: string, // e.g., '400px'
readOnly?: boolean, // Read-only mode
className?: string // Tailwind classes
}Lazy Loading Architecture
The plugin uses a two-file pattern for optimal code splitting:
MonacoImpl.tsx: Contains the actual Monaco Editor import (heavy)index.tsx: Entry point withReact.lazy()wrapper (light)
When bundled, Vite automatically creates separate chunks:
index.js(~200 bytes) - The entry pointMonacoImpl-xxx.js(~15-20 KB) - The lazy-loaded implementation
The Monaco Editor library is only downloaded when a code-editor component is actually rendered, not on initial page load.
Build Output Example
dist/index.js 0.19 kB # Entry point
dist/MonacoImpl-DCiwKyYW.js 19.42 kB # Lazy chunk (loaded on demand)
dist/index.umd.cjs 30.37 kB # UMD bundleDevelopment
# Build the plugin
pnpm build
# The package will generate proper ESM and UMD builds with lazy loading preserved