Skip to content

Commit

Permalink
eslint 9 (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj authored Sep 17, 2024
1 parent f761780 commit 50ca9a2
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 303 deletions.
24 changes: 0 additions & 24 deletions .eslintrc.cjs

This file was deleted.

7 changes: 7 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import antfu from '@antfu/eslint-config'

export default antfu({
formatters: {
html: true,
},
})
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"dev": "parcel page/index.html",
"lint": "pnpm run eslint && pnpm run stylelint",
"lint:fix": "pnpm run eslint:fix && pnpm run stylelint:fix",
"eslint": "eslint --ext .ts,.html page tests",
"eslint:fix": "eslint --fix --ext .ts,.html page tests",
"eslint": "eslint page tests",
"eslint:fix": "eslint --fix page tests",
"stylelint": "stylelint page/*.scss",
"stylelint:fix": "stylelint --fix page/*.scss",
"check": "tsc --noEmit",
Expand All @@ -18,16 +18,15 @@
},
"license": "GPL-3.0-or-later",
"devDependencies": {
"@antfu/eslint-config": "^3.6.2",
"@parcel/transformer-sass": "^2.12.0",
"@playwright/test": "^1.42.1",
"@types/node": "^20.11.24",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"eslint": "^8.57.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-html": "^8.0.0",
"@playwright/test": "^1.47.1",
"@types/node": "^22.5.5",
"eslint": "^9.10.0",
"eslint-plugin-format": "^0.1.2",
"parcel": "^2.12.0",
"stylelint": "^16.2.1",
"stylelint-config-standard-scss": "^13.0.0",
"typescript": "^5.3.3"
"stylelint": "^16.9.0",
"stylelint-config-standard-scss": "^13.1.0",
"typescript": "^5.6.2"
}
}
102 changes: 55 additions & 47 deletions page/api.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import { fcitx } from './distribution'
import { setStyle } from './customize' // eslint-disable-line perfectionist/sort-imports
import { fcitxLog } from './log'
import {
panel,
loadPlugins,
pluginManager,
unloadPlugins,
} from './plugin'
import {
fetchComplete,
getScrollState,
recalculateScroll,
scrollKeyAction,
setScrollEnd,
setScrollState,
} from './scroll'
import {
auxDown,
auxUp,
hoverables,
panel,
preedit,
auxUp,
auxDown
} from './selector'
import {
div,
setActions,
setAccentColor,
setTheme,
} from './theme'
import {
answerActions,
hideContextmenu,
div,
getHoverBehavior,
getPagingButtonsStyle,
hideContextmenu,
resetMouseMoveState,
resize
resize,
setActions,
} from './ux'
import {
setTheme,
setAccentColor
} from './theme'
import { setStyle } from './customize'
import { fcitxLog } from './log'
import {
getScrollState,
setScrollState,
setScrollEnd,
recalculateScroll,
scrollKeyAction,
fetchComplete
} from './scroll'
import {
pluginManager,
loadPlugins,
unloadPlugins
} from './plugin'

function escapeWS (s: string) {
function escapeWS(s: string) {
// XXX:   is broken in Safari
return s.replaceAll(' ', '&nbsp;').replaceAll('\n', '<br>').replaceAll('\t', '&emsp;')
}

function divider (paging: boolean = false) {
function divider(paging: boolean = false) {
const e = div('fcitx-divider')
// Is this divider between candidates and paging buttons?
if (paging) {
Expand All @@ -54,7 +54,7 @@ function divider (paging: boolean = false) {
return e
}

function setLayout (layout : 0 | 1) {
function setLayout(layout: 0 | 1) {
switch (layout) {
case 0:
hoverables.classList.remove('fcitx-vertical')
Expand All @@ -66,18 +66,19 @@ function setLayout (layout : 0 | 1) {
}
}

function setWritingMode (mode: 0 | 1 | 2) {
function setWritingMode(mode: 0 | 1 | 2) {
const classes = ['fcitx-horizontal-tb', 'fcitx-vertical-rl', 'fcitx-vertical-lr']
for (let i = 0; i < classes.length; ++i) {
if (mode === i) {
panel.classList.add(classes[i])
} else {
}
else {
panel.classList.remove(classes[i])
}
}
}

function moveHighlight (from: Element | null, to: Element | null) {
function moveHighlight(from: Element | null, to: Element | null) {
from?.classList.remove('fcitx-highlighted')
to?.classList.add('fcitx-highlighted')
// In vertical or scroll mode, there are multiple marks,
Expand All @@ -102,21 +103,23 @@ const caretRight = common.replace('{}', '0 0 192 512').replace('{}', 'M0 384.662
const arrowBack = common.replace('{}', '0 0 24 24').replace('{}', 'M16.62 2.99a1.25 1.25 0 0 0-1.77 0L6.54 11.3a.996.996 0 0 0 0 1.41l8.31 8.31c.49.49 1.28.49 1.77 0s.49-1.28 0-1.77L9.38 12l7.25-7.25c.48-.48.48-1.28-.01-1.76z')
const arrowForward = common.replace('{}', '0 0 24 24').replace('{}', 'M7.38 21.01c.49.49 1.28.49 1.77 0l8.31-8.31a.996.996 0 0 0 0-1.41L9.15 2.98c-.49-.49-1.28-.49-1.77 0s-.49 1.28 0 1.77L14.62 12l-7.25 7.25c-.48.48-.48 1.28.01 1.76z')

function setCandidates (cands: Candidate[], highlighted: number, markText: string, pageable: boolean, hasPrev: boolean, hasNext: boolean, scrollState: SCROLL_STATE, scrollStart: boolean, scrollEnd: boolean) {
function setCandidates(cands: Candidate[], highlighted: number, markText: string, pageable: boolean, hasPrev: boolean, hasNext: boolean, scrollState: SCROLL_STATE, scrollStart: boolean, scrollEnd: boolean) {
resetMouseMoveState()
hideContextmenu()
setScrollState(scrollState)
// Clear existing candidates when scroll continues.
if (scrollState !== 2 || scrollStart) {
hoverables.innerHTML = ''
hoverables.scrollTop = 0 // Otherwise last scroll position will be kept.
} else {
}
else {
fetchComplete()
}
if (scrollState === 2) {
hoverables.classList.add('fcitx-horizontal-scroll')
setScrollEnd(scrollEnd)
} else {
}
else {
hoverables.classList.remove('fcitx-horizontal-scroll')
}
for (let i = 0; i < cands.length; ++i) {
Expand All @@ -138,7 +141,8 @@ function setCandidates (cands: Candidate[], highlighted: number, markText: strin
const mark = div('fcitx-mark')
if (markText === '') {
mark.classList.add('fcitx-no-text')
} else {
}
else {
mark.innerHTML = markText
}
candidateInner.append(mark)
Expand Down Expand Up @@ -180,7 +184,8 @@ function setCandidates (cands: Candidate[], highlighted: number, markText: strin
const paging = div('fcitx-paging', 'fcitx-scroll', 'fcitx-hoverable')
paging.append(expand)
hoverables.append(paging)
} else if (scrollState === 0 && pageable) {
}
else if (scrollState === 0 && pageable) {
const isArrow = getPagingButtonsStyle() === 'Arrow'
hoverables.append(divider(true))

Expand All @@ -203,13 +208,15 @@ function setCandidates (cands: Candidate[], highlighted: number, markText: strin
const paging = div('fcitx-paging')
if (isArrow) {
paging.classList.add('fcitx-arrow')
} else {
}
else {
paging.classList.add('fcitx-triangle')
}
paging.appendChild(prev)
paging.appendChild(next)
hoverables.appendChild(paging)
} else if (scrollState === 2) {
}
else if (scrollState === 2) {
window.requestAnimationFrame(() => {
recalculateScroll(scrollStart)
})
Expand All @@ -226,23 +233,24 @@ function setCandidates (cands: Candidate[], highlighted: number, markText: strin
}
}

function updateElement (element: Element, innerHTML: string) {
function updateElement(element: Element, innerHTML: string) {
if (innerHTML === '') {
element.classList.add('fcitx-hidden')
} else {
}
else {
element.innerHTML = innerHTML
element.classList.remove('fcitx-hidden')
}
}

function updateInputPanel (preeditHTML: string, auxUpHTML: string, auxDownHTML: string) {
function updateInputPanel(preeditHTML: string, auxUpHTML: string, auxDownHTML: string) {
hideContextmenu()
updateElement(preedit, preeditHTML)
updateElement(auxUp, auxUpHTML)
updateElement(auxDown, auxDownHTML)
}

function copyHTML () {
function copyHTML() {
const html = document.documentElement.outerHTML
fcitx._copyHTML(html)
}
Expand All @@ -256,7 +264,7 @@ hoverables.addEventListener('mouseleave', () => {
}
})

hoverables.addEventListener('wheel', e => {
hoverables.addEventListener('wheel', (e) => {
if (getScrollState() === 2) {
return
}
Expand All @@ -277,15 +285,15 @@ fcitx.scrollKeyAction = scrollKeyAction
fcitx.answerActions = answerActions

Object.defineProperty(fcitx, 'pluginManager', {
value: pluginManager
value: pluginManager,
})

Object.defineProperty(fcitx, 'loadPlugins', {
value: loadPlugins
value: loadPlugins,
})

Object.defineProperty(fcitx, 'unloadPlugins', {
value: unloadPlugins
value: unloadPlugins,
})

fcitx.fcitxLog = fcitxLog
Expand Down
Loading

0 comments on commit 50ca9a2

Please sign in to comment.