mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into wi-go-brrrrrr-too
This commit is contained in:
@ -3,7 +3,7 @@ import { getRequestHeaders } from '../script.js';
|
||||
import { isMobile } from './RossAscends-mods.js';
|
||||
import { collapseNewlines } from './power-user.js';
|
||||
import { debounce_timeout } from './constants.js';
|
||||
import { Popup } from './popup.js';
|
||||
import { Popup, POPUP_RESULT, POPUP_TYPE } from './popup.js';
|
||||
|
||||
/**
|
||||
* Pagination status string template.
|
||||
@ -334,12 +334,12 @@ export function debouncedThrottle(func, limit = 300) {
|
||||
let last, deferTimer;
|
||||
let db = debounce(func);
|
||||
|
||||
return function() {
|
||||
return function () {
|
||||
let now = +new Date, args = arguments;
|
||||
if(!last || (last && now < last + limit)) {
|
||||
if (!last || (last && now < last + limit)) {
|
||||
clearTimeout(deferTimer);
|
||||
db.apply(this, args);
|
||||
deferTimer = setTimeout(function() {
|
||||
deferTimer = setTimeout(function () {
|
||||
last = now;
|
||||
func.apply(this, args);
|
||||
}, limit);
|
||||
@ -1961,3 +1961,75 @@ export function toggleDrawer(drawer, expand = true) {
|
||||
// Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height
|
||||
content.querySelectorAll('textarea.autoSetHeight').forEach(resetScrollHeight);
|
||||
}
|
||||
|
||||
export async function fetchFaFile(name) {
|
||||
const style = document.createElement('style');
|
||||
style.innerHTML = await (await fetch(`/css/${name}`)).text();
|
||||
document.head.append(style);
|
||||
const sheet = style.sheet;
|
||||
style.remove();
|
||||
return [...sheet.cssRules].filter(it => it.style?.content).map(it => it.selectorText.split('::').shift().slice(1));
|
||||
}
|
||||
export async function fetchFa() {
|
||||
return [...new Set((await Promise.all([
|
||||
fetchFaFile('fontawesome.min.css'),
|
||||
])).flat())];
|
||||
}
|
||||
/**
|
||||
* Opens a popup with all the available Font Awesome icons and returns the selected icon's name.
|
||||
* @prop {string[]} customList A custom list of Font Awesome icons to use instead of all available icons.
|
||||
* @returns {Promise<string>} The icon name (fa-pencil) or null if cancelled.
|
||||
*/
|
||||
export async function showFontAwesomePicker(customList = null) {
|
||||
const faList = customList ?? await fetchFa();
|
||||
const fas = {};
|
||||
const dom = document.createElement('div'); {
|
||||
dom.classList.add('faPicker-container');
|
||||
const search = document.createElement('div'); {
|
||||
search.classList.add('faQuery-container');
|
||||
const qry = document.createElement('input'); {
|
||||
qry.classList.add('text_pole');
|
||||
qry.classList.add('faQuery');
|
||||
qry.type = 'search';
|
||||
qry.placeholder = 'Filter icons';
|
||||
qry.autofocus = true;
|
||||
const qryDebounced = debounce(() => {
|
||||
const result = faList.filter(it => it.includes(qry.value));
|
||||
for (const fa of faList) {
|
||||
if (!result.includes(fa)) {
|
||||
fas[fa].classList.add('hidden');
|
||||
} else {
|
||||
fas[fa].classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
qry.addEventListener('input', () => qryDebounced());
|
||||
search.append(qry);
|
||||
}
|
||||
dom.append(search);
|
||||
}
|
||||
const grid = document.createElement('div'); {
|
||||
grid.classList.add('faPicker');
|
||||
for (const fa of faList) {
|
||||
const opt = document.createElement('div'); {
|
||||
fas[fa] = opt;
|
||||
opt.classList.add('menu_button');
|
||||
opt.classList.add('fa-solid');
|
||||
opt.classList.add(fa);
|
||||
opt.title = fa.slice(3);
|
||||
opt.dataset.result = POPUP_RESULT.AFFIRMATIVE.toString();
|
||||
opt.addEventListener('click', () => value = fa);
|
||||
grid.append(opt);
|
||||
}
|
||||
}
|
||||
dom.append(grid);
|
||||
}
|
||||
}
|
||||
let value = '';
|
||||
const picker = new Popup(dom, POPUP_TYPE.TEXT, null, { allowVerticalScrolling: true, okButton: 'No Icon', cancelButton: 'Cancel' });
|
||||
await picker.show();
|
||||
if (picker.result == POPUP_RESULT.AFFIRMATIVE) {
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user