Skip to content

Commit 7bb7fe2

Browse files
committed
[WIP] Migration to TS.
1 parent e20d7bf commit 7bb7fe2

File tree

8 files changed

+940
-751
lines changed

8 files changed

+940
-751
lines changed

.size-snapshot.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,19 @@
1212
"code": 31592
1313
}
1414
}
15+
},
16+
"index.mjs": {
17+
"bundled": 65954,
18+
"minified": 37732,
19+
"gzipped": 9679,
20+
"treeshaked": {
21+
"rollup": {
22+
"code": 30085,
23+
"import_statements": 535
24+
},
25+
"webpack": {
26+
"code": 31592
27+
}
28+
}
1529
}
1630
}

package.json

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
"version": "4.0.0-beta.0",
44
"description": "Drag-and-drop sortable component for nested data and hierarchies",
55
"main": "./index.js",
6-
"module": "./esm/index.js",
76
"types": "./index.d.ts",
87
"exports": {
98
"./package.json": "./package.json",
10-
"./": "./",
119
".": {
1210
"types": "./index.d.ts",
1311
"module": "./esm/index.js",
14-
"import": "./esm/index.js",
12+
"import": "./esm/index.mjs",
1513
"default": "./index.js"
1614
}
1715
},
@@ -25,14 +23,14 @@
2523
"build:storybook": "build-storybook -o build",
2624
"clean": "rimraf dist",
2725
"clean:storybook": "rimraf build",
28-
"lint": "eslint \"**/*.{ts,tsx}\" --fix",
26+
"lint": "eslint --fix '*.{js,json}' '{src,tests}/**/*.{ts,tsx}'",
2927
"prepublishOnly": "yarn test && yarn build",
3028
"release": "standard-version",
3129
"test": "jest --env=jsdom",
3230
"test:watch": "jest --watchAll",
3331
"storybook": "start-storybook -p ${PORT:-3001} -h 0.0.0.0",
3432
"postbuild": "yarn copy",
35-
"copy": "rimraf dist/tests.d.ts && shx cp -r dist/*.d.ts dist/esm && shx mv dist/* dist && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined; this.jest=undefined; this['lint-staged']=undefined;\" && shx echo '{\"type\":\"module\"}' > dist/esm/package.json && json -I -f dist/esm/package.json",
33+
"copy": "rimraf dist/tests.d.ts && shx cp -r dist/*.d.ts dist/esm && shx mv dist/* dist && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined; this.jest=undefined; this['lint-staged']=undefined;\"",
3634
"publish:alpha": "cd dist && npm publish --tag alpha",
3735
"publish:beta": "cd dist && npm publish --tag beta",
3836
"publish:release": "cd dist && npm publish"
@@ -129,45 +127,45 @@
129127
"react-virtualized": "^9.22.3"
130128
},
131129
"devDependencies": {
132-
"@babel/core": "^7.15.0",
133-
"@babel/eslint-parser": "^7.15.0",
134-
"@babel/helper-module-imports": "^7.14.5",
130+
"@babel/core": "^7.15.5",
131+
"@babel/eslint-parser": "^7.15.4",
132+
"@babel/helper-module-imports": "^7.15.4",
135133
"@babel/plugin-transform-react-jsx": "^7.14.9",
136-
"@babel/preset-env": "^7.15.0",
137-
"@babel/types": "^7.15.0",
134+
"@babel/preset-env": "^7.15.4",
135+
"@babel/types": "^7.15.4",
138136
"@nosferatu500/theme-file-explorer": "^3.0.6",
139137
"@rollup/plugin-babel": "^5.3.0",
140138
"@rollup/plugin-node-resolve": "^13.0.4",
141139
"@rollup/plugin-typescript": "^8.2.5",
142-
"@storybook/addon-storyshots": "^6.3.7",
143-
"@storybook/addons": "^6.3.7",
144-
"@storybook/react": "^6.3.7",
145-
"@storybook/theming": "^6.3.7",
140+
"@storybook/addon-storyshots": "^6.3.8",
141+
"@storybook/addons": "^6.3.8",
142+
"@storybook/react": "^6.3.8",
143+
"@storybook/theming": "^6.3.8",
146144
"@testing-library/react": "^12.0.0",
147145
"@types/babel-plugin-macros": "^2.8.5",
148146
"@types/enzyme": "^3.10.9",
149147
"@types/jest": "^27.0.1",
150148
"@types/lodash.isequal": "^4.5.5",
151-
"@types/react": "^17.0.18",
149+
"@types/react": "^17.0.20",
152150
"@types/react-dom": "^17.0.9",
153151
"@types/react-lifecycles-compat": "^3.0.1",
154152
"@types/react-test-renderer": "^17.0.1",
155153
"@types/react-virtualized": "^9.21.13",
156-
"@typescript-eslint/eslint-plugin": "^4.29.2",
157-
"@typescript-eslint/parser": "^4.29.2",
154+
"@typescript-eslint/eslint-plugin": "^4.30.0",
155+
"@typescript-eslint/parser": "^4.30.0",
158156
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.3",
159157
"acorn-jsx": "^5.3.2",
160158
"babel-plugin-macros": "^3.1.0",
161159
"babel-plugin-tester": "^10.1.0",
162160
"enzyme": "^3.11.0",
163-
"esbuild": "^0.12.20",
161+
"esbuild": "^0.12.25",
164162
"eslint": "^7.32.0",
165163
"eslint-config-prettier": "^8.3.0",
166-
"eslint-plugin-import": "^2.24.0",
164+
"eslint-plugin-import": "^2.24.2",
167165
"eslint-plugin-jest": "^24.4.0",
168-
"eslint-plugin-prettier": "^3.4.0",
169-
"eslint-plugin-react": "^7.24.0",
170-
"jest": "^27.0.6",
166+
"eslint-plugin-prettier": "^4.0.0",
167+
"eslint-plugin-react": "^7.25.1",
168+
"jest": "^27.1.0",
171169
"jest-enzyme": "^7.1.2",
172170
"json": "^11.0.0",
173171
"postcss": "^8.3.6",
@@ -178,14 +176,14 @@
178176
"react-dom": "^17.0.2",
179177
"react-test-renderer": "^17.0.2",
180178
"rimraf": "^3.0.2",
181-
"rollup": "^2.56.2",
179+
"rollup": "^2.56.3",
182180
"rollup-plugin-esbuild": "^4.5.0",
183181
"rollup-plugin-postcss": "^4.0.1",
184182
"rollup-plugin-size-snapshot": "^0.12.0",
185183
"shx": "^0.3.3",
186184
"ts-jest": "^27.0.5",
187185
"tslib": "^2.3.1",
188-
"typescript": "^4.3.5"
186+
"typescript": "4.3.5"
189187
},
190188
"peerDependencies": {
191189
"react": ">=17.0.0",

rollup.config.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import nodeResolve from '@rollup/plugin-node-resolve'
1+
import path from 'path'
22
import babel from '@rollup/plugin-babel'
3+
import nodeResolve from '@rollup/plugin-node-resolve'
4+
import typescript from '@rollup/plugin-typescript'
5+
import jsx from 'acorn-jsx'
36
import esbuild from 'rollup-plugin-esbuild'
47
import postcss from 'rollup-plugin-postcss'
58
import { sizeSnapshot } from 'rollup-plugin-size-snapshot'
6-
import typescript from '@rollup/plugin-typescript'
7-
import jsx from 'acorn-jsx'
8-
import path from 'path'
9-
109
const createBabelConfig = require('./babel.config')
10+
1111
const extensions = ['.js', '.ts', '.tsx']
1212
const { root } = path.parse(process.cwd())
1313

@@ -42,7 +42,11 @@ function createDeclarationConfig(input, output) {
4242
acornInjectPlugins: [jsx()],
4343
plugins: [
4444
postcss({ extract: 'style.css' }),
45-
typescript({ declaration: true, outDir: output }),
45+
typescript({
46+
declaration: true,
47+
emitDeclarationOnly: true,
48+
outDir: output,
49+
}),
4650
],
4751
}
4852
}
@@ -81,6 +85,7 @@ export default function (args) {
8185
return [
8286
createDeclarationConfig('src/index.ts', 'dist'),
8387
createCommonJSConfig('src/index.ts', 'dist/index.js'),
88+
createESMConfig('src/index.ts', 'dist/esm/index.mjs'),
8489
createESMConfig('src/index.ts', 'dist/esm/index.js'),
8590
]
8691
}

src/node-renderer-default.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { ConnectDragPreview, ConnectDragSource } from 'react-dnd'
44
import { classnames } from './utils/classnames'
55
import { isDescendant } from './utils/tree-data-utils'
66
import './node-renderer-default.css'
7-
import { NodeData, NumberOrStringArray, TreeItem } from '.'
8-
// eslint-disable-next-line import/named
7+
import { NodeData, TreeItem } from '.'
98

109
const defaultProps = {
1110
isSearchMatch: false,
@@ -25,7 +24,7 @@ const defaultProps = {
2524

2625
export interface NodeRendererProps {
2726
node: TreeItem
28-
path: NumberOrStringArray
27+
path: number[]
2928
treeIndex: number
3029
isSearchMatch: boolean
3130
isSearchFocus: boolean

src/tree-node.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ConnectDropTarget } from 'react-dnd'
44
import { classnames } from './utils/classnames'
55
import './tree-node.css'
66
// eslint-disable-next-line import/named
7-
import { NumberOrStringArray, TreeItem, TreePath } from '.'
7+
import { TreeItem, TreePath } from '.'
88

99
export interface TreeNode {
1010
node: TreeItem
@@ -38,7 +38,7 @@ export interface TreeRendererProps {
3838
// used in dndManager
3939
getPrevRow: () => FlatDataItem | null
4040
node: TreeItem
41-
path: NumberOrStringArray
41+
path: number[]
4242
}
4343

4444
const defaultProps = {

src/utils/default-handlers.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { ReactNode } from 'react'
2+
13
export interface GetTreeItemChildren {
24
done: (children: TreeItem[]) => void
35
node: TreeItem
4-
path: NumberOrStringArray
6+
path: number[]
57
lowerSiblingCounts: number[]
68
treeIndex: number
79
}
@@ -10,11 +12,9 @@ export type GetTreeItemChildrenFn = (data: GetTreeItemChildren) => void
1012

1113
export type GetNodeKeyFunction = (data: TreeIndex & TreeNode) => string | number
1214

13-
export type NumberOrStringArray = Array<string | number>
14-
1515
export interface TreeItem {
16-
title?: React.ReactNode | undefined
17-
subtitle?: React.ReactNode | undefined
16+
title?: ReactNode | undefined
17+
subtitle?: ReactNode | undefined
1818
expanded?: boolean | undefined
1919
children?: TreeItem[] | GetTreeItemChildrenFn | undefined
2020
[x: string]: any
@@ -25,7 +25,7 @@ export interface TreeNode {
2525
}
2626

2727
export interface TreePath {
28-
path: NumberOrStringArray | number
28+
path: number[]
2929
}
3030

3131
export interface TreeIndex {
@@ -39,7 +39,7 @@ export interface FullTree {
3939
export interface NodeData extends TreeNode, TreePath, TreeIndex {}
4040

4141
export interface SearchData extends NodeData {
42-
searchQuery: any
42+
searchQuery: string
4343
}
4444

4545
export const defaultGetNodeKey = ({ treeIndex }: TreeIndex) => treeIndex
@@ -75,7 +75,7 @@ const stringSearch = (
7575
key: string,
7676
searchQuery: string,
7777
node: TreeItem,
78-
path: NumberOrStringArray | number,
78+
path: number[],
7979
treeIndex: number
8080
) => {
8181
if (typeof node[key] === 'function') {

tsconfig.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,9 @@
88
"moduleResolution": "node",
99
"baseUrl": ".",
1010
"paths": {
11-
"@nosferatu500/react-sortable-tree": [
12-
"./src/index.ts"
13-
]
11+
"@nosferatu500/react-sortable-tree": ["./src/index.ts"]
1412
}
1513
},
16-
"include": [
17-
"src/**/*",
18-
"tests/**/*"
19-
],
20-
"exclude": [
21-
"node_modules",
22-
"dist"
23-
]
24-
}
14+
"include": ["src/**/*", "tests/**/*"],
15+
"exclude": ["node_modules", "dist"]
16+
}

0 commit comments

Comments
 (0)