Import plugins: a side panel like the others (pinned/overlay, swaps with them) instead of a flyout
This commit is contained in:
1 parent
7ea5e72a2c
commit
21c5c2f21b
3 files changed
+36
-19
No files matched your search
+18
-17
@@ -1,7 +1,7 @@
|
||||
import { PLUGIN_ICON } from "/js/icons.js";
|
||||
import { notifyGpxStoreChanged } from "/js/panels.js";
|
||||
import { notifyGpxStoreChanged, notifySidePanelOpen, onlyOneSidePanelOpen } from "/js/panels.js";
|
||||
|
||||
// A sidebar flyout listing whatever import plugins are on disk (see
|
||||
// A side panel (#plugins-panel) listing whatever import plugins are on disk (see
|
||||
// lib/maptool/plugins.rb for the contract) — each one just a "Run for
|
||||
// this area" button using the current map viewport as the bbox, so there's
|
||||
// no separate area-picker to build: pan/zoom to where you want, click Run.
|
||||
@@ -16,27 +16,28 @@ export class PluginsControl {
|
||||
mount(sidebar) {
|
||||
this._container = document.createElement("div");
|
||||
this._container.className = "sidebar-item";
|
||||
this._container.innerHTML = `
|
||||
<button type="button" class="sidebar-icon" title="Import plugins" aria-label="Import plugins">${PLUGIN_ICON}</button>
|
||||
<div class="sidebar-flyout" hidden>
|
||||
<p class="plugins-panel__hint">Runs for whatever area is currently on screen.</p>
|
||||
<ul class="plugins-panel__list"></ul>
|
||||
</div>
|
||||
`;
|
||||
this._container.innerHTML = `<button type="button" class="sidebar-icon" title="Import plugins" aria-label="Import plugins">${PLUGIN_ICON}</button>`;
|
||||
this._icon = this._container.querySelector(".sidebar-icon");
|
||||
this._flyout = this._container.querySelector(".sidebar-flyout");
|
||||
this._list = this._container.querySelector(".plugins-panel__list");
|
||||
this._icon.addEventListener("click", () => this._togglePanel());
|
||||
|
||||
this._icon.addEventListener("click", () => {
|
||||
const opening = this._flyout.hidden;
|
||||
this._flyout.hidden = !opening;
|
||||
this._icon.classList.toggle("active", opening);
|
||||
if (opening) this._loadPlugins();
|
||||
});
|
||||
this._panel = document.getElementById("plugins-panel");
|
||||
this._list = this._panel.querySelector(".plugins-panel__list");
|
||||
this._panel.querySelector(".basemap-panel__close").addEventListener("click", () => this._togglePanel(false));
|
||||
onlyOneSidePanelOpen(this._panel, () => this._icon.classList.remove("active"));
|
||||
|
||||
sidebar.appendChild(this._container);
|
||||
}
|
||||
|
||||
_togglePanel(force) {
|
||||
const open = force === undefined ? this._panel.hidden : force;
|
||||
this._panel.hidden = !open;
|
||||
this._icon.classList.toggle("active", open);
|
||||
if (open) {
|
||||
notifySidePanelOpen(this._panel);
|
||||
this._loadPlugins();
|
||||
}
|
||||
}
|
||||
|
||||
async _loadPlugins() {
|
||||
this._list.innerHTML = `<li class="plugins-panel__empty">Loading…</li>`;
|
||||
let plugins;
|
||||
|
||||
Reference in new issue
Block a user