Comprehensive UI system with toolbar, buttons, dropdowns, and other interface components for building custom editor interfaces and extending the visual editing experience.
Main UI interface for the Classic Editor providing access to all UI components and layout management.
/**
* Classic Editor UI interface
*/
interface ClassicEditorUI {
/**
* Main UI container element
*/
readonly element: HTMLElement;
/**
* Main UI view component
*/
readonly view: ClassicEditorUIView;
/**
* Focus tracking utilities
*/
readonly focusTracker: FocusTracker;
/**
* Component factory for creating UI elements
*/
readonly componentFactory: ComponentFactory;
/**
* Tooltip manager
*/
readonly tooltipManager: TooltipManager;
/**
* Power management for the UI
*/
readonly poweredBy: PoweredBy;
/**
* Initialize the UI
*/
init(): void;
/**
* Destroy the UI
*/
destroy(): void;
/**
* Update the UI
*/
update(): void;
}
/**
* Classic Editor UI View
*/
interface ClassicEditorUIView {
/**
* Main toolbar view
*/
readonly toolbar: ToolbarView;
/**
* Editable area view
*/
readonly editable: EditableUIView;
/**
* Sticky panel for toolbar
*/
readonly stickyPanel: StickyPanelView;
/**
* Main UI element
*/
readonly element: HTMLElement;
}Usage Examples:
// Access main UI components
const ui = editor.ui;
const mainElement = ui.element;
const toolbar = ui.view.toolbar;
const editable = ui.view.editable;
// Get toolbar height for layout calculations
const toolbarHeight = toolbar.element.offsetHeight;
console.log('Toolbar height:', toolbarHeight);
// Access sticky panel for viewport offset
const stickyPanel = ui.view.stickyPanel;
stickyPanel.viewportTopOffset = 50; // Account for fixed header
// Update UI manually if needed
ui.update();Factory for creating and managing UI components like buttons, dropdowns, and custom elements.
/**
* Component factory for creating UI elements
*/
interface ComponentFactory {
/**
* Create a component by name
*/
create(name: string): View;
/**
* Add component definition
*/
add(name: string, callback: (locale: Locale) => View): void;
/**
* Check if component exists
*/
has(name: string): boolean;
/**
* Get component names
*/
names(): Array<string>;
/**
* Destroy factory
*/
destroy(): void;
}
/**
* Button view for creating toolbar buttons
*/
interface ButtonView extends View {
/**
* Button label text
*/
label: string;
/**
* Button icon (SVG string)
*/
icon: string;
/**
* Button tooltip text
*/
tooltip: string | boolean;
/**
* Whether button is enabled
*/
isEnabled: boolean;
/**
* Whether button is visible
*/
isVisible: boolean;
/**
* Whether button is toggled on
*/
isOn: boolean;
/**
* Button click handler
*/
on(eventName: 'execute', callback: () => void): void;
}
/**
* Dropdown view for creating dropdown components
*/
interface DropdownView extends View {
/**
* Dropdown button view
*/
readonly buttonView: ButtonView;
/**
* Dropdown panel view
*/
readonly panelView: DropdownPanelView;
/**
* Whether dropdown is open
*/
isOpen: boolean;
/**
* Open the dropdown
*/
open(): void;
/**
* Close the dropdown
*/
close(): void;
}Usage Examples:
// Access component factory
const componentFactory = editor.ui.componentFactory;
// Create custom button
componentFactory.add('customButton', locale => {
const button = new ButtonView(locale);
button.set({
label: 'Custom Action',
icon: '<svg>...</svg>',
tooltip: true,
isEnabled: true
});
// Handle button click
button.on('execute', () => {
console.log('Custom button clicked!');
editor.execute('bold'); // Example action
});
return button;
});
// Create the button instance
const customButton = componentFactory.create('customButton');
// Add button to toolbar
editor.ui.view.toolbar.items.add(customButton);
// Create dropdown component
componentFactory.add('customDropdown', locale => {
const dropdown = createDropdown(locale);
dropdown.buttonView.set({
label: 'Custom Dropdown',
icon: '<svg>...</svg>',
tooltip: 'Custom dropdown menu'
});
// Add items to dropdown
const items = new Collection();
items.add({
type: 'button',
model: new Model({
label: 'Option 1',
withText: true
})
});
addListToDropdown(dropdown, items);
return dropdown;
});Comprehensive toolbar customization and management capabilities.
/**
* Toolbar view for managing toolbar items
*/
interface ToolbarView extends View {
/**
* Collection of toolbar items
*/
readonly items: ViewCollection;
/**
* Toolbar options
*/
options: {
shouldGroupWhenFull?: boolean;
isFloating?: boolean;
};
/**
* Maximum width before grouping
*/
maxWidth: string;
/**
* Whether toolbar should group items
*/
shouldGroupWhenFull: boolean;
/**
* Add item to toolbar
*/
addItem(item: View, index?: number): void;
/**
* Remove item from toolbar
*/
removeItem(item: View): void;
/**
* Focus first toolbar item
*/
focus(): void;
/**
* Focus last toolbar item
*/
focusLast(): void;
}
/**
* View collection for managing UI components
*/
interface ViewCollection {
/**
* Add view to collection
*/
add(view: View, index?: number): void;
/**
* Remove view from collection
*/
remove(view: View): void;
/**
* Get view by index
*/
get(index: number): View;
/**
* Number of views in collection
*/
readonly length: number;
/**
* Find view by predicate
*/
find(predicate: (view: View) => boolean): View | undefined;
}Usage Examples:
// Access toolbar
const toolbar = editor.ui.view.toolbar;
// Add custom separator
const separator = new ToolbarSeparatorView();
toolbar.items.add(separator);
// Add custom button to toolbar
const customButton = editor.ui.componentFactory.create('customButton');
toolbar.items.add(customButton, 5); // Insert at position 5
// Remove item from toolbar
const boldButton = toolbar.items.find(item =>
item.label === 'Bold'
);
if (boldButton) {
toolbar.items.remove(boldButton);
}
// Configure toolbar grouping
toolbar.options.shouldGroupWhenFull = false;
// Focus toolbar
toolbar.focus();
// Monitor toolbar changes
toolbar.items.on('add', (evt, item, index) => {
console.log(`Item added to toolbar at position ${index}:`, item.label);
});
toolbar.items.on('remove', (evt, item, index) => {
console.log(`Item removed from toolbar at position ${index}:`, item.label);
});Track and manage focus within the editor UI components.
/**
* Focus tracker for managing focus state
*/
interface FocusTracker {
/**
* Whether any tracked element is focused
*/
readonly isFocused: boolean;
/**
* Currently focused element
*/
readonly focusedElement: HTMLElement | null;
/**
* Add element to focus tracking
*/
add(element: HTMLElement): void;
/**
* Remove element from focus tracking
*/
remove(element: HTMLElement): void;
/**
* Destroy focus tracker
*/
destroy(): void;
/**
* Focus change events
*/
on(eventName: 'change:isFocused', callback: (evt: EventInfo, name: string, value: boolean) => void): void;
on(eventName: 'change:focusedElement', callback: (evt: EventInfo, name: string, element: HTMLElement | null) => void): void;
}Usage Examples:
// Access focus tracker
const focusTracker = editor.ui.focusTracker;
// Check if editor has focus
console.log('Editor is focused:', focusTracker.isFocused);
console.log('Focused element:', focusTracker.focusedElement);
// Add custom element to focus tracking
const customPanel = document.createElement('div');
focusTracker.add(customPanel);
// Listen for focus changes
focusTracker.on('change:isFocused', (evt, propertyName, isFocused) => {
console.log('Editor focus changed:', isFocused);
if (isFocused) {
document.body.classList.add('editor-focused');
} else {
document.body.classList.remove('editor-focused');
}
});
focusTracker.on('change:focusedElement', (evt, propertyName, element) => {
if (element) {
console.log('Focus moved to:', element.tagName, element.className);
}
});
// Clean up when no longer needed
focusTracker.remove(customPanel);Manage tooltips for UI components and custom elements.
/**
* Tooltip manager for displaying contextual help
*/
interface TooltipManager {
/**
* Show tooltip for element
*/
show(element: HTMLElement, options: TooltipOptions): void;
/**
* Hide tooltip
*/
hide(): void;
/**
* Destroy tooltip manager
*/
destroy(): void;
}
/**
* Tooltip configuration options
*/
interface TooltipOptions {
/**
* Tooltip text content
*/
text: string;
/**
* Tooltip position relative to element
*/
position?: 'top' | 'bottom' | 'left' | 'right';
/**
* Additional CSS classes
*/
class?: string;
/**
* Delay before showing tooltip
*/
delay?: number;
}Usage Examples:
// Access tooltip manager
const tooltipManager = editor.ui.tooltipManager;
// Show custom tooltip for element
const customElement = document.querySelector('.custom-button');
tooltipManager.show(customElement, {
text: 'This is a custom tooltip',
position: 'top',
class: 'custom-tooltip',
delay: 500
});
// Hide tooltip manually
setTimeout(() => {
tooltipManager.hide();
}, 3000);
// Create button with tooltip
const buttonWithTooltip = editor.ui.componentFactory.create('customTooltipButton');
buttonWithTooltip.tooltip = 'Click me for custom action';
// Tooltip will automatically show on hoverBase view system for creating custom UI components.
/**
* Base view class for all UI components
*/
interface View {
/**
* View element
*/
readonly element: HTMLElement;
/**
* View locale
*/
readonly locale: Locale;
/**
* Whether view is rendered
*/
readonly isRendered: boolean;
/**
* View template
*/
template: Template;
/**
* Render the view
*/
render(): void;
/**
* Destroy the view
*/
destroy(): void;
/**
* Set multiple properties
*/
set(properties: Record<string, any>): void;
/**
* Bind property to another observable
*/
bind(property: string): BindChain;
}
/**
* Template for defining view structure
*/
interface Template {
/**
* HTML tag name
*/
tag: string;
/**
* Element attributes
*/
attributes?: Record<string, any>;
/**
* CSS classes
*/
children?: Array<View | Template | string>;
/**
* Child elements
*/
on?: Record<string, Function>;
}Usage Examples:
// Create custom view
class CustomPanelView extends View {
constructor(locale) {
super(locale);
this.set({
isVisible: true,
title: 'Custom Panel'
});
this.template = new Template({
tag: 'div',
attributes: {
class: ['custom-panel'],
style: {
display: this.bindTemplate.if('isVisible', 'block', 'none')
}
},
children: [
{
tag: 'h3',
children: [this.bindTemplate.to('title')]
},
{
tag: 'div',
attributes: {
class: ['custom-panel-content']
}
}
]
});
}
}
// Create and use custom view
const customPanel = new CustomPanelView(editor.locale);
customPanel.render();
document.body.appendChild(customPanel.element);
// Update view properties
customPanel.set({
title: 'Updated Panel Title',
isVisible: false
});
// Clean up
customPanel.destroy();