mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-12-23 23:02:08 +03:00
Lexical: Started image resize controls, Defined thorough decorator model
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import {EditorFormModal, EditorFormModalDefinition} from "./modals";
|
||||
import {EditorUiContext} from "./core";
|
||||
import {EditorDecorator} from "./decorator";
|
||||
|
||||
|
||||
export class EditorUIManager {
|
||||
|
||||
protected modalDefinitionsByKey: Record<string, EditorFormModalDefinition> = {};
|
||||
protected decoratorConstructorsByType: Record<string, typeof EditorDecorator> = {};
|
||||
protected decoratorInstancesByNodeKey: Record<string, EditorDecorator> = {};
|
||||
protected context: EditorUiContext|null = null;
|
||||
|
||||
setContext(context: EditorUiContext) {
|
||||
@@ -26,7 +29,7 @@ export class EditorUIManager {
|
||||
createModal(key: string): EditorFormModal {
|
||||
const modalDefinition = this.modalDefinitionsByKey[key];
|
||||
if (!modalDefinition) {
|
||||
console.error(`Attempted to show modal of key [${key}] but no modal registered for that key`);
|
||||
throw new Error(`Attempted to show modal of key [${key}] but no modal registered for that key`);
|
||||
}
|
||||
|
||||
const modal = new EditorFormModal(modalDefinition);
|
||||
@@ -35,4 +38,23 @@ export class EditorUIManager {
|
||||
return modal;
|
||||
}
|
||||
|
||||
registerDecoratorType(type: string, decorator: typeof EditorDecorator) {
|
||||
this.decoratorConstructorsByType[type] = decorator;
|
||||
}
|
||||
|
||||
getDecorator(decoratorType: string, nodeKey: string): EditorDecorator {
|
||||
if (this.decoratorInstancesByNodeKey[nodeKey]) {
|
||||
return this.decoratorInstancesByNodeKey[nodeKey];
|
||||
}
|
||||
|
||||
const decoratorClass = this.decoratorConstructorsByType[decoratorType];
|
||||
if (!decoratorClass) {
|
||||
throw new Error(`Attempted to use decorator of type [${decoratorType}] but not decorator registered for that type`);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const decorator = new decoratorClass(nodeKey);
|
||||
this.decoratorInstancesByNodeKey[nodeKey] = decorator;
|
||||
return decorator;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user