Skip to content

Commit 34263ca

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

42 files changed

Lines changed: 1636 additions & 153671 deletions

Some content is hidden

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

.gitignore

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 45 additions & 0 deletions
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

Lines changed: 10 additions & 8 deletions
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

Lines changed: 44 additions & 2 deletions
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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 9 additions & 2 deletions
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const enum KeyCodes {
2+
ENTER = 'Enter',
3+
}

0 commit comments

Comments
 (0)