anki/ts/deck-options/index.ts
Damien Elmes f3b6deefe9 Combine all backend methods into a single js/d.ts file, like in Python
Easier to import from, and allows us to declare the output of the build
action without having to iterate over all the proto filenames. Have
confirmed it doesn't break esbuild's tree shaking.
2023-07-03 13:46:38 +10:00

68 lines
1.8 KiB
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
/* eslint
@typescript-eslint/no-explicit-any: "off",
*/
import "../sveltelib/export-runtime";
import "./deck-options-base.scss";
import { ModuleName, setupI18n } from "@tslib/i18n";
import { checkNightMode } from "@tslib/nightmode";
import { modalsKey, touchDeviceKey } from "../components/context-keys";
import DeckOptionsPage from "./DeckOptionsPage.svelte";
import { DeckOptionsState } from "./lib";
const i18n = setupI18n({
modules: [
ModuleName.HELP,
ModuleName.SCHEDULING,
ModuleName.ACTIONS,
ModuleName.DECK_CONFIG,
ModuleName.KEYBOARD,
],
});
export async function setupDeckOptions(did_: number): Promise<DeckOptionsPage> {
const did = BigInt(did_);
const [info] = await Promise.all([
getDeckConfigsForUpdate({ did }),
i18n,
]);
checkNightMode();
const context = new Map();
context.set(modalsKey, new Map());
context.set(touchDeviceKey, "ontouchstart" in document.documentElement);
const state = new DeckOptionsState(BigInt(did), info);
return new DeckOptionsPage({
target: document.body,
props: { state },
context,
});
}
import { getDeckConfigsForUpdate } from "@tslib/backend";
import TitledContainer from "../components/TitledContainer.svelte";
import EnumSelectorRow from "./EnumSelectorRow.svelte";
import SpinBoxFloatRow from "./SpinBoxFloatRow.svelte";
import SpinBoxRow from "./SpinBoxRow.svelte";
import SwitchRow from "./SwitchRow.svelte";
export const components = {
TitledContainer,
SpinBoxRow,
SpinBoxFloatRow,
EnumSelectorRow,
SwitchRow,
};
if (window.location.hash.startsWith("#test")) {
setupDeckOptions(1);
}