30 lines
990 B
JavaScript
30 lines
990 B
JavaScript
// The HTTP Client and OpenAPI tool windows, loaded the first time they are shown (or asked for): until then nothing of them runs.
|
|
import { el } from './ui.js';
|
|
|
|
function lazyTool(title, load) {
|
|
const node = el('div.hc-lazy', { style: { height: '100%' } });
|
|
let promise = null;
|
|
const view = {
|
|
node,
|
|
instance: null,
|
|
title: () => title,
|
|
ready() {
|
|
promise ||= load().then((instance) => {
|
|
view.instance = instance;
|
|
node.replaceChildren(instance.node);
|
|
return instance;
|
|
});
|
|
return promise;
|
|
},
|
|
shown() { view.ready().then((i) => i.shown?.()); },
|
|
};
|
|
return view;
|
|
}
|
|
|
|
/** {client, openapi}: the two windows' views for app.js (tools httpClient and openapi). */
|
|
export function httpTools(app) {
|
|
return {
|
|
client: lazyTool('HTTP Client', () => import('./http-client.js').then((m) => new m.HttpClientPanel(app))),
|
|
openapi: lazyTool('OpenAPI', () => import('./openapi.js').then((m) => new m.OpenApiPanel(app))),
|
|
};
|
|
}
|