mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00
experimental support for extending add-ons screen with Svelte
This commit is contained in:
parent
b485b8cbb9
commit
b7747b6a38
4 changed files with 24 additions and 2 deletions
|
@ -294,7 +294,12 @@ hooks = [
|
||||||
args=[
|
args=[
|
||||||
"deck_options: aqt.deckoptions.DeckOptionsDialog",
|
"deck_options: aqt.deckoptions.DeckOptionsDialog",
|
||||||
],
|
],
|
||||||
doc="Can be used to inject extra options into the config screen",
|
doc="""Can be used to inject extra options into the config screen.
|
||||||
|
|
||||||
|
See the example add-ons at:
|
||||||
|
https://github.com/ankitects/anki-addons/tree/main/demos/deckoptions_svelte
|
||||||
|
https://github.com/ankitects/anki-addons/tree/main/demos/deckoptions_raw_html
|
||||||
|
""",
|
||||||
),
|
),
|
||||||
# Filtered deck options
|
# Filtered deck options
|
||||||
###################
|
###################
|
||||||
|
|
|
@ -8,6 +8,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
export let state: DeckOptionsState;
|
export let state: DeckOptionsState;
|
||||||
let components = state.addonComponents;
|
let components = state.addonComponents;
|
||||||
|
const auxData = state.currentAuxData;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $components.length}
|
{#if $components.length}
|
||||||
|
@ -15,7 +16,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<h2>Add-ons</h2>
|
<h2>Add-ons</h2>
|
||||||
|
|
||||||
{#each $components as addon}
|
{#each $components as addon}
|
||||||
<svelte:component this={addon.component} {state} {...addon} />
|
<svelte:component this={addon.component} bind:data={$auxData} {...addon} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -10,6 +10,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import { registerShortcut } from "lib/shortcuts";
|
import { registerShortcut } from "lib/shortcuts";
|
||||||
import type { Writable } from "svelte/store";
|
import type { Writable } from "svelte/store";
|
||||||
import HtmlAddon from "./HtmlAddon.svelte";
|
import HtmlAddon from "./HtmlAddon.svelte";
|
||||||
|
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
|
||||||
|
|
||||||
export let state: DeckOptionsState;
|
export let state: DeckOptionsState;
|
||||||
let addons = state.addonComponents;
|
let addons = state.addonComponents;
|
||||||
|
@ -18,6 +19,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
return state.currentAuxData;
|
return state.currentAuxData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function addSvelteAddon(component: DynamicSvelteComponent): void {
|
||||||
|
$addons = [...$addons, component];
|
||||||
|
}
|
||||||
|
|
||||||
export function addHtmlAddon(html: string, mounted: () => void): void {
|
export function addHtmlAddon(html: string, mounted: () => void): void {
|
||||||
$addons = [
|
$addons = [
|
||||||
...$addons,
|
...$addons,
|
||||||
|
|
|
@ -5,6 +5,10 @@ import { getDeckOptionsInfo, DeckOptionsState } from "./lib";
|
||||||
import { setupI18n, ModuleName } from "lib/i18n";
|
import { setupI18n, ModuleName } from "lib/i18n";
|
||||||
import { checkNightMode } from "lib/nightmode";
|
import { checkNightMode } from "lib/nightmode";
|
||||||
import DeckOptionsPage from "./DeckOptionsPage.svelte";
|
import DeckOptionsPage from "./DeckOptionsPage.svelte";
|
||||||
|
import SpinBox from "./SpinBox.svelte";
|
||||||
|
import SpinBoxFloat from "./SpinBoxFloat.svelte";
|
||||||
|
import EnumSelector from "./EnumSelector.svelte";
|
||||||
|
import CheckBox from "./CheckBox.svelte";
|
||||||
|
|
||||||
export async function deckOptions(
|
export async function deckOptions(
|
||||||
target: HTMLDivElement,
|
target: HTMLDivElement,
|
||||||
|
@ -21,3 +25,10 @@ export async function deckOptions(
|
||||||
props: { state },
|
props: { state },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const deckConfigComponents = {
|
||||||
|
SpinBox,
|
||||||
|
SpinBoxFloat,
|
||||||
|
EnumSelector,
|
||||||
|
CheckBox,
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue