1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-12-20 22:22:06 +03:00

Merge pull request #5939 from BookStackApp/lexical_fixes_2512

Lexical fixes for v25.12
This commit is contained in:
Dan Brown
2025-12-20 14:05:30 +00:00
committed by GitHub
4 changed files with 31 additions and 8 deletions

View File

@@ -71,6 +71,9 @@ const actionsByKeys: Record<string, ShortcutAction> = {
return true; return true;
}, },
'meta+shift+k': (editor, context) => { 'meta+shift+k': (editor, context) => {
editor.getEditorState().read(() => {
const selection = $getSelection();
const selectionText = selection?.getTextContent() || '';
showLinkSelector(entity => { showLinkSelector(entity => {
insertOrUpdateLink(editor, { insertOrUpdateLink(editor, {
text: entity.name, text: entity.name,
@@ -78,6 +81,7 @@ const actionsByKeys: Record<string, ShortcutAction> = {
target: '', target: '',
url: entity.link, url: entity.link,
}); });
}, selectionText);
}); });
return true; return true;
}, },

View File

@@ -98,6 +98,13 @@ export class EditorForm extends EditorContainerUiElement {
this.definition = definition; this.definition = definition;
} }
focusOnFirst() {
const focusable = this.getDOMElement().querySelector('input,select,textarea');
if (focusable) {
(focusable as HTMLElement).focus();
}
}
setValues(values: Record<string, string>) { setValues(values: Record<string, string>) {
for (const name of Object.keys(values)) { for (const name of Object.keys(values)) {
const field = this.getFieldByName(name); const field = this.getFieldByName(name);

View File

@@ -14,6 +14,7 @@ export interface EditorFormModalDefinition extends EditorModalDefinition {
export class EditorFormModal extends EditorContainerUiElement { export class EditorFormModal extends EditorContainerUiElement {
protected definition: EditorFormModalDefinition; protected definition: EditorFormModalDefinition;
protected key: string; protected key: string;
protected originalFocus: Element|null = null;
constructor(definition: EditorFormModalDefinition, key: string) { constructor(definition: EditorFormModalDefinition, key: string) {
super([new EditorForm(definition.form)]); super([new EditorForm(definition.form)]);
@@ -22,6 +23,7 @@ export class EditorFormModal extends EditorContainerUiElement {
} }
show(defaultValues: Record<string, string>) { show(defaultValues: Record<string, string>) {
this.originalFocus = document.activeElement as Element;
const dom = this.getDOMElement(); const dom = this.getDOMElement();
document.body.append(dom); document.body.append(dom);
@@ -31,11 +33,15 @@ export class EditorFormModal extends EditorContainerUiElement {
form.setOnSuccessfulSubmit(this.hide.bind(this)); form.setOnSuccessfulSubmit(this.hide.bind(this));
this.getContext().manager.setModalActive(this.key, this); this.getContext().manager.setModalActive(this.key, this);
form.focusOnFirst();
} }
hide() { hide() {
this.getContext().manager.setModalInactive(this.key); this.getContext().manager.setModalInactive(this.key);
this.teardown(); this.teardown();
if (this.originalFocus instanceof HTMLElement && this.originalFocus.isConnected) {
this.originalFocus.focus();
}
} }
getForm(): EditorForm { getForm(): EditorForm {
@@ -69,6 +75,12 @@ export class EditorFormModal extends EditorContainerUiElement {
} }
}); });
wrapper.addEventListener('keydown', event => {
if (event.key === 'Escape') {
this.hide();
}
});
return wrapper; return wrapper;
} }
} }

View File

@@ -8,7 +8,7 @@ type EditorEntityData = {
export function showLinkSelector(callback: (entity: EditorEntityData) => any, selectionText?: string) { export function showLinkSelector(callback: (entity: EditorEntityData) => any, selectionText?: string) {
const selector: EntitySelectorPopup = window.$components.first('entity-selector-popup') as EntitySelectorPopup; const selector: EntitySelectorPopup = window.$components.first('entity-selector-popup') as EntitySelectorPopup;
selector.show((entity: EditorEntityData) => callback(entity), { selector.show((entity: EditorEntityData) => callback(entity), {
initialValue: selectionText, initialValue: selectionText || '',
searchEndpoint: '/search/entity-selector', searchEndpoint: '/search/entity-selector',
entityTypes: 'page,book,chapter,bookshelf', entityTypes: 'page,book,chapter,bookshelf',
entityPermission: 'view', entityPermission: 'view',