diff --git a/ui/@types/lichess/index.d.ts b/ui/@types/lichess/index.d.ts index 3eabd247fb..67322e7ff3 100644 --- a/ui/@types/lichess/index.d.ts +++ b/ui/@types/lichess/index.d.ts @@ -1,11 +1,9 @@ interface Lichess { load: Promise; // window.onload promise - // components info: any; requestIdleCallback(f: () => void): void; hasTouchEvents: boolean; sri: string; - isCol1(): boolean; storage: LichessStorageHelper; tempStorage: LichessStorageHelper; once(key: string, mod?: 'always'): boolean; diff --git a/ui/analyse/src/treeView/treeView.ts b/ui/analyse/src/treeView/treeView.ts index 495dbc1ba7..e6cf8ebfc7 100644 --- a/ui/analyse/src/treeView/treeView.ts +++ b/ui/analyse/src/treeView/treeView.ts @@ -12,6 +12,7 @@ import column from './columnView'; import inline from './inlineView'; import { empty, defined } from 'common'; import throttle from 'common/throttle'; +import isCol1 from 'common/isCol1'; import { storedProp, StoredProp } from 'common/storage'; export interface Ctx { @@ -68,7 +69,7 @@ export function ctrl(initialValue: TreeViewKey = 'column'): TreeView { // entry point, dispatching to selected view export function render(ctrl: AnalyseCtrl, concealOf?: ConcealOf): VNode { - return (ctrl.treeView.inline() || window.lichess.isCol1()) ? inline(ctrl) : column(ctrl, concealOf); + return (ctrl.treeView.inline() || isCol1()) ? inline(ctrl) : column(ctrl, concealOf); } export function nodeClasses(ctx: Ctx, path: Tree.Path): NodeClasses { diff --git a/ui/site/src/component/is-col1.ts b/ui/common/src/isCol1.ts similarity index 93% rename from ui/site/src/component/is-col1.ts rename to ui/common/src/isCol1.ts index 0608b5a336..9ce28bb4af 100644 --- a/ui/site/src/component/is-col1.ts +++ b/ui/common/src/isCol1.ts @@ -1,6 +1,6 @@ let cache: 'init' | 'rec' | boolean = 'init'; -export function isCol1() { +export default function(): boolean { if (typeof cache == 'string') { if (cache == 'init') { // only once window.addEventListener('resize', () => { diff --git a/ui/common/tsconfig.json b/ui/common/tsconfig.json index f6a53d4f13..4bc4b6d574 100644 --- a/ui/common/tsconfig.json +++ b/ui/common/tsconfig.json @@ -3,6 +3,6 @@ "include": ["src/*.ts"], "exclude": [], "compilerOptions": { - "outDir": "./", + "outDir": "./" } } diff --git a/ui/round/src/view/replay.ts b/ui/round/src/view/replay.ts index b9fe08b054..17acf8e3fb 100644 --- a/ui/round/src/view/replay.ts +++ b/ui/round/src/view/replay.ts @@ -2,6 +2,7 @@ import { h } from 'snabbdom' import { VNode } from 'snabbdom/vnode' import * as round from '../round'; import throttle from 'common/throttle'; +import isCol1 from 'common/isCol1'; import * as game from 'game'; import * as status from 'game/status'; import { game as gameRoute } from 'game/router'; @@ -20,13 +21,13 @@ const autoScroll = throttle(100, (movesEl: HTMLElement, ctrl: RoundController) = else if (ctrl.ply == round.lastPly(ctrl.data)) st = scrollMax; else { const plyEl = movesEl.querySelector('.' + activeClass) as HTMLElement | undefined; - if (plyEl) st = window.lichess.isCol1() ? + if (plyEl) st = isCol1() ? plyEl.offsetLeft - movesEl.offsetWidth / 2 + plyEl.offsetWidth / 2 : plyEl.offsetTop - movesEl.offsetHeight / 2 + plyEl.offsetHeight / 2; } if (typeof st == 'number') { if (st == scrollMax) movesEl.scrollLeft = movesEl.scrollTop = st; - else if (window.lichess.isCol1()) movesEl.scrollLeft = st; + else if (isCol1()) movesEl.scrollLeft = st; else movesEl.scrollTop = st; } }) @@ -185,7 +186,6 @@ function col1Button(ctrl: RoundController, dir: number, icon: string, disabled: export function render(ctrl: RoundController): VNode | undefined { const d = ctrl.data, - col1 = window.lichess.isCol1(), moves = ctrl.replayEnabledByPref() && h(movesTag, { hook: util.onInsert(el => { el.addEventListener('mousedown', e => { @@ -208,7 +208,7 @@ export function render(ctrl: RoundController): VNode | undefined { return ctrl.nvui ? undefined : h(rmovesTag, [ renderButtons(ctrl), initMessage(d, ctrl.trans.noarg) || (moves ? ( - col1 ? h('div.col1-moves', [ + isCol1() ? h('div.col1-moves', [ col1Button(ctrl, -1, 'Y', ctrl.ply == round.firstPly(d)), moves, col1Button(ctrl, 1, 'X', ctrl.ply == round.lastPly(d)) diff --git a/ui/site/src/site.lichess.globals.ts b/ui/site/src/site.lichess.globals.ts index 9d0be1f9f6..b43ab15f84 100644 --- a/ui/site/src/site.lichess.globals.ts +++ b/ui/site/src/site.lichess.globals.ts @@ -5,7 +5,6 @@ import once from './component/once'; import hasTouchEvents from './component/touchEvents'; import spinnerHtml from './component/spinner'; import sri from './component/sri'; -import { isCol1 } from "./component/is-col1"; import { storage, tempStorage } from "./component/storage"; import powertip from "./component/powertip"; import { assetUrl, soundUrl, loadCss, loadCssPath, jsModule, loadScript, hopscotch, slider } from "./component/assets"; @@ -30,7 +29,6 @@ export default function() { l.requestIdleCallback = requestIdleCallback; l.hasTouchEvents = hasTouchEvents; l.sri = sri; - l.isCol1 = isCol1; l.storage = storage; l.tempStorage = tempStorage; l.once = once;