Skip to content

Commit 9c38fee

Browse files
committed
feat: resolve conflicts
2 parents 421e78a + c162116 commit 9c38fee

26 files changed

+1007
-81
lines changed

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
"immutability-helper": "^3.1.1",
3232
"loadsh": "^0.0.4",
3333
"monaco-editor": "^0.21.2",
34-
"rc-collapse": "^2.0.1",
35-
"rc-textarea": "^0.3.1",
36-
"rc-tree": "^3.10.0",
37-
"rc-util": "^5.5.0",
34+
"rc-collapse": "~2.0.1",
35+
"rc-dialog": "8.2.1",
36+
"rc-textarea": "~0.3.1",
37+
"rc-tree": "~3.10.0",
38+
"rc-util": "~5.5.0",
3839
"react": "^16.13.1",
3940
"react-dnd": "^9.3.4",
4041
"react-dnd-html5-backend": "^9.3.4",

src/common/event/eventEmitter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class EventEmitter {
66
if (events && events.length > 0) {
77
// The log for development
88
events.forEach((callEvent) => {
9-
callEvent(args);
9+
callEvent(...args);
1010
});
1111
}
1212
}

src/common/utils.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export function cloneInstance<T>(origin: T) {
77
const prototypes = Object.getPrototypeOf(origin) || {};
88
Object.keys(prototypes).forEach((prop) => {
99
if (typeof prototypes[prop] === 'function') {
10-
console.log('bind:', prototypes[prop], origin);
1110
prototypes[prop].bind(origin);
1211
}
1312
});
@@ -16,6 +15,16 @@ export function cloneInstance<T>(origin: T) {
1615
...prototypes,
1716
};
1817
} catch (e) {
19-
console.error('cloneInstance error:', e);
18+
console.error('Function cloneInstance error:', e);
2019
}
2120
}
21+
22+
/**
23+
* Merge multiple functions to one function
24+
* @param funcs
25+
*/
26+
export function mergeFunctions(...funcs) {
27+
return function (...args) {
28+
funcs.filter((fn) => !!fn).forEach((fn) => fn?.(...args));
29+
};
30+
}

src/components/button/index.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@ import { classNames, getBEMModifier, prefixClaName } from 'mo/common/className';
44

55
type BtnSizeType = 'normal' | 'large';
66
export interface IButton extends React.ComponentProps<'a'> {
7-
/**
8-
* Default size is normal
9-
*/
7+
disabled?: boolean;
108
size?: BtnSizeType;
9+
onClick?(event: React.MouseEvent): void;
1110
}
1211

1312
const defaultButtonClassName = prefixClaName('btn');
1413
const normalButtonClassName = getBEMModifier(defaultButtonClassName, 'normal');
1514
const largeButtonClassName = getBEMModifier(defaultButtonClassName, 'large');
15+
const disableButtonClassName = getBEMModifier(
16+
defaultButtonClassName,
17+
'disabled'
18+
);
1619

1720
export function Button(props: React.PropsWithChildren<IButton>) {
1821
const { className, children, size = 'normal', ...custom } = props;
1922

23+
const disabled = props.disabled ? disableButtonClassName : null;
24+
2025
const sizeClassName =
2126
size === 'large' ? largeButtonClassName : normalButtonClassName;
2227

2328
const claNames = classNames(
29+
className,
2430
defaultButtonClassName,
2531
sizeClassName,
26-
className
32+
disabled
2733
);
2834

2935
return (

src/components/button/style.scss

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@
77
cursor: pointer;
88
display: flex;
99
justify-content: center;
10-
margin: 10px;
10+
margin: 4px 5px;
1111
outline-offset: 2px;
12+
padding: 4px 10px;
1213
text-align: center;
13-
width: 100%;
1414

1515
&--normal {
16-
padding: 4px;
16+
padding: 4px 15px;
1717
}
1818

1919
&--large {
2020
font-size: 16px;
21-
padding: 8px;
21+
padding: 8px 15px;
22+
}
23+
24+
&--disabled {
25+
cursor: not-allowed;
26+
opacity: 0.4;
27+
pointer-events: none;
2228
}
2329

2430
&:hover {

src/components/collapse/index.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as React from 'react';
22
import { useState } from 'react';
33
import RcCollapse, { Panel } from 'rc-collapse';
4-
import { CollapseProps } from 'rc-collapse/lib/interface';
54
import Toolbar from 'mo/components/toolbar';
65
import { Icon } from 'mo/components/icon';
76
import { prefixClaName, classNames } from 'mo/common/className';
@@ -10,7 +9,7 @@ import { IPanelItem } from 'mo/model/workbench/explorer';
109
interface IExpandProps {
1110
isActive?: boolean;
1211
}
13-
interface ICollapseProps extends CollapseProps {
12+
interface ICollapseProps {
1413
data?: IPanelItem[];
1514
className?: string;
1615
}
+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import * as React from 'react';
2+
import {
3+
classNames,
4+
getBEMElement,
5+
getBEMModifier,
6+
prefixClaName,
7+
} from 'mo/common/className';
8+
import Dialog, { IModalFuncProps } from './modal';
9+
import ActionButton from './actionButton';
10+
11+
interface ConfirmDialogProps extends IModalFuncProps {
12+
afterClose?: () => void;
13+
close: (...args: any[]) => void;
14+
actions?: React.ReactNode;
15+
}
16+
17+
export const confirmClassName = prefixClaName('confirm');
18+
const containerClassName = getBEMElement(confirmClassName, 'container');
19+
const indicatorClassName = getBEMElement(confirmClassName, 'indicator');
20+
const contentClassName = getBEMElement(confirmClassName, 'content');
21+
const messageClassName = getBEMElement(confirmClassName, 'message');
22+
const btnsClassName = getBEMElement(confirmClassName, 'btns');
23+
24+
const ConfirmDialog = (props: ConfirmDialogProps) => {
25+
const {
26+
actions,
27+
icon,
28+
onCancel,
29+
onOk,
30+
close,
31+
maskStyle,
32+
okText = 'delete',
33+
okButtonProps,
34+
cancelText = 'cancel',
35+
cancelButtonProps,
36+
bodyStyle,
37+
closable = true,
38+
className,
39+
okCancel,
40+
width = 520,
41+
style = {},
42+
mask = true,
43+
maskClosable = false,
44+
transitionName = 'zoom',
45+
maskTransitionName = 'fade',
46+
...resetProps
47+
} = props;
48+
49+
const confirmDescriperClassName = getBEMElement(
50+
confirmClassName,
51+
`${props.type}`
52+
);
53+
const classString = classNames(
54+
confirmClassName,
55+
confirmDescriperClassName,
56+
className
57+
);
58+
const cancelButton = okCancel && (
59+
<ActionButton
60+
actionFn={onCancel}
61+
closeModal={close}
62+
{...cancelButtonProps}
63+
>
64+
{cancelText}
65+
</ActionButton>
66+
);
67+
68+
return (
69+
<Dialog
70+
prefixCls={confirmClassName}
71+
className={classString}
72+
wrapClassName={classNames({
73+
[getBEMModifier(
74+
confirmClassName,
75+
'centered'
76+
)]: !!props.centered,
77+
})}
78+
onCancel={() => close({ triggerCancel: true })}
79+
title=""
80+
transitionName={transitionName}
81+
footer=""
82+
maskTransitionName={maskTransitionName}
83+
mask={mask}
84+
maskClosable={maskClosable}
85+
style={style}
86+
width={width}
87+
closable={closable}
88+
{...resetProps}
89+
>
90+
<div className={containerClassName} style={bodyStyle}>
91+
<div className={contentClassName}>
92+
<div className={indicatorClassName}> {icon} </div>
93+
<div className={messageClassName}>
94+
{props.title !== undefined && (
95+
<span
96+
className={getBEMModifier(
97+
messageClassName,
98+
'text'
99+
)}
100+
>
101+
{props.title}
102+
</span>
103+
)}
104+
<div
105+
className={getBEMModifier(
106+
messageClassName,
107+
'detail'
108+
)}
109+
>
110+
{props.content}
111+
</div>
112+
</div>
113+
</div>
114+
<div className={btnsClassName}>
115+
{actions === undefined ? (
116+
<>
117+
{cancelButton}
118+
{
119+
<ActionButton
120+
actionFn={onOk}
121+
closeModal={close}
122+
{...okButtonProps}
123+
>
124+
{okText}
125+
</ActionButton>
126+
}
127+
</>
128+
) : (
129+
actions
130+
)}
131+
</div>
132+
</div>
133+
</Dialog>
134+
);
135+
};
136+
137+
export default ConfirmDialog;
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import * as React from 'react';
2+
import { Button, IButton } from 'mo/components/button';
3+
export interface ActionButtonProps extends IButton {
4+
actionFn?: (...args: any[]) => any | PromiseLike<any>;
5+
closeModal: Function;
6+
}
7+
8+
const ActionButton: React.FC<ActionButtonProps> = (props) => {
9+
const clickedRef = React.useRef<boolean>(false);
10+
11+
const handlePromiseOnOk = (returnValueOfOnOk?: PromiseLike<any>) => {
12+
const { closeModal } = props;
13+
if (!returnValueOfOnOk || !returnValueOfOnOk.then) {
14+
return;
15+
}
16+
returnValueOfOnOk.then(
17+
(...args: any[]) => {
18+
closeModal(...args);
19+
},
20+
(e: Error) => {
21+
// eslint-disable-next-line no-console
22+
console.error(e);
23+
clickedRef.current = false;
24+
}
25+
);
26+
};
27+
28+
const onClick = () => {
29+
const { actionFn, closeModal } = props;
30+
if (clickedRef.current) {
31+
return;
32+
}
33+
clickedRef.current = true;
34+
if (!actionFn) {
35+
closeModal();
36+
return;
37+
}
38+
let returnValueOfOnOk;
39+
if (actionFn.length) {
40+
returnValueOfOnOk = actionFn(closeModal);
41+
clickedRef.current = false;
42+
} else {
43+
returnValueOfOnOk = actionFn();
44+
if (!returnValueOfOnOk) {
45+
closeModal();
46+
return;
47+
}
48+
}
49+
handlePromiseOnOk(returnValueOfOnOk);
50+
};
51+
52+
const { children, ...resetProps } = props;
53+
return (
54+
<Button onClick={onClick} {...resetProps}>
55+
{children}
56+
</Button>
57+
);
58+
};
59+
60+
export default ActionButton;

0 commit comments

Comments
 (0)