jodit
Version:
Jodit is an awesome and useful wysiwyg editor with filebrowser
80 lines (79 loc) • 2.97 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 "../../../decorators/component/component.js";
import { assert } from "../../../helpers/utils/assert.js";
import { UIButton } from "../button/button.js";
import { UIGroup } from "../../group/group.js";
let UIButtonGroup = class UIButtonGroup extends UIGroup {
/** @override */
className() {
return 'UIButtonGroup';
}
/** @override */
render(options) {
return `<div>
<div class="&__label">~${options.label}~</div>
<div class="&__options"></div>
</div>`;
}
/** @override */
appendChildToContainer(childContainer) {
const options = this.getElm('options');
assert(options != null, 'Options does not exist');
options.appendChild(childContainer);
}
constructor(jodit, options = {
radio: true
}) {
var _a, _b;
super(jodit, (_a = options.options) === null || _a === void 0 ? void 0 : _a.map(opt => {
const btn = new UIButton(jodit, {
text: opt.text,
value: opt.value,
variant: 'primary'
});
btn.onAction(() => {
this.select(opt.value);
});
return btn;
}), options);
this.options = options;
this.select((_b = options.value) !== null && _b !== void 0 ? _b : 0);
}
select(indexOrValue) {
var _a, _b;
this.elements.forEach((elm, index) => {
if (index === indexOrValue || elm.state.value === indexOrValue) {
elm.state.activated = true;
}
else if (this.options.radio) {
elm.state.activated = false;
}
});
const result = this.elements
.filter(elm => elm.state.activated)
.map(elm => ({
text: elm.state.text,
value: elm.state.value
}));
this.jodit.e.fire(this, 'select', result);
(_b = (_a = this.options).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, result);
}
};
UIButtonGroup = __decorate([
component
], UIButtonGroup);
export { UIButtonGroup };