feat: add global toggle buttons for lorebook always-active state (#754)

# PR Checklist
- [x] Have you checked if it works normally in all models? *Ignore this
if it doesn't use models.*
- [x] Have you checked if it works normally in all web, local, and node
hosted versions? If it doesn't, have you blocked it in those versions?
- [ ] Have you added type definitions?

# Preview

![off](https://github.com/user-attachments/assets/0b062220-a101-4c77-ac58-9e87d7e8985c)


![on](https://github.com/user-attachments/assets/1441ad33-6608-4df4-8d8d-4de9c927d180)

# Description
This PR introduces following:
- Add buttons to toggle all character/chat lorebooks' always-active
state at once
- Show SunIcon when all lorebooks are active, LinkIcon otherwise
This commit is contained in:
kwaroran
2025-02-09 16:25:19 +09:00
committed by GitHub

View File

@@ -2,13 +2,13 @@
import { DBState } from 'src/ts/stores.svelte';
import { language } from "../../../lang";
import { DownloadIcon, FolderUpIcon, ImportIcon, PlusIcon } from "lucide-svelte";
import { DownloadIcon, FolderUpIcon, ImportIcon, PlusIcon, SunIcon, LinkIcon } from "lucide-svelte";
import { addLorebook, exportLoreBook, importLoreBook } from "../../../ts/process/lorebook.svelte";
import Check from "../../UI/GUI/CheckInput.svelte";
import NumberInput from "../../UI/GUI/NumberInput.svelte";
import LoreBookList from "./LoreBookList.svelte";
import Help from "src/lib/Others/Help.svelte";
import { selectedCharID } from "src/ts/stores.svelte";
import { selectedCharID } from "src/ts/stores.svelte";
let submenu = $state(0)
interface Props {
@@ -16,6 +16,40 @@
}
let { globalMode = $bindable(false) }: Props = $props();
function isAllCharacterLoreAlwaysActive() {
const globalLore = DBState.db.characters[$selectedCharID].globalLore;
return globalLore && globalLore.every((book) => book.alwaysActive);
}
function isAllChatLoreAlwaysActive() {
const localLore = DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].localLore;
return localLore && localLore.every((book) => book.alwaysActive);
}
function toggleCharacterLoreAlwaysActive() {
const globalLore = DBState.db.characters[$selectedCharID].globalLore;
if (!globalLore) return;
const allActive = globalLore.every((book) => book.alwaysActive);
globalLore.forEach((book) => {
book.alwaysActive = !allActive;
});
}
function toggleChatLoreAlwaysActive() {
const localLore = DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].localLore;
if (!localLore) return;
const allActive = localLore.every((book) => book.alwaysActive);
localLore.forEach((book) => {
book.alwaysActive = !allActive;
});
}
</script>
{#if !globalMode}
@@ -99,5 +133,25 @@
}} class="hover:text-textcolor ml-2 cursor-pointer">
<FolderUpIcon />
</button>
<button onclick={() => {
toggleCharacterLoreAlwaysActive()
}} class="hover:text-textcolor ml-2 cursor-pointer flex items-center gap-1">
{#if isAllCharacterLoreAlwaysActive()}
<SunIcon />
{:else}
<LinkIcon />
{/if}
<span class="text-xs">CHAR</span>
</button>
<button onclick={() => {
toggleChatLoreAlwaysActive()
}} class="hover:text-textcolor ml-2 cursor-pointer flex items-center gap-1">
{#if isAllChatLoreAlwaysActive()}
<SunIcon />
{:else}
<LinkIcon />
{/if}
<span class="text-xs">CHAT</span>
</button>
</div>
{/if}