From 04ba24cb54a09978ef4b138caf4f7c19e01b5ce0 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 28 Sep 2021 11:04:10 +1000 Subject: [PATCH] silence execCommand deprecation warnings for now --- ts/editor/ColorButtons.svelte | 6 +++--- ts/editor/CommandIconButton.svelte | 14 +++++++------- ts/editor/FormatBlockButtons.svelte | 6 +++--- ts/editor/TagEditor.svelte | 3 ++- ts/editor/helpers.ts | 14 ++++++++++++++ ts/svelte/svelte.bzl | 2 +- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/ts/editor/ColorButtons.svelte b/ts/editor/ColorButtons.svelte index 0f4e17acf..251fe078d 100644 --- a/ts/editor/ColorButtons.svelte +++ b/ts/editor/ColorButtons.svelte @@ -16,7 +16,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import { bridgeCommand } from "lib/bridgecommand"; import { withButton } from "components/helpers"; import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons"; - import { appendInParentheses } from "./helpers"; + import { appendInParentheses, execCommand } from "./helpers"; export let api = {}; 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); const wrapWithForecolor = (color: string) => () => { - document.execCommand("forecolor", false, color); + execCommand("forecolor", false, color); }; const wrapWithBackcolor = (color: string) => () => { - document.execCommand("backcolor", false, color); + execCommand("backcolor", false, color); }; diff --git a/ts/editor/CommandIconButton.svelte b/ts/editor/CommandIconButton.svelte index db4a065b5..26adb8688 100644 --- a/ts/editor/CommandIconButton.svelte +++ b/ts/editor/CommandIconButton.svelte @@ -9,7 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import OnlyEditable from "./OnlyEditable.svelte"; import { withButton } from "components/helpers"; - import { appendInParentheses } from "./helpers"; + import { appendInParentheses, execCommand, queryCommandState } from "./helpers"; export let key: string; export let tooltip: string; @@ -21,13 +21,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html {#if withoutShortcut && withoutState} - document.execCommand(key)}> + execCommand(key)}> {:else if withoutShortcut} document.queryCommandState(key)} + update={() => queryCommandState(key)} let:state={active} let:updateState > @@ -36,7 +36,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html {active} {disabled} on:click={(event) => { - document.execCommand(key); + execCommand(key); updateState(event); }} > @@ -48,7 +48,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html document.execCommand(key)} + on:click={() => execCommand(key)} on:mount={withButton(createShortcut)} > @@ -58,7 +58,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html document.queryCommandState(key)} + update={() => queryCommandState(key)} let:state={active} let:updateState > @@ -67,7 +67,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html {active} {disabled} on:click={(event) => { - document.execCommand(key); + execCommand(key); updateState(event); }} on:mount={withButton(createShortcut)} diff --git a/ts/editor/FormatBlockButtons.svelte b/ts/editor/FormatBlockButtons.svelte index b7cf587c8..b8f08b7c7 100644 --- a/ts/editor/FormatBlockButtons.svelte +++ b/ts/editor/FormatBlockButtons.svelte @@ -15,7 +15,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import CommandIconButton from "./CommandIconButton.svelte"; import { getListItem } from "lib/dom"; - import { getCurrentField } from "./helpers"; + import { getCurrentField, execCommand } from "./helpers"; import { ulIcon, olIcon, @@ -33,7 +33,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html function outdentListItem() { const currentField = getCurrentField(); if (getListItem(currentField!.editableContainer.shadowRoot!)) { - document.execCommand("outdent"); + execCommand("outdent"); } else { 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() { const currentField = getCurrentField(); if (getListItem(currentField!.editableContainer.shadowRoot!)) { - document.execCommand("indent"); + execCommand("indent"); } else { alert("Indent/unindent currently only works with lists."); } diff --git a/ts/editor/TagEditor.svelte b/ts/editor/TagEditor.svelte index 022aafdce..05b046a14 100644 --- a/ts/editor/TagEditor.svelte +++ b/ts/editor/TagEditor.svelte @@ -22,6 +22,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } from "./tags"; import { Tags } from "lib/proto"; import { postRequest } from "lib/postrequest"; + import { execCommand } from "./helpers"; 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"; document.body.appendChild(textarea); textarea.select(); - document.execCommand("copy"); + execCommand("copy"); document.body.removeChild(textarea); } diff --git a/ts/editor/helpers.ts b/ts/editor/helpers.ts index b92b57fd5..3064aa6b8 100644 --- a/ts/editor/helpers.ts +++ b/ts/editor/helpers.ts @@ -10,3 +10,17 @@ export function getCurrentField(): EditingArea | null { export function appendInParentheses(text: string, appendix: string): string { 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); +} diff --git a/ts/svelte/svelte.bzl b/ts/svelte/svelte.bzl index 71daf46c7..3c87a21d2 100644 --- a/ts/svelte/svelte.bzl +++ b/ts/svelte/svelte.bzl @@ -85,7 +85,7 @@ def svelte_check(name = "svelte_check", srcs = []): "--workspace", native.package_name(), "--fail-on-warnings", - #"--fail-on-hints", + "--fail-on-hints", ], data = [ "//ts:tsconfig.json",