jodit
Version:
Jodit is an awesome and useful wysiwyg editor with filebrowser
39 lines (38 loc) • 1.65 kB
JavaScript
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
*/
import { IS_PROD } from "../../constants.js";
import { getClassName } from "../../helpers/utils/get-class-name.js";
const componentRegistry = new Map();
/**
* Decorate components and set status isReady after constructor
* @param constructorFunction - Component constructor class
*/
export function component(constructorFunction) {
class newConstructorFunction extends constructorFunction {
constructor(...args) {
super(...args);
const isRootConstructor = this.constructor === newConstructorFunction;
// We can add a decorator to multiple classes in a chain.
// Status should be set only as root
if (isRootConstructor) {
// In some es/minimizer builds, JS instantiates the original class rather than the new constructor
if (!(this instanceof newConstructorFunction)) {
Object.setPrototypeOf(this, newConstructorFunction.prototype);
}
this.setStatus('ready');
}
}
}
const name = getClassName(constructorFunction.prototype);
if (componentRegistry.has(name) && !IS_PROD) {
throw new Error(`Component with name "${name}" is already registered`);
}
componentRegistry.set(name, newConstructorFunction);
return newConstructorFunction;
}
export function getComponentClass(name) {
return componentRegistry.get(name);
}