2 * Helper class to construct the CKEditor configuration.
4 * @author Alexander Ebert
5 * @copyright 2001-2023 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
8 * @woltlabExcludeBundle tiny
10 define(["require", "exports", "../../Language"], function (require
, exports
, Language_1
) {
12 Object
.defineProperty(exports
, "__esModule", { value
: true });
13 exports
.createConfigurationFor
= void 0;
14 class ConfigurationBuilder
{
20 constructor(features
) {
21 this.#features
= features
;
24 if (this.#features
.undo
) {
25 this.#toolbar
.push("undo", "redo");
28 this.#removePlugins
.push("Undo");
32 this.#toolbar
.push("bold", "italic");
36 if (this.#features
.heading
) {
37 items
.push("heading");
40 this.#removePlugins
.push("Heading");
42 if (this.#features
.underline
) {
43 items
.push("underline");
46 this.#removePlugins
.push("Underline");
48 if (this.#features
.strikethrough
) {
49 items
.push("strikethrough");
52 this.#removePlugins
.push("Strikethrough");
54 items
.push(this.#divider
);
55 if (this.#features
.mark
) {
56 items
.push("highlight");
59 this.#removePlugins
.push("Highlight");
61 if (this.#features
.fontColor
) {
62 items
.push("fontColor");
65 this.#removePlugins
.push("FontColor");
67 if (this.#features
.fontFamily
) {
68 items
.push("fontFamily");
71 this.#removePlugins
.push("FontFamily");
73 if (this.#features
.fontSize
) {
74 items
.push("fontSize");
77 this.#removePlugins
.push("FontSize");
79 items
.push(this.#divider
);
80 if (this.#features
.subscript
) {
81 items
.push("subscript");
84 this.#removePlugins
.push("Subscript");
86 if (this.#features
.superscript
) {
87 items
.push("superscript");
90 this.#removePlugins
.push("Superscript");
92 if (items
.length
!== 0) {
93 items
.push(this.#divider
, "removeFormat");
95 if (items
.length
> 0) {
97 label
: "woltlabToolbarGroup_format",
100 this.#toolbarGroups
["format"] = {
101 icon
: "ellipsis;false",
102 label
: (0, Language_1
.getPhrase
)("wcf.editor.button.group.format"),
107 if (this.#features
.list
) {
109 label
: "woltlabToolbarGroup_list",
110 items
: ["bulletedList", "numberedList", "outdent", "indent"],
112 this.#toolbarGroups
["list"] = {
114 label
: (0, Language_1
.getPhrase
)("wcf.editor.button.group.list"),
118 this.#removePlugins
.push("List");
122 if (this.#features
.alignment
) {
123 this.#toolbar
.push("alignment");
126 this.#removePlugins
.push("Alignment");
130 if (this.#features
.link
) {
131 this.#toolbar
.push("link");
134 this.#removePlugins
.push("Link", "LinkImage");
138 if (this.#features
.image
) {
139 this.#toolbar
.push("insertImage");
140 if (!this.#features
.attachment
) {
141 this.#removePlugins
.push("ImageUpload", "ImageUploadUI", "WoltlabAttachment");
145 this.#removePlugins
.push("ImageInsertUI");
146 if (this.#features
.link
) {
147 this.#removePlugins
.push("LinkImage");
152 if (this.#features
.codeBlock
) {
153 this.#toolbar
.push("codeBlock");
156 this.#removePlugins
.push("CodeBlock", "WoltlabCodeBlock");
158 if (this.#features
.code
) {
159 this.#toolbar
.push("code");
162 this.#removePlugins
.push("Code", "WoltlabCode");
166 if (this.#features
.table
) {
167 this.#toolbar
.push("insertTable");
170 this.#removePlugins
.push("Table", "TableToolbar");
172 if (this.#features
.quoteBlock
) {
173 this.#toolbar
.push("blockQuote");
176 this.#removePlugins
.push("BlockQuote", "WoltlabBlockQuote");
178 if (this.#features
.spoiler
) {
179 this.#toolbar
.push("spoiler");
182 this.#removePlugins
.push("WoltlabSpoiler");
184 if (this.#features
.html
) {
185 this.#toolbar
.push("htmlEmbed");
188 this.#removePlugins
.push("HtmlEmbed", "WoltlabHtmlEmbed");
192 this.#toolbar
.push(this.#divider
);
195 if (!this.#features
.media
) {
196 this.#removePlugins
.push("WoltlabMedia");
200 if (!this.#features
.mention
) {
201 this.#removePlugins
.push("Mention", "WoltlabMention");
205 let allowDivider
= false;
206 const toolbar
= this.#toolbar
.filter((item
) => {
207 if (typeof item
=== "string" && item
=== this.#divider
) {
211 allowDivider
= false;
220 if (this.#removePlugins
.length
> 0 || this.#toolbar
.length
> 0) {
221 throw new Error("Cannot build the configuration twice.");
224 this.#insertDivider();
225 this.#insertDivider();
226 this.#setupBasicFormat();
228 this.#setupTextFormat();
229 this.#insertDivider();
231 this.#setupAlignment();
232 this.#insertDivider();
234 this.#setupCodeFormat();
236 this.#insertDivider();
238 this.#setupMention();
241 const language
= Object
.keys(window
.CKEDITOR_TRANSLATIONS
).find((language
) => language
!== "en");
242 const key
= language
? language
: "en";
243 const { dictionary
} = window
.CKEDITOR_TRANSLATIONS
[key
];
244 dictionary
["Author"] = (0, Language_1
.getPhrase
)("wcf.ckeditor.quote.author");
245 dictionary
["Filename"] = (0, Language_1
.getPhrase
)("wcf.ckeditor.code.fileName");
246 dictionary
["Line number"] = (0, Language_1
.getPhrase
)("wcf.ckeditor.code.lineNumber");
247 dictionary
["Quote"] = (0, Language_1
.getPhrase
)("wcf.ckeditor.quote");
248 dictionary
["Quote from %0"] = (0, Language_1
.getPhrase
)("wcf.ckeditor.quoteFrom");
249 dictionary
["Spoiler"] = (0, Language_1
.getPhrase
)("wcf.editor.button.spoiler");
250 // TODO: The typings are both incompleted and outdated.
254 { name
: "left", className
: "text-left" },
255 { name
: "center", className
: "text-center" },
256 { name
: "right", className
: "text-right" },
257 { name
: "justify", className
: "text-justify" },
263 model
: "markerWarning",
264 class: "marker-warning",
265 title
: (0, Language_1
.getPhrase
)("wcf.ckeditor.marker.warning"),
266 color
: "var(--marker-warning)",
270 model
: "markerError",
271 class: "marker-error",
272 title
: (0, Language_1
.getPhrase
)("wcf.ckeditor.marker.error"),
273 color
: "var(--marker-error)",
278 class: "marker-info",
279 title
: (0, Language_1
.getPhrase
)("wcf.ckeditor.marker.info"),
280 color
: "var(--marker-info)",
284 model
: "markerSuccess",
285 class: "marker-success",
286 title
: (0, Language_1
.getPhrase
)("wcf.ckeditor.marker.success"),
287 color
: "var(--marker-success)",
294 defaultProtocol
: "https://",
296 removePlugins
: this.#removePlugins
,
300 "Arial, Helvetica, sans-serif",
301 "Comic Sans MS, Marker Felt, cursive",
302 "Consolas, Courier New, Courier, monospace",
304 "Lucida Sans Unicode, Lucida Grande, sans-serif",
305 "Tahoma, Geneva, sans-serif",
306 "Times New Roman, Times, serif",
307 'Trebuchet MS", Helvetica, sans-serif',
308 "Verdana, Geneva, sans-serif",
312 options
: [12, "default", 18, 23, 28],
314 toolbar
: this.#getToolbar(),
323 woltlabToolbarGroup
: this.#toolbarGroups
,
328 function createConfigurationFor(features
) {
329 const configuration
= new ConfigurationBuilder(features
);
330 configuration
.build();
331 return configuration
.toConfig();
333 exports
.createConfigurationFor
= createConfigurationFor
;