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

Replaced el.components mapping with component service weakmap

Old system was hard to track in terms of usage and it's application of
'components' properties directly to elements was shoddy.
This routes usage via the components service, with element-specific
component usage tracked via a local weakmap.
Updated existing found usages to use the new system.
This commit is contained in:
Dan Brown
2022-11-16 15:46:41 +00:00
parent 25c23a2e5f
commit be736b3939
9 changed files with 81 additions and 22 deletions

View File

@ -43,7 +43,9 @@ export class Attachments extends Component {
reloadList() {
this.stopEdit();
this.mainTabs.components.tabs.show('items');
/** @var {Tabs} */
const tabs = window.$components.firstOnElement(this.mainTabs, 'tabs');
tabs.show('items');
window.$http.get(`/attachments/get/page/${this.pageId}`).then(resp => {
this.list.innerHTML = resp.data;
window.$components.init(this.list);

View File

@ -126,7 +126,7 @@ export class CodeEditor extends Component {
}
this.loadHistory();
this.popup.components.popup.show(() => {
this.getPopup().show(() => {
Code.updateLayout(this.editor);
this.editor.focus();
}, () => {
@ -135,10 +135,17 @@ export class CodeEditor extends Component {
}
hide() {
this.popup.components.popup.hide();
this.getPopup().hide();
this.addHistory();
}
/**
* @returns {Popup}
*/
getPopup() {
return window.$components.firstOnElement(this.popup, 'popup');
}
async updateEditorMode(language) {
const Code = await window.importVersioned('code');
Code.setMode(this.editor, language, this.editor.getValue());

View File

@ -34,7 +34,7 @@ export class ConfirmDialog extends Component {
* @returns {Popup}
*/
getPopup() {
return this.container.components.popup;
return window.$components.firstOnElement(this.container, 'popup');
}
/**

View File

@ -17,16 +17,26 @@ export class EntitySelectorPopup extends Component {
show(callback) {
this.callback = callback;
this.container.components.popup.show();
this.getPopup().show();
this.getSelector().focusSearch();
}
hide() {
this.container.components.popup.hide();
this.getPopup().hide();
}
/**
* @returns {Popup}
*/
getPopup() {
return window.$components.firstOnElement(this.container, 'popup');
}
/**
* @returns {EntitySelector}
*/
getSelector() {
return this.selectorEl.components['entity-selector'];
return window.$components.firstOnElement(this.selectorEl, 'entity-selector');
}
onSelectButtonClick() {

View File

@ -94,7 +94,7 @@ export class ImageManager extends Component {
this.callback = callback;
this.type = type;
this.popupEl.components.popup.show();
this.getPopup().show();
this.dropzoneContainer.classList.toggle('hidden', type !== 'gallery');
if (!this.hasData) {
@ -104,7 +104,14 @@ export class ImageManager extends Component {
}
hide() {
this.popupEl.components.popup.hide();
this.getPopup().hide();
}
/**
* @returns {Popup}
*/
getPopup() {
return window.$components.firstOnElement(this.popupEl, 'popup');
}
async loadGallery() {

View File

@ -196,7 +196,8 @@ export class PageEditor extends Component {
event.preventDefault();
const link = event.target.closest('a').href;
const dialog = this.switchDialogContainer.components['confirm-dialog'];
/** @var {ConfirmDialog} **/
const dialog = window.$components.firstOnElement(this.switchDialogContainer, 'confirm-dialog');
const [saved, confirmed] = await Promise.all([this.saveDraft(), dialog.show()]);
if (saved && confirmed) {

View File

@ -11,7 +11,8 @@ export class TagManager extends Component {
setupListeners() {
this.container.addEventListener('change', event => {
const addRemoveComponent = this.addRemoveComponentEl.components['add-remove-rows'];
/** @var {AddRemoveRows} **/
const addRemoveComponent = window.$components.firstOnElement(this.addRemoveComponentEl, 'add-remove-rows');
if (!this.hasEmptyRows()) {
addRemoveComponent.add();
}

View File

@ -4,12 +4,11 @@ import {Component} from "./component";
export class UserSelect extends Component {
setup() {
this.container = this.$el;
this.input = this.$refs.input;
this.userInfoContainer = this.$refs.userInfo;
this.hide = this.$el.components.dropdown.hide;
onChildEvent(this.$el, 'a.dropdown-search-item', 'click', this.selectUser.bind(this));
onChildEvent(this.container, 'a.dropdown-search-item', 'click', this.selectUser.bind(this));
}
selectUser(event, userEl) {
@ -20,4 +19,10 @@ export class UserSelect extends Component {
this.hide();
}
hide() {
/** @var {Dropdown} **/
const dropdown = window.$components.firstOnElement(this.container, 'dropdown');
dropdown.hide();
}
}