Fix typing issues

This commit is contained in:
Henrik Giesel 2021-05-06 03:37:21 +02:00
parent 9c1936698c
commit 862905c58a
10 changed files with 26 additions and 10 deletions

View File

@ -9,7 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { writable } from "svelte/store";
import { buttonGroupKey } from "./contextKeys";
import type { Identifier } from "./identifier";
import { insert, add, update, find } from "./identifier";
import { insert, add, find } from "./identifier";
import type { ButtonRegistration } from "./buttons";
import { ButtonPosition } from "./buttons";

View File

@ -18,6 +18,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
</style>
<div {id} class={`dropdown-menu`}>
<div {id} class="dropdown-menu">
<slot />
</div>

View File

@ -6,6 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type { Readable } from "svelte/store";
import { getContext, onMount, createEventDispatcher } from "svelte";
import { disabledKey, nightModeKey, dropdownKey } from "./contextKeys";
import type { DropdownProps } from "./dropdown";
export let id: string | undefined = undefined;
let className = "";
@ -22,7 +23,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
$: _disabled = disables && $disabled;
const nightMode = getContext<boolean>(nightModeKey);
const dropdownProps = getContext(dropdownKey) ?? { dropdown: false };
const dropdownProps = getContext<DropdownProps>(dropdownKey) ?? { dropdown: false };
const dispatch = createEventDispatcher();
onMount(() => dispatch("mount", { button: buttonRef }));

View File

@ -6,6 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type { Readable } from "svelte/store";
import { onMount, createEventDispatcher, getContext } from "svelte";
import { disabledKey, nightModeKey, dropdownKey } from "./contextKeys";
import type { DropdownProps } from "./dropdown";
export let id: string | undefined = undefined;
let className: string = "";
@ -19,7 +20,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
$: _disabled = disables && $disabled;
const nightMode = getContext<boolean>(nightModeKey);
const dropdownProps = getContext(dropdownKey) ?? {};
const dropdownProps = getContext<DropdownProps>(dropdownKey) ?? { dropdown: false };
let buttonRef: HTMLButtonElement;

View File

@ -4,11 +4,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="typescript">
import type { Readable } from "svelte/store";
import type { Option } from "./SelectButton";
import { onMount, createEventDispatcher, getContext } from "svelte";
import { disabledKey } from "./contextKeys";
import SelectOption from "./SelectOption.svelte";
interface Option {
label: string;
value: string;
selected?: false;
}
export let id: string;
export let className = "";
export let tooltip: string;

View File

@ -29,17 +29,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
export function updateAllState(event: Event): void {
updateAllStateWithCallback((key: string): T => updaterMap.get(key)(event));
updateAllStateWithCallback((key: string): T => updaterMap.get(key)!(event));
}
export function resetAllState(state: T): void {
updateAllStateWithCallback((): T => state);
}
function updateStateByKey(key: string, event: MouseEvent): void {
function updateStateByKey(key: string, event: Event): void {
stateStore.update(
(map: StateMap): StateMap => {
map.set(key, updaterMap.get(key)(event));
map.set(key, updaterMap.get(key)!(event));
return map;
}
);

View File

@ -0,0 +1,7 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
export interface DropdownProps {
dropdown: boolean;
"data-bs-toggle"?: string;
"aria-expanded"?: string;
}

View File

@ -48,7 +48,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let:shortcutLabel>
<IconButton
tooltip={`${tr.editingClozeDeletion()} (${shortcutLabel})`}
on:click={onCloze}>
on:click={onCloze}
on:mount={createShortcut}>
{@html bracketsIcon}
</IconButton>
</WithShortcut>

View File

@ -16,6 +16,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
disabled.set(true);
}
// @ts-expect-error insufficient typing of svelte modules
import { updateAllState, resetAllState } from "components/WithState.svelte";
export function updateActiveButtons(event: Event) {

View File

@ -137,7 +137,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<WithShortcut shortcut="Control+KeyR" let:createShortcut let:shortcutLabel>
<IconButton
tooltip={appendInParentheses(tr.editingRemoveFormatting(), shortcutLabel)}
on:click={(event) => {
on:click={() => {
document.execCommand('removeFormat');
}}
on:mount={createShortcut}>