mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-23 07:27:41 +01:00
Filter out hidden items in context menus
Add CSS to apply label show/hide settings to QRs in context menus Add provision for QR set applied to one of its own buttons as "burger" menu
This commit is contained in:
parent
a444a782e2
commit
2f7bc7ca8d
@ -38,7 +38,6 @@ export class ContextMenu {
|
|||||||
label: qr.label,
|
label: qr.label,
|
||||||
title: qr.title,
|
title: qr.title,
|
||||||
message: (chainedMessage && qr.message ? `${chainedMessage} | ` : '') + qr.message,
|
message: (chainedMessage && qr.message ? `${chainedMessage} | ` : '') + qr.message,
|
||||||
isHidden: qr.isHidden,
|
|
||||||
children: [],
|
children: [],
|
||||||
};
|
};
|
||||||
qr.contextList.forEach((cl) => {
|
qr.contextList.forEach((cl) => {
|
||||||
@ -47,7 +46,23 @@ export class ContextMenu {
|
|||||||
const nextHierarchy = [...hierarchy, cl.set];
|
const nextHierarchy = [...hierarchy, cl.set];
|
||||||
const nextLabelHierarchy = [...labelHierarchy, tree.label];
|
const nextLabelHierarchy = [...labelHierarchy, tree.label];
|
||||||
tree.children.push(new MenuHeader(cl.set.name));
|
tree.children.push(new MenuHeader(cl.set.name));
|
||||||
cl.set.qrList.forEach(subQr => {
|
|
||||||
|
// If the Quick Reply's own set is added as a context menu,
|
||||||
|
// show only the sub-QRs that are Invisible but have an icon
|
||||||
|
// intent: allow a QR set to be assigned to one of its own QR buttons for a "burger" menu
|
||||||
|
// with "UI" QRs either in the bar or in the menu, and "library function" QRs still hidden.
|
||||||
|
// - QRs already visible on the bar are filtered out,
|
||||||
|
// - hidden QRs without an icon are filtered out,
|
||||||
|
// - hidden QRs **with an icon** are shown in the menu
|
||||||
|
// so everybody is happy
|
||||||
|
const qrsOwnSetAddedAsContextMenu = cl.set.qrList.includes(qr);
|
||||||
|
const visible = (subQr) => {
|
||||||
|
return qrsOwnSetAddedAsContextMenu
|
||||||
|
? subQr.isHidden && !!subQr.icon // yes .isHidden gets inverted here
|
||||||
|
: !subQr.isHidden;
|
||||||
|
};
|
||||||
|
|
||||||
|
cl.set.qrList.filter(visible).forEach(subQr => {
|
||||||
const subTree = this.build(subQr, cl.isChained ? tree.message : null, nextHierarchy, nextLabelHierarchy);
|
const subTree = this.build(subQr, cl.isChained ? tree.message : null, nextHierarchy, nextLabelHierarchy);
|
||||||
tree.children.push(new MenuItem(
|
tree.children.push(new MenuItem(
|
||||||
subTree.icon,
|
subTree.icon,
|
||||||
@ -55,7 +70,6 @@ export class ContextMenu {
|
|||||||
subTree.label,
|
subTree.label,
|
||||||
subTree.title,
|
subTree.title,
|
||||||
subTree.message,
|
subTree.message,
|
||||||
subTree.isHidden,
|
|
||||||
(evt) => {
|
(evt) => {
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
const finalQr = Object.assign(new QuickReply(), subQr);
|
const finalQr = Object.assign(new QuickReply(), subQr);
|
||||||
|
@ -2,7 +2,7 @@ import { MenuItem } from './MenuItem.js';
|
|||||||
|
|
||||||
export class MenuHeader extends MenuItem {
|
export class MenuHeader extends MenuItem {
|
||||||
constructor(/**@type {String}*/label) {
|
constructor(/**@type {String}*/label) {
|
||||||
super(null, null, label, null, null, false, null, []);
|
super(null, null, label, null, null, null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ export class MenuItem {
|
|||||||
/**@type {string}*/ label;
|
/**@type {string}*/ label;
|
||||||
/**@type {string}*/ title;
|
/**@type {string}*/ title;
|
||||||
/**@type {object}*/ value;
|
/**@type {object}*/ value;
|
||||||
/**@type {boolean}*/ isHidden = false;
|
|
||||||
/**@type {function}*/ callback;
|
/**@type {function}*/ callback;
|
||||||
/**@type {MenuItem[]}*/ childList = [];
|
/**@type {MenuItem[]}*/ childList = [];
|
||||||
/**@type {SubMenu}*/ subMenu;
|
/**@type {SubMenu}*/ subMenu;
|
||||||
@ -25,44 +24,20 @@ export class MenuItem {
|
|||||||
* @param {string} label
|
* @param {string} label
|
||||||
* @param {?string} title Tooltip
|
* @param {?string} title Tooltip
|
||||||
* @param {object} value
|
* @param {object} value
|
||||||
* @param {boolean} isHidden QR is Invisible (auto-execute only)
|
|
||||||
* @param {function} callback
|
* @param {function} callback
|
||||||
* @param {MenuItem[]} children
|
* @param {MenuItem[]} children
|
||||||
*/
|
*/
|
||||||
constructor(icon, showLabel, label, title, value, isHidden, callback, children = []) {
|
constructor(icon, showLabel, label, title, value, callback, children = []) {
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.showLabel = showLabel;
|
this.showLabel = showLabel;
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.isHidden = isHidden;
|
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.childList = children;
|
this.childList = children;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the MenuItem
|
|
||||||
*
|
|
||||||
* A .qr--hidden class is added to:
|
|
||||||
* - the item if it is "Invisible (auto-execute only)"
|
|
||||||
* - the icon if no icon is set
|
|
||||||
* - the label if an icon is set and showLabel is false
|
|
||||||
*
|
|
||||||
* There is no .qr--hidden class defined in default CSS, since having items
|
|
||||||
* that are invisible on the QR bar but visible in the context menu,
|
|
||||||
* or icon-only on the QR bar but labelled in the context menu, is a valid use case.
|
|
||||||
*
|
|
||||||
* To hide optional labels when icons are present, add this user CSS:
|
|
||||||
* .ctx-menu .ctx-item .qr--button-label.qr--hidden {display: none;}
|
|
||||||
* To hide icons when no icon is present (removes unwanted padding):
|
|
||||||
* .ctx-menu .ctx-item .qr--button-icon.qr--hidden {display: none;}
|
|
||||||
* To hide items that are set "invisible":
|
|
||||||
* .ctx-menu .ctx-item.qr--hidden {display: none;}
|
|
||||||
* To target submenus only, use .ctx-menu .ctx-sub-menu .qr--hidden {display: none;}
|
|
||||||
*
|
|
||||||
* @returns {HTMLElement}
|
|
||||||
*/
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.root) {
|
if (!this.root) {
|
||||||
const item = document.createElement('li'); {
|
const item = document.createElement('li'); {
|
||||||
@ -70,9 +45,6 @@ export class MenuItem {
|
|||||||
item.classList.add('list-group-item');
|
item.classList.add('list-group-item');
|
||||||
item.classList.add('ctx-item');
|
item.classList.add('ctx-item');
|
||||||
|
|
||||||
// if this item is Invisible, add the hidden class
|
|
||||||
if (this.isHidden) item.classList.add('qr--hidden');
|
|
||||||
|
|
||||||
// if a title/tooltip is set, add it, otherwise use the QR content
|
// if a title/tooltip is set, add it, otherwise use the QR content
|
||||||
// same as for the main QR list
|
// same as for the main QR list
|
||||||
item.title = this.title || this.value;
|
item.title = this.title || this.value;
|
||||||
|
@ -174,6 +174,9 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
}
|
}
|
||||||
|
.ctx-menu .ctx-item .qr--hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
.list-group .list-group-item.ctx-header {
|
.list-group .list-group-item.ctx-header {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
|
@ -176,6 +176,10 @@
|
|||||||
overflow: visible;
|
overflow: visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ctx-menu .ctx-item .qr--hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.list-group .list-group-item.ctx-header {
|
.list-group .list-group-item.ctx-header {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user