2022-07-25 01:09:31 +02:00
|
|
|
import {Controller} from "@hotwired/stimulus";
|
|
|
|
|
|
|
|
import { default as FullEditor } from "../../ckeditor/markdown_full";
|
|
|
|
import { default as SingleLineEditor} from "../../ckeditor/markdown_single_line";
|
2022-07-26 21:23:31 +02:00
|
|
|
import { default as HTMLLabelEditor } from "../../ckeditor/html_label";
|
2022-07-26 01:20:58 +02:00
|
|
|
|
|
|
|
import EditorWatchdog from '@ckeditor/ckeditor5-watchdog/src/editorwatchdog';
|
|
|
|
|
2022-07-25 01:09:31 +02:00
|
|
|
|
|
|
|
/* stimulusFetch: 'lazy' */
|
|
|
|
export default class extends Controller {
|
|
|
|
connect() {
|
|
|
|
const mode = this.element.dataset.mode;
|
|
|
|
|
|
|
|
let EDITOR_TYPE = "Invalid";
|
|
|
|
|
2022-07-26 21:23:31 +02:00
|
|
|
switch (mode) {
|
|
|
|
case "markdown-full":
|
2022-07-26 01:20:58 +02:00
|
|
|
EDITOR_TYPE = FullEditor['Editor'];
|
2022-07-26 21:23:31 +02:00
|
|
|
break;
|
|
|
|
case "markdown-single_line":
|
2022-07-26 01:20:58 +02:00
|
|
|
EDITOR_TYPE = SingleLineEditor['Editor'];
|
2022-07-26 21:23:31 +02:00
|
|
|
break;
|
|
|
|
case "html-label":
|
|
|
|
EDITOR_TYPE = HTMLLabelEditor['Editor'];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.error("Unknown mode: " + mode);
|
|
|
|
return;
|
2022-07-25 01:09:31 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 01:43:30 +02:00
|
|
|
const language = document.body.dataset.locale ?? "en";
|
|
|
|
|
2022-07-26 11:50:27 +02:00
|
|
|
const config = {
|
2022-07-26 01:43:30 +02:00
|
|
|
language: language,
|
2022-07-26 11:50:27 +02:00
|
|
|
}
|
2022-07-26 01:20:58 +02:00
|
|
|
|
2022-07-26 21:23:31 +02:00
|
|
|
const watchdog = new EditorWatchdog();
|
2022-07-26 01:20:58 +02:00
|
|
|
watchdog.setCreator((elementOrData, editorConfig) => {
|
|
|
|
return EDITOR_TYPE.create(elementOrData, editorConfig)
|
|
|
|
.then(editor => {
|
|
|
|
if(this.element.disabled) {
|
|
|
|
editor.enableReadOnlyMode("readonly");
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(editor);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-07-26 11:50:27 +02:00
|
|
|
watchdog.create(this.element, config).catch(error => {
|
2022-07-26 01:43:30 +02:00
|
|
|
console.error(error);
|
2022-07-26 11:50:27 +02:00
|
|
|
});
|
2022-07-25 01:09:31 +02:00
|
|
|
}
|
|
|
|
}
|