1
0
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:
Dan Brown
2024-06-05 13:04:49 +01:00
parent a74e04141c
commit ba871ec46a
6 changed files with 244 additions and 16 deletions

View File

@@ -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;
}
}