Skip to content

Commit

Permalink
chore: check lint (#48)
Browse files Browse the repository at this point in the history
* chore: check lint

* chore: add missing type definition

* fix: undefined lineData in BlockGroup
  • Loading branch information
orzyyyy committed Apr 13, 2019
1 parent d154608 commit 655247e
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 139 deletions.
100 changes: 52 additions & 48 deletions package.json
@@ -1,48 +1,52 @@
{
"name": "mini-xmind",
"version": "1.1.3",
"scripts": {
"start": "nino go -e ./src/go",
"test": "nino test",
"build": "tsc && nino koei -c scripts/nino.koei.js",
"compile": "tsc && nino compile",
"codecov": "nino test -d",
"lint": "npx eslint .",
"prettier": "nino prettier",
"lint-staged": "lint-staged",
"backup": "npm config set registry=https://registry.npmjs.org && npm publish && npm config set registry=https://registry.npm.taobao.org",
"pub": "npm run build && npm run compile && git push origin master && npm publish",
"pre-deploy": "node scripts/copyCircleCiConfig.js",
"deploy": "npm run build && npm run pre-deploy && bash scripts/gh-pages.sh"
},
"description": "A tool to make mind-mapping easier",
"files": [
"lib",
"dist"
],
"license": "MIT",
"main": "lib/index",
"dependencies": {
"antd": "^3.16.2",
"react-draggable": "^3.2.1"
},
"devDependencies": {
"@types/classnames": "^2.2.7",
"@types/enzyme": "^3.9.1",
"@types/react": "^16.8.13",
"@types/react-dom": "^16.8.3",
"dekko": "^0.2.1",
"lint-staged": "^8.1.5",
"nino-cli": "^0.7.2",
"typescript": "^3.4.3"
},
"pre-commit": [
"lint-staged"
],
"lint-staged": {
"*.{ts,tsx}": [
"npm run prettier",
"git add"
]
}
}
{
"name": "mini-xmind",
"version": "1.1.3",
"scripts": {
"start": "nino go -e ./src/go",
"test": "nino test",
"build": "tsc && nino koei -c scripts/nino.koei.js",
"compile": "tsc && nino compile",
"codecov": "nino test -d",
"lint": "tslint -c tslint.json 'src/**/*.ts[x]'",
"prettier": "nino prettier",
"lint-staged": "lint-staged",
"backup": "npm config set registry=https://registry.npmjs.org && npm publish && npm config set registry=https://registry.npm.taobao.org",
"pub": "npm run build && npm run compile && git push origin master && npm publish",
"pre-deploy": "node scripts/copyCircleCiConfig.js",
"deploy": "npm run build && npm run pre-deploy && bash scripts/gh-pages.sh"
},
"description": "A tool to make mind-mapping easier",
"files": [
"lib",
"dist"
],
"license": "MIT",
"main": "lib/index",
"dependencies": {
"antd": "^3.16.2",
"react-draggable": "^3.2.1"
},
"devDependencies": {
"@types/classnames": "^2.2.7",
"@types/enzyme": "^3.9.1",
"@types/react": "^16.8.13",
"@types/react-dom": "^16.8.3",
"dekko": "^0.2.1",
"lint-staged": "^8.1.5",
"nino-cli": "^0.7.2",
"tslint": "^5.15.0",
"tslint-config-prettier": "^1.18.0",
"tslint-eslint-rules": "^5.4.0",
"tslint-react": "^4.0.0",
"typescript": "^3.4.3"
},
"pre-commit": [
"lint-staged"
],
"lint-staged": {
"*.{ts,tsx}": [
"npm run prettier",
"git add"
]
}
}
38 changes: 22 additions & 16 deletions src/canvas/core.tsx
Expand Up @@ -26,16 +26,9 @@ export interface CanvasState {
position: { x: number; y: number };
}

let dataCollector: any = {};
const dataCollector: any = {};

export default class Canvas extends Component<CanvasProps, CanvasState> {
state: CanvasState = {
blockProps: {},
linesProps: {},
tagProps: {},
position: { x: 0, y: 0 },
};

static defaultProps = {
style: {},
className: '',
Expand All @@ -50,7 +43,7 @@ export default class Canvas extends Component<CanvasProps, CanvasState> {
const data = nextProps.data || {};
// hack
// don't know why when change Input in TagGroup,
// it would return a event object that unexpected
// it would return an event object that unexpected
if (Object.keys(data).length > 4) {
return {
blockProps: dataCollector.BlockGroup,
Expand All @@ -60,23 +53,34 @@ export default class Canvas extends Component<CanvasProps, CanvasState> {
};
}
if (Object.keys(data).length !== 0) {
const { BlockGroup, TagGroup, LineGroup, CanvasPosition } = data;
const {
BlockGroup: blockProps,
TagGroup: tagProps,
LineGroup: linesProps,
CanvasPosition,
} = data;

let position = nextState.position;
if (position.x == 0 && position.y == 0 && CanvasPosition) {
if (position.x === 0 && position.y === 0 && CanvasPosition) {
position = CanvasPosition;
dataCollector['CanvasPosition'] = CanvasPosition;
dataCollector.CanvasPosition = CanvasPosition;
}

return {
blockProps: BlockGroup,
tagProps: TagGroup,
linesProps: LineGroup,
blockProps,
tagProps,
linesProps,
position,
};
}
return null;
}
state: CanvasState = {
blockProps: {},
linesProps: {},
tagProps: {},
position: { x: 0, y: 0 },
};

// to repaint Line instantly
handleBlockChange = (blockProps: any, linesProps: any) => {
Expand Down Expand Up @@ -107,7 +111,7 @@ export default class Canvas extends Component<CanvasProps, CanvasState> {
}
dragItem = dragItem ? JSON.parse(dragItem) : {};
const { value } = dragItem;
let { blockProps, tagProps, position } = this.state;
const { blockProps, tagProps, position } = this.state;
const { clientX, clientY } = e;
let defaultWidth = 100;
let defaultHeight = 80;
Expand All @@ -131,6 +135,8 @@ export default class Canvas extends Component<CanvasProps, CanvasState> {
};
this.setState({ tagProps });
break;
default:
break;
}
return {
x: clientX - defaultWidth / 2 - position.x,
Expand Down
1 change: 1 addition & 0 deletions src/demo/index.tsx
Expand Up @@ -52,6 +52,7 @@ export default class Demo extends Component<any, DemoState> {
};

useDebounce(data: any) {
// tslint:disable-next-line
console.log(data);
}

Expand Down
11 changes: 6 additions & 5 deletions src/line/LineTo.tsx
Expand Up @@ -34,6 +34,8 @@ export function parseAnchorText(value: string) {
return { y: 1 };
case 'right':
return { x: 1 };
default:
break;
}
return null;
}
Expand All @@ -60,11 +62,6 @@ export interface LineToState {
}

export default class LineTo extends Component<LineToProps, LineToState> {
state = {
offsetX: 0,
offsetY: 0,
};

static defaultProps = {
className: '',
style: {},
Expand All @@ -85,6 +82,10 @@ export default class LineTo extends Component<LineToProps, LineToState> {
}
return null;
}
state: LineToState = {
offsetX: 0,
offsetY: 0,
};

detect = () => {
const { from, to, offset = { x: 0, y: 0 } } = this.props;
Expand Down
57 changes: 24 additions & 33 deletions src/line/__tests__/SteppedLine.test.tsx
Expand Up @@ -16,43 +16,38 @@ describe('SteppedLine', () => {
);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('.line-core').length).toBe(3);
console.log(getTargetIndexProps(wrapper, 'Line', 0));
expect(getTargetIndexProps(wrapper, 'Line', 0)['orientation']).toBe(
expect(getTargetIndexProps(wrapper, 'Line', 0).orientation).toBe(
'vertical',
);
expect(getTargetIndexProps(wrapper, '.line-core', 0)['style'].left).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 0).style.left).toBe(
'1px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 0)['style'].top).toBe(
'1px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 0)['style'].width).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 0).style.top).toBe('1px');
expect(getTargetIndexProps(wrapper, '.line-core', 0).style.width).toBe(
'0.5px',
);

expect(getTargetIndexProps(wrapper, 'Line', 1)['orientation']).toBe(
expect(getTargetIndexProps(wrapper, 'Line', 1).orientation).toBe(
'vertical',
);
expect(getTargetIndexProps(wrapper, '.line-core', 1)['style'].left).toBe(
'0px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 1)['style'].top).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 1).style.left).toBe(
'0px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 1)['style'].width).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 1).style.top).toBe('0px');
expect(getTargetIndexProps(wrapper, '.line-core', 1).style.width).toBe(
'0.5px',
);

expect(getTargetIndexProps(wrapper, 'Line', 2)['orientation']).toBe(
expect(getTargetIndexProps(wrapper, 'Line', 2).orientation).toBe(
'vertical',
);
expect(getTargetIndexProps(wrapper, '.line-core', 2)['style'].left).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 2).style.left).toBe(
'0px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 2)['style'].top).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 2).style.top).toBe(
'0.5px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 2)['style'].width).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 2).style.width).toBe(
'1px',
);
});
Expand All @@ -64,42 +59,38 @@ describe('SteppedLine', () => {
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('.line-core').length).toBe(3);

expect(getTargetIndexProps(wrapper, 'Line', 0)['orientation']).toBe(
expect(getTargetIndexProps(wrapper, 'Line', 0).orientation).toBe(
'horizonal',
);
expect(getTargetIndexProps(wrapper, '.line-core', 0)['style'].left).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 0).style.left).toBe(
'1px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 0)['style'].top).toBe(
'1px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 0)['style'].width).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 0).style.top).toBe('1px');
expect(getTargetIndexProps(wrapper, '.line-core', 0).style.width).toBe(
'0.5px',
);

expect(getTargetIndexProps(wrapper, 'Line', 1)['orientation']).toBe(
expect(getTargetIndexProps(wrapper, 'Line', 1).orientation).toBe(
'horizonal',
);
expect(getTargetIndexProps(wrapper, '.line-core', 1)['style'].left).toBe(
'0px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 1)['style'].top).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 1).style.left).toBe(
'0px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 1)['style'].width).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 1).style.top).toBe('0px');
expect(getTargetIndexProps(wrapper, '.line-core', 1).style.width).toBe(
'0.5px',
);

expect(getTargetIndexProps(wrapper, 'Line', 2)['orientation']).toBe(
expect(getTargetIndexProps(wrapper, 'Line', 2).orientation).toBe(
'horizonal',
);
expect(getTargetIndexProps(wrapper, '.line-core', 2)['style'].left).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 2).style.left).toBe(
'0.5px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 2)['style'].top).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 2).style.top).toBe(
'-1px',
);
expect(getTargetIndexProps(wrapper, '.line-core', 2)['style'].width).toBe(
expect(getTargetIndexProps(wrapper, '.line-core', 2).style.width).toBe(
'2px',
);
});
Expand Down

0 comments on commit 655247e

Please sign in to comment.