Fix typing issues
This commit is contained in:
parent
9c1936698c
commit
862905c58a
@ -9,7 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
import { buttonGroupKey } from "./contextKeys";
|
import { buttonGroupKey } from "./contextKeys";
|
||||||
import type { Identifier } from "./identifier";
|
import type { Identifier } from "./identifier";
|
||||||
import { insert, add, update, find } from "./identifier";
|
import { insert, add, find } from "./identifier";
|
||||||
import type { ButtonRegistration } from "./buttons";
|
import type { ButtonRegistration } from "./buttons";
|
||||||
import { ButtonPosition } from "./buttons";
|
import { ButtonPosition } from "./buttons";
|
||||||
|
|
||||||
|
@ -18,6 +18,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div {id} class={`dropdown-menu`}>
|
<div {id} class="dropdown-menu">
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
@ -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 type { Readable } from "svelte/store";
|
||||||
import { getContext, onMount, createEventDispatcher } from "svelte";
|
import { getContext, onMount, createEventDispatcher } from "svelte";
|
||||||
import { disabledKey, nightModeKey, dropdownKey } from "./contextKeys";
|
import { disabledKey, nightModeKey, dropdownKey } from "./contextKeys";
|
||||||
|
import type { DropdownProps } from "./dropdown";
|
||||||
|
|
||||||
export let id: string | undefined = undefined;
|
export let id: string | undefined = undefined;
|
||||||
let className = "";
|
let className = "";
|
||||||
@ -22,7 +23,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
$: _disabled = disables && $disabled;
|
$: _disabled = disables && $disabled;
|
||||||
|
|
||||||
const nightMode = getContext<boolean>(nightModeKey);
|
const nightMode = getContext<boolean>(nightModeKey);
|
||||||
const dropdownProps = getContext(dropdownKey) ?? { dropdown: false };
|
const dropdownProps = getContext<DropdownProps>(dropdownKey) ?? { dropdown: false };
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
onMount(() => dispatch("mount", { button: buttonRef }));
|
onMount(() => dispatch("mount", { button: buttonRef }));
|
||||||
|
@ -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 type { Readable } from "svelte/store";
|
||||||
import { onMount, createEventDispatcher, getContext } from "svelte";
|
import { onMount, createEventDispatcher, getContext } from "svelte";
|
||||||
import { disabledKey, nightModeKey, dropdownKey } from "./contextKeys";
|
import { disabledKey, nightModeKey, dropdownKey } from "./contextKeys";
|
||||||
|
import type { DropdownProps } from "./dropdown";
|
||||||
|
|
||||||
export let id: string | undefined = undefined;
|
export let id: string | undefined = undefined;
|
||||||
let className: string = "";
|
let className: string = "";
|
||||||
@ -19,7 +20,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
$: _disabled = disables && $disabled;
|
$: _disabled = disables && $disabled;
|
||||||
|
|
||||||
const nightMode = getContext<boolean>(nightModeKey);
|
const nightMode = getContext<boolean>(nightModeKey);
|
||||||
const dropdownProps = getContext(dropdownKey) ?? {};
|
const dropdownProps = getContext<DropdownProps>(dropdownKey) ?? { dropdown: false };
|
||||||
|
|
||||||
let buttonRef: HTMLButtonElement;
|
let buttonRef: HTMLButtonElement;
|
||||||
|
|
||||||
|
@ -4,11 +4,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import type { Readable } from "svelte/store";
|
import type { Readable } from "svelte/store";
|
||||||
import type { Option } from "./SelectButton";
|
|
||||||
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";
|
import SelectOption from "./SelectOption.svelte";
|
||||||
|
|
||||||
|
interface Option {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
selected?: false;
|
||||||
|
}
|
||||||
|
|
||||||
export let id: string;
|
export let id: string;
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let tooltip: string;
|
export let tooltip: string;
|
||||||
|
@ -29,17 +29,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function updateAllState(event: Event): void {
|
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 {
|
export function resetAllState(state: T): void {
|
||||||
updateAllStateWithCallback((): T => state);
|
updateAllStateWithCallback((): T => state);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStateByKey(key: string, event: MouseEvent): void {
|
function updateStateByKey(key: string, event: Event): void {
|
||||||
stateStore.update(
|
stateStore.update(
|
||||||
(map: StateMap): StateMap => {
|
(map: StateMap): StateMap => {
|
||||||
map.set(key, updaterMap.get(key)(event));
|
map.set(key, updaterMap.get(key)!(event));
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
7
ts/components/dropdown.ts
Normal file
7
ts/components/dropdown.ts
Normal 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;
|
||||||
|
}
|
@ -48,7 +48,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
let:shortcutLabel>
|
let:shortcutLabel>
|
||||||
<IconButton
|
<IconButton
|
||||||
tooltip={`${tr.editingClozeDeletion()} (${shortcutLabel})`}
|
tooltip={`${tr.editingClozeDeletion()} (${shortcutLabel})`}
|
||||||
on:click={onCloze}>
|
on:click={onCloze}
|
||||||
|
on:mount={createShortcut}>
|
||||||
{@html bracketsIcon}
|
{@html bracketsIcon}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</WithShortcut>
|
</WithShortcut>
|
||||||
|
@ -16,6 +16,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
disabled.set(true);
|
disabled.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-expect-error insufficient typing of svelte modules
|
||||||
import { updateAllState, resetAllState } from "components/WithState.svelte";
|
import { updateAllState, resetAllState } from "components/WithState.svelte";
|
||||||
|
|
||||||
export function updateActiveButtons(event: Event) {
|
export function updateActiveButtons(event: Event) {
|
||||||
|
@ -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>
|
<WithShortcut shortcut="Control+KeyR" let:createShortcut let:shortcutLabel>
|
||||||
<IconButton
|
<IconButton
|
||||||
tooltip={appendInParentheses(tr.editingRemoveFormatting(), shortcutLabel)}
|
tooltip={appendInParentheses(tr.editingRemoveFormatting(), shortcutLabel)}
|
||||||
on:click={(event) => {
|
on:click={() => {
|
||||||
document.execCommand('removeFormat');
|
document.execCommand('removeFormat');
|
||||||
}}
|
}}
|
||||||
on:mount={createShortcut}>
|
on:mount={createShortcut}>
|
||||||
|
Loading…
Reference in New Issue
Block a user