Skip to content

Commit 1245960

Browse files
committed
feat(ui): allow component-based settings tabs
1 parent be38df3 commit 1245960

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/UI/Settings/UIWindowSettings.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20+
import Placeholder from '../../util/Placeholder.js';
2021
import UIWindow from '../UIWindow.js'
2122

2223
async function UIWindowSettings(options){
@@ -26,6 +27,7 @@ async function UIWindowSettings(options){
2627
const svc_settings = globalThis.services.get('settings');
2728

2829
const tabs = svc_settings.get_tabs();
30+
const tab_placeholders = [];
2931

3032
let h = '';
3133

@@ -42,9 +44,14 @@ async function UIWindowSettings(options){
4244
h += `<div class="settings-content-container">`;
4345

4446
tabs.forEach((tab, i) => {
45-
h += `<div class="settings-content ${i === 0 ? 'active' : ''}" data-settings="${tab.id}">
46-
${tab.html()}
47-
</div>`;
47+
h += `<div class="settings-content ${i === 0 ? 'active' : ''}" data-settings="${tab.id}">`;
48+
if ( tab.factory ) {
49+
tab_placeholders[i] = Placeholder();
50+
h += tab_placeholders[i].html;
51+
} else {
52+
h += tab.html();
53+
}
54+
h += `</div>`;
4855
});
4956

5057
h += `</div>`;
@@ -85,7 +92,13 @@ async function UIWindowSettings(options){
8592
}
8693
});
8794
const $el_window = $(el_window);
88-
tabs.forEach(tab => tab.init($el_window));
95+
tabs.forEach((tab, i) => {
96+
tab.init && tab.init($el_window);
97+
if ( tab.factory ) {
98+
const component = tab.factory();
99+
component.attach(tab_placeholders[i]);
100+
}
101+
});
89102

90103
$(el_window).on('click', '.settings-sidebar-item', function(){
91104
const $this = $(this);

src/init_sync.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ logger.info('start -> blocking initialization');
8484
}
8585

8686
if ( registry_.classes_m[id] ) {
87-
throw new Error(`Class with ID ${id} already registered`);
87+
// throw new Error(`Class with ID ${id} already registered`);
88+
return;
8889
}
8990

9091
registry_.classes_m[id] = cls;

src/util/Placeholder.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @returns {PlaceholderReturn}
2020
*/
21-
const Placeholder = () => {
21+
const Placeholder = def(() => {
2222
const id = Placeholder.get_next_id_();
2323
return {
2424
$: 'placeholder',
@@ -29,7 +29,7 @@ const Placeholder = () => {
2929
place.replaceWith(el);
3030
}
3131
};
32-
};
32+
}, 'util.Placeholder');
3333

3434
const anti_collision = `94d2cb6b85a1`; // Arbitrary random string
3535
Placeholder.next_id_ = 0;

0 commit comments

Comments
 (0)