Add back ColorButtons

This commit is contained in:
Henrik Giesel 2021-04-28 22:32:12 +02:00
parent bd31a19852
commit 9d9df2a04b
4 changed files with 19 additions and 23 deletions

View File

@ -5,20 +5,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<script lang="typescript"> <script lang="typescript">
import { onMount, createEventDispatcher, getContext } from "svelte"; import { onMount, createEventDispatcher, getContext } from "svelte";
import { nightModeKey } from "./contextKeys"; import { nightModeKey } from "./contextKeys";
import { mergeTooltipAndShortcut } from "./helpers";
export let id: string; export let id: string;
export let className = ""; export let className = "";
export let tooltip: string | undefined; export let tooltip: string | undefined;
export let shortcutLabel: string | undefined;
$: title = mergeTooltipAndShortcut(tooltip, shortcutLabel);
export let onChange: (event: Event) => void;
function extendClassName(className: string): string {
return `btn ${className}`;
}
const nightMode = getContext(nightModeKey); const nightMode = getContext(nightModeKey);
@ -68,11 +58,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
bind:this={buttonRef} bind:this={buttonRef}
tabindex="-1" tabindex="-1"
{id} {id}
class={extendClassName(className)} class={`btn ${className}`}
class:btn-day={!nightMode} class:btn-day={!nightMode}
class:btn-night={nightMode} class:btn-night={nightMode}
{title} title={tooltip}
on:click={delegateToInput} on:click={delegateToInput}
on:mousedown|preventDefault> on:mousedown|preventDefault>
<input tabindex="-1" bind:this={inputRef} type="color" on:change={onChange} /> <input tabindex="-1" bind:this={inputRef} type="color" on:change />
</button> </button>

View File

@ -15,21 +15,18 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import "./color.css"; import "./color.css";
const foregroundColorKeyword = "--foreground-color"; const foregroundColorKeyword = "--foreground-color";
let color = "black";
function setForegroundColor(color: string): void { $: {
document.documentElement.style.setProperty(foregroundColorKeyword, color); document.documentElement.style.setProperty(foregroundColorKeyword, color);
} }
function getForecolor(): string { function wrapWithForecolor(): void {
return document.documentElement.style.getPropertyValue(foregroundColorKeyword);
}
function wrapWithForecolor(color: string): void {
document.execCommand("forecolor", false, color); document.execCommand("forecolor", false, color);
} }
function setWithCurrentColor({ currentTarget }: Event): void { function setWithCurrentColor({ currentTarget }: Event): void {
return setForegroundColor((currentTarget as HTMLInputElement).value); color = (currentTarget as HTMLInputElement).value;
} }
</script> </script>
@ -38,7 +35,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<IconButton <IconButton
class="forecolor" class="forecolor"
tooltip={`${tr.editingSetForegroundColor} (${shortcutLabel})`} tooltip={`${tr.editingSetForegroundColor} (${shortcutLabel})`}
on:click={() => wrapWithForecolor(getForecolor())} on:click={wrapWithForecolor}
on:mount={createShortcut}> on:mount={createShortcut}>
{@html squareFillIcon} {@html squareFillIcon}
</IconButton> </IconButton>

View File

@ -58,5 +58,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<NoteTypeButtons /> <NoteTypeButtons />
<FormatInlineButtons /> <FormatInlineButtons />
<FormatBlockButtons /> <FormatBlockButtons />
<ColorButtons />
</StickyBar> </StickyBar>
</WithTheming> </WithTheming>

View File

@ -33,5 +33,13 @@ export function initToolbar(i18n: Promise<void>): Promise<EditorToolbar> {
} }
/* Exports for editor */ /* Exports for editor */
// @ts-expect-error insufficient typing of svelte modules export {
export { enableButtons, disableButtons, updateActiveButtons, clearActiveButtons } from "./EditorToolbar.svelte"; // @ts-expect-error insufficient typing of svelte modules
enableButtons,
// @ts-expect-error insufficient typing of svelte modules
disableButtons,
// @ts-expect-error insufficient typing of svelte modules
updateActiveButtons,
// @ts-expect-error insufficient typing of svelte modules
clearActiveButtons,
} from "./EditorToolbar.svelte";