Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions resources/js/wysiwyg/services/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ const actionsByKeys: Record<string, ShortcutAction> = {
return true;
},
'meta+shift+k': (editor, context) => {
showLinkSelector(entity => {
insertOrUpdateLink(editor, {
text: entity.name,
title: entity.link,
target: '',
url: entity.link,
});
editor.getEditorState().read(() => {
const selection = $getSelection();
const selectionText = selection?.getTextContent() || '';
showLinkSelector(entity => {
insertOrUpdateLink(editor, {
text: entity.name,
title: entity.link,
target: '',
url: entity.link,
});
}, selectionText);
});
return true;
},
Expand Down
7 changes: 7 additions & 0 deletions resources/js/wysiwyg/ui/framework/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export class EditorForm extends EditorContainerUiElement {
this.definition = definition;
}

focusOnFirst() {
const focusable = this.getDOMElement().querySelector('input,select,textarea');
if (focusable) {
(focusable as HTMLElement).focus();
}
}

setValues(values: Record<string, string>) {
for (const name of Object.keys(values)) {
const field = this.getFieldByName(name);
Expand Down
12 changes: 12 additions & 0 deletions resources/js/wysiwyg/ui/framework/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface EditorFormModalDefinition extends EditorModalDefinition {
export class EditorFormModal extends EditorContainerUiElement {
protected definition: EditorFormModalDefinition;
protected key: string;
protected originalFocus: Element|null = null;

constructor(definition: EditorFormModalDefinition, key: string) {
super([new EditorForm(definition.form)]);
Expand All @@ -22,6 +23,7 @@ export class EditorFormModal extends EditorContainerUiElement {
}

show(defaultValues: Record<string, string>) {
this.originalFocus = document.activeElement as Element;
const dom = this.getDOMElement();
document.body.append(dom);

Expand All @@ -31,11 +33,15 @@ export class EditorFormModal extends EditorContainerUiElement {
form.setOnSuccessfulSubmit(this.hide.bind(this));

this.getContext().manager.setModalActive(this.key, this);
form.focusOnFirst();
}

hide() {
this.getContext().manager.setModalInactive(this.key);
this.teardown();
if (this.originalFocus instanceof HTMLElement && this.originalFocus.isConnected) {
this.originalFocus.focus();
}
}

getForm(): EditorForm {
Expand Down Expand Up @@ -69,6 +75,12 @@ export class EditorFormModal extends EditorContainerUiElement {
}
});

wrapper.addEventListener('keydown', event => {
if (event.key === 'Escape') {
this.hide();
}
});

return wrapper;
}
}
2 changes: 1 addition & 1 deletion resources/js/wysiwyg/utils/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type EditorEntityData = {
export function showLinkSelector(callback: (entity: EditorEntityData) => any, selectionText?: string) {
const selector: EntitySelectorPopup = window.$components.first('entity-selector-popup') as EntitySelectorPopup;
selector.show((entity: EditorEntityData) => callback(entity), {
initialValue: selectionText,
initialValue: selectionText || '',
searchEndpoint: '/search/entity-selector',
entityTypes: 'page,book,chapter,bookshelf',
entityPermission: 'view',
Expand Down