silence execCommand deprecation warnings for now

This commit is contained in:
Damien Elmes 2021-09-28 11:04:10 +10:00
parent 2a2469e7a2
commit 04ba24cb54
6 changed files with 30 additions and 15 deletions

View file

@ -16,7 +16,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { bridgeCommand } from "lib/bridgecommand"; import { bridgeCommand } from "lib/bridgecommand";
import { withButton } from "components/helpers"; import { withButton } from "components/helpers";
import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons"; import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons";
import { appendInParentheses } from "./helpers"; import { appendInParentheses, execCommand } from "./helpers";
export let api = {}; export let api = {};
export let textColor: string; export let textColor: string;
@ -26,11 +26,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
$: backcolorWrap = wrapWithBackcolor(highlightColor); $: backcolorWrap = wrapWithBackcolor(highlightColor);
const wrapWithForecolor = (color: string) => () => { const wrapWithForecolor = (color: string) => () => {
document.execCommand("forecolor", false, color); execCommand("forecolor", false, color);
}; };
const wrapWithBackcolor = (color: string) => () => { const wrapWithBackcolor = (color: string) => () => {
document.execCommand("backcolor", false, color); execCommand("backcolor", false, color);
}; };
</script> </script>

View file

@ -9,7 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import OnlyEditable from "./OnlyEditable.svelte"; import OnlyEditable from "./OnlyEditable.svelte";
import { withButton } from "components/helpers"; import { withButton } from "components/helpers";
import { appendInParentheses } from "./helpers"; import { appendInParentheses, execCommand, queryCommandState } from "./helpers";
export let key: string; export let key: string;
export let tooltip: string; export let tooltip: string;
@ -21,13 +21,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<OnlyEditable let:disabled> <OnlyEditable let:disabled>
{#if withoutShortcut && withoutState} {#if withoutShortcut && withoutState}
<IconButton {tooltip} {disabled} on:click={() => document.execCommand(key)}> <IconButton {tooltip} {disabled} on:click={() => execCommand(key)}>
<slot /> <slot />
</IconButton> </IconButton>
{:else if withoutShortcut} {:else if withoutShortcut}
<WithState <WithState
{key} {key}
update={() => document.queryCommandState(key)} update={() => queryCommandState(key)}
let:state={active} let:state={active}
let:updateState let:updateState
> >
@ -36,7 +36,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
{active} {active}
{disabled} {disabled}
on:click={(event) => { on:click={(event) => {
document.execCommand(key); execCommand(key);
updateState(event); updateState(event);
}} }}
> >
@ -48,7 +48,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<IconButton <IconButton
tooltip={appendInParentheses(tooltip, shortcutLabel)} tooltip={appendInParentheses(tooltip, shortcutLabel)}
{disabled} {disabled}
on:click={() => document.execCommand(key)} on:click={() => execCommand(key)}
on:mount={withButton(createShortcut)} on:mount={withButton(createShortcut)}
> >
<slot /> <slot />
@ -58,7 +58,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<WithShortcut {shortcut} let:createShortcut let:shortcutLabel> <WithShortcut {shortcut} let:createShortcut let:shortcutLabel>
<WithState <WithState
{key} {key}
update={() => document.queryCommandState(key)} update={() => queryCommandState(key)}
let:state={active} let:state={active}
let:updateState let:updateState
> >
@ -67,7 +67,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
{active} {active}
{disabled} {disabled}
on:click={(event) => { on:click={(event) => {
document.execCommand(key); execCommand(key);
updateState(event); updateState(event);
}} }}
on:mount={withButton(createShortcut)} on:mount={withButton(createShortcut)}

View file

@ -15,7 +15,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import CommandIconButton from "./CommandIconButton.svelte"; import CommandIconButton from "./CommandIconButton.svelte";
import { getListItem } from "lib/dom"; import { getListItem } from "lib/dom";
import { getCurrentField } from "./helpers"; import { getCurrentField, execCommand } from "./helpers";
import { import {
ulIcon, ulIcon,
olIcon, olIcon,
@ -33,7 +33,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
function outdentListItem() { function outdentListItem() {
const currentField = getCurrentField(); const currentField = getCurrentField();
if (getListItem(currentField!.editableContainer.shadowRoot!)) { if (getListItem(currentField!.editableContainer.shadowRoot!)) {
document.execCommand("outdent"); execCommand("outdent");
} else { } else {
alert("Indent/unindent currently only works with lists."); alert("Indent/unindent currently only works with lists.");
} }
@ -42,7 +42,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
function indentListItem() { function indentListItem() {
const currentField = getCurrentField(); const currentField = getCurrentField();
if (getListItem(currentField!.editableContainer.shadowRoot!)) { if (getListItem(currentField!.editableContainer.shadowRoot!)) {
document.execCommand("indent"); execCommand("indent");
} else { } else {
alert("Indent/unindent currently only works with lists."); alert("Indent/unindent currently only works with lists.");
} }

View file

@ -22,6 +22,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} from "./tags"; } from "./tags";
import { Tags } from "lib/proto"; import { Tags } from "lib/proto";
import { postRequest } from "lib/postrequest"; import { postRequest } from "lib/postrequest";
import { execCommand } from "./helpers";
export let tags: TagType[] = []; export let tags: TagType[] = [];
@ -355,7 +356,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
textarea.style.left = "-9999px"; textarea.style.left = "-9999px";
document.body.appendChild(textarea); document.body.appendChild(textarea);
textarea.select(); textarea.select();
document.execCommand("copy"); execCommand("copy");
document.body.removeChild(textarea); document.body.removeChild(textarea);
} }

View file

@ -10,3 +10,17 @@ export function getCurrentField(): EditingArea | null {
export function appendInParentheses(text: string, appendix: string): string { export function appendInParentheses(text: string, appendix: string): string {
return `${text} (${appendix})`; return `${text} (${appendix})`;
} }
/// trivial wrapper to silence Svelte deprecation warnings
export function execCommand(
command: string,
showUI?: boolean | undefined,
value?: string | undefined
): void {
document.execCommand(command, showUI, value);
}
/// trivial wrapper to silence Svelte deprecation warnings
export function queryCommandState(command: string): boolean {
return document.queryCommandState(command);
}

View file

@ -85,7 +85,7 @@ def svelte_check(name = "svelte_check", srcs = []):
"--workspace", "--workspace",
native.package_name(), native.package_name(),
"--fail-on-warnings", "--fail-on-warnings",
#"--fail-on-hints", "--fail-on-hints",
], ],
data = [ data = [
"//ts:tsconfig.json", "//ts:tsconfig.json",