jodit
Version:
Jodit is an awesome and useful wysiwyg editor with filebrowser
49 lines (48 loc) • 1.87 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 { pluginSystem } from "../../core/global.js";
import { normalizeColor } from "../../core/helpers/index.js";
import "./config.js";
/**
* Process commands `background` and `forecolor`
*/
export function color(editor) {
editor.registerButton({
name: 'brush',
group: 'color'
});
const callback = (command, second, third) => {
var _a;
const colorHEX = normalizeColor(third);
const value = !colorHEX ? '' : colorHEX;
const style = command === 'background'
? { backgroundColor: value }
: { color: value };
// Cells selected with the `select-cells` plugin drop or collapse the
// native range, so `commitStyle` would paint a pending caret format
// outside the table instead of the selection the user sees. Apply the
// style to the content of every selected cell instead. See #1250
const selectedCells = editor
.getInstance('Table', editor.o)
.getAllSelectedCells();
if (selectedCells.length && editor.s.isCollapsed()) {
selectedCells.forEach(cell => {
editor.s.select(cell, true);
editor.s.commitStyle({ attributes: { style } });
});
(_a = editor.s.sel) === null || _a === void 0 ? void 0 : _a.removeAllRanges();
}
else {
editor.s.commitStyle({ attributes: { style } });
}
editor.synchronizeValues();
return false;
};
editor
.registerCommand('forecolor', callback)
.registerCommand('background', callback);
}
pluginSystem.add('color', color);