2023-04-18 22:20:02 +01:00
|
|
|
import {Component} from './component';
|
2019-08-11 20:04:43 +01:00
|
|
|
|
2022-11-16 13:04:22 +00:00
|
|
|
export class WysiwygEditor extends Component {
|
2017-09-23 12:24:06 +01:00
|
|
|
|
2020-07-05 21:18:17 +01:00
|
|
|
setup() {
|
|
|
|
this.elem = this.$el;
|
2024-07-01 10:44:23 +01:00
|
|
|
this.editContainer = this.$refs.editContainer;
|
2024-07-01 15:10:22 +01:00
|
|
|
this.input = this.$refs.input;
|
2020-07-05 21:18:17 +01:00
|
|
|
|
2024-07-04 13:09:53 +01:00
|
|
|
/** @var {SimpleWysiwygEditorInterface|null} */
|
|
|
|
this.editor = null;
|
|
|
|
|
2024-05-27 15:39:41 +01:00
|
|
|
window.importVersioned('wysiwyg').then(wysiwyg => {
|
2024-07-01 15:10:22 +01:00
|
|
|
const editorContent = this.input.value;
|
2024-07-04 13:09:53 +01:00
|
|
|
this.editor = wysiwyg.createPageEditorInstance(this.editContainer, editorContent);
|
|
|
|
});
|
|
|
|
|
|
|
|
let handlingFormSubmit = false;
|
|
|
|
this.input.form.addEventListener('submit', event => {
|
|
|
|
if (!this.editor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handlingFormSubmit) {
|
|
|
|
event.preventDefault();
|
|
|
|
handlingFormSubmit = true;
|
|
|
|
this.editor.getContentAsHtml().then(html => {
|
|
|
|
this.input.value = html;
|
|
|
|
this.input.form.submit();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
handlingFormSubmit = false;
|
|
|
|
}
|
2023-02-23 12:30:27 +00:00
|
|
|
});
|
2018-04-01 13:21:11 +01:00
|
|
|
}
|
|
|
|
|
2022-02-05 23:15:58 +00:00
|
|
|
getDrawIoUrl() {
|
2024-07-04 13:09:53 +01:00
|
|
|
// TODO
|
2020-04-05 17:27:16 +01:00
|
|
|
const drawioUrlElem = document.querySelector('[drawio-url]');
|
|
|
|
if (drawioUrlElem) {
|
2022-02-05 23:15:58 +00:00
|
|
|
return drawioUrlElem.getAttribute('drawio-url');
|
2018-04-01 13:21:11 +01:00
|
|
|
}
|
2022-02-05 23:15:58 +00:00
|
|
|
return '';
|
2017-09-23 12:24:06 +01:00
|
|
|
}
|
|
|
|
|
2023-02-23 12:30:27 +00:00
|
|
|
/**
|
|
|
|
* Get the content of this editor.
|
|
|
|
* Used by the parent page editor component.
|
2024-07-04 13:09:53 +01:00
|
|
|
* @return {Promise<{html: String}>}
|
2023-02-23 12:30:27 +00:00
|
|
|
*/
|
2024-07-04 13:09:53 +01:00
|
|
|
async getContent() {
|
2023-02-23 12:30:27 +00:00
|
|
|
return {
|
2024-07-04 13:09:53 +01:00
|
|
|
html: await this.editor.getContentAsHtml(),
|
2023-02-23 12:30:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-04-18 22:20:02 +01:00
|
|
|
}
|