From b2049209ff932f694304a8afdc7c21b0a9653d7d Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 28 Nov 2022 09:33:04 +1000 Subject: [PATCH] Re-enable formatting for .ts files There are some style differences compared to prettier, and not all are necessarily an improvement, but it's much faster now. --- .dprint.json | 1 - qt/aqt/data/web/js/deckbrowser.ts | 2 +- qt/aqt/data/web/js/reviewer-bottom.ts | 2 +- qt/aqt/data/web/js/webview.ts | 2 +- ts/change-notetype/lib.ts | 2 +- ts/components/helpers.ts | 16 +++----- ts/deck-options/lib.test.ts | 1 - ts/deck-options/lib.ts | 2 +- ts/domlib/location/index.ts | 9 +---- ts/domlib/surround/build/build-tree.ts | 4 +- ts/domlib/surround/build/format.ts | 8 ++-- ts/domlib/surround/flat-range.ts | 3 +- ts/domlib/surround/match-type.ts | 2 +- ts/domlib/surround/split-text.ts | 4 +- ts/domlib/surround/surround.ts | 16 ++------ ts/domlib/surround/test-utils.ts | 14 +++---- ts/editable/decorated.ts | 4 +- ts/editor/destroyable.ts | 4 +- ts/editor/icons.ts | 5 ++- .../rich-text-input/normalizing-node-store.ts | 8 ++-- ts/editor/rich-text-input/transform.ts | 14 +++---- ts/graphs/buttons.ts | 2 +- ts/graphs/calendar.ts | 2 +- ts/graphs/histogram-graph.ts | 2 +- ts/graphs/hours.ts | 2 +- ts/graphs/reviews.ts | 5 +-- ts/graphs/tooltip.ts | 5 +-- ts/html-filter/element.ts | 40 ++++++++----------- ts/html-filter/index.test.ts | 18 ++++----- ts/html-filter/index.ts | 9 +---- ts/html-filter/node.ts | 32 +++++++-------- ts/lib/dom.ts | 13 +++--- ts/lib/events.ts | 30 +++++--------- ts/lib/i18n/utils.ts | 12 +++--- ts/lib/platform.ts | 6 +-- ts/lib/runtime-require.ts | 20 +++++----- ts/lib/shortcuts.ts | 16 +++----- ts/lib/uuid.ts | 9 ++--- ts/lib/wrap.ts | 4 +- ts/reviewer/css.ts | 12 +++--- ts/reviewer/images.ts | 6 +-- ts/sveltelib/async.ts | 2 +- ts/sveltelib/asyncReactive.ts | 4 +- ts/sveltelib/dynamicComponent.ts | 19 +++++---- ts/sveltelib/position/position-floating.ts | 20 ++-------- ts/sveltelib/position/position-overlay.ts | 9 +---- ts/sveltelib/preferences.ts | 10 +++-- 47 files changed, 174 insertions(+), 258 deletions(-) diff --git a/.dprint.json b/.dprint.json index cae319ef9..f74d7261e 100644 --- a/.dprint.json +++ b/.dprint.json @@ -18,7 +18,6 @@ "**/node_modules", "out/**", "**/*-lock.json", - "**/*.{ts}", "qt/aqt/data/web/js/vendor/*.js", "ftl/qt-repo", "ftl/core-repo", diff --git a/qt/aqt/data/web/js/deckbrowser.ts b/qt/aqt/data/web/js/deckbrowser.ts index 78677653a..6f6360b33 100644 --- a/qt/aqt/data/web/js/deckbrowser.ts +++ b/qt/aqt/data/web/js/deckbrowser.ts @@ -8,7 +8,7 @@ function init() { scroll: false, // can't use "helper: 'clone'" because of a bug in jQuery 1.5 - helper: function (_event) { + helper: function(_event) { return $(this).clone(false); }, delay: 200, diff --git a/qt/aqt/data/web/js/reviewer-bottom.ts b/qt/aqt/data/web/js/reviewer-bottom.ts index b13b8f6aa..be0485853 100644 --- a/qt/aqt/data/web/js/reviewer-bottom.ts +++ b/qt/aqt/data/web/js/reviewer-bottom.ts @@ -10,7 +10,7 @@ let time: number; // set in python code let maxTime = 0; document.addEventListener("DOMContentLoaded", () => { updateTime(); - setInterval(function () { + setInterval(function() { time += 1; updateTime(); }, 1000); diff --git a/qt/aqt/data/web/js/webview.ts b/qt/aqt/data/web/js/webview.ts index c25c29427..6c812bef8 100644 --- a/qt/aqt/data/web/js/webview.ts +++ b/qt/aqt/data/web/js/webview.ts @@ -2,7 +2,7 @@ * License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */ // prevent backspace key from going back a page -document.addEventListener("keydown", function (evt: KeyboardEvent) { +document.addEventListener("keydown", function(evt: KeyboardEvent) { if (evt.keyCode !== 8) { return; } diff --git a/ts/change-notetype/lib.ts b/ts/change-notetype/lib.ts index 7dda92992..ecbf0575f 100644 --- a/ts/change-notetype/lib.ts +++ b/ts/change-notetype/lib.ts @@ -4,7 +4,7 @@ import * as tr from "@tslib/ftl"; import { Notetypes, notetypes } from "@tslib/proto"; import { isEqual } from "lodash-es"; -import type { Readable} from "svelte/store"; +import type { Readable } from "svelte/store"; import { readable } from "svelte/store"; function nullToNegativeOne(list: (number | null)[]): number[] { diff --git a/ts/components/helpers.ts b/ts/components/helpers.ts index 14e87cb77..12e9af02c 100644 --- a/ts/components/helpers.ts +++ b/ts/components/helpers.ts @@ -15,14 +15,10 @@ export function mergeTooltipAndShortcut( return buf; } -export const withButton = - (f: (button: HTMLButtonElement) => void) => - ({ detail }: CustomEvent): void => { - f(detail.button); - }; +export const withButton = (f: (button: HTMLButtonElement) => void) => ({ detail }: CustomEvent): void => { + f(detail.button); +}; -export const withSpan = - (f: (span: HTMLSpanElement) => void) => - ({ detail }: CustomEvent): void => { - f(detail.span); - }; +export const withSpan = (f: (span: HTMLSpanElement) => void) => ({ detail }: CustomEvent): void => { + f(detail.span); +}; diff --git a/ts/deck-options/lib.test.ts b/ts/deck-options/lib.test.ts index 550b54379..21907db83 100644 --- a/ts/deck-options/lib.test.ts +++ b/ts/deck-options/lib.test.ts @@ -5,7 +5,6 @@ @typescript-eslint/no-explicit-any: "off", */ - import { DeckConfig } from "@tslib/proto"; import { get } from "svelte/store"; diff --git a/ts/deck-options/lib.ts b/ts/deck-options/lib.ts index a1539eeb9..4ba8c0ed8 100644 --- a/ts/deck-options/lib.ts +++ b/ts/deck-options/lib.ts @@ -4,7 +4,7 @@ import { localeCompare } from "@tslib/i18n"; import { DeckConfig, deckConfig } from "@tslib/proto"; import { cloneDeep, isEqual } from "lodash-es"; -import type { Readable, Writable} from "svelte/store"; +import type { Readable, Writable } from "svelte/store"; import { get, readable, writable } from "svelte/store"; import type { DynamicSvelteComponent } from "../sveltelib/dynamicComponent"; diff --git a/ts/domlib/location/index.ts b/ts/domlib/location/index.ts index 16552391a..7042483cf 100644 --- a/ts/domlib/location/index.ts +++ b/ts/domlib/location/index.ts @@ -13,13 +13,6 @@ registerPackage("anki/location", { saveSelection, }); -export { - findNodeFromCoordinates, - getNodeCoordinates, - getRangeCoordinates, - Position, - restoreSelection, - saveSelection, -}; +export { findNodeFromCoordinates, getNodeCoordinates, getRangeCoordinates, Position, restoreSelection, saveSelection }; export type { RangeCoordinates } from "./range"; export type { SelectionLocation } from "./selection"; diff --git a/ts/domlib/surround/build/build-tree.ts b/ts/domlib/surround/build/build-tree.ts index ace00d8af..ed0107d5f 100644 --- a/ts/domlib/surround/build/build-tree.ts +++ b/ts/domlib/surround/build/build-tree.ts @@ -62,9 +62,9 @@ function buildFromElement( if ( // blocking - only instanceof BlockNode || + only instanceof BlockNode // ascension - (only instanceof FormattingNode && format.tryAscend(only, matchNode)) + || (only instanceof FormattingNode && format.tryAscend(only, matchNode)) ) { return [only]; } diff --git a/ts/domlib/surround/build/format.ts b/ts/domlib/surround/build/format.ts index 1316796be..fe317bd7b 100644 --- a/ts/domlib/surround/build/format.ts +++ b/ts/domlib/surround/build/format.ts @@ -6,7 +6,7 @@ import { Position } from "../../location"; import { Match } from "../match-type"; import type { SplitRange } from "../split-text"; import type { SurroundFormat } from "../surround-format"; -import type { ElementNode} from "../tree"; +import type { ElementNode } from "../tree"; import { FormattingNode } from "../tree"; function nodeWithinRange(node: Node, range: Range): boolean { @@ -14,9 +14,9 @@ function nodeWithinRange(node: Node, range: Range): boolean { nodeRange.selectNodeContents(node); return ( - range.compareBoundaryPoints(Range.START_TO_START, nodeRange) !== - Position.After && - range.compareBoundaryPoints(Range.END_TO_END, nodeRange) !== Position.Before + range.compareBoundaryPoints(Range.START_TO_START, nodeRange) + !== Position.After + && range.compareBoundaryPoints(Range.END_TO_END, nodeRange) !== Position.Before ); } diff --git a/ts/domlib/surround/flat-range.ts b/ts/domlib/surround/flat-range.ts index e4f7a47f2..a261c0b53 100644 --- a/ts/domlib/surround/flat-range.ts +++ b/ts/domlib/surround/flat-range.ts @@ -69,8 +69,7 @@ export class FlatRange { if (range.collapsed) { // If the range is collapsed to a single element, move the range inside the element. // This prevents putting the surround above the base element. - const selected = - range.commonAncestorContainer.childNodes[range.startOffset]; + const selected = range.commonAncestorContainer.childNodes[range.startOffset]; if (nodeIsElement(selected)) { range.selectNode(selected); diff --git a/ts/domlib/surround/match-type.ts b/ts/domlib/surround/match-type.ts index 06dc62073..447ba259d 100644 --- a/ts/domlib/surround/match-type.ts +++ b/ts/domlib/surround/match-type.ts @@ -83,7 +83,7 @@ class FakeMatch implements MatchType { export function boolMatcher( format: SurroundFormat, ): (element: Element) => boolean { - return function (element: Element): boolean { + return function(element: Element): boolean { const fake = new FakeMatch(); format.matcher(element as HTMLElement | SVGElement, fake); return fake.value; diff --git a/ts/domlib/surround/split-text.ts b/ts/domlib/surround/split-text.ts index 98bb1b986..0aa19500a 100644 --- a/ts/domlib/surround/split-text.ts +++ b/ts/domlib/surround/split-text.ts @@ -10,8 +10,8 @@ function length(node: Node): number { if (node instanceof CharacterData) { return node.length; } else if ( - node.nodeType === Node.DOCUMENT_TYPE_NODE || - node.nodeType === Node.ATTRIBUTE_NODE + node.nodeType === Node.DOCUMENT_TYPE_NODE + || node.nodeType === Node.ATTRIBUTE_NODE ) { return 0; } diff --git a/ts/domlib/surround/surround.ts b/ts/domlib/surround/surround.ts index 781083b88..1c23a428b 100644 --- a/ts/domlib/surround/surround.ts +++ b/ts/domlib/surround/surround.ts @@ -3,18 +3,8 @@ import type { Matcher } from "../find-above"; import { findFarthest } from "../find-above"; -import { - apply, - ApplyFormat, - ReformatApplyFormat, - UnsurroundApplyFormat, -} from "./apply"; -import { - build, - BuildFormat, - ReformatBuildFormat, - UnsurroundBuildFormat, -} from "./build"; +import { apply, ApplyFormat, ReformatApplyFormat, UnsurroundApplyFormat } from "./apply"; +import { build, BuildFormat, ReformatBuildFormat, UnsurroundBuildFormat } from "./build"; import { boolMatcher } from "./match-type"; import { splitPartiallySelected } from "./split-text"; import type { SurroundFormat } from "./surround-format"; @@ -53,7 +43,7 @@ function reformatInner( * Assumes that there are no matching ancestor elements above * `range.commonAncestorContainer`. Make sure that the range is not placed * inside the format before using this. - **/ + */ export function surround( range: Range, base: Element, diff --git a/ts/domlib/surround/test-utils.ts b/ts/domlib/surround/test-utils.ts index 6160cbb97..bf9ede87e 100644 --- a/ts/domlib/surround/test-utils.ts +++ b/ts/domlib/surround/test-utils.ts @@ -3,13 +3,11 @@ import type { MatchType } from "./match-type"; -export const matchTagName = - (tagName: string) => - (element: Element, match: MatchType): void => { - if (element.matches(tagName)) { - match.remove(); - } - }; +export const matchTagName = (tagName: string) => (element: Element, match: MatchType): void => { + if (element.matches(tagName)) { + match.remove(); + } +}; export const easyBold = { surroundElement: document.createElement("b"), @@ -38,7 +36,7 @@ export function t(data: string): Text { } function element(tagName: string): (...childNodes: Node[]) => HTMLElement { - return function (...childNodes: Node[]): HTMLElement { + return function(...childNodes: Node[]): HTMLElement { const element = document.createElement(tagName); element.append(...childNodes); return element; diff --git a/ts/editable/decorated.ts b/ts/editable/decorated.ts index 8df02479e..b79a1e375 100644 --- a/ts/editable/decorated.ts +++ b/ts/editable/decorated.ts @@ -24,9 +24,7 @@ interface WithTagName { tagName: string; } -export interface DecoratedElementConstructor - extends CustomElementConstructor, - WithTagName { +export interface DecoratedElementConstructor extends CustomElementConstructor, WithTagName { prototype: DecoratedElement; /** * Transforms elements in input HTML from undecorated to stored state. diff --git a/ts/editor/destroyable.ts b/ts/editor/destroyable.ts index 60399d220..54dba71de 100644 --- a/ts/editor/destroyable.ts +++ b/ts/editor/destroyable.ts @@ -9,7 +9,7 @@ export function clearableArray(): (T & Destroyable)[] { const list: (T & Destroyable)[] = []; return new Proxy(list, { - get: function (target: (T & Destroyable)[], prop: string | symbol) { + get: function(target: (T & Destroyable)[], prop: string | symbol) { if (!(typeof prop === "symbol") && !isNaN(Number(prop)) && !target[prop]) { const item = {} as T & Destroyable; @@ -19,7 +19,7 @@ export function clearableArray(): (T & Destroyable)[] { }; target[prop] = new Proxy(item, { - get: function (target: T & Destroyable, prop: string | symbol) { + get: function(target: T & Destroyable, prop: string | symbol) { if (prop === "destroy") { return destroy; } diff --git a/ts/editor/icons.ts b/ts/editor/icons.ts index 018bb7071..73fcc7546 100644 --- a/ts/editor/icons.ts +++ b/ts/editor/icons.ts @@ -3,7 +3,6 @@ /// -export { default as incrementClozeIcon } from "../icons/contain-plus.svg"; export { default as alertIcon } from "@mdi/svg/svg/alert.svg"; export { default as chevronDown } from "@mdi/svg/svg/chevron-down.svg"; export { default as chevronUp } from "@mdi/svg/svg/chevron-up.svg"; @@ -11,3 +10,7 @@ export { default as plainTextIcon } from "@mdi/svg/svg/code-tags.svg"; export { default as clozeIcon } from "@mdi/svg/svg/contain.svg"; export { default as richTextIcon } from "@mdi/svg/svg/format-font.svg"; export { default as stickyIcon } from "@mdi/svg/svg/pin-outline.svg"; + +// This comment prevents disagreement between eslint-plugin-simple-sort and +// dprint about whether .. or @ should come first. +export { default as incrementClozeIcon } from "../icons/contain-plus.svg"; diff --git a/ts/editor/rich-text-input/normalizing-node-store.ts b/ts/editor/rich-text-input/normalizing-node-store.ts index 7a8b10923..90d11e74a 100644 --- a/ts/editor/rich-text-input/normalizing-node-store.ts +++ b/ts/editor/rich-text-input/normalizing-node-store.ts @@ -10,9 +10,11 @@ function normalizeFragment(fragment: DocumentFragment): void { fragment.normalize(); for (const decorated of decoratedElements) { - for (const element of fragment.querySelectorAll( - decorated.tagName, - ) as NodeListOf) { + for ( + const element of fragment.querySelectorAll( + decorated.tagName, + ) as NodeListOf + ) { element.undecorate(); } } diff --git a/ts/editor/rich-text-input/transform.ts b/ts/editor/rich-text-input/transform.ts index b71a4b888..bf3725546 100644 --- a/ts/editor/rich-text-input/transform.ts +++ b/ts/editor/rich-text-input/transform.ts @@ -1,11 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import { - fragmentToString, - nodeContainsInlineContent, - nodeIsElement, -} from "../../lib/dom"; +import { fragmentToString, nodeContainsInlineContent, nodeIsElement } from "../../lib/dom"; import { createDummyDoc } from "../../lib/parsing"; import { decoratedElements } from "../decorated-elements"; @@ -35,10 +31,10 @@ export function storedToFragment(storedHTML: string): DocumentFragment { function adjustOutputFragment(fragment: DocumentFragment): void { if ( - fragment.hasChildNodes() && - nodeIsElement(fragment.lastChild!) && - nodeContainsInlineContent(fragment) && - fragment.lastChild!.tagName === "BR" + fragment.hasChildNodes() + && nodeIsElement(fragment.lastChild!) + && nodeContainsInlineContent(fragment) + && fragment.lastChild!.tagName === "BR" ) { fragment.lastChild!.remove(); } diff --git a/ts/graphs/buttons.ts b/ts/graphs/buttons.ts index d0bb7bda2..9b545bb72 100644 --- a/ts/graphs/buttons.ts +++ b/ts/graphs/buttons.ts @@ -20,7 +20,7 @@ import { sum, } from "d3"; -import type { GraphBounds, GraphRange} from "./graph-helpers"; +import type { GraphBounds, GraphRange } from "./graph-helpers"; import { millisecondCutoffForRange, setDataAvailable } from "./graph-helpers"; import { hideTooltip, showTooltip } from "./tooltip"; diff --git a/ts/graphs/calendar.ts b/ts/graphs/calendar.ts index fbbb303ac..8b1c2592b 100644 --- a/ts/graphs/calendar.ts +++ b/ts/graphs/calendar.ts @@ -19,7 +19,7 @@ import { timeYear, } from "d3"; -import type { GraphBounds, SearchDispatch} from "./graph-helpers"; +import type { GraphBounds, SearchDispatch } from "./graph-helpers"; import { RevlogRange, setDataAvailable } from "./graph-helpers"; import { clickableClass } from "./graph-styles"; import { hideTooltip, showTooltip } from "./tooltip"; diff --git a/ts/graphs/histogram-graph.ts b/ts/graphs/histogram-graph.ts index bc5236c48..f05f5eb4e 100644 --- a/ts/graphs/histogram-graph.ts +++ b/ts/graphs/histogram-graph.ts @@ -9,7 +9,7 @@ import { localizedNumber } from "@tslib/i18n"; import type { Bin, ScaleLinear, ScaleSequential } from "d3"; import { area, axisBottom, axisLeft, axisRight, cumsum, curveBasis, max, pointer, scaleLinear, select } from "d3"; -import type { GraphBounds} from "./graph-helpers"; +import type { GraphBounds } from "./graph-helpers"; import { setDataAvailable } from "./graph-helpers"; import { clickableClass } from "./graph-styles"; import { hideTooltip, showTooltip } from "./tooltip"; diff --git a/ts/graphs/hours.ts b/ts/graphs/hours.ts index cde27bbe9..b0b418e31 100644 --- a/ts/graphs/hours.ts +++ b/ts/graphs/hours.ts @@ -22,7 +22,7 @@ import { select, } from "d3"; -import type { GraphBounds, GraphRange} from "./graph-helpers"; +import type { GraphBounds, GraphRange } from "./graph-helpers"; import { millisecondCutoffForRange, setDataAvailable } from "./graph-helpers"; import { oddTickClass } from "./graph-styles"; import { hideTooltip, showTooltip } from "./tooltip"; diff --git a/ts/graphs/reviews.ts b/ts/graphs/reviews.ts index cd65ecb07..f4e8657b0 100644 --- a/ts/graphs/reviews.ts +++ b/ts/graphs/reviews.ts @@ -9,8 +9,7 @@ import * as tr from "@tslib/ftl"; import { localizedNumber } from "@tslib/i18n"; import { Stats } from "@tslib/proto"; import { dayLabel, timeSpan } from "@tslib/time"; -import type { Bin , - ScaleSequential} from "d3"; +import type { Bin, ScaleSequential } from "d3"; import { area, axisBottom, @@ -32,7 +31,7 @@ import { sum, } from "d3"; -import type { GraphBounds,TableDatum } from "./graph-helpers"; +import type { GraphBounds, TableDatum } from "./graph-helpers"; import { GraphRange, setDataAvailable } from "./graph-helpers"; import { hideTooltip, showTooltip } from "./tooltip"; diff --git a/ts/graphs/tooltip.ts b/ts/graphs/tooltip.ts index ef54c7341..1f94a029b 100644 --- a/ts/graphs/tooltip.ts +++ b/ts/graphs/tooltip.ts @@ -1,7 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import type { DebouncedFunc} from "lodash-es"; +import type { DebouncedFunc } from "lodash-es"; import { throttle } from "lodash-es"; import Tooltip from "./Tooltip.svelte"; @@ -26,8 +26,7 @@ function showTooltipInner(msg: string, x: number, y: number): void { tooltip.$set({ html: msg, x, y, show: true }); } -export const showTooltip: DebouncedFunc<(msg: string, x: number, y: number) => void> = - throttle(showTooltipInner, 16); +export const showTooltip: DebouncedFunc<(msg: string, x: number, y: number) => void> = throttle(showTooltipInner, 16); export function hideTooltip(): void { const tooltip = getOrCreateTooltip(); diff --git a/ts/html-filter/element.ts b/ts/html-filter/element.ts index cd9cff72c..b3ee90753 100644 --- a/ts/html-filter/element.ts +++ b/ts/html-filter/element.ts @@ -3,11 +3,7 @@ import { isHTMLElement, isNightMode } from "./helpers"; import { removeNode as removeElement } from "./node"; -import { - filterStylingInternal, - filterStylingLightMode, - filterStylingNightMode, -} from "./styling"; +import { filterStylingInternal, filterStylingLightMode, filterStylingNightMode } from "./styling"; interface TagsAllowed { [tagName: string]: FilterMethod; @@ -32,13 +28,11 @@ function allowNone(element: Element): void { filterAttributes(() => false, element); } -const allow = - (attrs: string[]): FilterMethod => - (element: Element): void => - filterAttributes( - (attributeName: string) => attrs.includes(attributeName), - element, - ); +const allow = (attrs: string[]): FilterMethod => (element: Element): void => + filterAttributes( + (attributeName: string) => attrs.includes(attributeName), + element, + ); function unwrapElement(element: Element): void { element.replaceWith(...element.childNodes); @@ -93,19 +87,17 @@ const tagsAllowedExtended: TagsAllowed = { UL: allowNone, }; -const filterElementTagsAllowed = - (tagsAllowed: TagsAllowed) => - (element: Element): void => { - const tagName = element.tagName; +const filterElementTagsAllowed = (tagsAllowed: TagsAllowed) => (element: Element): void => { + const tagName = element.tagName; - if (Object.prototype.hasOwnProperty.call(tagsAllowed, tagName)) { - tagsAllowed[tagName](element); - } else if (element.innerHTML) { - unwrapElement(element); - } else { - removeElement(element); - } - }; + if (Object.prototype.hasOwnProperty.call(tagsAllowed, tagName)) { + tagsAllowed[tagName](element); + } else if (element.innerHTML) { + unwrapElement(element); + } else { + removeElement(element); + } +}; export const filterElementBasic = filterElementTagsAllowed(tagsAllowedBasic); export const filterElementExtended = filterElementTagsAllowed(tagsAllowedExtended); diff --git a/ts/html-filter/index.test.ts b/ts/html-filter/index.test.ts index 98a5403d8..12d179d39 100644 --- a/ts/html-filter/index.test.ts +++ b/ts/html-filter/index.test.ts @@ -13,35 +13,35 @@ describe("filterHTML", () => { // font-size is filtered, weight is not expect( filterHTML( - '
', + "
", true, true, ), - ).toBe('
'); + ).toBe("
"); }); test("background color", () => { // transparent is stripped, other colors are not expect( filterHTML( - '', + "", false, true, ), - ).toBe(''); + ).toBe(""); expect( - filterHTML('', false, true), - ).toBe(''); + filterHTML("", false, true), + ).toBe(""); // except if extended mode is off expect( - filterHTML('x', false, false), + filterHTML("x", false, false), ).toBe("x"); // no filtering on internal paste expect( filterHTML( - '', + "", true, true, ), - ).toBe(''); + ).toBe(""); }); }); diff --git a/ts/html-filter/index.ts b/ts/html-filter/index.ts index 2d1a3152c..fee6e607d 100644 --- a/ts/html-filter/index.ts +++ b/ts/html-filter/index.ts @@ -1,11 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import { - filterElementBasic, - filterElementExtended, - filterElementInternal, -} from "./element"; +import { filterElementBasic, filterElementExtended, filterElementInternal } from "./element"; import { filterNode } from "./node"; enum FilterMode { @@ -31,8 +27,7 @@ function trim(value: string): string { } const outputHTMLProcessors: Record string> = { - [FilterMode.Basic]: (outputHTML: string): string => - trim(collapseWhitespace(outputHTML)), + [FilterMode.Basic]: (outputHTML: string): string => trim(collapseWhitespace(outputHTML)), [FilterMode.Extended]: trim, [FilterMode.Internal]: trim, }; diff --git a/ts/html-filter/node.ts b/ts/html-filter/node.ts index 989bc028c..e2a0d0afb 100644 --- a/ts/html-filter/node.ts +++ b/ts/html-filter/node.ts @@ -14,24 +14,22 @@ function iterateElement( } } -export const filterNode = - (elementFilter: (element: Element) => void) => - (node: Node): void => { - switch (node.nodeType) { - case Node.COMMENT_NODE: - removeNode(node); - break; +export const filterNode = (elementFilter: (element: Element) => void) => (node: Node): void => { + switch (node.nodeType) { + case Node.COMMENT_NODE: + removeNode(node); + break; - case Node.DOCUMENT_FRAGMENT_NODE: - iterateElement(filterNode(elementFilter), node as DocumentFragment); - break; + case Node.DOCUMENT_FRAGMENT_NODE: + iterateElement(filterNode(elementFilter), node as DocumentFragment); + break; - case Node.ELEMENT_NODE: - iterateElement(filterNode(elementFilter), node as Element); - elementFilter(node as Element); - break; + case Node.ELEMENT_NODE: + iterateElement(filterNode(elementFilter), node as Element); + elementFilter(node as Element); + break; - default: + default: // do nothing - } - }; + } +}; diff --git a/ts/lib/dom.ts b/ts/lib/dom.ts index 60b79689a..c3925ef8c 100644 --- a/ts/lib/dom.ts +++ b/ts/lib/dom.ts @@ -99,8 +99,8 @@ export function elementIsEmpty(element: Element): boolean { export function nodeContainsInlineContent(node: Node): boolean { for (const child of node.childNodes) { if ( - (nodeIsElement(child) && elementIsBlock(child)) || - !nodeContainsInlineContent(child) + (nodeIsElement(child) && elementIsBlock(child)) + || !nodeContainsInlineContent(child) ) { return false; } @@ -122,8 +122,7 @@ export function fragmentToString(fragment: DocumentFragment): string { } const getAnchorParent = - (predicate: (element: Element) => element is T) => - (root: Node): T | null => { + (predicate: (element: Element) => element is T) => (root: Node): T | null => { const anchor = getSelection(root)?.anchorNode; if (!anchor) { @@ -143,12 +142,10 @@ const getAnchorParent = const isListItem = (element: Element): element is HTMLLIElement => window.getComputedStyle(element).display === "list-item"; -const isParagraph = (element: Element): element is HTMLParamElement => - element.tagName === "P"; +const isParagraph = (element: Element): element is HTMLParamElement => element.tagName === "P"; const isBlockElement = ( element: Element, -): element is HTMLLIElement & HTMLParamElement => - isListItem(element) || isParagraph(element); +): element is HTMLLIElement & HTMLParamElement => isListItem(element) || isParagraph(element); export const getListItem = getAnchorParent(isListItem); export const getParagraph = getAnchorParent(isParagraph); diff --git a/ts/lib/events.ts b/ts/lib/events.ts index bd6bb4d87..91cf4abaf 100644 --- a/ts/lib/events.ts +++ b/ts/lib/events.ts @@ -1,24 +1,15 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -export type EventTargetToMap = A extends HTMLElement - ? HTMLElementEventMap - : A extends Document - ? DocumentEventMap - : A extends Window - ? WindowEventMap - : A extends FileReader - ? FileReaderEventMap - : A extends Element - ? ElementEventMap - : A extends Animation - ? AnimationEventMap - : A extends EventSource - ? EventSourceEventMap - : A extends AbortSignal - ? AbortSignalEventMap - : A extends AbstractWorker - ? AbstractWorkerEventMap +export type EventTargetToMap = A extends HTMLElement ? HTMLElementEventMap + : A extends Document ? DocumentEventMap + : A extends Window ? WindowEventMap + : A extends FileReader ? FileReaderEventMap + : A extends Element ? ElementEventMap + : A extends Animation ? AnimationEventMap + : A extends EventSource ? EventSourceEventMap + : A extends AbortSignal ? AbortSignalEventMap + : A extends AbstractWorker ? AbstractWorkerEventMap : never; export function on>( @@ -28,8 +19,7 @@ export function on>( options?: AddEventListenerOptions, ): () => void { target.addEventListener(eventType, handler as EventListener, options); - return () => - target.removeEventListener(eventType, handler as EventListener, options); + return () => target.removeEventListener(eventType, handler as EventListener, options); } export function preventDefault(event: Event): void { diff --git a/ts/lib/i18n/utils.ts b/ts/lib/i18n/utils.ts index f37f0e605..b6f853183 100644 --- a/ts/lib/i18n/utils.ts +++ b/ts/lib/i18n/utils.ts @@ -12,18 +12,18 @@ import type { ModuleName } from "./modules"; export function supportsVerticalText(): boolean { const firstLang = firstLanguage(); return ( - firstLang.startsWith("ja") || - firstLang.startsWith("zh") || - firstLang.startsWith("ko") + firstLang.startsWith("ja") + || firstLang.startsWith("zh") + || firstLang.startsWith("ko") ); } export function direction(): string { const firstLang = firstLanguage(); if ( - firstLang.startsWith("ar") || - firstLang.startsWith("he") || - firstLang.startsWith("fa") + firstLang.startsWith("ar") + || firstLang.startsWith("he") + || firstLang.startsWith("fa") ) { return "rtl"; } else { diff --git a/ts/lib/platform.ts b/ts/lib/platform.ts index 9122146aa..057ceeeb8 100644 --- a/ts/lib/platform.ts +++ b/ts/lib/platform.ts @@ -3,9 +3,9 @@ export function isApplePlatform(): boolean { // avoid deprecation warning - const platform = window.navigator["platform" + ""] + const platform = window.navigator["platform" + ""]; return ( - platform.startsWith("Mac") || - platform.startsWith("iP") + platform.startsWith("Mac") + || platform.startsWith("iP") ); } diff --git a/ts/lib/runtime-require.ts b/ts/lib/runtime-require.ts index 00ef9a018..6a973d436 100644 --- a/ts/lib/runtime-require.ts +++ b/ts/lib/runtime-require.ts @@ -52,17 +52,17 @@ export function registerPackage< >(name: T, entries: U, deprecation?: PackageDeprecation): void { const pack = deprecation ? new Proxy(entries, { - set: prohibit, - defineProperty: prohibit, - deleteProperty: prohibit, - get: (target, name: string) => { - if (name in deprecation) { - console.log(`anki: ${name} is deprecated: ${deprecation[name]}`); - } + set: prohibit, + defineProperty: prohibit, + deleteProperty: prohibit, + get: (target, name: string) => { + if (name in deprecation) { + console.log(`anki: ${name} is deprecated: ${deprecation[name]}`); + } - return target[name]; - }, - }) + return target[name]; + }, + }) : entries; registerPackageRaw(name, pack); diff --git a/ts/lib/shortcuts.ts b/ts/lib/shortcuts.ts index 6535edeb8..02dbfe9cf 100644 --- a/ts/lib/shortcuts.ts +++ b/ts/lib/shortcuts.ts @@ -3,12 +3,7 @@ import { on } from "./events"; import type { Modifier } from "./keys"; -import { - checkIfModifierKey, - checkModifiers, - keyToPlatformString, - modifiersToPlatformString, -} from "./keys"; +import { checkIfModifierKey, checkModifiers, keyToPlatformString, modifiersToPlatformString } from "./keys"; import { registerPackage } from "./runtime-require"; const keyCodeLookup = { @@ -65,7 +60,7 @@ export function getPlatformString(keyCombinationString: string): string { function checkKey(event: KeyboardEvent, key: number): boolean { // avoid deprecation warning - const which = event["which" + ""] + const which = event["which" + ""]; return which === key; } @@ -101,8 +96,8 @@ const check = (keyCode: number, requiredModifiers: Modifier[], optionalModifiers: Modifier[]) => (event: KeyboardEvent): boolean => { return ( - checkKey(event, keyCode) && - checkModifiers(requiredModifiers, optionalModifiers)(event) + checkKey(event, keyCode) + && checkModifiers(requiredModifiers, optionalModifiers)(event) ); }; @@ -166,8 +161,7 @@ export function registerShortcut( event = defaultRegisterShortcutRestParams.event, } = restParams; - const [check, ...restChecks] = - splitKeyCombinationString(keyCombinationString).map(keyCombinationToCheck); + const [check, ...restChecks] = splitKeyCombinationString(keyCombinationString).map(keyCombinationToCheck); function handler(event: KeyboardEvent): void { if (check(event)) { diff --git a/ts/lib/uuid.ts b/ts/lib/uuid.ts index fc4052758..8598261b0 100644 --- a/ts/lib/uuid.ts +++ b/ts/lib/uuid.ts @@ -9,9 +9,8 @@ export function randomUUID(): string { return value.replace(/[018]/g, (character: string): string => ( - Number(character) ^ - (crypto.getRandomValues(new Uint8Array(1))[0] & - (15 >> (Number(character) / 4))) - ).toString(16), - ); + Number(character) + ^ (crypto.getRandomValues(new Uint8Array(1))[0] + & (15 >> (Number(character) / 4))) + ).toString(16)); } diff --git a/ts/lib/wrap.ts b/ts/lib/wrap.ts index 8096df1d2..39b10e9d1 100644 --- a/ts/lib/wrap.ts +++ b/ts/lib/wrap.ts @@ -45,8 +45,8 @@ export function wrapInternal( } if ( - wasCollapsed && - /* ugly solution: treat differently than other wraps */ !front.includes( + wasCollapsed + /* ugly solution: treat differently than other wraps */ && !front.includes( " { } function clearPreloadedCss(): void { - [...document.head.getElementsByClassName(preloadCssClassName)].forEach((css) => - css.remove(), - ); + [...document.head.getElementsByClassName(preloadCssClassName)].forEach((css) => css.remove()); } function extractExternalCssElements(fragment: DocumentFragment): CssElementType[] { - return ( + return ( [...fragment.querySelectorAll("style, link")].filter( (css) => - (css instanceof HTMLStyleElement && - css.innerHTML.includes("@import")) || - (css instanceof HTMLLinkElement && css.rel === "stylesheet"), + (css instanceof HTMLStyleElement + && css.innerHTML.includes("@import")) + || (css instanceof HTMLLinkElement && css.rel === "stylesheet"), ) ); } diff --git a/ts/reviewer/images.ts b/ts/reviewer/images.ts index 38eb983b8..a30c354fe 100644 --- a/ts/reviewer/images.ts +++ b/ts/reviewer/images.ts @@ -19,9 +19,9 @@ function imageLoaded(img: HTMLImageElement): Promise { return img.complete ? Promise.resolve() : new Promise((resolve) => { - img.addEventListener("load", () => resolve()); - img.addEventListener("error", () => resolve()); - }); + img.addEventListener("load", () => resolve()); + img.addEventListener("error", () => resolve()); + }); } function clearPreloadLinks(): void { diff --git a/ts/sveltelib/async.ts b/ts/sveltelib/async.ts index 5cd149087..42d203209 100644 --- a/ts/sveltelib/async.ts +++ b/ts/sveltelib/async.ts @@ -1,7 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // 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 { readable } from "svelte/store"; interface AsyncData { diff --git a/ts/sveltelib/asyncReactive.ts b/ts/sveltelib/asyncReactive.ts index 500d4d18f..c1e7a9821 100644 --- a/ts/sveltelib/asyncReactive.ts +++ b/ts/sveltelib/asyncReactive.ts @@ -31,7 +31,7 @@ function useAsyncReactive( const error = derived( promise, - ($promise, set: (error: E | null) => void): (() => void) => { + ($promise, set: (error: E | null) => void): () => void => { $promise?.catch((error: E) => set(error)); return (): void => set(null); }, @@ -40,7 +40,7 @@ function useAsyncReactive( const loading = derived( promise, - ($promise, set: (value: boolean) => void): (() => void) => { + ($promise, set: (value: boolean) => void): () => void => { $promise?.finally(() => set(false)); return (): void => set(true); }, diff --git a/ts/sveltelib/dynamicComponent.ts b/ts/sveltelib/dynamicComponent.ts index 25a267b5c..120366879 100644 --- a/ts/sveltelib/dynamicComponent.ts +++ b/ts/sveltelib/dynamicComponent.ts @@ -9,13 +9,12 @@ export interface DynamicSvelteComponent< [k: string]: unknown; } -export const dynamicComponent = - < - Comp extends typeof SvelteComponentDev, - DefaultProps = NonNullable[0]["props"]>, - >( - component: Comp, - ) => - (props: Props): DynamicSvelteComponent & Props => { - return { component, ...props }; - }; +export const dynamicComponent = < + Comp extends typeof SvelteComponentDev, + DefaultProps = NonNullable[0]["props"]>, +>( + component: Comp, +) => +(props: Props): DynamicSvelteComponent & Props => { + return { component, ...props }; +}; diff --git a/ts/sveltelib/position/position-floating.ts b/ts/sveltelib/position/position-floating.ts index 100b4bb04..e834cf724 100644 --- a/ts/sveltelib/position/position-floating.ts +++ b/ts/sveltelib/position/position-floating.ts @@ -1,22 +1,8 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import type { - ComputePositionConfig, - FloatingElement, - Middleware, - Placement, - ReferenceElement, -} from "@floating-ui/dom"; -import { - arrow, - computePosition, - flip, - hide, - inline, - offset, - shift, -} from "@floating-ui/dom"; +import type { ComputePositionConfig, FloatingElement, Middleware, Placement, ReferenceElement } from "@floating-ui/dom"; +import { arrow, computePosition, flip, hide, inline, offset, shift } from "@floating-ui/dom"; import type { PositionAlgorithm } from "./position-algorithm"; @@ -41,7 +27,7 @@ function positionFloating({ hideIfReferenceHidden, hideCallback, }: PositionFloatingArgs): PositionAlgorithm { - return async function ( + return async function( reference: ReferenceElement, floating: FloatingElement, ): Promise { diff --git a/ts/sveltelib/position/position-overlay.ts b/ts/sveltelib/position/position-overlay.ts index 7f3091926..8660cbb18 100644 --- a/ts/sveltelib/position/position-overlay.ts +++ b/ts/sveltelib/position/position-overlay.ts @@ -1,12 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import type { - ComputePositionConfig, - FloatingElement, - Middleware, - ReferenceElement, -} from "@floating-ui/dom"; +import type { ComputePositionConfig, FloatingElement, Middleware, ReferenceElement } from "@floating-ui/dom"; import { computePosition, inline, offset } from "@floating-ui/dom"; import type { PositionAlgorithm } from "./position-algorithm"; @@ -22,7 +17,7 @@ function positionOverlay({ inline: inlineArg, hideCallback, }: PositionOverlayArgs): PositionAlgorithm { - return async function ( + return async function( reference: ReferenceElement, floating: FloatingElement, ): Promise { diff --git a/ts/sveltelib/preferences.ts b/ts/sveltelib/preferences.ts index 40882a7d0..dabf9a119 100644 --- a/ts/sveltelib/preferences.ts +++ b/ts/sveltelib/preferences.ts @@ -1,7 +1,7 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import type { Writable} from "svelte/store"; +import type { Writable } from "svelte/store"; import { get, writable } from "svelte/store"; export interface CustomStore extends Writable { @@ -61,9 +61,11 @@ function preparePreferences( setter(constructPreferences()); } - for (const [key, value] of Object.entries( - toObject(Preferences, { defaults: true }), - )) { + for ( + const [key, value] of Object.entries( + toObject(Preferences, { defaults: true }), + ) + ) { preferences[key] = createPreference(value, savePreferences); }