mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
add qr context menus
This commit is contained in:
46
public/scripts/extensions/quick-reply/src/ContextMenu.js
Normal file
46
public/scripts/extensions/quick-reply/src/ContextMenu.js
Normal file
@ -0,0 +1,46 @@
|
||||
import { MenuItem } from "./MenuItem.js";
|
||||
|
||||
export class ContextMenu {
|
||||
/**@type {HTMLElement}*/ root;
|
||||
/**@type {HTMLElement}*/ menu;
|
||||
|
||||
/**@type {MenuItem[]}*/ itemList = [];
|
||||
|
||||
|
||||
|
||||
|
||||
constructor(/**@type {MenuItem[]}*/items) {
|
||||
this.itemList = items;
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.root) {
|
||||
const blocker = document.createElement('div'); {
|
||||
this.root = blocker;
|
||||
blocker.classList.add('ctx-blocker');
|
||||
blocker.addEventListener('click', ()=>this.hide());
|
||||
const menu = document.createElement('ul'); {
|
||||
this.menu = menu;
|
||||
menu.classList.add('list-group');
|
||||
menu.classList.add('ctx-menu');
|
||||
this.itemList.forEach(it=>menu.append(it.render()));
|
||||
blocker.append(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.root;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
show({screenX, screenY}) {
|
||||
this.render();
|
||||
this.menu.style.bottom = `${window.innerHeight - screenY}px`;
|
||||
this.menu.style.left = `${screenX}px`;
|
||||
document.body.append(this.root);
|
||||
}
|
||||
hide() {
|
||||
this.root.remove();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user