Skip to content

Commit 34263ca

Browse files
committed
feat: sync code
2 parents 2e5e9cf + 48b2766 commit 34263ca

Some content is hidden

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

42 files changed

+1636
-153671
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
node_modules
33
dist
44
coverage
5-
.DS_Store
5+
.DS_Store
6+
.yarn-error.log

.gitlab-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static-checking:
1717
stage: static-checking
1818
script:
1919
- yarn eslint
20-
- yarn prettier
20+
- yarn prettier --check # If you want autofix --write option
2121
- yarn stylelint
2222
only:
2323
- merge_requests

.prettierignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ dist
33
.history
44
node_modules
55
yarn.lock
6-
coverage
6+
coverage
7+
storybook-static

.yarnclean

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# test directories
2+
__tests__
3+
test
4+
tests
5+
powered-test
6+
7+
# asset directories
8+
docs
9+
doc
10+
website
11+
images
12+
assets
13+
14+
# examples
15+
example
16+
examples
17+
18+
# code coverage directories
19+
coverage
20+
.nyc_output
21+
22+
# build scripts
23+
Makefile
24+
Gulpfile.js
25+
Gruntfile.js
26+
27+
# configs
28+
appveyor.yml
29+
circle.yml
30+
codeship-services.yml
31+
codeship-steps.yml
32+
wercker.yml
33+
.tern-project
34+
.gitattributes
35+
.editorconfig
36+
.*ignore
37+
.eslintrc
38+
.jshintrc
39+
.flowconfig
40+
.documentup.json
41+
.yarn-metadata.json
42+
.travis.yml
43+
44+
# misc
45+
*.md

package.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build": "tsc --project tsconfig.build.json",
1313
"eslint": "eslint ./src/**/*.ts ./src/**/*.tsx",
1414
"stylelint": "stylelint ./src/**/*.scss",
15-
"prettier": "prettier --ignore-unknown --write . ",
15+
"prettier": "prettier --ignore-unknown .",
1616
"release": "standard-version",
1717
"web": "webpack serve --env prod --config ./build/web.js"
1818
},
@@ -33,7 +33,9 @@
3333
"monaco-editor": "^0.21.2",
3434
"rc-collapse": "^2.0.1",
3535
"rc-dialog": "^8.4.5",
36+
"rc-textarea": "^0.3.1",
3637
"rc-tree": "^3.10.0",
38+
"rc-util": "^5.5.0",
3739
"react": "^16.13.1",
3840
"react-dnd": "^9.3.4",
3941
"react-dnd-html5-backend": "^9.3.4",
@@ -47,12 +49,12 @@
4749
"devDependencies": {
4850
"@commitlint/cli": "^11.0.0",
4951
"@commitlint/config-conventional": "^11.0.0",
50-
"@storybook/addon-actions": "6.1.2",
51-
"@storybook/addon-knobs": "^6.1.2",
52-
"@storybook/addon-links": "6.1.2",
52+
"@storybook/addon-actions": "6.1.10",
53+
"@storybook/addon-knobs": "^6.1.10",
54+
"@storybook/addon-links": "6.1.10",
5355
"@storybook/addon-notes": "^5.3.21",
54-
"@storybook/addons": "6.1.2",
55-
"@storybook/react": "6.1.2",
56+
"@storybook/addons": "6.1.10",
57+
"@storybook/react": "6.1.10",
5658
"@types/jest": "^26.0.0",
5759
"@typescript-eslint/eslint-plugin": "^3.1.0",
5860
"@typescript-eslint/parser": "^3.1.0",
@@ -74,15 +76,15 @@
7476
"stylelint-config-sass-guidelines": "^7.1.0",
7577
"ts-jest": "^26.1.0",
7678
"ts-loader": "^7.0.5",
77-
"typescript": "^3.9.5",
79+
"typescript": "^4.0.5",
7880
"webpack-cli": "^4.0.0",
7981
"webpack-dev-server": "^3.11.0",
8082
"webpack-merge": "^5.2.0"
8183
},
8284
"husky": {
8385
"hooks": {
8486
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
85-
"pre-push": "prettier --ignore-unknown --check ."
87+
"pre-push": "yarn prettier --write"
8688
}
8789
},
8890
"config": {

src/common/className.ts

+44-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isEmpty } from 'loadsh';
12
import { APP_PREFIX } from 'mo/common/const';
23
/**
34
* This function help you prefix a css class name, default is molecule.
@@ -10,6 +11,47 @@ export function prefixClaName(name: string, prefix: string = APP_PREFIX) {
1011
return name ? `${prefix}-${name}` : '';
1112
}
1213

13-
export function classNames(...names) {
14-
return names.filter((name) => !!name).join(' ');
14+
export function classNames(...args) {
15+
if (isEmpty(args)) return;
16+
const classList: string[] = [];
17+
for (const arg of args) {
18+
if (!arg) continue;
19+
const argType = typeof arg;
20+
if (argType === 'string' || argType === 'number') {
21+
classList.push(`${arg}`);
22+
continue;
23+
}
24+
if (argType === 'object') {
25+
if (arg.toString !== Object.prototype.toString) {
26+
classList.push(arg.toString());
27+
continue;
28+
}
29+
for (const key in arg) {
30+
if (Object.hasOwnProperty.call(arg, key) && arg[key]) {
31+
classList.push(key);
32+
}
33+
}
34+
}
35+
}
36+
return classList.join(' ');
37+
}
38+
/**
39+
* Element names may consist of Latin letters, digits, dashes and underscores.
40+
* CSS class is formed as block name plus two underscores plus element name: .block__elem
41+
* @param block
42+
* @param element
43+
*/
44+
export function getBEMElement(block: string, element: string) {
45+
return `${block}__${element}`;
46+
}
47+
48+
/**
49+
* CSS class is formed as block’s or element’s name plus two dashes:
50+
* .block--mod or .block__elem--mod and .block--color-black with .block--color-red.
51+
* Spaces in complicated modifiers are replaced by dash.
52+
* @param blockOrElement
53+
* @param modifier
54+
*/
55+
export function getBEMModifier(blockOrElement: string, modifier: string) {
56+
return `${blockOrElement}--${modifier}`;
1557
}

src/common/css.ts

+21
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,24 @@
66
export function em2Px(em: number, fontSize: number): number {
77
return em * fontSize;
88
}
9+
10+
/**
11+
* Apply css content to workbench
12+
* @param styleSheetContent CSS sheet content
13+
* @param rulesClassName Style tag class Name
14+
*/
15+
export function applyStyleSheetRules(
16+
styleSheetContent: string,
17+
rulesClassName: string
18+
) {
19+
const themeStyles = document.head.getElementsByClassName(rulesClassName);
20+
if (themeStyles.length === 0) {
21+
const elStyle = document.createElement('style');
22+
elStyle.type = 'text/css';
23+
elStyle.className = rulesClassName;
24+
elStyle.innerHTML = styleSheetContent;
25+
document.head.appendChild(elStyle);
26+
} else {
27+
(<HTMLStyleElement>themeStyles[0]).innerHTML = styleSheetContent;
28+
}
29+
}

src/common/dom.ts

+4
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,7 @@ export function getPositionByPlacement(
126126
console.log('getPositionByPlacement', x, y);
127127
return { x, y };
128128
}
129+
130+
export function getAttr(domElement: HTMLElement, attr) {
131+
return domElement.getAttribute(attr) || '';
132+
}

src/common/event/eventEmitter.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ export class EventEmitter {
2121
}
2222
}
2323

24-
// TODO
25-
public unsubscribe() {}
24+
public unsubscribe(name: string | string[]) {
25+
if (Array.isArray(name)) {
26+
name.forEach((key: string) => {
27+
this._events.delete(key);
28+
});
29+
} else {
30+
this._events.delete(name);
31+
}
32+
}
2633

2734
public assignEvent<T>(name: string, callback: Function) {
2835
const event = this._events.get(name);

src/common/keyCodes.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const enum KeyCodes {
2+
ENTER = 'Enter',
3+
}

src/components/checkbox/checkbox.tsx

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import './style.scss';
2+
import * as React from 'react';
3+
import { ComponentProps } from 'react';
4+
import { prefixClaName, classNames, getBEMElement } from 'mo/common/className';
5+
6+
export interface ICheckbox extends ComponentProps<any> {
7+
id: string;
8+
value?: string;
9+
children?: ReactNode;
10+
onChange?(e: React.ChangeEvent, options?: ICheckbox): void;
11+
}
12+
13+
export const checkboxClassName = prefixClaName('checkbox');
14+
const checkboxLabelClassName = getBEMElement(checkboxClassName, 'label');
15+
const checkboxInputClassName = getBEMElement(checkboxClassName, 'input');
16+
17+
export function Checkbox(props: ICheckbox) {
18+
const { className, id, children, value, onChange, ...custom } = props;
19+
20+
const claNames = classNames(checkboxClassName, className);
21+
22+
const handleCheckboxChange = (e: React.ChangeEvent<HTMLInputElement>) => {
23+
onChange?.(e, { id, value: e.target.value });
24+
};
25+
26+
return (
27+
<div className={claNames} {...(custom as any)}>
28+
<input
29+
id={id}
30+
type="checkbox"
31+
className={checkboxInputClassName}
32+
value={value}
33+
onChange={handleCheckboxChange}
34+
></input>
35+
<label
36+
htmlFor={id}
37+
className={classNames(checkboxLabelClassName, 'codicon')}
38+
>
39+
{children}
40+
</label>
41+
</div>
42+
);
43+
}

src/components/checkbox/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './checkbox';

src/components/checkbox/style.scss

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@import 'mo/style/common';
2+
$checkbox: prefix('checkbox');
3+
4+
#{$checkbox} {
5+
user-select: none;
6+
7+
&__input {
8+
height: 0;
9+
visibility: hidden;
10+
width: 0;
11+
12+
&[type='checkbox']:checked + label::before {
13+
content: '\eab2';
14+
}
15+
}
16+
17+
&__label {
18+
cursor: pointer;
19+
outline: none;
20+
padding-left: 26px;
21+
position: relative;
22+
23+
&::before {
24+
border: 1px solid transparent;
25+
border-radius: 3px;
26+
box-sizing: border-box;
27+
content: ' ';
28+
display: inline-block;
29+
font: normal normal normal 16px/1 codicon;
30+
-webkit-font-smoothing: antialiased;
31+
-moz-osx-font-smoothing: grayscale;
32+
height: 18px;
33+
left: 0;
34+
outline: 1px solid transparent;
35+
position: absolute;
36+
text-align: center;
37+
text-decoration: none;
38+
text-rendering: auto;
39+
top: 0;
40+
user-select: none;
41+
width: 18px;
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)