Skip to content

Commit 18bdea0

Browse files
author
adamhe(何方舟)
committed
init
0 parents  commit 18bdea0

File tree

811 files changed

+25476
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

811 files changed

+25476
-0
lines changed

.babelrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [
3+
"react",
4+
[
5+
"es2015", {
6+
loose: true
7+
}
8+
],
9+
"stage-0"
10+
],
11+
"plugins": [
12+
"syntax-dynamic-import"
13+
]
14+
}

.cilintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
"stopCommit": true,
3+
"ignore": [
4+
"*.js",
5+
"src/**/node_modules"
6+
]
7+
}

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_style = space
9+
indent_size = 4
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true

.eslintrc.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
module.exports = {
2+
"extends": "airbnb",
3+
"installedESLint": true,
4+
"parser": "babel-eslint",
5+
"env": {
6+
"browser": true,
7+
"node": true
8+
},
9+
"plugins": [
10+
"react",
11+
"jsx-a11y",
12+
"import"
13+
],
14+
"rules": {
15+
"indent": [
16+
"error",
17+
4,
18+
{
19+
"SwitchCase": 1
20+
}
21+
],
22+
"quote-props": "off",
23+
"max-len": "off",
24+
"semi": ["off", "never"],
25+
"prefer-template": "off",
26+
"no-unused-vars": "warn",
27+
"no-use-before-define": "off",
28+
"comma-dangle": "off",
29+
"no-param-reassign": "warn",
30+
"no-underscore-dangle": "off",
31+
"no-bitwise": "off",
32+
"class-methods-use-this": "warn",
33+
"no-unused-expressions": "warn",
34+
"keyword-spacing": "warn",
35+
"consistent-return": "off",
36+
"one-var": [
37+
"warn",
38+
"always"
39+
],
40+
"arrow-body-style": [
41+
"warn",
42+
"as-needed"
43+
],
44+
"space-before-function-paren": [
45+
"error",
46+
"never"
47+
],
48+
"no-trailing-spaces": [
49+
"error",
50+
{
51+
"skipBlankLines": true
52+
}
53+
],
54+
"import/no-absolute-path": "off",
55+
"import/extensions": "off",
56+
"import/no-unresolved": "off",
57+
"import/no-named-as-default-member": "off",
58+
"import/no-named-as-default": "off",
59+
"import/no-extraneous-dependencies": "warn",
60+
"react/prop-types": "off",
61+
"react/jsx-filename-extension": "off",
62+
"react/jsx-indent": [
63+
"error",
64+
4
65+
],
66+
"react/jsx-indent-props": [
67+
"error",
68+
4
69+
]
70+
}
71+
}

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*.*~
2+
*.swp
3+
*.swo
4+
.svn
5+
.DS_Store
6+
node_modules
7+
*.log
8+
*.cache
9+
lerna-debug.log
10+
storybook-static
11+
/dist
12+
/dev
13+
/public
14+
/packages/*/*/src-dist
15+
/packages/*/*/lib
16+
/packages/*/*/dist
17+
.idea
18+
./make

.storybook/now-design-ui/compose.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { setDefaults } from 'react-komposer';
2+
3+
let context;
4+
let actions;
5+
6+
export const setContext = (c) => {
7+
context = c;
8+
};
9+
10+
export const setActions = (a) => {
11+
actions = a;
12+
};
13+
14+
const compose = setDefaults({
15+
propsToWatch: [],
16+
pure: true,
17+
env: {
18+
context: () => context,
19+
actions: () => actions,
20+
},
21+
});
22+
23+
export default compose;

.storybook/now-design-ui/context.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function (reduxStore, domNode, provider) {
2+
return {
3+
reduxStore,
4+
domNode,
5+
provider,
6+
};
7+
}

.storybook/now-design-ui/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { createStore, combineReducers } from 'redux';
2+
import { createApp } from 'mantra-core';
3+
4+
import buildContext from './context.js';
5+
import shortcutsModule from './modules/shortcuts';
6+
import apiModule from './modules/api';
7+
import uiModule from './modules/ui';
8+
import { setContext, setActions } from './compose';
9+
10+
export class Provider {
11+
renderPreview(selectedKind, selectedStory, stories) { // eslint-disable-line no-unused-vars
12+
throw new Error('Provider.renderPreview() is not implemented!');
13+
}
14+
15+
handleAPI(api) { // eslint-disable-line no-unused-vars
16+
throw new Error('Provider.handleAPI() is not implemented!');
17+
}
18+
}
19+
20+
export default function (domNode, provider) {
21+
if (!(provider instanceof Provider)) {
22+
throw new Error('provider is not extended from the base Provider');
23+
}
24+
25+
const reducer = combineReducers({
26+
...shortcutsModule.reducers,
27+
...apiModule.reducers,
28+
...uiModule.reducers,
29+
});
30+
31+
const devTools = window.devToolsExtension && window.devToolsExtension();
32+
const reduxStore = createStore(reducer, devTools);
33+
34+
const context = buildContext(reduxStore, domNode, provider);
35+
const app = createApp(context);
36+
37+
app.loadModule(shortcutsModule);
38+
app.loadModule(apiModule);
39+
app.loadModule(uiModule);
40+
41+
setContext(context);
42+
setActions(app._bindContext(app.actions));
43+
44+
app.init();
45+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import keycode from 'keycode';
2+
3+
export const features = {
4+
FULLSCREEN: 1,
5+
DOWN_PANEL: 2,
6+
LEFT_PANEL: 3,
7+
SHORTCUTS_HELP: 4,
8+
ESCAPE: 5,
9+
NEXT_STORY: 6,
10+
PREV_STORY: 7,
11+
SEARCH: 8,
12+
DOWN_PANEL_IN_RIGHT: 9,
13+
};
14+
15+
export function isModifierPressed(e) {
16+
return (e.ctrlKey || e.keyCode === 91 || e.metaKey) && e.shiftKey;
17+
}
18+
19+
export default function handle(e) {
20+
if (e.keyCode === keycode('escape')) {
21+
// We don't need to preventDefault escape.
22+
// Just getting the event is enough for us.
23+
return features.ESCAPE;
24+
}
25+
26+
if (!isModifierPressed(e)) return false;
27+
28+
switch (e.keyCode) {
29+
case keycode('F'):
30+
e.preventDefault();
31+
return features.FULLSCREEN;
32+
case keycode('D'):
33+
e.preventDefault();
34+
return features.DOWN_PANEL;
35+
case keycode('L'):
36+
e.preventDefault();
37+
return features.LEFT_PANEL;
38+
case keycode('right'):
39+
e.preventDefault();
40+
return features.NEXT_STORY;
41+
case keycode('left'):
42+
e.preventDefault();
43+
return features.PREV_STORY;
44+
case keycode('P'):
45+
e.preventDefault();
46+
return features.SEARCH;
47+
case keycode('J'):
48+
e.preventDefault();
49+
return features.DOWN_PANEL_IN_RIGHT;
50+
default:
51+
return false;
52+
}
53+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import actions from '../api';
2+
import { expect } from 'chai';
3+
import sinon from 'sinon';
4+
import { types } from '../';
5+
const { describe, it } = global;
6+
7+
describe('manager.api.actions.api', () => {
8+
describe('setStories', () => {
9+
it('should dispatch related redux action', () => {
10+
const reduxStore = {
11+
dispatch: sinon.stub(),
12+
};
13+
const stories = [{ kind: 'aa', stories: [] }];
14+
15+
actions.setStories({ reduxStore }, stories);
16+
const action = reduxStore.dispatch.args[0][0];
17+
expect(action).to.deep.equal({
18+
type: types.SET_STORIES,
19+
stories,
20+
});
21+
});
22+
});
23+
24+
describe('selectStory', () => {
25+
it('should dispatch related redux action', () => {
26+
const reduxStore = {
27+
dispatch: sinon.stub(),
28+
};
29+
const kind = 'kkkind';
30+
const story = 'ssstory';
31+
32+
actions.selectStory({ reduxStore }, kind, story);
33+
const action = reduxStore.dispatch.args[0][0];
34+
expect(action).to.deep.equal({
35+
type: types.SELECT_STORY,
36+
kind,
37+
story,
38+
});
39+
});
40+
});
41+
42+
describe('jumpToStory', () => {
43+
it('should dispatch related redux action', () => {
44+
const reduxStore = {
45+
dispatch: sinon.stub(),
46+
};
47+
const direction = -1;
48+
49+
actions.jumpToStory({ reduxStore }, direction);
50+
const action = reduxStore.dispatch.args[0][0];
51+
expect(action).to.deep.equal({
52+
type: types.JUMP_TO_STORY,
53+
direction,
54+
});
55+
});
56+
});
57+
58+
describe('setOptions', () => {
59+
it('should dispatch related redux action', () => {
60+
const reduxStore = {
61+
dispatch: sinon.stub(),
62+
};
63+
const options = {};
64+
65+
actions.setOptions({ reduxStore }, options);
66+
const a = reduxStore.dispatch.args[0][0];
67+
expect(a).to.deep.equal({
68+
type: types.SET_OPTIONS,
69+
options,
70+
});
71+
});
72+
});
73+
74+
describe('setQueryParams', () => {
75+
it('should dispatch related redux action', () => {
76+
const reduxStore = {
77+
dispatch: sinon.stub(),
78+
};
79+
const customQueryParams = {
80+
foo: 'bar',
81+
};
82+
83+
actions.setQueryParams({ reduxStore }, customQueryParams);
84+
const a = reduxStore.dispatch.args[0][0];
85+
expect(a).to.deep.equal({
86+
type: types.SET_QUERY_PARAMS,
87+
customQueryParams,
88+
});
89+
});
90+
});
91+
});

0 commit comments

Comments
 (0)