Skip to content

Commit 14282cf

Browse files
committed
Initial setup with storybook
1 parent 07f65f9 commit 14282cf

21 files changed

+1261
-2
lines changed

.babelrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"presets": [
3+
["@babel/preset-env", {"modules": false}],
4+
"@babel/preset-react"
5+
],
6+
"plugins": [
7+
"react-hot-loader/babel",
8+
"@babel/plugin-syntax-dynamic-import"
9+
],
10+
"env": {
11+
"production": {
12+
"presets": ["minify"]
13+
},
14+
"test": {
15+
"presets": ["@babel/preset-env", "@babel/preset-react"]
16+
}
17+
}
18+
}

.storybook/addons.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@storybook/addon-storysource/register';

.storybook/config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { configure } from '@storybook/react';
2+
3+
// automatically import all files ending in *.stories.js
4+
const req = require.context('../stories', true, /\.stories\.js$/);
5+
function loadStories() {
6+
req.keys().forEach(filename => req(filename));
7+
}
8+
9+
configure(loadStories, module);

.storybook/webpack.config.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// you can use this file to add your custom webpack plugins, loaders and anything you like.
2+
// This is just the basic way to add additional webpack configurations.
3+
// For more information refer the docs: https://storybook.js.org/configurations/custom-webpack-config
4+
5+
// IMPORTANT
6+
// When you add this file, we won't add the default configurations which is similar
7+
// to "React Create App". This only has babel loader to load JavaScript.
8+
9+
const common = require('../config/webpack/common.js');
10+
11+
module.exports = Object.assign({}, common, {
12+
module: Object.assign({}, common.module, {
13+
rules: common.module.rules.concat([
14+
{
15+
test: /\.stories\.jsx?$/,
16+
loaders: [require.resolve('@storybook/addon-storysource/loader')],
17+
enforce: 'pre',
18+
}
19+
]),
20+
}),
21+
});

README.md

-2
This file was deleted.

config/webpack/common.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
require('typescript-require');
2+
3+
// shared config (dev and prod)
4+
const path = require('path');
5+
const { CheckerPlugin } = require('awesome-typescript-loader');
6+
7+
module.exports = {
8+
resolve: {
9+
extensions: ['.ts', '.tsx', '.js', '.jsx', 'index.ts', 'index.tsx', 'index.js', 'index.jsx'],
10+
alias: {
11+
'scss': path.join(__dirname, '..', '..', 'src', 'scss'),
12+
'components': path.join(__dirname, '..', '..', 'src', 'components', 'universal'),
13+
'pages': path.join(__dirname, '..', '..', 'src', 'components', 'pages'),
14+
'langs': path.join(__dirname, '..', '..', 'src', 'langs'),
15+
'routes': path.join(__dirname, '..', '..', 'src', 'routes'),
16+
'themes': path.join(__dirname, '..', '..', 'src', 'themes'),
17+
'modules': path.join(__dirname, '..', '..', 'src', 'modules'),
18+
'img': path.join(__dirname, '..', '..', 'src', 'assets', 'img')
19+
}
20+
},
21+
context: path.resolve(__dirname, '../../src'),
22+
module: {
23+
rules: [
24+
/*{
25+
test: /\.ts|\.tsx$/,
26+
enforce: 'pre',
27+
use: [
28+
{
29+
loader: 'tslint-loader',
30+
options: {
31+
configFile: 'tslint.json',
32+
typeCheck: true,
33+
tsConfigFile: 'tsconfig.json',
34+
emitErrors: true,
35+
failOnHint: true,
36+
fix: true
37+
}
38+
}
39+
]
40+
},*/
41+
{
42+
test: /\.js$/,
43+
use: ['babel-loader', 'source-map-loader'],
44+
exclude: /node_modules/,
45+
},
46+
{
47+
test: /\.tsx?$/,
48+
use: ['babel-loader', 'awesome-typescript-loader'],
49+
},
50+
{
51+
test: /\.css$/,
52+
use: ['style-loader', { loader: 'css-loader', options: { importLoaders: 1 } }],
53+
},
54+
{
55+
test: /\.(jpe?g|png|gif|svg)$/i,
56+
loaders: [
57+
'file-loader?hash=sha512&digest=hex&name=img/[hash].[ext]',
58+
'image-webpack-loader?bypassOnDebug&optipng.optimizationLevel=7&gifsicle.interlaced=false',
59+
],
60+
},
61+
],
62+
},
63+
plugins: [
64+
new CheckerPlugin(),
65+
],
66+
performance: {
67+
hints: false,
68+
},
69+
};

config/webpack/dev.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// development config
2+
const merge = require('webpack-merge');
3+
const webpack = require('webpack');
4+
const commonConfig = require('./common');
5+
6+
module.exports = merge(commonConfig, {
7+
mode: 'development',
8+
entry: [
9+
'react-hot-loader/patch', // activate HMR for React
10+
'webpack-dev-server/client?http://localhost:8080',// bundle the client for webpack-dev-server and connect to the provided endpoint
11+
'webpack/hot/only-dev-server', // bundle the client for hot reloading, only- means to only hot reload for successful updates
12+
'./index.tsx' // the entry point of our app
13+
],
14+
devServer: {
15+
hot: true, // enable HMR on the server
16+
inline: true,
17+
disableHostCheck: true,
18+
historyApiFallback: true
19+
},
20+
devtool: 'cheap-module-eval-source-map',
21+
plugins: [
22+
new webpack.HotModuleReplacementPlugin(), // enable HMR globally
23+
new webpack.NamedModulesPlugin(), // prints more readable module names in the browser console on HMR updates
24+
],
25+
output: {
26+
chunkFilename: '[name].bundle.js',
27+
},
28+
});

config/webpack/prod.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// production config
2+
const merge = require('webpack-merge');
3+
const {resolve} = require('path');
4+
5+
const TypedocWebpackPlugin = require('typedoc-webpack-plugin');
6+
7+
const commonConfig = require('./common');
8+
9+
module.exports = merge(commonConfig, {
10+
mode: 'production',
11+
entry: './index.tsx',
12+
output: {
13+
filename: 'js/bundle.[hash].min.js',
14+
chunkFilename: '[name].bundle.js',
15+
path: resolve(__dirname, '../../dist'),
16+
publicPath: '/',
17+
},
18+
devtool: 'source-map',
19+
plugins: [
20+
21+
],
22+
});

package.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "react-json-blinkforms",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"dependencies": {
7+
"styled-components": "^4.2.0"
8+
},
9+
"devDependencies": {
10+
"@babel/core": "^7.2.0",
11+
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
12+
"@babel/preset-env": "^7.4.2",
13+
"@babel/preset-react": "^7.0.0",
14+
"@storybook/addon-actions": "^5.0.5",
15+
"@storybook/addon-links": "^5.0.5",
16+
"@storybook/addon-storysource": "^5.0.5",
17+
"@storybook/addons": "^5.0.5",
18+
"@storybook/react": "^5.0.5",
19+
"@types/react": "^16.0.25",
20+
"awesome-typescript-loader": "^5.0.0",
21+
"babel-loader": "^8.0.5",
22+
"css-loader": "^2.1.1",
23+
"file-loader": "^3.0.1",
24+
"image-webpack-loader": "^4.6.0",
25+
"react-hot-loader": "^4.8.2",
26+
"source-map-loader": "^0.2.4",
27+
"style-loader": "^0.23.1",
28+
"typescript": "^3.2.1",
29+
"typescript-require": "^0.2.10"
30+
},
31+
"scripts": {
32+
"storybook": "start-storybook -p 6006",
33+
"build-storybook": "build-storybook"
34+
},
35+
"keywords": [],
36+
"author": "",
37+
"license": "MIT"
38+
}

src/compositeNodes.tsx

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import * as React from "react";
2+
3+
import {
4+
FormContext,
5+
Node,
6+
NodeAny,
7+
NodeOutputValue,
8+
NodeSchema,
9+
NodeState,
10+
} from "./schemaTypes";
11+
12+
export type NodeS = {
13+
[key: string]: NodeState<any>;
14+
};
15+
16+
export type NodeO = {
17+
[key: string]: NodeOutputValue<any>;
18+
};
19+
20+
export type ChildrenMap<T> = {
21+
[key: string]: T;
22+
};
23+
24+
export abstract class CompositeNode<O, M extends NodeSchema> extends Node<NodeS, O, M> {
25+
26+
abstract getChildrenMapFromSchema(): ChildrenMap<NodeSchema>;
27+
28+
abstract getCompositeOutput(output: NodeO): NodeOutputValue<O>;
29+
30+
renderComposite(context: FormContext, children: ChildrenMap<React.ReactNode>): React.ReactNode {
31+
return Object.values(children);
32+
}
33+
34+
resolveInitialState() {
35+
const initialState = {};
36+
Object.keys(this.getChildrenMapFromSchema()).forEach(key => {
37+
initialState[key] = null;
38+
});
39+
return initialState;
40+
}
41+
42+
getRawOutput() {
43+
const output = {};
44+
Object.keys(this.getChildrenMapFromSchema()).forEach(key => {
45+
output[key] = this.findChild(key).getOutput();
46+
});
47+
return this.getCompositeOutput(output);
48+
}
49+
50+
onChildStateChanged(state: NodeState<any>, source: NodeAny, originalSource?: NodeAny) {
51+
this.setState({
52+
[source.getTag()]: state,
53+
});
54+
}
55+
56+
resolveChildren() {
57+
const childrenMap: ChildrenMap<NodeSchema> = this.getChildrenMapFromSchema();
58+
59+
return Object.keys(childrenMap).map(key => {
60+
const child = this.resolveNode(childrenMap[key], this, this.getConfig());
61+
child.setTag(key);
62+
return child;
63+
});
64+
}
65+
66+
render(context: FormContext): React.ReactNode {
67+
const childrenMap: ChildrenMap<React.ReactNode> = {};
68+
69+
Object.keys(this.getChildrenMapFromSchema()).forEach((key: string, index: number) => {
70+
childrenMap[key] = this.findChild(key).render(context);
71+
});
72+
73+
return this.renderComposite(context, childrenMap);
74+
}
75+
}

src/defaultParserConfig.tsx

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { SchemaParserConfig } from "./schemaTypes";
2+
3+
import ObjectDefault from "./renderers/ObjectDefault";
4+
import StringDefault from "./renderers/StringDefault";
5+
6+
export const defaultParserConfig: SchemaParserConfig = {
7+
handlers: {
8+
ROOT: {
9+
default: null,
10+
},
11+
STRING: {
12+
default: StringDefault,
13+
},
14+
OBJECT: {
15+
default: ObjectDefault,
16+
},
17+
},
18+
rootState: null,
19+
rootSetState: () => {},
20+
rootSetContext: () => {},
21+
rootModifyContext: () => {},
22+
uidGenerator: null,
23+
uidGeneratorFactory: () => {
24+
let uid = 0;
25+
return () => {
26+
++uid;
27+
return uid;
28+
};
29+
},
30+
};

0 commit comments

Comments
 (0)