mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-13 17:29:55 -05:00
@@ -41,6 +41,48 @@ export const UPDATE_SOURCE_PREFERENCE = `
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const SET_SOURCE_METAS = `
|
||||||
|
mutation SetSourceMetas($input: SetSourceMetasInput!) {
|
||||||
|
setSourceMetas(input: $input) {
|
||||||
|
metas { sourceId key value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const DELETE_SOURCE_METAS = `
|
||||||
|
mutation DeleteSourceMetas($input: DeleteSourceMetasInput!) {
|
||||||
|
deleteSourceMetas(input: $input) {
|
||||||
|
metas { sourceId key value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const UPDATE_SOURCE_METADATA = `
|
||||||
|
mutation UpdateSourceMetadata(
|
||||||
|
$preUpdateDeleteInput: DeleteSourceMetasInput!
|
||||||
|
$hasPreUpdateDeletions: Boolean!
|
||||||
|
$updateInput: SetSourceMetasInput!
|
||||||
|
$hasUpdates: Boolean!
|
||||||
|
$postUpdateDeleteInput: DeleteSourceMetasInput!
|
||||||
|
$hasPostUpdateDeletions: Boolean!
|
||||||
|
$migrateInput: SetSourceMetasInput!
|
||||||
|
$isMigration: Boolean!
|
||||||
|
) {
|
||||||
|
preUpdateDeletedMeta: deleteSourceMetas(input: $preUpdateDeleteInput) @include(if: $hasPreUpdateDeletions) {
|
||||||
|
metas { sourceId key value }
|
||||||
|
}
|
||||||
|
updatedMeta: setSourceMetas(input: $updateInput) @include(if: $hasUpdates) {
|
||||||
|
metas { sourceId key value }
|
||||||
|
}
|
||||||
|
postUpdateDeletedMeta: deleteSourceMetas(input: $postUpdateDeleteInput) @include(if: $hasPostUpdateDeletions) {
|
||||||
|
metas { sourceId key value }
|
||||||
|
}
|
||||||
|
migrationMeta: setSourceMetas(input: $migrateInput) @include(if: $isMigration) {
|
||||||
|
metas { sourceId key value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
export const SET_SOURCE_META = `
|
export const SET_SOURCE_META = `
|
||||||
mutation SetSourceMeta($sourceId: LongString!, $key: String!, $value: String!) {
|
mutation SetSourceMeta($sourceId: LongString!, $key: String!, $value: String!) {
|
||||||
setSourceMeta(input: { meta: { sourceId: $sourceId, key: $key, value: $value } }) {
|
setSourceMeta(input: { meta: { sourceId: $sourceId, key: $key, value: $value } }) {
|
||||||
|
|||||||
@@ -23,6 +23,77 @@ export const GET_SOURCES = `
|
|||||||
nodes {
|
nodes {
|
||||||
id name lang displayName iconUrl isNsfw
|
id name lang displayName iconUrl isNsfw
|
||||||
isConfigurable supportsLatest baseUrl
|
isConfigurable supportsLatest baseUrl
|
||||||
|
extension { pkgName }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const GET_SOURCE_SETTINGS = `
|
||||||
|
query GetSourceSettings($id: LongString!) {
|
||||||
|
source(id: $id) {
|
||||||
|
id
|
||||||
|
displayName
|
||||||
|
preferences {
|
||||||
|
... on CheckBoxPreference {
|
||||||
|
type: __typename
|
||||||
|
CheckBoxTitle: title
|
||||||
|
CheckBoxSummary: summary
|
||||||
|
CheckBoxDefault: default
|
||||||
|
CheckBoxCurrentValue: currentValue
|
||||||
|
key
|
||||||
|
}
|
||||||
|
... on SwitchPreference {
|
||||||
|
type: __typename
|
||||||
|
SwitchPreferenceTitle: title
|
||||||
|
SwitchPreferenceSummary: summary
|
||||||
|
SwitchPreferenceDefault: default
|
||||||
|
SwitchPreferenceCurrentValue: currentValue
|
||||||
|
key
|
||||||
|
}
|
||||||
|
... on ListPreference {
|
||||||
|
type: __typename
|
||||||
|
ListPreferenceTitle: title
|
||||||
|
ListPreferenceSummary: summary
|
||||||
|
ListPreferenceDefault: default
|
||||||
|
ListPreferenceCurrentValue: currentValue
|
||||||
|
entries
|
||||||
|
entryValues
|
||||||
|
key
|
||||||
|
}
|
||||||
|
... on EditTextPreference {
|
||||||
|
type: __typename
|
||||||
|
EditTextPreferenceTitle: title
|
||||||
|
EditTextPreferenceSummary: summary
|
||||||
|
EditTextPreferenceDefault: default
|
||||||
|
EditTextPreferenceCurrentValue: currentValue
|
||||||
|
dialogTitle
|
||||||
|
dialogMessage
|
||||||
|
key
|
||||||
|
}
|
||||||
|
... on MultiSelectListPreference {
|
||||||
|
type: __typename
|
||||||
|
MultiSelectListPreferenceTitle: title
|
||||||
|
MultiSelectListPreferenceSummary: summary
|
||||||
|
MultiSelectListPreferenceDefault: default
|
||||||
|
MultiSelectListPreferenceCurrentValue: currentValue
|
||||||
|
entries
|
||||||
|
entryValues
|
||||||
|
key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const GET_MIGRATABLE_SOURCES = `
|
||||||
|
query GetMigratableSources {
|
||||||
|
mangas(condition: { inLibrary: true }) {
|
||||||
|
nodes {
|
||||||
|
sourceId
|
||||||
|
source {
|
||||||
|
id name lang displayName iconUrl isNsfw isConfigurable supportsLatest baseUrl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { CircleNotch, CaretRight, CaretDown } from "phosphor-svelte";
|
import { CircleNotch, CaretRight, CaretDown, Books } from "phosphor-svelte";
|
||||||
import Thumbnail from "@shared/manga/Thumbnail.svelte";
|
import Thumbnail from "@shared/manga/Thumbnail.svelte";
|
||||||
import type { Extension } from "@types/index";
|
import type { Extension } from "@types/index";
|
||||||
|
|
||||||
|
type SourceEntry = { id: string; displayName: string };
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
base: string;
|
base: string;
|
||||||
primary: Extension;
|
primary: Extension;
|
||||||
@@ -10,17 +12,27 @@
|
|||||||
expanded: boolean;
|
expanded: boolean;
|
||||||
working: Set<string>;
|
working: Set<string>;
|
||||||
anims: boolean;
|
anims: boolean;
|
||||||
|
sources: SourceEntry[];
|
||||||
|
libraryCount: number;
|
||||||
onToggle: (base: string) => void;
|
onToggle: (base: string) => void;
|
||||||
onMutate: (pkgName: string, op: "install" | "update" | "uninstall") => void;
|
onMutate: (pkgName: string, op: "install" | "update" | "uninstall") => void;
|
||||||
|
onLibrary: (pkgName: string, extensionName: string, iconUrl: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { base, primary, variants, expanded, working, anims, onToggle, onMutate }: Props = $props();
|
let { base, primary, variants, expanded, working, anims, sources, libraryCount, onToggle, onMutate, onLibrary }: Props = $props();
|
||||||
|
|
||||||
|
const clickable = $derived(primary.isInstalled);
|
||||||
|
|
||||||
const hasVariants = $derived(variants.length > 0);
|
const hasVariants = $derived(variants.length > 0);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="group">
|
<div class="group">
|
||||||
<div class="row">
|
<svelte:element
|
||||||
|
this={clickable ? "button" : "div"}
|
||||||
|
class="row"
|
||||||
|
class:row-clickable={clickable}
|
||||||
|
onclick={clickable ? () => onLibrary(primary.pkgName, base, primary.iconUrl) : undefined}
|
||||||
|
>
|
||||||
<Thumbnail
|
<Thumbnail
|
||||||
src={primary.iconUrl}
|
src={primary.iconUrl}
|
||||||
alt={primary.name}
|
alt={primary.name}
|
||||||
@@ -31,6 +43,13 @@
|
|||||||
<span class="name">{base}</span>
|
<span class="name">{base}</span>
|
||||||
<span class="meta">
|
<span class="meta">
|
||||||
<span class="lang-tag">{primary.lang.toUpperCase()}</span>
|
<span class="lang-tag">{primary.lang.toUpperCase()}</span>
|
||||||
|
{#if primary.isInstalled}
|
||||||
|
<span class="lib-badge" class:lib-badge-empty={libraryCount === 0}>
|
||||||
|
<Books size={10} weight={libraryCount > 0 ? "fill" : "regular"} />
|
||||||
|
{libraryCount > 0 ? libraryCount : 0}
|
||||||
|
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
v{primary.versionName}
|
v{primary.versionName}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -39,22 +58,24 @@
|
|||||||
<CircleNotch size={14} weight="light" class="anim-spin" style="color:var(--text-faint)" />
|
<CircleNotch size={14} weight="light" class="anim-spin" style="color:var(--text-faint)" />
|
||||||
{:else if primary.hasUpdate}
|
{:else if primary.hasUpdate}
|
||||||
<div class="row-actions">
|
<div class="row-actions">
|
||||||
<button class="action-btn" onclick={() => onMutate(primary.pkgName, "update")}>Update</button>
|
<button class="action-btn" onclick={(e) => { e.stopPropagation(); onMutate(primary.pkgName, "update"); }}>Update</button>
|
||||||
<button class="action-btn-dim" onclick={() => onMutate(primary.pkgName, "uninstall")}>Remove</button>
|
<button class="action-btn-dim" onclick={(e) => { e.stopPropagation(); onMutate(primary.pkgName, "uninstall"); }}>Remove</button>
|
||||||
</div>
|
</div>
|
||||||
{:else if primary.isInstalled}
|
{:else if primary.isInstalled}
|
||||||
<button class="action-btn-dim" onclick={() => onMutate(primary.pkgName, "uninstall")}>Remove</button>
|
<div class="row-actions">
|
||||||
|
<button class="action-btn-dim" onclick={(e) => { e.stopPropagation(); onMutate(primary.pkgName, "uninstall"); }}>Remove</button>
|
||||||
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<button class="action-btn" onclick={() => onMutate(primary.pkgName, "install")}>Install</button>
|
<button class="action-btn" onclick={() => onMutate(primary.pkgName, "install")}>Install</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if hasVariants}
|
{#if hasVariants}
|
||||||
<button class="expand-btn" onclick={() => onToggle(base)} title="{variants.length + 1} languages">
|
<button class="expand-btn" onclick={(e) => { e.stopPropagation(); onToggle(base); }} title="{variants.length + 1} languages">
|
||||||
{#if expanded}<CaretDown size={12} weight="light" />{:else}<CaretRight size={12} weight="light" />{/if}
|
{#if expanded}<CaretDown size={12} weight="light" />{:else}<CaretRight size={12} weight="light" />{/if}
|
||||||
<span class="expand-count">{variants.length + 1}</span>
|
<span class="expand-count">{variants.length + 1}</span>
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</svelte:element>
|
||||||
|
|
||||||
{#if expanded && hasVariants}
|
{#if expanded && hasVariants}
|
||||||
<div class="variants" class:variants-anim={anims}>
|
<div class="variants" class:variants-anim={anims}>
|
||||||
@@ -83,15 +104,18 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
.group { display: flex; flex-direction: column; }
|
.group { display: flex; flex-direction: column; }
|
||||||
.row { display: flex; align-items: center; gap: var(--sp-3); padding: 8px var(--sp-3); border-radius: var(--radius-md); border: 1px solid transparent; transition: background var(--t-fast), border-color var(--t-fast); }
|
.row { display: flex; align-items: center; gap: var(--sp-3); padding: 8px var(--sp-3); border-radius: var(--radius-md); border: 1px solid transparent; transition: background var(--t-fast), border-color var(--t-fast); width: 100%; text-align: left; background: none; }
|
||||||
.row:hover { background: var(--bg-raised); border-color: var(--border-dim); }
|
.row:hover { background: var(--bg-raised); border-color: var(--border-dim); }
|
||||||
|
.row-clickable { cursor: pointer; }
|
||||||
:global(.icon) { width: 32px; height: 32px; border-radius: var(--radius-md); object-fit: cover; flex-shrink: 0; background: var(--bg-raised); }
|
:global(.icon) { width: 32px; height: 32px; border-radius: var(--radius-md); object-fit: cover; flex-shrink: 0; background: var(--bg-raised); }
|
||||||
.info { flex: 1; display: flex; flex-direction: column; gap: 2px; overflow: hidden; min-width: 0; }
|
.info { flex: 1; display: flex; flex-direction: column; gap: 2px; overflow: hidden; min-width: 0; }
|
||||||
.name { font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
.name { font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||||
.meta { display: flex; align-items: center; gap: var(--sp-2); font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--text-faint); letter-spacing: var(--tracking-wide); }
|
.meta { display: flex; align-items: center; gap: var(--sp-2); font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--text-faint); letter-spacing: var(--tracking-wide); }
|
||||||
.lang-tag { background: var(--bg-overlay); border: 1px solid var(--border-dim); border-radius: var(--radius-sm); padding: 1px 5px; font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--text-muted); letter-spacing: var(--tracking-wider); }
|
.lang-tag { background: var(--bg-overlay); border: 1px solid var(--border-dim); border-radius: var(--radius-sm); padding: 1px 5px; font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--text-muted); letter-spacing: var(--tracking-wider); }
|
||||||
|
.lib-badge { display: inline-flex; align-items: center; gap: 4px; font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-wide); padding: 2px 7px; border-radius: var(--radius-sm); border: 1px solid var(--accent-dim); background: var(--accent-muted); color: var(--accent-fg); flex-shrink: 0; }
|
||||||
|
.lib-badge-empty { border-color: var(--border-dim); background: var(--bg-overlay); color: var(--text-faint); }
|
||||||
.update-badge-small { font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--accent-fg); flex-shrink: 0; }
|
.update-badge-small { font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--accent-fg); flex-shrink: 0; }
|
||||||
.row-actions { display: flex; gap: var(--sp-1); flex-shrink: 0; }
|
.row-actions { display: flex; align-items: center; gap: var(--sp-1); flex-shrink: 0; }
|
||||||
.action-btn { font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); padding: 4px 10px; border-radius: var(--radius-md); background: var(--accent-muted); color: var(--accent-fg); border: 1px solid var(--accent-dim); cursor: pointer; flex-shrink: 0; transition: filter var(--t-base); }
|
.action-btn { font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); padding: 4px 10px; border-radius: var(--radius-md); background: var(--accent-muted); color: var(--accent-fg); border: 1px solid var(--accent-dim); cursor: pointer; flex-shrink: 0; transition: filter var(--t-base); }
|
||||||
.action-btn:hover { filter: brightness(1.1); }
|
.action-btn:hover { filter: brightness(1.1); }
|
||||||
.action-btn-dim { font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); padding: 4px 10px; border-radius: var(--radius-md); background: none; color: var(--text-faint); border: 1px solid var(--border-dim); cursor: pointer; flex-shrink: 0; transition: color var(--t-base), border-color var(--t-base); }
|
.action-btn-dim { font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); padding: 4px 10px; border-radius: var(--radius-md); background: none; color: var(--text-faint); border: 1px solid var(--border-dim); cursor: pointer; flex-shrink: 0; transition: color var(--t-base), border-color var(--t-base); }
|
||||||
@@ -106,5 +130,5 @@
|
|||||||
.variant-row:hover { background: var(--bg-raised); }
|
.variant-row:hover { background: var(--bg-raised); }
|
||||||
.variant-name { flex: 1; font-size: var(--text-sm); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
.variant-name { flex: 1; font-size: var(--text-sm); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||||
.variant-version { font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--text-faint); letter-spacing: var(--tracking-wide); flex-shrink: 0; }
|
.variant-version { font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--text-faint); letter-spacing: var(--tracking-wide); flex-shrink: 0; }
|
||||||
.variant-actions { flex-shrink: 0; }
|
.variant-actions { display: flex; align-items: center; gap: var(--sp-1); flex-shrink: 0; }
|
||||||
</style>
|
</style>
|
||||||
@@ -3,14 +3,21 @@
|
|||||||
import { CircleNotch, X, Check, HardDrives } from "phosphor-svelte";
|
import { CircleNotch, X, Check, HardDrives } from "phosphor-svelte";
|
||||||
import { gql } from "@api/client";
|
import { gql } from "@api/client";
|
||||||
import { store, addToast } from "@store/state.svelte";
|
import { store, addToast } from "@store/state.svelte";
|
||||||
import { GET_EXTENSIONS, GET_SETTINGS, GET_LOCAL_MANGA } from "@api/queries";
|
import { GET_EXTENSIONS, GET_SOURCES, GET_SETTINGS, GET_LOCAL_MANGA, GET_LIBRARY } from "@api/queries";
|
||||||
import { SET_EXTENSION_REPOS, INSTALL_EXTERNAL_EXTENSION, FETCH_EXTENSIONS, UPDATE_EXTENSION } from "@api/mutations";
|
import { SET_EXTENSION_REPOS, INSTALL_EXTERNAL_EXTENSION, FETCH_EXTENSIONS, UPDATE_EXTENSION } from "@api/mutations";
|
||||||
import type { Extension } from "@types/index";
|
import type { Extension } from "@types/index";
|
||||||
import { matchesFilter, groupExtensions, validateUrl, type Filter, type Panel } from "../lib/extensionHelpers";
|
import { matchesFilter, groupExtensions, validateUrl, type Filter, type Panel } from "../lib/extensionHelpers";
|
||||||
|
import { libraryCountByPkg, type LibraryManga, type SourceNode } from "../lib/extensionLibrary";
|
||||||
import ExtensionFilters from "./ExtensionFilters.svelte";
|
import ExtensionFilters from "./ExtensionFilters.svelte";
|
||||||
import ExtensionCard from "./ExtensionCard.svelte";
|
import ExtensionCard from "./ExtensionCard.svelte";
|
||||||
|
import ExtensionSettingsPanel from "../panels/ExtensionSettingsPanel.svelte";
|
||||||
|
import ExtensionLibraryPanel from "../panels/ExtensionLibraryPanel.svelte";
|
||||||
|
|
||||||
const anims = $derived(store.settings.qolAnimations ?? true);
|
const anims = $derived(store.settings.qolAnimations ?? true);
|
||||||
|
const cols = $derived(store.settings.libraryCols ?? 5);
|
||||||
|
const cropCovers = $derived(store.settings.cropCovers ?? true);
|
||||||
|
const statsAlways = $derived(store.settings.statsAlways ?? false);
|
||||||
|
|
||||||
let tabsEl = $state<HTMLDivElement | undefined>(undefined);
|
let tabsEl = $state<HTMLDivElement | undefined>(undefined);
|
||||||
let tabIndicator = $state({ left: 0, width: 0 });
|
let tabIndicator = $state({ left: 0, width: 0 });
|
||||||
|
|
||||||
@@ -33,6 +40,15 @@
|
|||||||
let expanded = $state(new Set<string>());
|
let expanded = $state(new Set<string>());
|
||||||
let panel = $state<Panel>(null);
|
let panel = $state<Panel>(null);
|
||||||
|
|
||||||
|
type SourceEntry = { id: string; displayName: string };
|
||||||
|
type SettingsTarget = { extensionName: string; iconUrl: string; sources: SourceEntry[] };
|
||||||
|
type LibraryTarget = { pkgName: string; extensionName: string; iconUrl: string };
|
||||||
|
|
||||||
|
let settingsTarget = $state<SettingsTarget | null>(null);
|
||||||
|
let libraryTarget = $state<LibraryTarget | null>(null);
|
||||||
|
let sourcesByPkg = $state<Record<string, SourceEntry[]>>({});
|
||||||
|
let libCountByPkg = $state<Record<string, number>>({});
|
||||||
|
|
||||||
$effect(() => { filter; extensions; if (anims) requestAnimationFrame(() => requestAnimationFrame(updateIndicator)); });
|
$effect(() => { filter; extensions; if (anims) requestAnimationFrame(() => requestAnimationFrame(updateIndicator)); });
|
||||||
|
|
||||||
let externalUrl = $state("");
|
let externalUrl = $state("");
|
||||||
@@ -47,8 +63,25 @@
|
|||||||
let savingRepos = $state(false);
|
let savingRepos = $state(false);
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
const d = await gql<{ extensions: { nodes: Extension[] } }>(GET_EXTENSIONS).catch(console.error);
|
const [extData, srcData, libData] = await Promise.all([
|
||||||
if (d) extensions = d.extensions.nodes;
|
gql<{ extensions: { nodes: Extension[] } }>(GET_EXTENSIONS).catch(console.error),
|
||||||
|
gql<{ sources: { nodes: SourceNode[] } }>(GET_SOURCES).catch(console.error),
|
||||||
|
gql<{ mangas: { nodes: LibraryManga[] } }>(GET_LIBRARY).catch(console.error),
|
||||||
|
]);
|
||||||
|
if (extData) extensions = extData.extensions.nodes;
|
||||||
|
if (srcData) {
|
||||||
|
const map: Record<string, SourceEntry[]> = {};
|
||||||
|
for (const s of srcData.sources.nodes) {
|
||||||
|
if (!s.isConfigurable || !s.extension?.pkgName) continue;
|
||||||
|
const pkg = s.extension.pkgName;
|
||||||
|
if (!map[pkg]) map[pkg] = [];
|
||||||
|
map[pkg].push({ id: s.id, displayName: s.displayName });
|
||||||
|
}
|
||||||
|
sourcesByPkg = map;
|
||||||
|
}
|
||||||
|
if (libData && srcData) {
|
||||||
|
libCountByPkg = libraryCountByPkg(libData.mangas.nodes, srcData.sources.nodes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadLocalManga() {
|
async function loadLocalManga() {
|
||||||
@@ -213,6 +246,17 @@
|
|||||||
function focusOnMount(node: HTMLElement) { node.focus(); }
|
function focusOnMount(node: HTMLElement) { node.focus(); }
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if libraryTarget}
|
||||||
|
<ExtensionLibraryPanel
|
||||||
|
pkgName={libraryTarget.pkgName}
|
||||||
|
extensionName={libraryTarget.extensionName}
|
||||||
|
iconUrl={libraryTarget.iconUrl}
|
||||||
|
{cols} {cropCovers} {statsAlways} {anims}
|
||||||
|
sources={sourcesByPkg[libraryTarget.pkgName] ?? []}
|
||||||
|
onBack={() => libraryTarget = null}
|
||||||
|
onSettings={() => { settingsTarget = { extensionName: libraryTarget!.extensionName, iconUrl: libraryTarget!.iconUrl, sources: sourcesByPkg[libraryTarget!.pkgName] ?? [] }; }}
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
<div class="root anim-fade-in">
|
<div class="root anim-fade-in">
|
||||||
<ExtensionFilters
|
<ExtensionFilters
|
||||||
{filter} {search} {panel} {refreshing} {updateCount} {availableLangs} {langFilter}
|
{filter} {search} {panel} {refreshing} {updateCount} {availableLangs} {langFilter}
|
||||||
@@ -307,9 +351,12 @@
|
|||||||
{#each groups as { base, primary, variants }}
|
{#each groups as { base, primary, variants }}
|
||||||
<ExtensionCard
|
<ExtensionCard
|
||||||
{base} {primary} {variants} {working} {anims}
|
{base} {primary} {variants} {working} {anims}
|
||||||
|
sources={sourcesByPkg[primary.pkgName] ?? []}
|
||||||
|
libraryCount={libCountByPkg[primary.pkgName] ?? 0}
|
||||||
expanded={expanded.has(base)}
|
expanded={expanded.has(base)}
|
||||||
onToggle={toggleExpand}
|
onToggle={toggleExpand}
|
||||||
onMutate={mutate}
|
onMutate={mutate}
|
||||||
|
onLibrary={(pkgName, extensionName, iconUrl) => libraryTarget = { pkgName, extensionName, iconUrl }}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
{#if !showLocal && groups.length === 0}
|
{#if !showLocal && groups.length === 0}
|
||||||
@@ -318,6 +365,16 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if settingsTarget}
|
||||||
|
<ExtensionSettingsPanel
|
||||||
|
extensionName={settingsTarget.extensionName}
|
||||||
|
iconUrl={settingsTarget.iconUrl}
|
||||||
|
sources={settingsTarget.sources}
|
||||||
|
onClose={() => settingsTarget = null}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.root { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
|
.root { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
export interface LibraryManga {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
thumbnailUrl: string;
|
||||||
|
unreadCount: number;
|
||||||
|
downloadCount: number;
|
||||||
|
source: { id: string; displayName: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SourceLibrary {
|
||||||
|
sourceId: string;
|
||||||
|
displayName: string;
|
||||||
|
manga: LibraryManga[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SourceNode = {
|
||||||
|
id: string;
|
||||||
|
displayName: string;
|
||||||
|
isConfigurable: boolean;
|
||||||
|
extension: { pkgName: string };
|
||||||
|
};
|
||||||
|
|
||||||
|
export function libraryByExtension(
|
||||||
|
libraryManga: LibraryManga[],
|
||||||
|
sources: SourceNode[],
|
||||||
|
pkgName: string,
|
||||||
|
): SourceLibrary[] {
|
||||||
|
const pkgSources = sources.filter(s => s.extension?.pkgName === pkgName);
|
||||||
|
const sourceIds = new Set(pkgSources.map(s => s.id));
|
||||||
|
|
||||||
|
const bySource = new Map<string, LibraryManga[]>();
|
||||||
|
for (const src of pkgSources) bySource.set(src.id, []);
|
||||||
|
for (const m of libraryManga) {
|
||||||
|
if (sourceIds.has(m.source.id)) bySource.get(m.source.id)!.push(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pkgSources
|
||||||
|
.map(src => ({ sourceId: src.id, displayName: src.displayName, manga: bySource.get(src.id)! }))
|
||||||
|
.filter(g => g.manga.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function libraryCountByPkg(
|
||||||
|
libraryManga: LibraryManga[],
|
||||||
|
sources: SourceNode[],
|
||||||
|
): Record<string, number> {
|
||||||
|
const sourceIdToPkg = new Map<string, string>();
|
||||||
|
for (const s of sources) {
|
||||||
|
if (s.extension?.pkgName) sourceIdToPkg.set(s.id, s.extension.pkgName);
|
||||||
|
}
|
||||||
|
const counts: Record<string, number> = {};
|
||||||
|
for (const m of libraryManga) {
|
||||||
|
const pkg = sourceIdToPkg.get(m.source.id);
|
||||||
|
if (pkg) counts[pkg] = (counts[pkg] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
}
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { ArrowLeft, MagnifyingGlass, GearSix } from "phosphor-svelte";
|
||||||
|
import Thumbnail from "@shared/manga/Thumbnail.svelte";
|
||||||
|
import { resolvedCover } from "@core/cover/coverResolver";
|
||||||
|
import { gql } from "@api/client";
|
||||||
|
import { setPreviewManga } from "@store/state.svelte";
|
||||||
|
import { GET_LIBRARY, GET_SOURCES } from "@api/queries";
|
||||||
|
import { libraryByExtension, type LibraryManga, type SourceNode, type SourceLibrary } from "../lib/extensionLibrary";
|
||||||
|
|
||||||
|
type SourceEntry = { id: string; displayName: string };
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
pkgName: string;
|
||||||
|
extensionName: string;
|
||||||
|
iconUrl: string;
|
||||||
|
cols: number;
|
||||||
|
cropCovers: boolean;
|
||||||
|
statsAlways: boolean;
|
||||||
|
anims: boolean;
|
||||||
|
sources: SourceEntry[];
|
||||||
|
onBack: () => void;
|
||||||
|
onSettings: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { pkgName, extensionName, iconUrl, cols, cropCovers, statsAlways, anims, sources, onBack, onSettings }: Props = $props();
|
||||||
|
|
||||||
|
let groups: SourceLibrary[] = $state([]);
|
||||||
|
let loading = $state(true);
|
||||||
|
let search = $state("");
|
||||||
|
|
||||||
|
const allManga = $derived(groups.flatMap(g => g.manga));
|
||||||
|
const filtered = $derived(
|
||||||
|
search.trim()
|
||||||
|
? allManga.filter(m => m.title.toLowerCase().includes(search.toLowerCase()))
|
||||||
|
: allManga
|
||||||
|
);
|
||||||
|
|
||||||
|
$effect(() => { load(); });
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
loading = true;
|
||||||
|
try {
|
||||||
|
const [libData, srcData] = await Promise.all([
|
||||||
|
gql<{ mangas: { nodes: LibraryManga[] } }>(GET_LIBRARY),
|
||||||
|
gql<{ sources: { nodes: SourceNode[] } }>(GET_SOURCES),
|
||||||
|
]);
|
||||||
|
groups = libraryByExtension(libData.mangas.nodes, srcData.sources.nodes, pkgName);
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="root">
|
||||||
|
<div class="header">
|
||||||
|
<button class="back-btn" onclick={onBack}>
|
||||||
|
<ArrowLeft size={14} weight="bold" />
|
||||||
|
</button>
|
||||||
|
{#if iconUrl}
|
||||||
|
<Thumbnail src={iconUrl} alt={extensionName} class="header-icon" onerror={(e) => ((e.target as HTMLImageElement).style.display = "none")} />
|
||||||
|
{/if}
|
||||||
|
<div class="title-block">
|
||||||
|
<span class="eyebrow">In Library</span>
|
||||||
|
<span class="title">{extensionName}</span>
|
||||||
|
</div>
|
||||||
|
{#if !loading}
|
||||||
|
<span class="count-badge">{allManga.length}</span>
|
||||||
|
{/if}
|
||||||
|
<div class="search-wrap">
|
||||||
|
<MagnifyingGlass size={12} class="search-icon" weight="light" />
|
||||||
|
<input class="search" placeholder="Search" bind:value={search} autocomplete="off" />
|
||||||
|
</div>
|
||||||
|
{#if sources.length > 0}
|
||||||
|
<button class="settings-btn" onclick={onSettings} title="Extension settings">
|
||||||
|
<GearSix size={14} weight="bold" />
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
{#if loading}
|
||||||
|
<div class="grid" style="--cols:{cols}">
|
||||||
|
{#each Array(12) as _}
|
||||||
|
<div class="card-skeleton">
|
||||||
|
<div class="cover-skeleton skeleton"></div>
|
||||||
|
<div class="title-skeleton skeleton"></div>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{:else if filtered.length === 0}
|
||||||
|
<div class="empty">
|
||||||
|
{allManga.length === 0 ? "Nothing from this extension is in your library." : "No matches."}
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="grid" style="--cols:{cols}">
|
||||||
|
{#each filtered as m (m.id)}
|
||||||
|
{@const isCompleted = !m.unreadCount && (m.downloadCount > 0)}
|
||||||
|
<button class="card" class:anims onclick={() => setPreviewManga(m as any)}>
|
||||||
|
<div class="cover-wrap" class:completed={isCompleted}>
|
||||||
|
<Thumbnail
|
||||||
|
src={resolvedCover(m.id, m.thumbnailUrl)}
|
||||||
|
alt={m.title}
|
||||||
|
class="cover"
|
||||||
|
style="object-fit:{cropCovers ? 'cover' : 'contain'}"
|
||||||
|
draggable="false"
|
||||||
|
/>
|
||||||
|
<div class="card-info-overlay" class:anim={anims} class:instant={!anims} class:always={statsAlways}>
|
||||||
|
<div class="overlay-badges">
|
||||||
|
{#if isCompleted}
|
||||||
|
<span class="badge badge-done">✓ Done</span>
|
||||||
|
{:else if m.unreadCount}
|
||||||
|
<span class="badge badge-unread">{m.unreadCount} new</span>
|
||||||
|
{/if}
|
||||||
|
{#if m.downloadCount}
|
||||||
|
<span class="badge badge-dl">↓ {m.downloadCount}</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="card-title">{m.title}</p>
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.root { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
|
||||||
|
|
||||||
|
:global(.header-icon) { width: 24px; height: 24px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; background: var(--bg-raised); }
|
||||||
|
|
||||||
|
.header { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-6); border-bottom: 1px solid var(--border-dim); flex-shrink: 0; }
|
||||||
|
|
||||||
|
.back-btn { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: var(--radius-md); color: var(--text-faint); flex-shrink: 0; transition: color var(--t-base), background var(--t-base); }
|
||||||
|
.back-btn:hover { color: var(--text-primary); background: var(--bg-raised); }
|
||||||
|
|
||||||
|
.title-block { display: flex; flex-direction: column; gap: 1px; }
|
||||||
|
.eyebrow { font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--text-faint); letter-spacing: var(--tracking-wider); text-transform: uppercase; }
|
||||||
|
.title { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-primary); }
|
||||||
|
|
||||||
|
.count-badge { font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-wide); padding: 2px 8px; border-radius: var(--radius-sm); background: var(--bg-overlay); border: 1px solid var(--border-dim); color: var(--text-muted); flex-shrink: 0; }
|
||||||
|
|
||||||
|
.search-wrap { position: relative; display: flex; align-items: center; margin-left: auto; }
|
||||||
|
.search-wrap :global(.search-icon) { position: absolute; left: 9px; color: var(--text-faint); pointer-events: none; }
|
||||||
|
.search { background: var(--bg-raised); border: 1px solid var(--border-dim); border-radius: var(--radius-md); padding: 5px 10px 5px 26px; color: var(--text-primary); font-size: var(--text-sm); width: 160px; outline: none; transition: border-color var(--t-base); }
|
||||||
|
.search::placeholder { color: var(--text-faint); }
|
||||||
|
.search:focus { border-color: var(--border-strong); }
|
||||||
|
|
||||||
|
.settings-btn { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: var(--radius-md); color: var(--text-faint); flex-shrink: 0; transition: color var(--t-base), background var(--t-base); }
|
||||||
|
.settings-btn:hover { color: var(--text-primary); background: var(--bg-raised); }
|
||||||
|
|
||||||
|
.content { flex: 1; overflow-y: auto; padding: var(--sp-5) var(--sp-6) var(--sp-6); will-change: scroll-position; }
|
||||||
|
|
||||||
|
.grid { display: grid; grid-template-columns: repeat(var(--cols, auto-fill), minmax(130px, 1fr)); gap: var(--sp-4); }
|
||||||
|
|
||||||
|
.card { background: none; border: none; padding: 0; cursor: pointer; text-align: left; }
|
||||||
|
.card.anims:hover .cover-wrap { transform: translateY(-3px); border-color: var(--border-strong); box-shadow: 0 6px 20px rgba(0,0,0,0.35); }
|
||||||
|
.card:hover .card-title { color: var(--text-primary); }
|
||||||
|
|
||||||
|
.cover-wrap { position: relative; aspect-ratio: 2/3; overflow: hidden; border-radius: var(--radius-md); background: var(--bg-raised); border: 1px solid var(--border-dim); will-change: transform; }
|
||||||
|
.card.anims .cover-wrap { transition: transform 0.18s cubic-bezier(0.16,1,0.3,1), border-color var(--t-base), box-shadow 0.18s cubic-bezier(0.16,1,0.3,1); }
|
||||||
|
.cover-wrap.completed { box-shadow: inset 0 -2px 0 0 var(--accent); }
|
||||||
|
|
||||||
|
.card-info-overlay { position: absolute; bottom: -4px; left: 0; right: 0; z-index: 2; padding: 32px 6px 10px; background: linear-gradient(to top, rgba(0,0,0,0.88) 0%, rgba(0,0,0,0.5) 50%, transparent 100%); opacity: 0; pointer-events: none; }
|
||||||
|
.card-info-overlay.anim { transition: opacity 0.18s ease; }
|
||||||
|
.card-info-overlay.instant { transition: none; }
|
||||||
|
.card-info-overlay.always { opacity: 1; }
|
||||||
|
.card:hover .card-info-overlay { opacity: 1; }
|
||||||
|
|
||||||
|
.overlay-badges { display: flex; align-items: flex-end; justify-content: space-between; gap: 4px; flex-wrap: wrap; }
|
||||||
|
.badge { font-family: var(--font-ui); font-size: 9.5px; font-weight: 700; letter-spacing: 0.04em; line-height: 1; padding: 3px 7px; border-radius: 20px; white-space: nowrap; }
|
||||||
|
.badge-unread { background: var(--accent); color: #fff; box-shadow: 0 1px 8px rgba(0,0,0,0.5); }
|
||||||
|
.badge-done { background: rgba(255,255,255,0.18); color: rgba(255,255,255,0.9); border: 1px solid rgba(255,255,255,0.25); }
|
||||||
|
.badge-dl { background: rgba(0,0,0,0.55); color: rgba(255,255,255,0.8); border: 1px solid rgba(255,255,255,0.18); margin-left: auto; }
|
||||||
|
|
||||||
|
.card-title { margin-top: var(--sp-2); font-size: var(--text-sm); color: var(--text-secondary); line-height: var(--leading-snug); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; height: 2lh; }
|
||||||
|
.card.anims .card-title { transition: color var(--t-base); }
|
||||||
|
|
||||||
|
.card-skeleton { padding: 0; }
|
||||||
|
.cover-skeleton { aspect-ratio: 2/3; border-radius: var(--radius-md); }
|
||||||
|
.title-skeleton { height: 12px; margin-top: var(--sp-2); width: 80%; border-radius: var(--radius-sm); }
|
||||||
|
|
||||||
|
.empty { display: flex; align-items: center; justify-content: center; height: 60%; color: var(--text-muted); font-size: var(--text-sm); }
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,526 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { X, CircleNotch, CaretUpDown, Check, CaretLeft } from "phosphor-svelte";
|
||||||
|
import Thumbnail from "@shared/manga/Thumbnail.svelte";
|
||||||
|
import { gql } from "@api/client";
|
||||||
|
import { addToast } from "@store/state.svelte";
|
||||||
|
import { GET_SOURCE_SETTINGS } from "@api/queries";
|
||||||
|
import { UPDATE_SOURCE_PREFERENCE } from "@api/mutations";
|
||||||
|
|
||||||
|
interface Preference {
|
||||||
|
type: string;
|
||||||
|
key: string;
|
||||||
|
CheckBoxTitle?: string;
|
||||||
|
CheckBoxSummary?: string;
|
||||||
|
CheckBoxDefault?: boolean;
|
||||||
|
CheckBoxCurrentValue?: boolean;
|
||||||
|
SwitchPreferenceTitle?: string;
|
||||||
|
SwitchPreferenceSummary?: string;
|
||||||
|
SwitchPreferenceDefault?: boolean;
|
||||||
|
SwitchPreferenceCurrentValue?: boolean;
|
||||||
|
ListPreferenceTitle?: string;
|
||||||
|
ListPreferenceSummary?: string;
|
||||||
|
ListPreferenceDefault?: string;
|
||||||
|
ListPreferenceCurrentValue?: string;
|
||||||
|
entries?: string[];
|
||||||
|
entryValues?: string[];
|
||||||
|
EditTextPreferenceTitle?: string;
|
||||||
|
EditTextPreferenceSummary?: string;
|
||||||
|
EditTextPreferenceDefault?: string;
|
||||||
|
EditTextPreferenceCurrentValue?: string;
|
||||||
|
dialogTitle?: string;
|
||||||
|
dialogMessage?: string;
|
||||||
|
MultiSelectListPreferenceTitle?: string;
|
||||||
|
MultiSelectListPreferenceSummary?: string;
|
||||||
|
MultiSelectListPreferenceDefault?: string[];
|
||||||
|
MultiSelectListPreferenceCurrentValue?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SourceEntry = { id: string; displayName: string };
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
extensionName: string;
|
||||||
|
iconUrl: string;
|
||||||
|
sources: SourceEntry[];
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { extensionName, iconUrl, sources, onClose }: Props = $props();
|
||||||
|
|
||||||
|
let phase = $state<"pick" | "settings">("pick");
|
||||||
|
let activeSource = $state<SourceEntry | null>(null);
|
||||||
|
let prefs = $state<Preference[]>([]);
|
||||||
|
let loading = $state(false);
|
||||||
|
let saving = $state<string | null>(null);
|
||||||
|
let editKey = $state<string | null>(null);
|
||||||
|
let editValue = $state("");
|
||||||
|
let listOpen = $state<string | null>(null);
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (sources.length === 1) openSource(sources[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function openSource(src: SourceEntry) {
|
||||||
|
activeSource = src;
|
||||||
|
phase = "settings";
|
||||||
|
loading = true;
|
||||||
|
prefs = [];
|
||||||
|
editKey = null;
|
||||||
|
listOpen = null;
|
||||||
|
try {
|
||||||
|
const d = await gql<{ source: { preferences: Preference[] } }>(
|
||||||
|
GET_SOURCE_SETTINGS,
|
||||||
|
{ id: String(src.id) },
|
||||||
|
);
|
||||||
|
prefs = d.source.preferences ?? [];
|
||||||
|
} catch (e: any) {
|
||||||
|
addToast({ kind: "error", title: "Failed to load settings", body: e?.message ?? "" });
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function backToPicker() {
|
||||||
|
phase = "pick";
|
||||||
|
activeSource = null;
|
||||||
|
prefs = [];
|
||||||
|
editKey = null;
|
||||||
|
listOpen = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save(position: number, changeType: string, value: unknown) {
|
||||||
|
if (!activeSource) return;
|
||||||
|
const pref = prefs[position];
|
||||||
|
saving = pref.key;
|
||||||
|
try {
|
||||||
|
await gql(UPDATE_SOURCE_PREFERENCE, {
|
||||||
|
source: String(activeSource.id),
|
||||||
|
change: { position, [changeType]: value },
|
||||||
|
});
|
||||||
|
const d = await gql<{ source: { preferences: Preference[] } }>(
|
||||||
|
GET_SOURCE_SETTINGS,
|
||||||
|
{ id: String(activeSource.id) },
|
||||||
|
);
|
||||||
|
prefs = d.source.preferences ?? [];
|
||||||
|
} catch (e: any) {
|
||||||
|
addToast({ kind: "error", title: "Failed to save", body: e?.message ?? "" });
|
||||||
|
} finally {
|
||||||
|
saving = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTitle(p: Preference) {
|
||||||
|
return p.CheckBoxTitle ?? p.SwitchPreferenceTitle ?? p.ListPreferenceTitle
|
||||||
|
?? p.EditTextPreferenceTitle ?? p.MultiSelectListPreferenceTitle ?? p.key;
|
||||||
|
}
|
||||||
|
function getSummary(p: Preference) {
|
||||||
|
return p.CheckBoxSummary ?? p.SwitchPreferenceSummary ?? p.ListPreferenceSummary
|
||||||
|
?? p.EditTextPreferenceSummary ?? p.MultiSelectListPreferenceSummary ?? null;
|
||||||
|
}
|
||||||
|
function getBoolValue(p: Preference) {
|
||||||
|
if (p.type === "CheckBoxPreference")
|
||||||
|
return p.CheckBoxCurrentValue ?? p.CheckBoxDefault ?? false;
|
||||||
|
return p.SwitchPreferenceCurrentValue ?? p.SwitchPreferenceDefault ?? false;
|
||||||
|
}
|
||||||
|
function getListValue(p: Preference) {
|
||||||
|
return p.ListPreferenceCurrentValue ?? p.ListPreferenceDefault ?? "";
|
||||||
|
}
|
||||||
|
function getListLabel(p: Preference, val: string) {
|
||||||
|
const idx = p.entryValues?.indexOf(val) ?? -1;
|
||||||
|
return idx >= 0 ? (p.entries?.[idx] ?? val) : val;
|
||||||
|
}
|
||||||
|
function getMultiValue(p: Preference): string[] {
|
||||||
|
return p.MultiSelectListPreferenceCurrentValue ?? p.MultiSelectListPreferenceDefault ?? [];
|
||||||
|
}
|
||||||
|
function toggleMulti(position: number, p: Preference, val: string) {
|
||||||
|
const current = getMultiValue(p);
|
||||||
|
const next = current.includes(val) ? current.filter(v => v !== val) : [...current, val];
|
||||||
|
save(position, "multiSelectState", next);
|
||||||
|
}
|
||||||
|
function submitEdit(position: number) {
|
||||||
|
save(position, "editTextState", editValue);
|
||||||
|
editKey = null;
|
||||||
|
}
|
||||||
|
function openEdit(p: Preference) {
|
||||||
|
editKey = p.key;
|
||||||
|
editValue = p.EditTextPreferenceCurrentValue ?? p.EditTextPreferenceDefault ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function langTag(displayName: string) {
|
||||||
|
const m = displayName.match(/\(([^)]+)\)$/);
|
||||||
|
return m ? m[1].toUpperCase() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onBackdrop(e: MouseEvent) {
|
||||||
|
if (e.target === e.currentTarget) onClose();
|
||||||
|
}
|
||||||
|
function onKeydown(e: KeyboardEvent) {
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
if (editKey) { editKey = null; return; }
|
||||||
|
if (listOpen) { listOpen = null; return; }
|
||||||
|
if (phase === "settings" && sources.length > 1) { backToPicker(); return; }
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:window onkeydown={onKeydown} />
|
||||||
|
|
||||||
|
<div class="backdrop" role="dialog" aria-modal="true" onmousedown={onBackdrop}>
|
||||||
|
<div class="modal">
|
||||||
|
|
||||||
|
<div class="modal-header">
|
||||||
|
<div class="modal-title-wrap">
|
||||||
|
{#if phase === "settings" && sources.length > 1}
|
||||||
|
<button class="icon-btn" onclick={backToPicker} title="Back">
|
||||||
|
<CaretLeft size={13} weight="bold" />
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
{#if iconUrl}
|
||||||
|
<Thumbnail src={iconUrl} alt={extensionName} class="modal-ext-icon" onerror={(e) => ((e.target as HTMLImageElement).style.display = "none")} />
|
||||||
|
{/if}
|
||||||
|
<div class="modal-titles">
|
||||||
|
<span class="modal-eyebrow">Extension Settings</span>
|
||||||
|
<span class="modal-title">
|
||||||
|
{phase === "pick" ? extensionName : (activeSource?.displayName ?? extensionName)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="icon-btn" onclick={onClose}>
|
||||||
|
<X size={14} weight="bold" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
|
||||||
|
{#if phase === "pick"}
|
||||||
|
<div class="source-list">
|
||||||
|
{#each sources as src}
|
||||||
|
{@const tag = langTag(src.displayName)}
|
||||||
|
{@const baseName = src.displayName.replace(/\s*\([^)]+\)$/, "")}
|
||||||
|
<button class="source-row" onclick={() => openSource(src)}>
|
||||||
|
<span class="source-name">{baseName}</span>
|
||||||
|
{#if tag}<span class="lang-badge">{tag}</span>{/if}
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{:else}
|
||||||
|
{#if loading}
|
||||||
|
<div class="center-state">
|
||||||
|
<CircleNotch size={16} weight="light" class="anim-spin" style="color:var(--text-faint)" />
|
||||||
|
</div>
|
||||||
|
{:else if prefs.length === 0}
|
||||||
|
<div class="center-state empty-state">No configurable settings.</div>
|
||||||
|
{:else}
|
||||||
|
<div class="pref-list">
|
||||||
|
{#each prefs as pref, i}
|
||||||
|
{@const title = getTitle(pref)}
|
||||||
|
{@const summary = getSummary(pref)}
|
||||||
|
{@const isSaving = saving === pref.key}
|
||||||
|
|
||||||
|
{#if pref.type === "CheckBoxPreference" || pref.type === "SwitchPreference"}
|
||||||
|
{@const checked = getBoolValue(pref)}
|
||||||
|
<div class="pref-row">
|
||||||
|
<div class="pref-text">
|
||||||
|
<span class="pref-title">{title}</span>
|
||||||
|
{#if summary}<span class="pref-summary">{summary}</span>{/if}
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
class="toggle" class:toggle-on={checked}
|
||||||
|
disabled={isSaving}
|
||||||
|
onclick={() => save(i, pref.type === "CheckBoxPreference" ? "checkBoxState" : "switchState", !checked)}
|
||||||
|
>
|
||||||
|
{#if isSaving}
|
||||||
|
<CircleNotch size={10} weight="light" class="anim-spin" />
|
||||||
|
{:else}
|
||||||
|
<span class="toggle-thumb"></span>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{:else if pref.type === "ListPreference"}
|
||||||
|
{@const current = getListValue(pref)}
|
||||||
|
<div class="pref-row pref-row-col">
|
||||||
|
<div class="pref-text">
|
||||||
|
<span class="pref-title">{title}</span>
|
||||||
|
{#if summary}<span class="pref-summary">{summary}</span>{/if}
|
||||||
|
</div>
|
||||||
|
<div class="select-wrap">
|
||||||
|
<button
|
||||||
|
class="select-btn" class:select-open={listOpen === pref.key}
|
||||||
|
disabled={isSaving}
|
||||||
|
onclick={() => listOpen = listOpen === pref.key ? null : pref.key}
|
||||||
|
>
|
||||||
|
<span class="select-val">{getListLabel(pref, current)}</span>
|
||||||
|
{#if isSaving}
|
||||||
|
<CircleNotch size={11} weight="light" class="anim-spin" />
|
||||||
|
{:else}
|
||||||
|
<CaretUpDown size={11} weight="bold" />
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
{#if listOpen === pref.key}
|
||||||
|
<div class="dropdown">
|
||||||
|
{#each (pref.entries ?? []) as entry, j}
|
||||||
|
{@const val = pref.entryValues?.[j] ?? entry}
|
||||||
|
<button
|
||||||
|
class="dropdown-item" class:dropdown-item-active={val === current}
|
||||||
|
onclick={() => { save(i, "listState", val); listOpen = null; }}
|
||||||
|
>
|
||||||
|
{entry}
|
||||||
|
{#if val === current}<Check size={11} weight="bold" />{/if}
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{:else if pref.type === "EditTextPreference"}
|
||||||
|
{#if editKey === pref.key}
|
||||||
|
<div class="pref-row pref-row-col edit-active">
|
||||||
|
<div class="pref-text">
|
||||||
|
{#if pref.dialogTitle}<span class="pref-title">{pref.dialogTitle}</span>{/if}
|
||||||
|
{#if pref.dialogMessage}<span class="pref-summary">{pref.dialogMessage}</span>{/if}
|
||||||
|
</div>
|
||||||
|
<div class="edit-row">
|
||||||
|
<input
|
||||||
|
class="edit-input"
|
||||||
|
bind:value={editValue}
|
||||||
|
disabled={isSaving}
|
||||||
|
onkeydown={(e) => { if (e.key === "Enter") submitEdit(i); if (e.key === "Escape") editKey = null; }}
|
||||||
|
autofocus
|
||||||
|
/>
|
||||||
|
<button class="action-btn-dim" onclick={() => editKey = null}>Cancel</button>
|
||||||
|
<button class="action-btn" onclick={() => submitEdit(i)} disabled={isSaving}>
|
||||||
|
{#if isSaving}<CircleNotch size={11} weight="light" class="anim-spin" />{:else}Save{/if}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<button class="pref-row pref-row-btn" onclick={() => openEdit(pref)}>
|
||||||
|
<div class="pref-text">
|
||||||
|
<span class="pref-title">{title}</span>
|
||||||
|
{#if summary}<span class="pref-summary">{summary}</span>{/if}
|
||||||
|
</div>
|
||||||
|
<span class="pref-value-hint">
|
||||||
|
{pref.EditTextPreferenceCurrentValue ?? pref.EditTextPreferenceDefault ?? "—"}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{:else if pref.type === "MultiSelectListPreference"}
|
||||||
|
{@const selected = getMultiValue(pref)}
|
||||||
|
<div class="pref-row pref-row-col">
|
||||||
|
<div class="pref-text">
|
||||||
|
<span class="pref-title">{title}</span>
|
||||||
|
{#if summary}<span class="pref-summary">{summary}</span>{/if}
|
||||||
|
</div>
|
||||||
|
<div class="multi-list">
|
||||||
|
{#each (pref.entries ?? []) as entry, j}
|
||||||
|
{@const val = pref.entryValues?.[j] ?? entry}
|
||||||
|
{@const on = selected.includes(val)}
|
||||||
|
<button
|
||||||
|
class="multi-item" class:multi-item-on={on}
|
||||||
|
disabled={isSaving}
|
||||||
|
onclick={() => toggleMulti(i, pref, val)}
|
||||||
|
>
|
||||||
|
<span class="multi-check">{#if on}<Check size={10} weight="bold" />{/if}</span>
|
||||||
|
{entry}
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.backdrop {
|
||||||
|
position: fixed; inset: 0;
|
||||||
|
background: rgba(0,0,0,0.45);
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
z-index: var(--z-modal);
|
||||||
|
animation: fadeIn 0.15s ease both;
|
||||||
|
}
|
||||||
|
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
||||||
|
|
||||||
|
.modal {
|
||||||
|
display: flex; flex-direction: column;
|
||||||
|
width: 400px; max-width: calc(100vw - 32px); max-height: 78vh;
|
||||||
|
background: var(--bg-surface);
|
||||||
|
border: 1px solid var(--border-dim);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
overflow: hidden;
|
||||||
|
animation: slideUp 0.18s cubic-bezier(0.16,1,0.3,1) both;
|
||||||
|
box-shadow: var(--shadow-lg);
|
||||||
|
}
|
||||||
|
@keyframes slideUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
|
||||||
|
|
||||||
|
.modal-header {
|
||||||
|
display: flex; align-items: center; justify-content: space-between;
|
||||||
|
padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-4);
|
||||||
|
border-bottom: 1px solid var(--border-dim);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.modal-title-wrap { display: flex; align-items: center; gap: var(--sp-2); }
|
||||||
|
:global(.modal-ext-icon) { width: 22px; height: 22px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; background: var(--bg-raised); }
|
||||||
|
.modal-titles { display: flex; flex-direction: column; gap: 1px; }
|
||||||
|
.modal-eyebrow {
|
||||||
|
font-family: var(--font-ui); font-size: var(--text-2xs);
|
||||||
|
color: var(--text-faint); letter-spacing: var(--tracking-wider); text-transform: uppercase;
|
||||||
|
}
|
||||||
|
.modal-title { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-primary); }
|
||||||
|
|
||||||
|
.icon-btn {
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
width: 26px; height: 26px;
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
color: var(--text-faint); flex-shrink: 0;
|
||||||
|
transition: color var(--t-base), background var(--t-base);
|
||||||
|
}
|
||||||
|
.icon-btn:hover { color: var(--text-primary); background: var(--bg-overlay); }
|
||||||
|
|
||||||
|
.modal-body { overflow-y: auto; flex: 1; }
|
||||||
|
|
||||||
|
.source-list { display: flex; flex-direction: column; padding: var(--sp-2) 0; }
|
||||||
|
.source-row {
|
||||||
|
display: flex; align-items: center; justify-content: space-between;
|
||||||
|
padding: 10px var(--sp-4);
|
||||||
|
text-align: left;
|
||||||
|
transition: background var(--t-fast);
|
||||||
|
gap: var(--sp-3);
|
||||||
|
}
|
||||||
|
.source-row:hover { background: var(--bg-raised); }
|
||||||
|
.source-name { flex: 1; font-size: var(--text-sm); color: var(--text-secondary); font-weight: var(--weight-medium); }
|
||||||
|
.lang-badge {
|
||||||
|
font-family: var(--font-ui); font-size: 10px; letter-spacing: var(--tracking-wide);
|
||||||
|
color: var(--text-faint); background: var(--bg-overlay);
|
||||||
|
border: 1px solid var(--border-dim);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
padding: 1px 6px; flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.center-state { display: flex; align-items: center; justify-content: center; padding: var(--sp-8); }
|
||||||
|
.empty-state { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--text-faint); letter-spacing: var(--tracking-wide); }
|
||||||
|
|
||||||
|
.pref-list { display: flex; flex-direction: column; padding: var(--sp-2) 0; }
|
||||||
|
.pref-row {
|
||||||
|
display: flex; align-items: center; gap: var(--sp-3);
|
||||||
|
padding: 10px var(--sp-4);
|
||||||
|
border-bottom: 1px solid var(--border-dim);
|
||||||
|
}
|
||||||
|
.pref-row:last-child { border-bottom: none; }
|
||||||
|
.pref-row-col { flex-direction: column; align-items: stretch; gap: var(--sp-2); }
|
||||||
|
.pref-row-btn { width: 100%; text-align: left; transition: background var(--t-fast); }
|
||||||
|
.pref-row-btn:hover { background: var(--bg-raised); }
|
||||||
|
.edit-active { background: var(--bg-raised); }
|
||||||
|
|
||||||
|
.pref-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
|
||||||
|
.pref-title { font-size: var(--text-sm); color: var(--text-secondary); font-weight: var(--weight-medium); }
|
||||||
|
.pref-summary {
|
||||||
|
font-family: var(--font-ui); font-size: var(--text-2xs);
|
||||||
|
color: var(--text-faint); letter-spacing: var(--tracking-wide); line-height: 1.5;
|
||||||
|
}
|
||||||
|
.pref-value-hint {
|
||||||
|
font-family: var(--font-ui); font-size: var(--text-2xs);
|
||||||
|
color: var(--text-muted); letter-spacing: var(--tracking-wide);
|
||||||
|
flex-shrink: 0; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle {
|
||||||
|
position: relative; width: 32px; height: 18px; border-radius: 9px;
|
||||||
|
background: var(--bg-overlay); border: 1px solid var(--border-strong);
|
||||||
|
flex-shrink: 0; transition: background var(--t-base), border-color var(--t-base);
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
}
|
||||||
|
.toggle-on { background: var(--accent-muted); border-color: var(--accent-dim); }
|
||||||
|
.toggle-thumb {
|
||||||
|
position: absolute; left: 2px; width: 12px; height: 12px;
|
||||||
|
border-radius: 50%; background: var(--text-faint);
|
||||||
|
transition: left var(--t-base), background var(--t-base); pointer-events: none;
|
||||||
|
}
|
||||||
|
.toggle-on .toggle-thumb { left: 16px; background: var(--accent-fg); }
|
||||||
|
.toggle:disabled { opacity: 0.4; cursor: default; }
|
||||||
|
|
||||||
|
.select-wrap { position: relative; }
|
||||||
|
.select-btn {
|
||||||
|
display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
|
||||||
|
width: 100%; padding: 6px var(--sp-3);
|
||||||
|
background: var(--bg-base); border: 1px solid var(--border-strong);
|
||||||
|
border-radius: var(--radius-md); color: var(--text-secondary); font-size: var(--text-sm);
|
||||||
|
transition: border-color var(--t-base);
|
||||||
|
}
|
||||||
|
.select-btn:hover:not(:disabled) { border-color: var(--border-focus); }
|
||||||
|
.select-btn:disabled { opacity: 0.4; cursor: default; }
|
||||||
|
.select-open { border-color: var(--border-focus); }
|
||||||
|
.select-val { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
|
|
||||||
|
.dropdown {
|
||||||
|
position: absolute; top: calc(100% + 4px); left: 0; right: 0;
|
||||||
|
background: var(--bg-surface); border: 1px solid var(--border-strong);
|
||||||
|
border-radius: var(--radius-md); overflow: hidden;
|
||||||
|
box-shadow: var(--shadow-lg); z-index: 10;
|
||||||
|
animation: dropIn 0.12s cubic-bezier(0.16,1,0.3,1) both;
|
||||||
|
}
|
||||||
|
@keyframes dropIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
|
||||||
|
.dropdown-item {
|
||||||
|
display: flex; align-items: center; justify-content: space-between;
|
||||||
|
width: 100%; padding: 7px var(--sp-3);
|
||||||
|
font-size: var(--text-sm); color: var(--text-secondary);
|
||||||
|
transition: background var(--t-fast);
|
||||||
|
}
|
||||||
|
.dropdown-item:hover { background: var(--bg-raised); }
|
||||||
|
.dropdown-item-active { color: var(--accent-fg); }
|
||||||
|
|
||||||
|
.edit-row { display: flex; gap: var(--sp-2); }
|
||||||
|
.edit-input {
|
||||||
|
flex: 1; background: var(--bg-base); border: 1px solid var(--border-strong);
|
||||||
|
border-radius: var(--radius-md); padding: 6px var(--sp-3);
|
||||||
|
color: var(--text-primary); font-size: var(--text-sm);
|
||||||
|
outline: none; transition: border-color var(--t-base);
|
||||||
|
}
|
||||||
|
.edit-input:focus { border-color: var(--border-focus); }
|
||||||
|
|
||||||
|
.action-btn {
|
||||||
|
font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: var(--tracking-wide);
|
||||||
|
padding: 5px 12px; border-radius: var(--radius-md);
|
||||||
|
background: var(--accent-muted); color: var(--accent-fg); border: 1px solid var(--accent-dim);
|
||||||
|
flex-shrink: 0; display: flex; align-items: center; gap: var(--sp-1);
|
||||||
|
transition: filter var(--t-base);
|
||||||
|
}
|
||||||
|
.action-btn:hover:not(:disabled) { filter: brightness(1.1); }
|
||||||
|
.action-btn:disabled { opacity: 0.4; cursor: default; }
|
||||||
|
|
||||||
|
.action-btn-dim {
|
||||||
|
font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: var(--tracking-wide);
|
||||||
|
padding: 5px 12px; border-radius: var(--radius-md);
|
||||||
|
background: none; color: var(--text-faint); border: 1px solid var(--border-dim);
|
||||||
|
flex-shrink: 0; transition: color var(--t-base), border-color var(--t-base);
|
||||||
|
}
|
||||||
|
.action-btn-dim:hover { color: var(--text-secondary); border-color: var(--border-strong); }
|
||||||
|
|
||||||
|
.multi-list { display: flex; flex-direction: column; gap: 1px; }
|
||||||
|
.multi-item {
|
||||||
|
display: flex; align-items: center; gap: var(--sp-2);
|
||||||
|
padding: 6px var(--sp-2); border-radius: var(--radius-md);
|
||||||
|
font-size: var(--text-sm); color: var(--text-muted); border: 1px solid transparent;
|
||||||
|
transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
|
||||||
|
}
|
||||||
|
.multi-item:hover:not(:disabled) { background: var(--bg-raised); color: var(--text-secondary); }
|
||||||
|
.multi-item-on { color: var(--accent-fg); background: var(--accent-muted); border-color: var(--accent-dim); }
|
||||||
|
.multi-check {
|
||||||
|
width: 14px; height: 14px; border-radius: var(--radius-sm);
|
||||||
|
border: 1px solid var(--border-strong); background: var(--bg-base);
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
flex-shrink: 0; color: var(--accent-fg);
|
||||||
|
transition: background var(--t-fast), border-color var(--t-fast);
|
||||||
|
}
|
||||||
|
.multi-item-on .multi-check { background: var(--accent-muted); border-color: var(--accent-dim); }
|
||||||
|
</style>
|
||||||
@@ -6,6 +6,8 @@
|
|||||||
const leaving = new Set<string>();
|
const leaving = new Set<string>();
|
||||||
const timers = new Map<string, ReturnType<typeof setTimeout>>();
|
const timers = new Map<string, ReturnType<typeof setTimeout>>();
|
||||||
|
|
||||||
|
let detail = $state<Toast | null>(null);
|
||||||
|
|
||||||
function schedule(t: Toast) {
|
function schedule(t: Toast) {
|
||||||
if (timers.has(t.id)) return;
|
if (timers.has(t.id)) return;
|
||||||
const dur = t.duration ?? 3500;
|
const dur = t.duration ?? 3500;
|
||||||
@@ -30,12 +32,23 @@
|
|||||||
dismissToast(id);
|
dismissToast(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openDetail(e: MouseEvent, t: Toast) {
|
||||||
|
e.preventDefault();
|
||||||
|
detail = t;
|
||||||
|
if (timers.has(t.id)) { clearTimeout(timers.get(t.id)!); timers.delete(t.id); }
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeDetail() {
|
||||||
|
detail = null;
|
||||||
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const activeIds = new Set(store.toasts.map(t => t.id));
|
const activeIds = new Set(store.toasts.map(t => t.id));
|
||||||
store.toasts.forEach(schedule);
|
store.toasts.forEach(schedule);
|
||||||
for (const [id, timer] of timers) {
|
for (const [id, timer] of timers) {
|
||||||
if (!activeIds.has(id)) { clearTimeout(timer); timers.delete(id); }
|
if (!activeIds.has(id)) { clearTimeout(timer); timers.delete(id); }
|
||||||
}
|
}
|
||||||
|
if (detail && !activeIds.has(detail.id)) detail = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
const icons: Record<Toast["kind"], string> = {
|
const icons: Record<Toast["kind"], string> = {
|
||||||
@@ -49,7 +62,10 @@
|
|||||||
{#if store.toasts.length}
|
{#if store.toasts.length}
|
||||||
<div class="toaster" aria-live="polite">
|
<div class="toaster" aria-live="polite">
|
||||||
{#each store.toasts as t (t.id)}
|
{#each store.toasts as t (t.id)}
|
||||||
<button class="toast toast-{t.kind}" data-toast-id={t.id} aria-label="{t.title}{t.body ? ': ' + t.body : ''}" onclick={() => dismiss(t.id)}>
|
<button class="toast toast-{t.kind}" data-toast-id={t.id} aria-label="{t.title}{t.body ? ': ' + t.body : ''}"
|
||||||
|
onclick={() => dismiss(t.id)}
|
||||||
|
oncontextmenu={(e) => openDetail(e, t)}
|
||||||
|
>
|
||||||
<div class="accent-bar"></div>
|
<div class="accent-bar"></div>
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
@@ -65,6 +81,36 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if detail}
|
||||||
|
<div class="detail-backdrop" role="presentation" onclick={closeDetail} oncontextmenu={(e) => e.preventDefault()}>
|
||||||
|
<div class="detail-panel detail-{detail.kind}" role="dialog" onclick={(e) => e.stopPropagation()}>
|
||||||
|
<div class="detail-accent"></div>
|
||||||
|
<div class="detail-body">
|
||||||
|
<div class="detail-header">
|
||||||
|
<span class="detail-kind">{detail.kind}</span>
|
||||||
|
<button class="detail-close" onclick={closeDetail} aria-label="Close">
|
||||||
|
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round">
|
||||||
|
<line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p class="detail-title">{detail.title}</p>
|
||||||
|
{#if detail.body}
|
||||||
|
<pre class="detail-text">{detail.body}</pre>
|
||||||
|
{/if}
|
||||||
|
<div class="detail-actions">
|
||||||
|
<button class="detail-copy" onclick={() => navigator.clipboard.writeText(`${detail!.title}${detail!.body ? '\n' + detail!.body : ''}`)}>
|
||||||
|
Copy
|
||||||
|
</button>
|
||||||
|
<button class="detail-dismiss" onclick={() => { dismiss(detail!.id); closeDetail(); }}>
|
||||||
|
Dismiss
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.toaster { position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: 9999; display: flex; flex-direction: column; gap: 5px; pointer-events: none; }
|
.toaster { position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: 9999; display: flex; flex-direction: column; gap: 5px; pointer-events: none; }
|
||||||
|
|
||||||
@@ -105,4 +151,79 @@
|
|||||||
.body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
|
.body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
|
||||||
.title { font-size: var(--text-xs); font-family: var(--font-ui); color: var(--text-secondary); font-weight: var(--weight-medium); letter-spacing: var(--tracking-wide); line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
.title { font-size: var(--text-xs); font-family: var(--font-ui); color: var(--text-secondary); font-weight: var(--weight-medium); letter-spacing: var(--tracking-wide); line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||||
.sub { font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--text-faint); letter-spacing: var(--tracking-wide); line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
.sub { font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--text-faint); letter-spacing: var(--tracking-wide); line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||||
|
|
||||||
|
.detail-backdrop {
|
||||||
|
position: fixed; inset: 0; z-index: 10000;
|
||||||
|
background: rgba(0,0,0,0.45);
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
animation: fadeIn 0.15s ease both;
|
||||||
|
}
|
||||||
|
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
|
||||||
|
|
||||||
|
.detail-panel {
|
||||||
|
display: flex; width: 420px; max-width: calc(100vw - 32px); max-height: 60vh;
|
||||||
|
border-radius: var(--radius-lg); background: var(--bg-raised);
|
||||||
|
border: 1px solid var(--border-base);
|
||||||
|
box-shadow: 0 24px 64px rgba(0,0,0,0.7), 0 1px 0 rgba(255,255,255,0.05) inset;
|
||||||
|
overflow: hidden;
|
||||||
|
animation: popIn 0.2s cubic-bezier(0.16,1,0.3,1) both;
|
||||||
|
}
|
||||||
|
@keyframes popIn { from { opacity: 0; transform: scale(0.95) } to { opacity: 1; transform: scale(1) } }
|
||||||
|
|
||||||
|
.detail-accent { width: 3px; flex-shrink: 0; }
|
||||||
|
.detail-error .detail-accent { background: var(--color-error); }
|
||||||
|
.detail-success .detail-accent { background: var(--accent-fg); }
|
||||||
|
.detail-info .detail-accent { background: var(--text-faint); }
|
||||||
|
.detail-download .detail-accent { background: var(--accent-fg); }
|
||||||
|
|
||||||
|
.detail-body { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: var(--sp-3); gap: var(--sp-2); overflow: hidden; }
|
||||||
|
|
||||||
|
.detail-header { display: flex; align-items: center; justify-content: space-between; }
|
||||||
|
.detail-kind {
|
||||||
|
font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-wider);
|
||||||
|
text-transform: uppercase; color: var(--text-faint);
|
||||||
|
}
|
||||||
|
.detail-error .detail-kind { color: var(--color-error); }
|
||||||
|
|
||||||
|
.detail-close {
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
width: 20px; height: 20px; border-radius: var(--radius-sm);
|
||||||
|
background: none; border: none; color: var(--text-faint); cursor: pointer;
|
||||||
|
transition: color var(--t-fast), background var(--t-fast);
|
||||||
|
}
|
||||||
|
.detail-close:hover { color: var(--text-primary); background: var(--bg-overlay); }
|
||||||
|
|
||||||
|
.detail-title {
|
||||||
|
font-family: var(--font-ui); font-size: var(--text-sm);
|
||||||
|
color: var(--text-secondary); font-weight: var(--weight-medium);
|
||||||
|
line-height: var(--leading-snug); word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-text {
|
||||||
|
flex: 1; min-height: 0; overflow-y: auto;
|
||||||
|
font-family: var(--font-mono, monospace); font-size: var(--text-xs);
|
||||||
|
color: var(--text-muted); line-height: var(--leading-relaxed);
|
||||||
|
white-space: pre-wrap; word-break: break-all;
|
||||||
|
background: var(--bg-void); border: 1px solid var(--border-dim);
|
||||||
|
border-radius: var(--radius-sm); padding: var(--sp-2) var(--sp-3);
|
||||||
|
scrollbar-width: thin;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-1); }
|
||||||
|
.detail-copy, .detail-dismiss {
|
||||||
|
font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-wide);
|
||||||
|
padding: 5px var(--sp-3); border-radius: var(--radius-sm); cursor: pointer;
|
||||||
|
transition: color var(--t-base), background var(--t-base), border-color var(--t-base);
|
||||||
|
}
|
||||||
|
.detail-copy {
|
||||||
|
border: 1px solid var(--border-dim); background: none; color: var(--text-muted);
|
||||||
|
}
|
||||||
|
.detail-copy:hover { color: var(--text-primary); border-color: var(--border-strong); background: var(--bg-overlay); }
|
||||||
|
.detail-dismiss {
|
||||||
|
border: 1px solid color-mix(in srgb, var(--color-error) 40%, transparent);
|
||||||
|
background: color-mix(in srgb, var(--color-error) 10%, transparent);
|
||||||
|
color: var(--color-error);
|
||||||
|
}
|
||||||
|
.detail-dismiss:hover { background: color-mix(in srgb, var(--color-error) 18%, transparent); }
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user