浏览代码

Update tests, scaffolding

Migrate to pridepack.
master
父节点
当前提交
3a0e2b4d34
共有 19 个文件被更改,包括 4493 次插入12712 次删除
  1. +9
    -0
      .eslintrc
  2. +67
    -50
      .gitignore
  3. +0
    -11
      .prettierrc
  4. +4
    -18
      LICENSE
  5. +60
    -60
      package.json
  6. +3
    -0
      pridepack.json
  7. +1
    -0
      src/components/AccidentalKey/AccidentalKey.test.tsx
  8. +1
    -0
      src/components/Keyboard/Keyboard.test.tsx
  9. +9
    -9
      src/components/Keyboard/Keyboard.tsx
  10. +1
    -0
      src/components/NaturalKey/NaturalKey.test.tsx
  11. +1
    -0
      src/components/StyledAccidentalKey/StyledAccidentalKey.test.tsx
  12. +1
    -0
      src/components/StyledNaturalKey/StyledNaturalKey.test.tsx
  13. +3
    -3
      src/services/constants.ts
  14. +4
    -4
      src/services/getKeyBounds.ts
  15. +1
    -0
      src/services/isNaturalKey.test.ts
  16. +21
    -0
      tsconfig.eslint.json
  17. +5
    -6
      tsconfig.json
  18. +8
    -0
      vitest.config.ts
  19. +4294
    -12551
      yarn.lock

+ 9
- 0
.eslintrc 查看文件

@@ -0,0 +1,9 @@
{
"root": true,
"extends": [
"lxsmnsyc/typescript/react"
],
"parserOptions": {
"project": "./tsconfig.eslint.json"
}
}

+ 67
- 50
.gitignore 查看文件

@@ -1,92 +1,109 @@
.DS_Store
.AppleDouble
.LSOverride
._*
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
.idea/
cmake-build-*/
*.iws
out/
.idea_modules/
atlassian-ide-plugin.xml
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
.vscode/
*.code-workspace
.history/
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
*.stackdump
[Dd]esktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msix
*.msm
*.msp
*.lnk
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/
web_modules/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test
.env.production
.env.development

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
.vscode-test
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*

.npmrc
.idea/
/types/

+ 0
- 11
.prettierrc 查看文件

@@ -1,11 +0,0 @@
{
"printWidth": 120,
"semi": false,
"singleQuote": true,
"jsxSingleQuote": false,
"trailingComma": "all",
"arrowParens": "always",
"jsxBracketSameLine": false,
"quoteProps": "as-needed",
"endOfLine": "lf"
}

+ 4
- 18
LICENSE 查看文件

@@ -1,21 +1,7 @@
MIT License
MIT License Copyright (c) 2023 TheoryOfNekomata <allan.crisostomo@outlook.com>

Copyright (c) 2020 TheoryOfNekomata
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 60
- 60
package.json 查看文件

@@ -1,14 +1,6 @@
{
"version": "1.1.4",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"repository": "https://code.modal.sh/TheoryOfNekomata/react-musical-keyboard.git",
"files": [
"dist",
"src"
],
"private": false,
"name": "@theoryofnekomata/react-musical-keyboard",
"version": "1.2.0",
"publishing": {
"github": {
"repository": "https://github.com/TheoryOfNekomata/react-musical-keyboard.git",
@@ -28,57 +20,14 @@
}
}
},
"files": [
"dist",
"src"
],
"engines": {
"node": ">=10"
},
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint",
"prepare": "tsdx build",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"peerDependencies": {
"react": ">=16",
"mem": "^6.1.0"
},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
},
"name": "@theoryofnekomata/react-musical-keyboard",
"description": "Musical keyboard component written in React.",
"author": "TheoryOfNekomata <allan.crisostomo@outlook.com>",
"module": "dist/react-musical-keyboard.esm.js",
"devDependencies": {
"@babel/core": "^7.11.1",
"@storybook/addon-actions": "^5.3.19",
"@storybook/addon-docs": "^5.3.19",
"@storybook/addon-info": "^5.3.19",
"@storybook/addon-links": "^5.3.19",
"@storybook/addons": "^5.3.19",
"@storybook/react": "^5.3.19",
"@types/prop-types": "^15.7.3",
"@types/react": "^16.9.44",
"@types/react-dom": "^16.9.8",
"@types/react-is": "^16.7.1",
"babel-loader": "^8.1.0",
"fast-check": "^2.0.0",
"husky": "^4.2.5",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-docgen-typescript-loader": "^3.7.2",
"react-dom": "^16.13.1",
"react-is": "^16.13.1",
"ts-loader": "^8.0.2",
"tsdx": "^0.13.2",
"tslib": "^2.0.0",
"typescript": "^3.9.7",
"mem": "^6.1.0"
"node": ">=12"
},
"license": "MIT",
"keywords": [
"component",
"react",
@@ -90,5 +39,56 @@
"keyboard",
"instrument",
"midi"
]
],
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@types/node": "^18.14.1",
"@types/react": "^18.0.27",
"@types/react-is": "^17.0.3",
"eslint": "^8.35.0",
"eslint-config-lxsmnsyc": "^0.5.0",
"fast-check": "^3.8.0",
"jsdom": "^21.1.0",
"pridepack": "2.4.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-test-renderer": "^18.2.0",
"tslib": "^2.5.0",
"typescript": "^4.9.5",
"vitest": "^0.28.1"
},
"peerDependencies": {
"react": "^16.8 || ^17.0 || ^18.0",
"react-dom": "^16.8 || ^17.0 || ^18.0"
},
"scripts": {
"prepublishOnly": "pridepack clean && pridepack build",
"build": "pridepack build",
"type-check": "pridepack check",
"lint": "pridepack lint",
"clean": "pridepack clean",
"watch": "pridepack watch",
"start": "pridepack start",
"dev": "pridepack dev",
"test": "vitest"
},
"private": false,
"description": "Musical keyboard component written in React.",
"repository": {
"url": "https://code.modal.sh/TheoryOfNekomata/react-musical-keyboard.git",
"type": "git"
},
"homepage": "https://code.modal.sh/TheoryOfNekomata/react-musical-keyboard",
"bugs": {
"url": "https://code.modal.sh/TheoryOfNekomata/react-musical-keyboard/issues"
},
"author": "TheoryOfNekomata <allan.crisostomo@outlook.com>",
"publishConfig": {
"access": "public"
},
"dependencies": {
"mem": "^9.0.2",
"react-is": "^18.2.0"
}
}

+ 3
- 0
pridepack.json 查看文件

@@ -0,0 +1,3 @@
{
"target": "es2018"
}

+ 1
- 0
src/components/AccidentalKey/AccidentalKey.test.tsx 查看文件

@@ -1,3 +1,4 @@
import { it, expect } from 'vitest';
import * as React from 'react'
import * as ReactIs from 'react-is'
import AccidentalKey from './AccidentalKey'


+ 1
- 0
src/components/Keyboard/Keyboard.test.tsx 查看文件

@@ -1,3 +1,4 @@
import { it, expect } from 'vitest';
import * as React from 'react'
import * as ReactIs from 'react-is'
import Keyboard from './Keyboard'


+ 9
- 9
src/components/Keyboard/Keyboard.tsx 查看文件

@@ -143,9 +143,9 @@ const Keyboard: React.FC<Props> = ({

const { natural: NaturalKey = DefaultNaturalKey, accidental: AccidentalKey = DefaultAccidentalKey } = keyComponents!

const getKeyWidth = React.useCallback((k) => getKeyWidthUnmemoized(startKey, endKey)(k), [startKey, endKey])
const getKeyLeft = React.useCallback((k) => getKeyLeftUnmemoized(startKey, endKey)(k), [startKey, endKey])
const isNaturalKey = React.useCallback((k) => isNaturalKeyUnmemoized(k), [])
const getKeyWidth = React.useCallback((k: number) => getKeyWidthUnmemoized(startKey, endKey)(k), [startKey, endKey])
const getKeyLeft = React.useCallback((k: number) => getKeyLeftUnmemoized(startKey, endKey)(k), [startKey, endKey])
const isNaturalKey = React.useCallback((k: number) => isNaturalKeyUnmemoized(k), [])
const baseRef = React.useRef<HTMLDivElement>(null)

React.useEffect(() => {
@@ -153,7 +153,7 @@ const Keyboard: React.FC<Props> = ({
}, [])

React.useEffect(() => {
setClientSideKeys(generateKeys(startKey!, endKey!))
setClientSideKeys(generateKeys(startKey, endKey))
}, [startKey, endKey])

const keys = clientSide ? clientSideKeys : generateKeys(startKey, endKey)
@@ -163,11 +163,6 @@ const Keyboard: React.FC<Props> = ({
let topDirection: string

switch (orientation) {
default:
case 0:
leftDirection = 'left'
topDirection = 'top'
break
case 90:
leftDirection = 'bottom'
topDirection = 'left'
@@ -180,6 +175,11 @@ const Keyboard: React.FC<Props> = ({
leftDirection = 'top'
topDirection = 'right'
break
case 0:
default:
leftDirection = 'left'
topDirection = 'top'
break
}

return (


+ 1
- 0
src/components/NaturalKey/NaturalKey.test.tsx 查看文件

@@ -1,3 +1,4 @@
import { it, expect } from 'vitest'
import * as React from 'react'
import * as ReactIs from 'react-is'
import NaturalKey from './NaturalKey'


+ 1
- 0
src/components/StyledAccidentalKey/StyledAccidentalKey.test.tsx 查看文件

@@ -1,3 +1,4 @@
import { it, expect } from 'vitest'
import * as React from 'react'
import * as ReactIs from 'react-is'
import StyledAccidentalKey from './StyledAccidentalKey'


+ 1
- 0
src/components/StyledNaturalKey/StyledNaturalKey.test.tsx 查看文件

@@ -1,3 +1,4 @@
import { it, expect } from 'vitest'
import * as React from 'react'
import * as ReactIs from 'react-is'
import StyledNaturalKey from './StyledNaturalKey'


+ 3
- 3
src/services/constants.ts 查看文件

@@ -94,21 +94,21 @@ export const OCTAVE_DIVISIONS = [12, 17, 19, 21, 24, 36] as const

export const ORIENTATIONS = [0, 90, 180, 270] as const

export const BOTTOM_CSS_ATTRIBUTES: Record<0 | 90 | 180 | 270, string> = {
export const BOTTOM_CSS_ATTRIBUTES: Record<typeof ORIENTATIONS[number], string> = {
0: 'bottom',
90: 'right',
180: 'top',
270: 'left',
}

export const LEFT_CSS_ATTRIBUTES: Record<0 | 90 | 180 | 270, string> = {
export const LEFT_CSS_ATTRIBUTES: Record<typeof ORIENTATIONS[number], string> = {
0: 'left',
90: 'bottom',
180: 'right',
270: 'top',
}

export const WIDTH_CSS_ATTRIBUTES: Record<0 | 90 | 180 | 270, string> = {
export const WIDTH_CSS_ATTRIBUTES: Record<typeof ORIENTATIONS[number], string> = {
0: 'width',
180: 'width',
90: 'height',


+ 4
- 4
src/services/getKeyBounds.ts 查看文件

@@ -16,20 +16,20 @@ const getKeyBounds: GetKeyBounds = (startKey, endKey, getKeyLeft, getKeyWidth) =
case 5:
return {
left,
right: key + 1 > endKey! ? left + width : getKeyLeft(key + 1),
right: key + 1 > endKey ? left + width : getKeyLeft(key + 1),
}
case 4:
case 11:
return {
left: key - 1 < startKey! ? left : getKeyLeft(key - 1) + getKeyWidth(key - 1),
left: key - 1 < startKey ? left : getKeyLeft(key - 1) + getKeyWidth(key - 1),
right: left + width,
}
case 2:
case 7:
case 9:
return {
left: key - 1 < startKey! ? left : getKeyLeft(key - 1) + getKeyWidth(key - 1),
right: key + 1 > endKey! ? left + width : getKeyLeft(key + 1),
left: key - 1 < startKey ? left : getKeyLeft(key - 1) + getKeyWidth(key - 1),
right: key + 1 > endKey ? left + width : getKeyLeft(key + 1),
}
default:
break


+ 1
- 0
src/services/isNaturalKey.test.ts 查看文件

@@ -1,3 +1,4 @@
import { describe, it, expect } from 'vitest'
import * as fc from 'fast-check'
import isNaturalKey from './isNaturalKey'



+ 21
- 0
tsconfig.eslint.json 查看文件

@@ -0,0 +1,21 @@
{
"exclude": ["node_modules"],
"include": ["src", "types", "test"],
"compilerOptions": {
"module": "ESNext",
"lib": ["DOM", "ESNext"],
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"jsx": "react",
"esModuleInterop": true,
"target": "es2018"
}
}

+ 5
- 6
tsconfig.json 查看文件

@@ -1,8 +1,9 @@
{
"exclude": ["node_modules"],
"include": ["src", "types"],
"compilerOptions": {
"module": "esnext",
"lib": ["dom", "esnext"],
"module": "ESNext",
"lib": ["DOM", "ESNext"],
"importHelpers": true,
"declaration": true,
"sourceMap": true,
@@ -11,12 +12,10 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"baseUrl": "./",
"jsx": "react",
"esModuleInterop": true
"esModuleInterop": true,
"target": "es2018"
}
}

+ 8
- 0
vitest.config.ts 查看文件

@@ -0,0 +1,8 @@
/// <reference types="vitest" />

export default ({
test: {
global: true,
environment: 'jsdom',
},
});

+ 4294
- 12551
yarn.lock
文件差异内容过多而无法显示
查看文件


正在加载...
取消
保存