1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Lexical: Range of fixes

- Prevented ui shortcuts running in editor
- Added form modal closing on submit
- Fixed ability to escape lists via enter on empty last item
This commit is contained in:
Dan Brown
2024-09-22 16:15:02 +01:00
parent ef3de1050f
commit c8ccb2bac7
6 changed files with 38 additions and 15 deletions

View File

@ -72,6 +72,7 @@ export class EditorFormField extends EditorUiElement {
export class EditorForm extends EditorContainerUiElement {
protected definition: EditorFormDefinition;
protected onCancel: null|(() => void) = null;
protected onSuccessfulSubmit: null|(() => void) = null;
constructor(definition: EditorFormDefinition) {
let children: (EditorFormField|EditorUiElement)[] = definition.fields.map(fieldDefinition => {
@ -98,6 +99,10 @@ export class EditorForm extends EditorContainerUiElement {
this.onCancel = callback;
}
setOnSuccessfulSubmit(callback: () => void) {
this.onSuccessfulSubmit = callback;
}
protected getFieldByName(name: string): EditorFormField|null {
const search = (children: EditorUiElement[]): EditorFormField|null => {
@ -128,10 +133,13 @@ export class EditorForm extends EditorContainerUiElement {
])
]);
form.addEventListener('submit', (event) => {
form.addEventListener('submit', async (event) => {
event.preventDefault();
const formData = new FormData(form as HTMLFormElement);
this.definition.action(formData, this.getContext());
const result = await this.definition.action(formData, this.getContext());
if (result && this.onSuccessfulSubmit) {
this.onSuccessfulSubmit();
}
});
cancelButton.addEventListener('click', (event) => {