jodit
Version:
Jodit is an awesome and useful wysiwyg editor with filebrowser
75 lines (74 loc) • 3.45 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
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { component } from "../../../core/decorators/index.js";
import { Dom } from "../../../core/dom/index.js";
import { attr, isString } from "../../../core/helpers/index.js";
import { UIButton } from "../../../core/ui/button/index.js";
let ToolbarContent = class ToolbarContent extends UIButton {
/** @override */
className() {
return 'ToolbarContent';
}
/** @override */
update() {
var _a, _b, _c;
const { control } = this;
const content = control.getContent(this.j, this);
if (isString(content) || content.parentNode !== this.container) {
Dom.detach(this.container);
this.container.appendChild(isString(content) ? this.j.create.fromHTML(content) : content);
}
// Content controls never went through the ToolbarButton status
// calculation, so `isDisabled`/`isActive`/`update` declared on the
// control were silently ignored (e.g. the FileBrowser Upload button
// ignored the backend permissions). See
// https://github.com/xdan/jodit/issues/1094
this.state.disabled = Boolean((_a = control.isDisabled) === null || _a === void 0 ? void 0 : _a.call(control, this.j, this));
this.state.activated = Boolean((_b = control.isActive) === null || _b === void 0 ? void 0 : _b.call(control, this.j, this));
(_c = control.update) === null || _c === void 0 ? void 0 : _c.call(control, this.j, this);
// The first update() runs before the state watchers are attached, so
// apply the calculated state explicitly (the calls are idempotent)
this.onChangeDisabled();
this.onChangeActivated();
super.update();
}
/**
* The content is arbitrary HTML — propagate the disabled state to the
* nested form controls (e.g. the file input of the Upload button),
* otherwise they stay interactive.
*/
onChangeDisabled() {
super.onChangeDisabled();
this.container
.querySelectorAll('input,button,select,textarea')
.forEach(elm => attr(elm, 'disabled', this.state.disabled || null));
}
/** @override */
createContainer() {
return this.j.c.span(this.componentName);
}
constructor(jodit, control, target = null) {
super(jodit);
this.control = control;
this.target = target;
this.container.classList.add(`${this.componentName}_${this.clearName(control.name)}`);
attr(this.container, 'role', 'content');
}
};
ToolbarContent = __decorate([
component
], ToolbarContent);
export { ToolbarContent };