Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
allConfig: js.configs.all
})
// npx @eslint/migrate-config .eslintrc.json
export default [
{
ignores: ['node_modules/**/*', '**/CHANGELOG.md', '**/package-lock.json', 'dist/**/*', 'build/**/*', '**/coverage'],
ignores: ['node_modules/**/*', '**/CHANGELOG.md', '**/package-lock.json', 'dist/**/*', 'build/**/*', '**/coverage']
},
...compat.extends('plugin:react/recommended', 'prettier'),
{
plugins: {
react,
'@typescript-eslint': typescriptEslint,
'react-hooks': fixupPluginRules(reactHooks),
'react-hooks': fixupPluginRules(reactHooks)
},

languageOptions: {
globals: {
...globals.browser,
...globals.browser
},

parser: tsParser,
Expand All @@ -43,15 +43,15 @@ export default [

parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
jsx: true
}
}
},

settings: {
react: {
version: 'detect',
},
version: 'detect'
}
},

rules: {
Expand Down Expand Up @@ -87,8 +87,8 @@ export default [
'no-inner-declarations': 'off',
'no-unused-expressions': 'off',
'no-unused-vars': 'off',
'no-plusplus': 'off',
},
'no-plusplus': 'off'
}
},
...storybook.configs['flat/recommended'],
...storybook.configs['flat/recommended']
]
6 changes: 3 additions & 3 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module.exports = {
testEnvironment: 'jsdom',
collectCoverage: true,
transform: {
'^.+\\.(t|j)sx?$': 'babel-jest',
'^.+\\.(t|j)sx?$': 'babel-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
moduleNameMapper: {
'\\.(css|less|scss)$': '<rootDir>/jest/styleMock.js',
'^@\\/(.*)$': '<rootDir>/src/$1',
'^@\\/(.*)$': '<rootDir>/src/$1'
},
testPathIgnorePatterns: ['/tests/e2e/'],
setupFilesAfterEnv: ['<rootDir>/jest/setupTests.js'],
setupFilesAfterEnv: ['<rootDir>/jest/setupTests.js']
}
12 changes: 6 additions & 6 deletions scripts/depcheck.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const buildScriptDeps = () => {
const depNames = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {}),
...Object.keys(pkg.optionalDependencies || {}),
...Object.keys(pkg.optionalDependencies || {})
]

for (const name of depNames) {
Expand Down Expand Up @@ -112,7 +112,7 @@ const buildConfigDeps = () => {
const depNames = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {}),
...Object.keys(pkg.optionalDependencies || {}),
...Object.keys(pkg.optionalDependencies || {})
]

const files = []
Expand Down Expand Up @@ -192,7 +192,7 @@ const report = await new Promise((resolve, reject) => {
'storybook-static',
'coverage',
'playwright-report',
'test-results',
'test-results'
],
// Avoid the ttypescript special (it reads tsconfig.json as strict JSON and can fail on JSONC).
specials: [
Expand All @@ -203,8 +203,8 @@ const report = await new Promise((resolve, reject) => {
depcheck.special.webpack,
depcheck.special.husky,
depcheck.special.prettier,
depcheck.special.commitizen,
],
depcheck.special.commitizen
]
},
(unused) => resolve(unused)
)
Expand All @@ -221,7 +221,7 @@ const ignoreMissingPrefixes = [
'@assets/',
'@app-hooks/',
'@container/',
'@theme/',
'@theme/'
]

const pickArray = (key) => {
Expand Down
30 changes: 15 additions & 15 deletions scripts/optimize-media.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ const MP4_AUDIO_BITRATE = process.env.MP4_AUDIO_BITRATE || '128k'
const MIN_SAVINGS_PCT = Number(process.env.MEDIA_MIN_SAVINGS_PCT || '5')
const SKIP_SMALL_KB = Number(process.env.MEDIA_SKIP_SMALL_KB || '256')

function bytesToMiB(bytes) {
function bytesToMiB (bytes) {
return (bytes / 1024 / 1024).toFixed(2)
}

function runFfmpeg(args) {
function runFfmpeg (args) {
const result = spawnSync('ffmpeg', args, {
stdio: 'inherit',
windowsHide: true,
windowsHide: true
})
if (result.error) {
throw result.error
Expand All @@ -38,7 +38,7 @@ function runFfmpeg(args) {
}
}

function isFileExists(filePath) {
function isFileExists (filePath) {
try {
fsSync.accessSync(filePath)
return true
Expand All @@ -47,29 +47,29 @@ function isFileExists(filePath) {
}
}

async function ensureDir(dirPath) {
async function ensureDir (dirPath) {
await fs.mkdir(dirPath, { recursive: true })
}

async function cleanDir(dirPath) {
async function cleanDir (dirPath) {
await fs.rm(dirPath, { recursive: true, force: true })
await ensureDir(dirPath)
}

async function* walkFiles(dirPath) {
async function * walkFiles (dirPath) {
if (!isFileExists(dirPath)) return
const entries = await fs.readdir(dirPath, { withFileTypes: true })
for (const entry of entries) {
const fullPath = path.join(dirPath, entry.name)
if (entry.isDirectory()) {
yield* walkFiles(fullPath)
yield * walkFiles(fullPath)
} else if (entry.isFile()) {
yield fullPath
}
}
}

async function optimizeOne({ inputPath, inputBaseDir, outputBaseDir }) {
async function optimizeOne ({ inputPath, inputBaseDir, outputBaseDir }) {
const relPath = path.relative(inputBaseDir, inputPath)
const outputPath = path.join(outputBaseDir, relPath)

Expand Down Expand Up @@ -111,7 +111,7 @@ async function optimizeOne({ inputPath, inputBaseDir, outputBaseDir }) {
MP3_BITRATE,
'-id3v2_version',
'3',
tmpPath,
tmpPath
])
} else {
// Re-encode MP4 (H.264 + AAC) and enable faststart
Expand All @@ -133,7 +133,7 @@ async function optimizeOne({ inputPath, inputBaseDir, outputBaseDir }) {
MP4_AUDIO_BITRATE,
'-movflags',
'+faststart',
tmpPath,
tmpPath
])
}

Expand All @@ -151,12 +151,12 @@ async function optimizeOne({ inputPath, inputBaseDir, outputBaseDir }) {
return { changed: true, reason: 'optimized', before: stat.size, after: outStat.size, outputPath }
}

function checkFfmpegAvailable() {
function checkFfmpegAvailable () {
const result = spawnSync('ffmpeg', ['-version'], { stdio: 'ignore', windowsHide: true })
return result.status === 0
}

async function main() {
async function main () {
if (!checkFfmpegAvailable()) {
console.error('[optimize:media] ffmpeg not found in PATH.')
console.error('Install ffmpeg and ensure `ffmpeg` is available in your terminal, then re-run.')
Expand All @@ -167,7 +167,7 @@ async function main() {
const targets = [
{ inputDir: SRC_AUDIO_DIR, outputDir: OUT_AUDIO_DIR },
{ inputDir: SRC_VIDEO_DIR, outputDir: OUT_VIDEO_DIR },
{ inputDir: SRC_PUBLIC_AUDIO_DIR, outputDir: OUT_PUBLIC_AUDIO_DIR },
{ inputDir: SRC_PUBLIC_AUDIO_DIR, outputDir: OUT_PUBLIC_AUDIO_DIR }
]

let changedCount = 0
Expand All @@ -188,7 +188,7 @@ async function main() {
const result = await optimizeOne({
inputPath,
inputBaseDir: target.inputDir,
outputBaseDir: target.outputDir,
outputBaseDir: target.outputDir
})
if (result.changed) {
changedCount += 1
Expand Down
18 changes: 9 additions & 9 deletions scripts/prepare-lib-publish.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs/promises'
import path from 'node:path'

async function fileExists(filePath) {
async function fileExists (filePath) {
try {
await fs.access(filePath)
return true
Expand All @@ -10,11 +10,11 @@ async function fileExists(filePath) {
}
}

function pickDefined(obj) {
function pickDefined (obj) {
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined))
}

async function main() {
async function main () {
const repoRoot = process.cwd()
const rootPkgPath = path.join(repoRoot, 'package.json')
const distDir = path.join(repoRoot, 'dist-lib')
Expand Down Expand Up @@ -46,25 +46,25 @@ async function main() {
'.': {
types: './index.d.ts',
import: './pro-react-components.es.js',
require: './pro-react-components.umd.js',
require: './pro-react-components.umd.js'
},
'./core': {
types: './entries/core.d.ts',
import: './entries/core.es.js',
require: './entries/core.cjs.js',
require: './entries/core.cjs.js'
},
'./stateful': {
types: './entries/stateful.d.ts',
import: './entries/stateful.es.js',
require: './entries/stateful.cjs.js',
require: './entries/stateful.cjs.js'
},
'./stateless': {
types: './entries/stateless.d.ts',
import: './entries/stateless.es.js',
require: './entries/stateless.cjs.js',
require: './entries/stateless.cjs.js'
},
'./style.css': './style.css',
},
'./style.css': './style.css'
}
}

const distPkgPath = path.join(distDir, 'package.json')
Expand Down
11 changes: 7 additions & 4 deletions scripts/run-lighthouse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const buildPortList = () => {
const raw = process.env.LH_PORTS
if (raw && raw.trim()) {
// supports: "8080,8081,8090" or "8080-8090"
const parts = raw.split(',').map((s) => s.trim()).filter(Boolean)
const parts = raw
.split(',')
.map((s) => s.trim())
.filter(Boolean)
const ports = []
for (const part of parts) {
const range = part.split('-').map((s) => s.trim())
Expand Down Expand Up @@ -48,8 +51,8 @@ const fetchOk = async (url) => {
signal: controller.signal,
headers: {
// Some dev servers behave differently for default fetch UA.
'User-Agent': 'wui-react-lighthouse-probe',
},
'User-Agent': 'wui-react-lighthouse-probe'
}
})
if (!res.ok) return false
const text = await res.text()
Expand Down Expand Up @@ -104,7 +107,7 @@ const runLighthouse = (url) => {
const args = ['--view', url, '--preset=desktop']
const result = spawnSync('lighthouse', args, {
stdio: 'inherit',
shell: process.platform === 'win32',
shell: process.platform === 'win32'
})

process.exit(result.status ?? 1)
Expand Down
17 changes: 9 additions & 8 deletions src/components/KeepAlive/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,16 @@ const createKeepAliveManager = () => {
// set global options: { deactivateDelay, keepInactiveCount, limit }
setOptions: (opts = {}) => {
if (typeof opts.deactivateDelay === 'number') deactivateDelay = opts.deactivateDelay
if (typeof opts.keepInactiveCount === 'number')
if (typeof opts.keepInactiveCount === 'number') {
keepInactiveCount = Math.max(0, Math.floor(opts.keepInactiveCount))
}
if (typeof opts.limit === 'number') limit = Math.max(0, Math.floor(opts.limit))
},
register: (id, opts) => {
// opts: { setShouldRender, persistOnUnmount }
instances.set(id, {
setShouldRender: opts.setShouldRender,
persistOnUnmount: !!opts.persistOnUnmount,
persistOnUnmount: !!opts.persistOnUnmount
})
},
unregister: (id) => {
Expand Down Expand Up @@ -196,7 +197,7 @@ const createKeepAliveManager = () => {
instances.delete(id)
activeMap.delete(id)
keys = keys.filter((k) => k !== id)
},
}
}
}

Expand Down Expand Up @@ -239,7 +240,7 @@ const KeepAlive = ({ id, active = false, children, persistOnUnmount = false, cac
const effectivePersist = ActivityComponent ? true : persistOnUnmount
keepAliveManager.register(id, {
setShouldRender,
persistOnUnmount: effectivePersist,
persistOnUnmount: effectivePersist
})
}
return () => {
Expand Down Expand Up @@ -308,14 +309,14 @@ const KeepAlive = ({ id, active = false, children, persistOnUnmount = false, cac
if (!active) return
scrollPos.current.set(e.target, {
left: e.target.scrollLeft,
top: e.target.scrollTop,
top: e.target.scrollTop
})
}

// Capture scroll events to record positions
container.addEventListener('scroll', onScroll, {
capture: true,
passive: true,
passive: true
})

return () => {
Expand Down Expand Up @@ -359,7 +360,7 @@ const KeepAlive = ({ id, active = false, children, persistOnUnmount = false, cac
if (container.parentNode !== placeholder) {
// 在移动DOM之前,发送自定义事件通知子组件
const event = new CustomEvent('keepalive-dom-move', {
detail: { from: container.parentNode, to: placeholder },
detail: { from: container.parentNode, to: placeholder }
})
container.dispatchEvent(event)

Expand Down Expand Up @@ -429,7 +430,7 @@ KeepAlive.propTypes = {
active: PropTypes.bool,
children: PropTypes.node,
persistOnUnmount: PropTypes.bool,
cacheLimit: PropTypes.number,
cacheLimit: PropTypes.number
}

export default KeepAlive
Loading
Loading