mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-26 20:22:18 +00:00
![Dan Brown](/assets/img/avatar_default.png)
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.
29 lines
942 B
JavaScript
29 lines
942 B
JavaScript
import {Component} from "./component";
|
|
|
|
export class TagManager extends Component {
|
|
setup() {
|
|
this.addRemoveComponentEl = this.$refs.addRemove;
|
|
this.container = this.$el;
|
|
this.rowSelector = this.$opts.rowSelector;
|
|
|
|
this.setupListeners();
|
|
}
|
|
|
|
setupListeners() {
|
|
this.container.addEventListener('change', event => {
|
|
/** @var {AddRemoveRows} **/
|
|
const addRemoveComponent = window.$components.firstOnElement(this.addRemoveComponentEl, 'add-remove-rows');
|
|
if (!this.hasEmptyRows()) {
|
|
addRemoveComponent.add();
|
|
}
|
|
});
|
|
}
|
|
|
|
hasEmptyRows() {
|
|
const rows = this.container.querySelectorAll(this.rowSelector);
|
|
const firstEmpty = [...rows].find(row => {
|
|
return [...row.querySelectorAll('input')].filter(input => input.value).length === 0;
|
|
});
|
|
return firstEmpty !== undefined;
|
|
}
|
|
} |