mirror of
https://github.com/ankitects/anki.git
synced 2025-12-12 22:36:55 -05:00
WIP: Use our components in deckoptions sticky bar
This commit is contained in:
parent
a8b1291f84
commit
e5d11ac547
13 changed files with 115 additions and 92 deletions
|
|
@ -9,7 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import WithTheming from "./WithTheming.svelte";
|
import WithTheming from "./WithTheming.svelte";
|
||||||
import ButtonToolbar from "./ButtonToolbar.svelte";
|
import ButtonToolbar from "./ButtonToolbar.svelte";
|
||||||
|
|
||||||
export let id: string | undefined;
|
export let id: string;
|
||||||
let className = "";
|
let className = "";
|
||||||
export { className as class };
|
export { className as class };
|
||||||
|
|
||||||
|
|
|
||||||
5
ts/components/DropdownDivider.svelte
Normal file
5
ts/components/DropdownDivider.svelte
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
<!--
|
||||||
|
Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
-->
|
||||||
|
<hr class="dropdown-divider" />
|
||||||
|
|
@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import { setContext } from "svelte";
|
import { setContext } from "svelte";
|
||||||
import { dropdownKey } from "./contextKeys";
|
import { dropdownKey } from "./contextKeys";
|
||||||
|
|
||||||
export let id: string | undefined;
|
export let id: string;
|
||||||
|
|
||||||
setContext(dropdownKey, null);
|
setContext(dropdownKey, null);
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
export let id: string | undefined = undefined;
|
export let id: string | undefined = undefined;
|
||||||
let className: string = "";
|
let className: string = "";
|
||||||
export { className as class };
|
export { className as class };
|
||||||
|
export let theme = "anki";
|
||||||
|
|
||||||
|
function extendClassName(className: string, theme: string): string {
|
||||||
|
return `btn ${theme !== "anki" ? `btn-${theme}` : ""}${className}`;
|
||||||
|
}
|
||||||
|
|
||||||
export let tooltip: string | undefined = undefined;
|
export let tooltip: string | undefined = undefined;
|
||||||
export let active = false;
|
export let active = false;
|
||||||
|
|
@ -48,11 +53,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<button
|
<button
|
||||||
bind:this={buttonRef}
|
bind:this={buttonRef}
|
||||||
{id}
|
{id}
|
||||||
class={`btn ${className}`}
|
class={extendClassName(className, theme)}
|
||||||
class:active
|
class:active
|
||||||
class:dropdown-toggle={dropdownProps.dropdown}
|
class:dropdown-toggle={dropdownProps.dropdown}
|
||||||
class:btn-day={!nightMode}
|
class:btn-day={theme === 'anki' && !nightMode}
|
||||||
class:btn-night={nightMode}
|
class:btn-night={theme === 'anki' && nightMode}
|
||||||
title={tooltip}
|
title={tooltip}
|
||||||
{...dropdownProps}
|
{...dropdownProps}
|
||||||
disabled={_disabled}
|
disabled={_disabled}
|
||||||
|
|
|
||||||
|
|
@ -6,24 +6,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import type { Readable } from "svelte/store";
|
import type { Readable } from "svelte/store";
|
||||||
import { onMount, createEventDispatcher, getContext } from "svelte";
|
import { onMount, createEventDispatcher, getContext } from "svelte";
|
||||||
import { disabledKey } from "./contextKeys";
|
import { disabledKey } from "./contextKeys";
|
||||||
import SelectOption from "./SelectOption.svelte";
|
|
||||||
|
|
||||||
interface Option {
|
export let id: string | undefined = undefined;
|
||||||
label: string;
|
let className = "";
|
||||||
value: string;
|
export { className as class };
|
||||||
selected?: false;
|
|
||||||
}
|
|
||||||
|
|
||||||
export let id: string;
|
export let tooltip: string | undefined = undefined;
|
||||||
export let className = "";
|
|
||||||
export let tooltip: string;
|
|
||||||
|
|
||||||
function extendClassName(classes: string) {
|
|
||||||
return `form-select ${classes}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export let disables = true;
|
export let disables = true;
|
||||||
export let options: Option[];
|
|
||||||
|
|
||||||
let buttonRef: HTMLSelectElement;
|
let buttonRef: HTMLSelectElement;
|
||||||
|
|
||||||
|
|
@ -57,14 +47,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!-- svelte-ignore a11y-no-onchange -->
|
||||||
|
|
||||||
<select
|
<select
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
bind:this={buttonRef}
|
bind:this={buttonRef}
|
||||||
disabled={_disabled}
|
disabled={_disabled}
|
||||||
{id}
|
{id}
|
||||||
class={extendClassName(className)}
|
class={` ${className}`}
|
||||||
title={tooltip}>
|
title={tooltip}
|
||||||
{#each options as option}
|
on:change>
|
||||||
<SelectOption {...option} />
|
<slot />
|
||||||
{/each}
|
|
||||||
</select>
|
</select>
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ Copyright: Ankitects Pty Ltd and contributors
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
export let label: string;
|
export let value: string | undefined = undefined;
|
||||||
export let value: string;
|
|
||||||
export let selected = false;
|
export let selected = false;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<option {selected} {value}>{label}</option>
|
<option {value} {selected}>
|
||||||
|
<slot />
|
||||||
|
</option>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
export let id: string | undefined = undefined;
|
export let id: string | undefined = undefined;
|
||||||
|
let className = "";
|
||||||
|
export { className as class };
|
||||||
export let style: string;
|
export let style: string;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -13,6 +15,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div {id} {style}>
|
<div {id} class={className} {style}>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ ts_library(
|
||||||
"DeckOptionsPage",
|
"DeckOptionsPage",
|
||||||
"lib",
|
"lib",
|
||||||
"//ts/lib",
|
"//ts/lib",
|
||||||
|
"//ts/components",
|
||||||
"@npm//@popperjs",
|
"@npm//@popperjs",
|
||||||
"@npm//svelte2tsx",
|
"@npm//svelte2tsx",
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import * as tr from "lib/i18n";
|
import * as tr from "lib/i18n";
|
||||||
import type { DeckOptionsState, ConfigListEntry } from "./lib";
|
import type { DeckOptionsState, ConfigListEntry } from "./lib";
|
||||||
|
|
||||||
|
import WithTheming from "components/WithTheming.svelte";
|
||||||
import StickyBar from "components/StickyBar.svelte";
|
import StickyBar from "components/StickyBar.svelte";
|
||||||
|
import ButtonToolbar from "components/ButtonToolbar.svelte";
|
||||||
|
import ButtonToolbarItem from "components/ButtonToolbarItem.svelte";
|
||||||
|
import ButtonGroup from "components/ButtonGroup.svelte";
|
||||||
|
import ButtonGroupItem from "components/ButtonGroupItem.svelte";
|
||||||
|
|
||||||
|
import SelectButton from "components/SelectButton.svelte";
|
||||||
|
import SelectOption from "components/SelectOption.svelte";
|
||||||
import OptionsDropdown from "./OptionsDropdown.svelte";
|
import OptionsDropdown from "./OptionsDropdown.svelte";
|
||||||
|
|
||||||
export let state: DeckOptionsState;
|
export let state: DeckOptionsState;
|
||||||
|
|
@ -21,28 +30,30 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
.selector-grid {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 6fr 1fr;
|
|
||||||
grid-column-gap: 0.5em;
|
|
||||||
padding-right: 0.5em;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<StickyBar>
|
<StickyBar>
|
||||||
<div>{tr.actionsOptionsFor({ val: state.currentDeck.name })}</div>
|
<div>{tr.actionsOptionsFor({ val: state.currentDeck.name })}</div>
|
||||||
|
|
||||||
<div class="selector-grid">
|
<WithTheming style="--toolbar-size: 30px; --toolbar-wrap: nowrap">
|
||||||
<!-- svelte-ignore a11y-no-onchange -->
|
<ButtonToolbar class="justify-content-between">
|
||||||
<select class="form-select" on:change={blur}>
|
<ButtonToolbarItem>
|
||||||
{#each $configList as entry}
|
<ButtonGroup class="flex-grow-1">
|
||||||
<option value={entry.idx} selected={entry.current}>
|
<ButtonGroupItem>
|
||||||
{configLabel(entry)}
|
<SelectButton class="flex-grow-1" on:change={blur}>
|
||||||
</option>
|
{#each $configList as entry}
|
||||||
{/each}
|
<SelectOption
|
||||||
</select>
|
value={String(entry.idx)}
|
||||||
|
selected={entry.current}>
|
||||||
|
{configLabel(entry)}
|
||||||
|
</SelectOption>
|
||||||
|
{/each}
|
||||||
|
</SelectButton>
|
||||||
|
</ButtonGroupItem>
|
||||||
|
</ButtonGroup>
|
||||||
|
</ButtonToolbarItem>
|
||||||
|
|
||||||
<OptionsDropdown {state} />
|
<ButtonToolbarItem>
|
||||||
</div>
|
<OptionsDropdown {state} />
|
||||||
|
</ButtonToolbarItem>
|
||||||
|
</ButtonToolbar>
|
||||||
|
</WithTheming>
|
||||||
</StickyBar>
|
</StickyBar>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import { textInputModal } from "./textInputModal";
|
import { textInputModal } from "./textInputModal";
|
||||||
import type { DeckOptionsState } from "./lib";
|
import type { DeckOptionsState } from "./lib";
|
||||||
|
|
||||||
|
import ButtonGroup from "components/ButtonGroup.svelte";
|
||||||
|
import ButtonGroupItem from "components/ButtonGroupItem.svelte";
|
||||||
|
|
||||||
|
import LabelButton from "components/LabelButton.svelte";
|
||||||
|
import DropdownMenu from "components/DropdownMenu.svelte";
|
||||||
|
import DropdownItem from "components/DropdownItem.svelte";
|
||||||
|
import DropdownDivider from "components/DropdownDivider.svelte";
|
||||||
|
import WithDropdownMenu from "components/WithDropdownMenu.svelte";
|
||||||
|
|
||||||
export let state: DeckOptionsState;
|
export let state: DeckOptionsState;
|
||||||
|
|
||||||
function addConfig(): void {
|
function addConfig(): void {
|
||||||
|
|
@ -60,38 +69,23 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<ButtonGroup>
|
||||||
:global(svg) {
|
<ButtonGroupItem>
|
||||||
vertical-align: text-bottom;
|
<LabelButton theme="primary" on:click={() => save(false)}>Save</LabelButton>
|
||||||
}
|
</ButtonGroupItem>
|
||||||
</style>
|
|
||||||
|
|
||||||
<div class="btn-group" dir="ltr">
|
<ButtonGroupItem>
|
||||||
<button
|
<WithDropdownMenu let:createDropdown let:menuId>
|
||||||
type="button"
|
<LabelButton on:mount={createDropdown} />
|
||||||
class="btn btn-primary"
|
<DropdownMenu id={menuId}>
|
||||||
on:click={() => save(false)}>Save</button>
|
<DropdownItem on:click={addConfig}>Add Config</DropdownItem>
|
||||||
<button
|
<DropdownItem on:click={renameConfig}>Rename Config</DropdownItem>
|
||||||
type="button"
|
<DropdownItem on:click={removeConfig}>Remove Config</DropdownItem>
|
||||||
class="btn btn-secondary dropdown-toggle dropdown-toggle-split"
|
<DropdownDivider />
|
||||||
data-bs-toggle="dropdown"
|
<DropdownItem on:click={() => save(true)}>
|
||||||
aria-expanded="false">
|
Save to All Children
|
||||||
<span class="visually-hidden">Toggle Dropdown</span>
|
</DropdownItem>
|
||||||
</button>
|
</DropdownMenu>
|
||||||
<ul class="dropdown-menu">
|
</WithDropdownMenu>
|
||||||
<li><a class="dropdown-item" href={'#'} on:click={addConfig}>Add Config</a></li>
|
</ButtonGroupItem>
|
||||||
<li>
|
</ButtonGroup>
|
||||||
<a class="dropdown-item" href={'#'} on:click={renameConfig}>Rename Config</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a class="dropdown-item" href={'#'} on:click={removeConfig}>Remove Config</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<hr class="dropdown-divider" />
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a class="dropdown-item" href={'#'} on:click={() => save(true)}>Save to All
|
|
||||||
Children</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,33 @@ import SpinBoxFloat from "./SpinBoxFloat.svelte";
|
||||||
import EnumSelector from "./EnumSelector.svelte";
|
import EnumSelector from "./EnumSelector.svelte";
|
||||||
import CheckBox from "./CheckBox.svelte";
|
import CheckBox from "./CheckBox.svelte";
|
||||||
|
|
||||||
|
import { nightModeKey } from "components/contextKeys";
|
||||||
|
|
||||||
export async function deckOptions(
|
export async function deckOptions(
|
||||||
target: HTMLDivElement,
|
target: HTMLDivElement,
|
||||||
deckId: number
|
deckId: number
|
||||||
): Promise<DeckOptionsPage> {
|
): Promise<DeckOptionsPage> {
|
||||||
checkNightMode();
|
const [info] = await Promise.all([
|
||||||
await setupI18n({
|
getDeckOptionsInfo(deckId),
|
||||||
modules: [ModuleName.SCHEDULING, ModuleName.ACTIONS, ModuleName.DECK_CONFIG],
|
setupI18n({
|
||||||
});
|
modules: [
|
||||||
const info = await getDeckOptionsInfo(deckId);
|
ModuleName.SCHEDULING,
|
||||||
|
ModuleName.ACTIONS,
|
||||||
|
ModuleName.DECK_CONFIG,
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const nightMode = checkNightMode();
|
||||||
|
const context = new Map();
|
||||||
|
context.set(nightModeKey, nightMode);
|
||||||
|
|
||||||
const state = new DeckOptionsState(deckId, info);
|
const state = new DeckOptionsState(deckId, info);
|
||||||
return new DeckOptionsPage({
|
return new DeckOptionsPage({
|
||||||
target,
|
target,
|
||||||
props: { state },
|
props: { state },
|
||||||
});
|
context,
|
||||||
|
} as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deckConfigComponents = {
|
export const deckConfigComponents = {
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
</ButtonGroupItem>
|
</ButtonGroupItem>
|
||||||
|
|
||||||
<ButtonGroupItem>
|
<ButtonGroupItem>
|
||||||
<WithDropdownMenu let:menuId let:createDropdown>
|
<WithDropdownMenu let:createDropdown let:menuId>
|
||||||
<IconButton on:mount={createDropdown}>
|
<IconButton on:mount={createDropdown}>
|
||||||
{@html functionIcon}
|
{@html functionIcon}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ export function initToolbar(i18n: Promise<void>): Promise<EditorToolbar> {
|
||||||
toolbarResolve = resolve;
|
toolbarResolve = resolve;
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () =>
|
||||||
i18n.then(() => {
|
i18n.then(() => {
|
||||||
const target = document.body;
|
const target = document.body;
|
||||||
const anchor = document.getElementById("fields")!;
|
const anchor = document.getElementById("fields")!;
|
||||||
|
|
@ -33,8 +33,8 @@ export function initToolbar(i18n: Promise<void>): Promise<EditorToolbar> {
|
||||||
);
|
);
|
||||||
|
|
||||||
toolbarResolve(new EditorToolbar({ target, anchor, context } as any));
|
toolbarResolve(new EditorToolbar({ target, anchor, context } as any));
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
return toolbarPromise;
|
return toolbarPromise;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue