@opentiny/fluent-editor
Version:
A rich text editor based on Quill 2.0, which extends rich modules and formats on the basis of Quill. It's powerful and out-of-the-box.
120 lines (119 loc) • 4.7 kB
JavaScript
import { inputFile, getListValue } from "../config/index.es.js";
import FluentEditor from "../core/fluent-editor.es.js";
import { CustomImageSpec } from "../modules/custom-image/specs/CustomImageSpec.es.js";
import BetterTable from "../modules/table/better-table.es.js";
import { FormatPainter } from "../tools/format-painter.es.js";
import { fullscreenHandler } from "../tools/fullscreen.es.js";
import { Screenshot } from "../tools/screenshot.es.js";
const SnowTheme = FluentEditor.imports["themes/snow"];
SnowTheme.DEFAULTS = {
modules: {
"i18n": true,
"keyboard": {
bindings: {
...BetterTable.keyboardBindings
}
},
"toolbar": {
handlers: {
...SnowTheme.DEFAULTS.modules.toolbar.handlers,
"formula": function() {
if (!this.quill.isEnabled()) return;
const mathlive = this.quill.getModule("mathlive");
if (!mathlive) {
this.quill.theme.tooltip.edit("formula");
} else {
mathlive.createDialog();
}
},
"undo": function() {
this.quill.history.undo();
},
"redo": function() {
this.quill.history.redo();
},
"better-table": function() {
this.quill.getModule("better-table").insertTable(3, 3);
},
"file": function() {
var _a, _b;
const accept = (_b = (_a = this.quill.options) == null ? void 0 : _a.uploadOption) == null ? void 0 : _b.fileAccept;
inputFile.call(this, "file", accept);
},
"image": function() {
var _a, _b;
const accept = (_b = (_a = this.quill.options) == null ? void 0 : _a.uploadOption) == null ? void 0 : _b.imageAccept;
inputFile.call(this, "image", accept);
},
"emoji": function() {
},
"fullscreen": fullscreenHandler,
"list": function(value) {
var _a, _b;
const range = this.quill.getSelection();
const formats = this.quill.getFormat(range);
const preListValue = Array.isArray(formats.list) ? (_a = formats.list[0]) == null ? void 0 : _a.value : (_b = formats.list) == null ? void 0 : _b.value;
const curListValue = getListValue(value, preListValue);
const lines = this.quill.getLines(range.index, range.length);
const tableCols = lines.filter((line) => line.statics.blotName === "table-col" && !line.prev);
if (tableCols.length) {
let start = range.index;
tableCols.forEach((item, index) => {
const table = item.domNode.closest("table.quill-better-table");
const tableBlot = FluentEditor.find(table);
const tableLength = tableBlot.length();
const tableStart = this.quill.getIndex(item);
const tableEnd = tableStart + tableLength;
const beforeTableRangeLength = tableStart - start;
this.quill.setSelection(start, beforeTableRangeLength, FluentEditor.sources.SILENT);
this.quill.format("list", curListValue, FluentEditor.sources.USER);
table.parentNode.classList.remove("quill-better-table-selected");
start = tableEnd;
if (index === tableCols.length - 1) {
this.quill.setSelection(tableEnd, range.index + range.length - tableEnd);
this.quill.format("list", curListValue, FluentEditor.sources.USER);
}
});
} else {
this.quill.format("list", curListValue, FluentEditor.sources.USER);
}
},
[FormatPainter.toolName]: FormatPainter,
[Screenshot.toolName]: Screenshot,
"lineheight": function(value) {
this.quill.format("line-height", value);
},
"divider": function() {
const range = this.quill.getSelection(true);
this.quill.insertText(range.index, "\n", FluentEditor.sources.USER);
this.quill.insertEmbed(range.index + 1, "divider", true, FluentEditor.sources.USER);
this.quill.setSelection(range.index + 2, FluentEditor.sources.SILENT);
}
}
},
"better-table": {
operationMenu: {
color: true
}
},
"image": {
specs: [CustomImageSpec],
overlay: {
style: {
border: "1px dashed rgb(68, 68, 68)"
}
},
align: {
icons: {
left: '<i class="icon-text-align-left"></i>',
center: '<i class="icon-text-align-center"></i>',
right: '<i class="icon-text-align-right"></i>'
}
}
}
}
};
export {
SnowTheme as default
};
//# sourceMappingURL=snow.es.js.map