Custom Editors
How Custom Editors Work
The useEditorLifecycle Hook
import { useEditorLifecycle } from '@nimbalyst/extension-sdk';
import type { EditorHostProps } from '@nimbalyst/extension-sdk';
export function MyEditor({ host }: EditorHostProps) {
const editorRef = useRef<MyEditorAPI>(null);
const { isLoading, error, theme, markDirty, diffState } = useEditorLifecycle(host, {
applyContent: (data) => editorRef.current?.load(data),
getCurrentContent: () => editorRef.current?.getData() ?? defaultValue,
parse: (raw) => JSON.parse(raw),
serialize: (data) => JSON.stringify(data),
});
if (error) return <div>Failed to load: {error.message}</div>;
if (isLoading) return <div>Loading...</div>;
return <MyEditorComponent ref={editorRef} onChange={markDirty} theme={theme} />;
}How It Works
What It Returns
Field
Type
Description
Editor Architecture Patterns
Additional Options
Option
Type
Description
Echo Detection
EditorHost Interface
Key Concepts
Content Ownership
Why Not Pass Content as a Prop?
Registering the Editor
Styling Your Editor
Using CSS Variables
Available CSS Variables
Variable
Purpose
Including Styles
Handling Large Files
Virtualization
Lazy Parsing
Undo/Redo Support
Keyboard Shortcuts
Example: Simple Table Editor
Best Practices
Next Steps
Last updated
