Skip to content

Commit 46cc4ca

Browse files
lottamusP0lip
authored andcommitted
feat: upgrade deps
1 parent 8d4fd67 commit 46cc4ca

File tree

13 files changed

+3023
-4062
lines changed

13 files changed

+3023
-4062
lines changed

.storybook/addons.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
require('@storybook/addon-knobs/register');
2-
3-
require('@storybook/addon-actions/register');
4-
5-
require('@storybook/addon-links/register');
6-
7-
require('@storybook/addon-options/register');
1+
import '@stoplight/storybook-config/addons';

.storybook/config.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1 @@
1-
import * as React from 'react';
2-
import { withOptions } from '@storybook/addon-options';
3-
import { addDecorator, configure } from '@storybook/react';
4-
5-
import '@stoplight/tree-list/styles/_tree-list.scss';
6-
import '@stoplight/ui-kit/styles/_ui-kit.scss';
7-
import { ThemeContainer } from '@stoplight/ui-kit';
8-
9-
addDecorator(
10-
withOptions({
11-
name: 'Stoplight Json Schema Viewer',
12-
url: 'https://github.com/stoplightio/json-schema-viewer',
13-
goFullScreen: false,
14-
showStoriesPanel: true,
15-
showAddonPanel: true,
16-
showSearchBox: false,
17-
addonPanelInRight: true,
18-
sortStoriesByKind: true,
19-
hierarchySeparator: /\//,
20-
hierarchyRootSeparator: /:/,
21-
selectedAddonPanel: undefined,
22-
}),
23-
);
24-
25-
function loadStories() {
26-
require('@project/stories');
27-
}
28-
29-
addDecorator(story => <ThemeContainer>{story()}</ThemeContainer>);
30-
31-
configure(loadStories, module);
1+
import "@stoplight/storybook-config/config";

.storybook/webpack.config.js

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,7 @@
1-
const path = require('path');
2-
const PackageImporter = require('node-sass-package-importer');
1+
const defaultConfig = require('@stoplight/storybook-config/webpack.config');
32

4-
const cwd = process.cwd();
5-
6-
module.exports = ({ config }) => {
7-
config.context = cwd;
8-
config.mode = 'development';
9-
10-
config.resolve.alias['@project/stories'] = require.resolve('src/__stories__/index.ts', { paths: [cwd] });
11-
config.resolve.extensions.push('.ts', '.tsx', '.js');
12-
config.resolve.modules = [...(config.resolve.modules || []), path.resolve('./')];
13-
14-
config.module.rules.push({
15-
test: /\.(ts|tsx)$/,
16-
include: [path.resolve(cwd, 'src')],
17-
use: [
18-
{
19-
loader: require.resolve('ts-loader'),
20-
options: {
21-
onlyCompileBundledFiles: true, // https://github.com/TypeStrong/ts-loader#onlycompilebundledfiles-boolean-defaultfalse
22-
},
23-
},
24-
],
25-
});
26-
27-
config.module.rules.push({
28-
test: /\.scss$/,
29-
use: [
30-
{
31-
loader: 'style-loader',
32-
options: {
33-
sourceMap: true,
34-
},
35-
},
36-
{
37-
loader: 'css-loader',
38-
options: {
39-
sourceMap: true,
40-
},
41-
},
42-
{
43-
loader: 'postcss-loader',
44-
options: {
45-
sourceMap: true,
46-
ident: 'postcss',
47-
plugins: loader => [require('postcss-import'), require('autoprefixer')],
48-
},
49-
},
50-
{
51-
loader: 'sass-loader',
52-
options: {
53-
sourceMap: true,
54-
importer: [PackageImporter()],
55-
},
56-
},
57-
],
58-
include: path.resolve(__dirname, '../'),
59-
});
3+
module.exports = (baseConfig, env, config) => {
4+
config = defaultConfig(baseConfig, env, config);
605

616
return config;
627
};

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A JSON Schema viewer React component
1212
- Full JSON Schema Draft 4 support, including `oneOf` and `anyOf` combiner properties
1313
- Renders complicated nested objects to any depth
1414
- Renders validation properties and markdown descriptions
15-
- Capable of linking resolved $refs
15+
- Capable of linking resolved \$refs
1616
- Theme-able
1717
- Collapsible
1818

@@ -28,12 +28,17 @@ yarn add @stoplight/json-schema-viewer
2828
### Usage
2929

3030
```jsx
31-
import { JsonSchemaViewer, ThemeProvider } from "@stoplight/json-schema-viewer";
32-
import { dark } from "@stoplight/json-schema-viewer/themes";
33-
34-
<ThemeProvider theme={dark}>
35-
<JsonSchemaViewer dereferencedSchema={dereferencedSchema} schema={schema} />
36-
</ThemeProvider>
31+
import { JsonSchemaViewer } from "@stoplight/json-schema-viewer";
32+
33+
<JsonSchemaViewer
34+
name="Todos Model"
35+
dereferencedSchema={schemaWithoutRefs}
36+
schema={schemaWithRefs}
37+
expanded={true}
38+
hideTopBar={false}
39+
emptyText="No schema defined"
40+
defaultExpandedDepth={0}
41+
/>;
3742
```
3843

3944
More examples can be find in the [Storybook stories](./src/__stories__/JsonSchemaViewer.tsx).

jest.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module.exports = {
2-
preset: '@stoplight/scripts',
3-
testEnvironment: 'jsdom',
4-
setupTestFrameworkScriptFile: './setupTests.ts',
5-
snapshotSerializers: ['enzyme-to-json/serializer'],
2+
preset: "@stoplight/scripts",
3+
testEnvironment: "jsdom",
4+
setupFilesAfterEnv: ["./setupTests.ts"],
5+
snapshotSerializers: ["enzyme-to-json/serializer"],
66
moduleNameMapper: {
7-
'\\.(css)$': '<rootDir>/__mocks__/styleMock.js',
8-
},
7+
"\\.(css)$": "<rootDir>/__mocks__/styleMock.js"
8+
}
99
};

package.json

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,40 @@
2323
"build": "sl-scripts build",
2424
"build.docs": "build-storybook -c .storybook -o docs-auto",
2525
"commit": "git-cz",
26-
"lint": "sl-scripts lint",
26+
"lint": "tslint -c tslint.json 'src/**/*.ts?'",
2727
"lint.fix": "yarn lint --fix",
2828
"release": "sl-scripts release",
2929
"release.docs": "sl-scripts release:docs",
3030
"release.dryRun": "sl-scripts release --dry-run --debug",
3131
"storybook": "start-storybook -p 9001",
32-
"test": "sl-scripts test",
32+
"test": "jest",
3333
"test.prod": "yarn lint && yarn test --coverage --maxWorkers=2",
3434
"test.update": "yarn test --updateSnapshot",
3535
"test.watch": "yarn test --watch"
3636
},
3737
"peerDependencies": {
38-
"@stoplight/tree-list": ">=4",
39-
"@stoplight/ui-kit": ">=2",
4038
"mobx": "5.x.x",
4139
"react": ">=16.8",
4240
"react-dom": ">=16.8"
4341
},
4442
"dependencies": {
4543
"@stoplight/json": "1.9.x",
46-
"@stoplight/markdown-viewer": "^3.0.0",
44+
"@stoplight/markdown-viewer": "3.0.0-beta.4",
4745
"@stoplight/tree-list": "^4.0.0",
4846
"@types/json-schema": "^7.0.3",
4947
"classnames": "^2.2.6",
50-
"lodash": "4.17.x",
48+
"lodash": "^4.17.11",
5149
"mobx-react-lite": "^1.3.1",
5250
"pluralize": "^7.0.0",
5351
"json-schema-merge-allof": "^0.6.0"
5452
},
5553
"devDependencies": {
5654
"@sambego/storybook-state": "^1.3.4",
57-
"@stoplight/scripts": "4.1.0",
58-
"@stoplight/storybook-config": "1.4.0",
55+
"@stoplight/scripts": "5.1.0",
56+
"@stoplight/storybook-config": "^2.0.1",
5957
"@stoplight/types": "4.1.0",
6058
"@stoplight/ui-kit": "2.0.0",
59+
"@types/classnames": "^2.2.7",
6160
"@types/enzyme": "3.9.1",
6261
"@types/json-schema": "^7.0.3",
6362
"@types/pluralize": "^0.0.29",
@@ -66,16 +65,14 @@
6665
"enzyme": "3.9.0",
6766
"enzyme-adapter-react-16": "1.12.1",
6867
"enzyme-to-json": "3.x.x",
68+
"jest": "^24.7.1",
6969
"jest-enzyme": "7.0.2",
7070
"mobx": "^5.9.4",
71-
"node-sass": "^4.11.0",
72-
"node-sass-package-importer": "^5.3.1",
73-
"postcss-import": "^12.0.1",
74-
"postcss-loader": "^3.0.0",
7571
"react": "16.8.6",
7672
"react-dom": "16.8.6",
77-
"sass-loader": "^7.1.0",
78-
"ts-loader": "^5.3.3",
73+
"ts-jest": "^24.0.2",
74+
"tslint": "^5.16.0",
75+
"tslint-config-stoplight": "^1.2.0",
7976
"typescript": "3.4.2"
8077
},
8178
"lint-staged": {

src/components/JsonSchemaViewer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import * as React from 'react';
66
import { isSchemaViewerEmpty, renderSchema } from '../utils';
77
import { ISchemaTree, SchemaTree } from './SchemaTree';
88

9-
export interface IJsonSchemaViewer extends Omit<ISchemaTree, 'emptyText' | 'treeStore'> {
9+
import '../styles/main.scss';
10+
11+
export interface IJsonSchemaViewer extends Omit<ISchemaTree, 'treeStore'> {
1012
emptyText?: string;
1113
defaultExpandedDepth?: number;
1214
}

src/components/Type.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1+
import { Dictionary } from '@stoplight/types';
12
import * as cn from 'classnames';
23
import { JSONSchema4TypeName } from 'json-schema';
34
import * as React from 'react';
45
import { ITreeNodeMeta, JSONSchema4CombinerName } from '../types';
56

67
export interface IType {
7-
type: JSONSchema4TypeName | JSONSchema4CombinerName | '$ref';
8+
type: JSONSchema4TypeName | JSONSchema4CombinerName | 'binary' | '$ref';
89
subtype?: ITreeNodeMeta['subtype'];
910
}
1011

1112
export const Type: React.FunctionComponent<IType> = ({ children, type, subtype }) => {
1213
return (
13-
<span className={cn(TypeClasses[type])}>
14+
<span className={cn(PropertyTypeColors[type])}>
1415
{type === 'array' && subtype && subtype !== 'array' ? `array[${subtype}]` : type}
1516
{children}
1617
</span>
1718
);
1819
};
1920

20-
const TypeClasses = {
21+
export const PropertyTypeColors: Dictionary<string, IType['type']> = {
2122
object: 'text-blue-6',
23+
any: 'text-blue-5',
2224
array: 'text-green-6',
2325
allOf: 'text-orange-5',
2426
oneOf: 'text-orange-5',

src/components/__tests__/JsonSchemaViewer.spec.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import { shallow } from 'enzyme';
22
import 'jest-enzyme';
33
import { JSONSchema4 } from 'json-schema';
44
import * as React from 'react';
5-
import { isSchemaViewerEmpty } from '../../utils';
6-
import { MutedText } from '../common/MutedText';
7-
import { JsonSchemaViewer } from '../JsonSchemaViewer';
8-
import { SchemaTree } from '../SchemaTree';
95

10-
jest.mock('../../theme');
11-
jest.mock('../../utils/isSchemaViewerEmpty');
6+
import { JSONSchema4 } from 'json-schema';
7+
import { JsonSchemaViewer, SchemaTree } from '../components';
8+
import { isSchemaViewerEmpty } from '../utils/isSchemaViewerEmpty';
9+
10+
jest.mock('../utils/isSchemaViewerEmpty');
1211

13-
const schema = {
12+
const schema: JSONSchema4 = {
1413
properties: {
1514
data: {
1615
items: {
@@ -32,15 +31,13 @@ describe('JSON Schema Viewer component', () => {
3231
(isSchemaViewerEmpty as jest.Mock).mockReturnValue(true);
3332
const wrapper = shallow(<JsonSchemaViewer schema={{}} />);
3433
expect(isSchemaViewerEmpty).toHaveBeenCalledWith({});
35-
expect(wrapper.find(MutedText)).toExist();
3634
expect(wrapper.find(SchemaTree)).not.toExist();
3735
});
3836

3937
test('should render SchemaView if schema is provided', () => {
4038
(isSchemaViewerEmpty as jest.Mock).mockReturnValue(false);
4139
const wrapper = shallow(<JsonSchemaViewer schema={schema as JSONSchema4} />);
4240
expect(isSchemaViewerEmpty).toHaveBeenCalledWith(schema);
43-
expect(wrapper.find(MutedText)).not.toExist();
4441
expect(wrapper.find(SchemaTree)).toExist();
4542
});
4643
});

src/components/__tests__/Type.spec.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { shallow } from 'enzyme';
22
import 'jest-enzyme';
33
import * as React from 'react';
4-
import { Type } from '../Type';
5-
6-
jest.mock('../../theme');
4+
import { IType, PropertyTypeColors, Type } from '../Type';
75

86
describe('Type component', () => {
9-
it.each(['integer', 'number', 'string'])('should handle $s type', type => {
10-
const wrapper = shallow(<Type type={type} />);
7+
it.each(Object.keys(PropertyTypeColors))('should handle $s type', type => {
8+
const wrapper = shallow(<Type type={type as IType['type']} />);
119

1210
expect(wrapper).toHaveText(type);
1311
});

0 commit comments

Comments
 (0)