mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-01-31 11:51:41 +03:00
feature(react-json-tree): convert example to TypeScript (#603)
This commit is contained in:
parent
e7304b5853
commit
0516c41b0e
|
@ -8,6 +8,8 @@
|
||||||
"@babel/preset-typescript": "^7.10.4",
|
"@babel/preset-typescript": "^7.10.4",
|
||||||
"@types/jest": "^26.0.9",
|
"@types/jest": "^26.0.9",
|
||||||
"@types/node": "^14.6.0",
|
"@types/node": "^14.6.0",
|
||||||
|
"@types/react": "^16.9.46",
|
||||||
|
"@types/react-dom": "^16.9.8",
|
||||||
"@types/react-test-renderer": "^16.9.3",
|
"@types/react-test-renderer": "^16.9.3",
|
||||||
"@types/webpack": "^4.41.21",
|
"@types/webpack": "^4.41.21",
|
||||||
"@types/webpack-dev-server": "^3.11.0",
|
"@types/webpack-dev-server": "^3.11.0",
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
|
examples
|
||||||
lib
|
lib
|
||||||
umd
|
umd
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
{
|
{
|
||||||
"presets": ["@babel/preset-env", "@babel/preset-react"],
|
"presets": [
|
||||||
|
"@babel/preset-env",
|
||||||
|
"@babel/preset-react",
|
||||||
|
"@babel/preset-typescript"
|
||||||
|
],
|
||||||
"plugins": ["@babel/plugin-proposal-class-properties"]
|
"plugins": ["@babel/plugin-proposal-class-properties"]
|
||||||
}
|
}
|
||||||
|
|
21
packages/react-json-tree/examples/.eslintrc.js
Normal file
21
packages/react-json-tree/examples/.eslintrc.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
module.exports = {
|
||||||
|
extends: '../../../.eslintrc',
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
files: ['*.ts', '*.tsx'],
|
||||||
|
extends: '../../../eslintrc.ts.react.base.json',
|
||||||
|
parserOptions: {
|
||||||
|
tsconfigRootDir: __dirname,
|
||||||
|
project: ['./tsconfig.json'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['webpack.config.ts'],
|
||||||
|
extends: '../../../eslintrc.ts.base.json',
|
||||||
|
parserOptions: {
|
||||||
|
tsconfigRootDir: __dirname,
|
||||||
|
project: ['./tsconfig.webpack.json'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
|
@ -2,45 +2,25 @@
|
||||||
"name": "react-json-tree-example",
|
"name": "react-json-tree-example",
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"description": "React-Json-Tree example",
|
"description": "React-Json-Tree example",
|
||||||
"private": true,
|
"homepage": "https://github.com/reduxjs/redux-devtools/tree/master/packages/react-json-tree/examples",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/reduxjs/redux-devtools/issues"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/reduxjs/redux-devtools.git"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack-dev-server --open",
|
"start": "webpack-dev-server --open",
|
||||||
"stats": "NODE_ENV=production webpack --json > dist/stats.json"
|
"stats": "NODE_ENV=production webpack --json > dist/stats.json"
|
||||||
},
|
},
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/gaearon/react-hot-boilerplate.git"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"react",
|
|
||||||
"reactjs",
|
|
||||||
"boilerplate",
|
|
||||||
"hot",
|
|
||||||
"reload",
|
|
||||||
"hmr",
|
|
||||||
"live",
|
|
||||||
"edit",
|
|
||||||
"webpack"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/gaearon/react-hot-boilerplate/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/gaearon/react-hot-boilerplate",
|
|
||||||
"devDependencies": {
|
|
||||||
"@babel/core": "^7.11.1",
|
|
||||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
|
||||||
"@babel/preset-env": "^7.11.0",
|
|
||||||
"@babel/preset-react": "^7.10.4",
|
|
||||||
"babel-loader": "^8.1.0",
|
|
||||||
"webpack": "^4.44.1",
|
|
||||||
"webpack-dev-server": "^3.11.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"immutable": "^4.0.0-rc.12",
|
"immutable": "^4.0.0-rc.12",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-base16-styling": "^0.7.0",
|
"react-base16-styling": "^0.7.0",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
"react-json-tree": "^0.12.1"
|
"react-json-tree": "^0.12.1"
|
||||||
}
|
},
|
||||||
|
"private": true
|
||||||
}
|
}
|
||||||
|
|
33
packages/react-json-tree/examples/src/App.js → packages/react-json-tree/examples/src/App.tsx
Executable file → Normal file
33
packages/react-json-tree/examples/src/App.js → packages/react-json-tree/examples/src/App.tsx
Executable file → Normal file
|
@ -1,15 +1,15 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Map } from 'immutable';
|
import { Map } from 'immutable';
|
||||||
import JSONTree from 'react-json-tree';
|
import JSONTree, { StylingValue } from 'react-json-tree';
|
||||||
|
|
||||||
const getLabelStyle = ({ style }, nodeType, expanded) => ({
|
const getLabelStyle: StylingValue = ({ style }, nodeType, expanded) => ({
|
||||||
style: {
|
style: {
|
||||||
...style,
|
...style,
|
||||||
textTransform: expanded ? 'uppercase' : style.textTransform,
|
textTransform: expanded ? 'uppercase' : style.textTransform,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const getBoolStyle = ({ style }, nodeType) => ({
|
const getBoolStyle: StylingValue = ({ style }, nodeType) => ({
|
||||||
style: {
|
style: {
|
||||||
...style,
|
...style,
|
||||||
border: nodeType === 'Boolean' ? '1px solid #DD3333' : style.border,
|
border: nodeType === 'Boolean' ? '1px solid #DD3333' : style.border,
|
||||||
|
@ -17,14 +17,14 @@ const getBoolStyle = ({ style }, nodeType) => ({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const getItemString = (type) => (
|
const getItemString = (type: string) => (
|
||||||
<span>
|
<span>
|
||||||
{' // '}
|
{' // '}
|
||||||
{type}
|
{type}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|
||||||
const getValueLabelStyle = ({ style }, nodeType, keyPath) => ({
|
const getValueLabelStyle: StylingValue = ({ style }, nodeType, keyPath) => ({
|
||||||
style: {
|
style: {
|
||||||
...style,
|
...style,
|
||||||
color:
|
color:
|
||||||
|
@ -37,10 +37,17 @@ const getValueLabelStyle = ({ style }, nodeType, keyPath) => ({
|
||||||
const longString =
|
const longString =
|
||||||
'Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.'; // eslint-disable-line max-len
|
'Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.'; // eslint-disable-line max-len
|
||||||
|
|
||||||
const Custom = function (value) {
|
class Custom {
|
||||||
this.value = value;
|
value: unknown;
|
||||||
};
|
|
||||||
Custom.prototype[Symbol.toStringTag] = 'Custom';
|
constructor(value: unknown) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get [Symbol.toStringTag]() {
|
||||||
|
return 'Custom';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
array: [1, 2, 3],
|
array: [1, 2, 3],
|
||||||
|
@ -64,16 +71,18 @@ const data = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
baz: undefined,
|
baz: undefined,
|
||||||
func: function User() {},
|
func: function User() {
|
||||||
|
// noop
|
||||||
|
},
|
||||||
},
|
},
|
||||||
emptyObject: {},
|
emptyObject: {},
|
||||||
symbol: Symbol('value'),
|
symbol: Symbol('value'),
|
||||||
// eslint-disable-next-line new-cap
|
// eslint-disable-next-line new-cap
|
||||||
immutable: Map([
|
immutable: Map<any, any>([
|
||||||
['key', 'value'],
|
['key', 'value'],
|
||||||
[{ objectKey: 'value' }, { objectKey: 'value' }],
|
[{ objectKey: 'value' }, { objectKey: 'value' }],
|
||||||
]),
|
]),
|
||||||
map: new window.Map([
|
map: new window.Map<any, any>([
|
||||||
['key', 'value'],
|
['key', 'value'],
|
||||||
[0, 'value'],
|
[0, 'value'],
|
||||||
[{ objectKey: 'value' }, { objectKey: 'value' }],
|
[{ objectKey: 'value' }, { objectKey: 'value' }],
|
0
packages/react-json-tree/examples/src/index.js → packages/react-json-tree/examples/src/index.tsx
Executable file → Normal file
0
packages/react-json-tree/examples/src/index.js → packages/react-json-tree/examples/src/index.tsx
Executable file → Normal file
7
packages/react-json-tree/examples/tsconfig.json
Normal file
7
packages/react-json-tree/examples/tsconfig.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../tsconfig.react.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "lib"
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
4
packages/react-json-tree/examples/tsconfig.webpack.json
Normal file
4
packages/react-json-tree/examples/tsconfig.webpack.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../tsconfig.base.json",
|
||||||
|
"include": ["webpack.config.ts"]
|
||||||
|
}
|
17
packages/react-json-tree/examples/webpack.config.js → packages/react-json-tree/examples/webpack.config.ts
Executable file → Normal file
17
packages/react-json-tree/examples/webpack.config.js → packages/react-json-tree/examples/webpack.config.ts
Executable file → Normal file
|
@ -1,11 +1,10 @@
|
||||||
var path = require('path');
|
import * as path from 'path';
|
||||||
var webpack = require('webpack');
|
import * as webpack from 'webpack';
|
||||||
|
|
||||||
var isProduction = process.env.NODE_ENV === 'production';
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mode: isProduction ? 'production' : 'development',
|
mode: isProduction ? 'production' : 'development',
|
||||||
devtool: 'eval-source-map',
|
|
||||||
entry: [
|
entry: [
|
||||||
!isProduction && 'webpack-dev-server/client?http://localhost:3000',
|
!isProduction && 'webpack-dev-server/client?http://localhost:3000',
|
||||||
!isProduction && 'webpack/hot/only-dev-server',
|
!isProduction && 'webpack/hot/only-dev-server',
|
||||||
|
@ -16,19 +15,23 @@ module.exports = {
|
||||||
filename: 'bundle.js',
|
filename: 'bundle.js',
|
||||||
publicPath: '/static/',
|
publicPath: '/static/',
|
||||||
},
|
},
|
||||||
plugins: [new webpack.HotModuleReplacementPlugin()],
|
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.js$/,
|
test: /\.(js|ts)x$/,
|
||||||
loader: 'babel-loader',
|
loader: 'babel-loader',
|
||||||
include: path.join(__dirname, 'src'),
|
exclude: /node_modules/,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||||
|
},
|
||||||
|
plugins: [new webpack.HotModuleReplacementPlugin()],
|
||||||
devServer: {
|
devServer: {
|
||||||
historyApiFallback: true,
|
historyApiFallback: true,
|
||||||
hot: true,
|
hot: true,
|
||||||
port: 3000,
|
port: 3000,
|
||||||
},
|
},
|
||||||
|
devtool: 'eval-source-map',
|
||||||
};
|
};
|
|
@ -46,10 +46,12 @@
|
||||||
"prepublishOnly": "npm run clean && npm run build"
|
"prepublishOnly": "npm run clean && npm run build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/prop-types": "^15.7.3",
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"react-base16-styling": "^0.7.0"
|
"react-base16-styling": "^0.7.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
"@types/react": "^16.3.18",
|
||||||
"react": "^16.3.0"
|
"react": "^16.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
invertTheme,
|
invertTheme,
|
||||||
StylingConfig,
|
StylingConfig,
|
||||||
StylingFunction,
|
StylingFunction,
|
||||||
|
StylingValue,
|
||||||
Theme,
|
Theme,
|
||||||
} from 'react-base16-styling';
|
} from 'react-base16-styling';
|
||||||
import { CircularPropsPassedThroughJSONTree } from './types';
|
import { CircularPropsPassedThroughJSONTree } from './types';
|
||||||
|
@ -174,3 +175,5 @@ export default class JSONTree extends React.Component<Props, State> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { StylingValue };
|
||||||
|
|
15
yarn.lock
15
yarn.lock
|
@ -3279,6 +3279,13 @@
|
||||||
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c"
|
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c"
|
||||||
integrity sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==
|
integrity sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==
|
||||||
|
|
||||||
|
"@types/react-dom@^16.9.8":
|
||||||
|
version "16.9.8"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.9.8.tgz#fe4c1e11dfc67155733dfa6aa65108b4971cb423"
|
||||||
|
integrity sha512-ykkPQ+5nFknnlU6lDd947WbQ6TE3NNzbQAkInC2EKY1qeYdTKp7onFusmYZb+ityzx2YviqT6BXSu+LyWWJwcA==
|
||||||
|
dependencies:
|
||||||
|
"@types/react" "*"
|
||||||
|
|
||||||
"@types/react-test-renderer@^16.9.3":
|
"@types/react-test-renderer@^16.9.3":
|
||||||
version "16.9.3"
|
version "16.9.3"
|
||||||
resolved "https://registry.yarnpkg.com/@types/react-test-renderer/-/react-test-renderer-16.9.3.tgz#96bab1860904366f4e848b739ba0e2f67bcae87e"
|
resolved "https://registry.yarnpkg.com/@types/react-test-renderer/-/react-test-renderer-16.9.3.tgz#96bab1860904366f4e848b739ba0e2f67bcae87e"
|
||||||
|
@ -3293,10 +3300,10 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/react" "*"
|
"@types/react" "*"
|
||||||
|
|
||||||
"@types/react@*", "@types/react@^16.9.11", "@types/react@^16.9.35":
|
"@types/react@*", "@types/react@^16.9.11", "@types/react@^16.9.35", "@types/react@^16.9.46":
|
||||||
version "16.9.45"
|
version "16.9.46"
|
||||||
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.45.tgz#b43ccf3d8a3d2020e6a48c8c8492e5a4bc10f097"
|
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.46.tgz#f0326cd7adceda74148baa9bff6e918632f5069e"
|
||||||
integrity sha512-vv950slTF5UZ5eDOf13b8qC1SD4rTvkqg3HfaUKzr17U97oeJZAa+dUaIHn0QoOJflNTIt6Pem9MmapULs9dkA==
|
integrity sha512-dbHzO3aAq1lB3jRQuNpuZ/mnu+CdD3H0WVaaBQA8LTT3S33xhVBUj232T8M3tAhSWJs/D/UqORYUlJNl/8VQZg==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/prop-types" "*"
|
"@types/prop-types" "*"
|
||||||
csstype "^3.0.2"
|
csstype "^3.0.2"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user