mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'SillyTavern:staging' into staging
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { fuzzySearchCharacters, fuzzySearchGroups, power_user } from "./power-user.js";
|
||||
import { fuzzySearchCharacters, fuzzySearchGroups, fuzzySearchWorldInfo, power_user } from "./power-user.js";
|
||||
import { tag_map } from "./tags.js";
|
||||
|
||||
export const FILTER_TYPES = {
|
||||
@ -6,6 +6,7 @@ export const FILTER_TYPES = {
|
||||
TAG: 'tag',
|
||||
FAV: 'fav',
|
||||
GROUP: 'group',
|
||||
WORLD_INFO_SEARCH: 'world_info_search',
|
||||
};
|
||||
|
||||
export class FilterHelper {
|
||||
@ -18,6 +19,7 @@ export class FilterHelper {
|
||||
[FILTER_TYPES.GROUP]: this.groupFilter.bind(this),
|
||||
[FILTER_TYPES.FAV]: this.favFilter.bind(this),
|
||||
[FILTER_TYPES.TAG]: this.tagFilter.bind(this),
|
||||
[FILTER_TYPES.WORLD_INFO_SEARCH]: this.wiSearchFilter.bind(this),
|
||||
}
|
||||
|
||||
filterData = {
|
||||
@ -25,6 +27,18 @@ export class FilterHelper {
|
||||
[FILTER_TYPES.GROUP]: false,
|
||||
[FILTER_TYPES.FAV]: false,
|
||||
[FILTER_TYPES.TAG]: { excluded: [], selected: [] },
|
||||
[FILTER_TYPES.WORLD_INFO_SEARCH]: '',
|
||||
}
|
||||
|
||||
wiSearchFilter(data) {
|
||||
const term = this.filterData[FILTER_TYPES.WORLD_INFO_SEARCH];
|
||||
|
||||
if (!term) {
|
||||
return data;
|
||||
}
|
||||
|
||||
const fuzzySearchResults = fuzzySearchWorldInfo(data, term);
|
||||
return data.filter(entity => fuzzySearchResults.includes(entity.uid));
|
||||
}
|
||||
|
||||
tagFilter(data) {
|
||||
@ -108,12 +122,12 @@ export class FilterHelper {
|
||||
return data.filter(entity => getIsValidSearch(entity));
|
||||
}
|
||||
|
||||
setFilterData(filterType, data) {
|
||||
setFilterData(filterType, data, suppressDataChanged = false) {
|
||||
const oldData = this.filterData[filterType];
|
||||
this.filterData[filterType] = data;
|
||||
|
||||
// only trigger a data change if the data actually changed
|
||||
if (JSON.stringify(oldData) !== JSON.stringify(data)) {
|
||||
if (JSON.stringify(oldData) !== JSON.stringify(data) && !suppressDataChanged) {
|
||||
this.onDataChanged();
|
||||
}
|
||||
}
|
||||
|
@ -947,6 +947,25 @@ export function fuzzySearchCharacters(searchValue) {
|
||||
return indices;
|
||||
}
|
||||
|
||||
export function fuzzySearchWorldInfo(data, searchValue) {
|
||||
const fuse = new Fuse(data, {
|
||||
keys: [
|
||||
{ name: 'key', weight: 3 },
|
||||
{ name: 'content', weight: 3 },
|
||||
{ name: 'comment', weight: 2 },
|
||||
{ name: 'keysecondary', weight: 2 },
|
||||
{ name: 'uid', weight: 1 },
|
||||
],
|
||||
includeScore: true,
|
||||
ignoreLocation: true,
|
||||
threshold: 0.2,
|
||||
});
|
||||
|
||||
const results = fuse.search(searchValue);
|
||||
console.debug('World Info fuzzy search results for ' + searchValue, results);
|
||||
return results.map(x => x.item?.uid);
|
||||
}
|
||||
|
||||
export function fuzzySearchGroups(searchValue) {
|
||||
const fuse = new Fuse(groups, {
|
||||
keys: [
|
||||
|
@ -4,6 +4,7 @@ import { getContext } from "./extensions.js";
|
||||
import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from "./authors-note.js";
|
||||
import { registerSlashCommand } from "./slash-commands.js";
|
||||
import { deviceInfo } from "./RossAscends-mods.js";
|
||||
import { FILTER_TYPES, FilterHelper } from "./filters.js";
|
||||
|
||||
export {
|
||||
world_info,
|
||||
@ -48,6 +49,9 @@ const sortFn = (a, b) => b.order - a.order;
|
||||
const navigation_option = { none: 0, previous: 1, last: 2, };
|
||||
let updateEditor = (navigation) => { navigation; };
|
||||
|
||||
// Do not optimize. updateEditor is a function that is updated by the displayWorldEntries with new data.
|
||||
const worldInfoFilter = new FilterHelper(() => updateEditor());
|
||||
|
||||
export function getWorldInfoSettings() {
|
||||
return {
|
||||
world_info,
|
||||
@ -236,13 +240,13 @@ function displayWorldEntries(name, data, navigation = navigation_option.none) {
|
||||
$("#world_popup_export").off('click').on('click', nullWorldInfo);
|
||||
$("#world_popup_delete").off('click').on('click', nullWorldInfo);
|
||||
$("#world_popup_entries_list").hide();
|
||||
$("#world_info_pagination").pagination('destroy');
|
||||
$('#world_info_pagination').html('');
|
||||
return;
|
||||
}
|
||||
|
||||
function getDataArray(callback) {
|
||||
// Convert the data.entries object into an array
|
||||
const entriesArray = Object.keys(data.entries).map(uid => {
|
||||
let entriesArray = Object.keys(data.entries).map(uid => {
|
||||
const entry = data.entries[uid];
|
||||
entry.displayIndex = entry.displayIndex ?? entry.uid;
|
||||
return entry;
|
||||
@ -250,7 +254,9 @@ function displayWorldEntries(name, data, navigation = navigation_option.none) {
|
||||
|
||||
// Sort the entries array by displayIndex and uid
|
||||
entriesArray.sort((a, b) => a.displayIndex - b.displayIndex || a.uid - b.uid);
|
||||
entriesArray = worldInfoFilter.applyFilters(entriesArray);
|
||||
callback(entriesArray);
|
||||
return entriesArray;
|
||||
}
|
||||
|
||||
let startPage = 1;
|
||||
@ -262,13 +268,14 @@ function displayWorldEntries(name, data, navigation = navigation_option.none) {
|
||||
const storageKey = 'WI_PerPage';
|
||||
$("#world_info_pagination").pagination({
|
||||
dataSource: getDataArray,
|
||||
pageSize: Number(localStorage.getItem(storageKey)) || 10,
|
||||
sizeChangerOptions: [10, 25, 50, 100],
|
||||
pageSize: 25,
|
||||
//pageSize: Number(localStorage.getItem(storageKey)) || 25,
|
||||
//sizeChangerOptions: [10, 25, 50, 100],
|
||||
//showSizeChanger: true,
|
||||
pageRange: 1,
|
||||
pageNumber: startPage,
|
||||
position: 'top',
|
||||
showPageNumbers: false,
|
||||
showSizeChanger: true,
|
||||
prevText: '<',
|
||||
nextText: '>',
|
||||
formatNavigator: PAGINATION_TEMPLATE,
|
||||
@ -1526,7 +1533,7 @@ jQuery(() => {
|
||||
await importWorldInfo(file);
|
||||
|
||||
// Will allow to select the same file twice in a row
|
||||
$("#form_world_import").trigger("reset");
|
||||
e.target.value = '';
|
||||
});
|
||||
|
||||
$("#world_create_button").on('click', async () => {
|
||||
@ -1539,6 +1546,8 @@ jQuery(() => {
|
||||
});
|
||||
|
||||
$("#world_editor_select").on('change', async () => {
|
||||
$("#world_info_search").val('');
|
||||
worldInfoFilter.setFilterData(FILTER_TYPES.WORLD_INFO_SEARCH, '', true);
|
||||
const selectedIndex = $("#world_editor_select").find(":selected").val();
|
||||
|
||||
if (selectedIndex === "") {
|
||||
@ -1619,23 +1628,10 @@ jQuery(() => {
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
$("#world_info").on('mousewheel', function (e) {
|
||||
e.preventDefault();
|
||||
if ($(this).is(':animated')) {
|
||||
return; //dont force multiple scroll animations
|
||||
}
|
||||
var wheelDelta = e.originalEvent.wheelDelta.toFixed(0);
|
||||
var DeltaPosNeg = (wheelDelta >= 0) ? 1 : -1; //determine if scrolling up or down
|
||||
var containerHeight = $(this).height().toFixed(0);
|
||||
var optionHeight = $(this).find('option').first().height().toFixed(0);
|
||||
var visibleOptions = (containerHeight / optionHeight).toFixed(0); //how many options we can see
|
||||
var pixelsToScroll = (optionHeight * visibleOptions * DeltaPosNeg).toFixed(0); //scroll a full container height
|
||||
var scrollTop = ($(this).scrollTop() - pixelsToScroll).toFixed(0);
|
||||
|
||||
$(this).animate({ scrollTop: scrollTop }, 200);
|
||||
$('#world_info_search').on('input', function () {
|
||||
const term = $(this).val();
|
||||
worldInfoFilter.setFilterData(FILTER_TYPES.WORLD_INFO_SEARCH, term);
|
||||
});
|
||||
*/
|
||||
|
||||
// Not needed on mobile
|
||||
if (deviceInfo.device.type === 'desktop') {
|
||||
|
Reference in New Issue
Block a user