mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-03 07:47:18 +00:00
Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3681622 * chore: remove unnecessary code * refactor: react-render using TypeScript * chore: build-script * refactor: editor-skeleton * refactor: designer * refactor: material-parser * refactor: editor-setters * refactor: js to ts for rax-provider Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3678180 * refactor: rax-provider * feat: add build command * chore: compilerOptions for rax-provider * refactor: JS to TS for Rax Renderer Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3678935 * refactor: rax-renderer * Merge remote-tracking branch 'origin/refactor/js-to-ts' into refactor/js2ts-rax-renderer * Merge remote-tracking branch 'origin/refactor/js-to-ts' into refactor/js2ts-rax-renderer * refactor: ts-nocheck * chore: ts compile error * fix: ts rootDir * fix: compile error * chore: using same tsconfig for rax component * refactor: ts compile rax-renderer && rax-provider * Merge remote-tracking branch 'origin/release/1.0.0' into refactor/js-to-ts # Conflicts: # packages/rax-render/src/utils/appHelper.js # packages/rax-render/src/utils/appHelper.ts # packages/utils/src/appHelper.ts * refactor: no JS file * refactor: remove lint * feat: add xima * feat: add eslint ignore * style: fix by lint * feat: lint command * fix: using the same eslint config * style: eslint settings * Merge remote-tracking branch 'origin/release/1.0.0' into refactor/code-style # Conflicts: # packages/plugin-event-bind-dialog/src/index.tsx # packages/plugin-source-editor/src/index.tsx # packages/runtime/src/core/container.ts # packages/runtime/src/core/provider.ts * Merge remote-tracking branch 'origin/release/1.0.0' into refactor/code-style # Conflicts: # packages/designer/src/document/document-model.ts # packages/designer/src/document/node/node-children.ts # packages/designer/src/document/node/props/prop.ts # packages/plugin-source-editor/src/index.tsx * fix: 修改dataSource items -> list * Merge remote-tracking branch 'origin/relase/1.0.0' into refactor/code-style # Conflicts: # packages/react-renderer/package.json * refactor: component-panel plugin-component-pane 代码规范化 Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3703771 * feat: support bizcomps * refactor: component-panel * style: eslint * Merge branch 'refactor/code-style' into fix/ducheng-source-style * style: code style * Merge branch 'fix/ducheng-source-style' into 'refactor/code-style' Code review title: Fix/ducheng source style Code review Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3705972 * style: for demo * style: for demo-server * style: for plugin-event-bind-dialog * style: for plugin-sample-preview * style: for plugin-undo-redo * style: plugin-variable-bind-dialog * style: types * style: for utils * Merge remote-tracking branch 'origin/release/1.0.0' into refactor/code-style # Conflicts: # packages/editor-setters/src/expression-setter/locale/snippets.ts # packages/editor-setters/src/json-setter/locale/snippets.ts # packages/editor-setters/src/locale/snippets.ts # packages/plugin-components-pane/package.json # packages/rax-render/src/hoc/compWrapper.tsx # packages/rax-render/src/utils/index.ts # packages/react-renderer/src/context/appContext.ts * style: editor-preset-general editor-preset-general 代码规范化 Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3707974 * style: editor-preset-general * fix: should set field * fix: should set field - demo-server * refactor(style): fix code style for designer refactor(style): fix code style for editor-core refactor(style): fix code style for editor-skeleton refactor(style): fix code style for react-simulator-renderer refactor(style): fix code style for rax-simulator-renderer * Merge branch 'refactor/lihao-code-style' into 'refactor/code-style' Code review title: refactor(style): fix code style for designer Code review description: refactor(style): fix code style for editor-core refactor(style): fix code style for editor-skeleton refactor(style): fix code style for react-simulator-renderer refactor(style): fix code style for rax-simulator-renderer Code review Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3709472 * style: react/no-multi-comp set to 0 for designer * style: ignore editor-prset-vision * style: fix for plugin-outline-pane * style: fix for rax-provider * style: react-provider * style: runtime * style: rax-render * Merge remote-tracking branch 'origin/release/1.0.0' into refactor/code-style # Conflicts: # packages/editor-setters/src/expression-setter/index.tsx # packages/plugin-source-editor/src/index.tsx # packages/plugin-source-editor/src/transform.ts * refactor: material parser code style 1. 修复eslint问题 2. instanceOf => any 3. 修复node类型解析失败问题 Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3716330 * refactor: material parser code style * refactor: code-generator code style 1. rax 出码合并 2. code style 修复 注:合并的代码中带了 datasource 的 Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3717159 * Merge branch 'feat/rax-code-generator' of gitlab.alibaba-inc.com:ali-lowcode/ali-lowcode-engine into feat/rax-code-generator # Conflicts: # packages/code-generator/src/generator/ProjectBuilder.ts # packages/code-generator/src/parser/SchemaParser.ts # packages/code-generator/src/plugins/component/rax/jsx.ts # packages/code-generator/src/plugins/project/constants.ts # packages/code-generator/src/plugins/project/framework/rax/plugins/packageJSON.ts # packages/code-generator/src/plugins/project/i18n.ts # packages/code-generator/src/publisher/disk/index.ts # packages/code-generator/src/publisher/disk/utils.ts # packages/code-generator/src/types/core.ts # packages/code-generator/src/types/schema.ts # packages/code-generator/src/utils/compositeType.ts # packages/code-generator/src/utils/nodeToJSX.ts * refactor: code-generator * Merge remote-tracking branch 'origin/refactor/code-style' into refactor/code-style-code-generator # Conflicts: # .vscode/launch.json * Revert "refactor: code-generator code style " This reverts commit ebc78e8788f83e8fda0e146758af43b878125c10. * chore: eslintrc && eslintignore * style: for plugin-source-editor * style: fix by eslint --fix * style: scripts/ * style: datasource-engine * feat: pre-commit * Merge branch 'refactor/code-style' of gitlab.alibaba-inc.com:ali-lowcode/ali-lowcode-engine into refactor/code-style # Conflicts: # .eslintignore # packages/code-generator/src/parser/SchemaParser.ts # packages/code-generator/src/plugins/component/rax/containerInitState.ts # packages/code-generator/src/plugins/component/rax/containerInjectDataSourceEngine.ts # packages/code-generator/src/plugins/component/rax/containerLifeCycle.ts # packages/code-generator/src/plugins/project/framework/rax/plugins/buildConfig.ts # packages/code-generator/src/utils/OrderedSet.ts # packages/code-generator/src/utils/ScopeBindings.ts # packages/code-generator/src/utils/expressionParser.ts # packages/code-generator/src/utils/schema.ts # packages/datasource-engine/src/core/DataSourceEngine.ts # packages/datasource-engine/src/core/RuntimeDataSource.ts # packages/datasource-engine/src/types/IRuntimeContext.ts # packages/datasource-engine/src/types/index.ts * refactor: code style code-generator 对 code style 分支上次合并的 code-generator 修改做了 revert 重新在 code style 分支基础上对代码样式做了修复 rax 合并分支会另行 fix 后向 release 分支提 MR Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3719702 * refactor: code style fix * style: for code-generator * Merge remote-tracking branch 'origin/release/1.0.0' into refactor/code-style # Conflicts: # packages/editor-skeleton/src/transducers/addon-combine.ts # packages/plugin-components-pane/package.json # packages/plugin-components-pane/src/components/base/index.tsx # packages/plugin-components-pane/src/components/component-list/index.tsx # packages/plugin-components-pane/src/i18n/index.ts # packages/plugin-components-pane/src/i18n/strings/index.ts # packages/plugin-components-pane/src/index.tsx # packages/plugin-event-bind-dialog/src/index.tsx # packages/plugin-source-editor/src/index.tsx # packages/plugin-source-editor/src/transform.ts * style: auto fix
243 lines
7.0 KiB
TypeScript
243 lines
7.0 KiB
TypeScript
import * as React from 'react';
|
|
import Animate from 'rc-animate';
|
|
import omit from 'omit.js';
|
|
import classNames from 'classnames';
|
|
import ScrollNumber from './ScrollNumber';
|
|
import { PresetColorTypes, PresetColorType, PresetStatusColorType } from '../_util/colors';
|
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
|
import { LiteralUnion } from '../_util/type';
|
|
|
|
export { ScrollNumberProps } from './ScrollNumber';
|
|
|
|
export interface BadgeProps {
|
|
/** Number to show in badge */
|
|
count?: React.ReactNode;
|
|
showZero?: boolean;
|
|
/** Max count to show */
|
|
overflowCount?: number;
|
|
/** whether to show red dot without number */
|
|
dot?: boolean;
|
|
style?: React.CSSProperties;
|
|
prefixCls?: string;
|
|
scrollNumberPrefixCls?: string;
|
|
className?: string;
|
|
status?: PresetStatusColorType;
|
|
color?: LiteralUnion<PresetColorType, string>;
|
|
text?: React.ReactNode;
|
|
offset?: [number | string, number | string];
|
|
title?: string;
|
|
}
|
|
|
|
function isPresetColor(color?: string): boolean {
|
|
return (PresetColorTypes as any[]).indexOf(color) !== -1;
|
|
}
|
|
|
|
export default class Badge extends React.Component<BadgeProps, any> {
|
|
static defaultProps = {
|
|
count: null,
|
|
showZero: false,
|
|
dot: false,
|
|
overflowCount: 99,
|
|
};
|
|
|
|
getNumberedDisplayCount() {
|
|
const { count, overflowCount } = this.props;
|
|
const displayCount =
|
|
(count as number) > (overflowCount as number) ? `${overflowCount}+` : count;
|
|
return displayCount as string | number | null;
|
|
}
|
|
|
|
getDisplayCount() {
|
|
const isDot = this.isDot();
|
|
// dot mode don't need count
|
|
if (isDot) {
|
|
return '';
|
|
}
|
|
return this.getNumberedDisplayCount();
|
|
}
|
|
|
|
getScrollNumberTitle() {
|
|
const { title, count } = this.props;
|
|
if (title) {
|
|
return title;
|
|
}
|
|
return typeof count === 'string' || typeof count === 'number' ? count : undefined;
|
|
}
|
|
|
|
getStyleWithOffset() {
|
|
const { offset, style } = this.props;
|
|
return offset
|
|
? {
|
|
right: -parseInt(offset[0] as string, 10),
|
|
marginTop: offset[1],
|
|
...style,
|
|
}
|
|
: style;
|
|
}
|
|
|
|
getBadgeClassName(prefixCls: string, direction = 'ltr') {
|
|
const { className, children } = this.props;
|
|
return classNames(className, prefixCls, {
|
|
[`${prefixCls}-status`]: this.hasStatus(),
|
|
[`${prefixCls}-not-a-wrapper`]: !children,
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
}) as string;
|
|
}
|
|
|
|
hasStatus(): boolean {
|
|
const { status, color } = this.props;
|
|
return !!status || !!color;
|
|
}
|
|
|
|
isZero() {
|
|
const numberedDisplayCount = this.getNumberedDisplayCount();
|
|
return numberedDisplayCount === '0' || numberedDisplayCount === 0;
|
|
}
|
|
|
|
isDot() {
|
|
const { dot } = this.props;
|
|
const isZero = this.isZero();
|
|
return (dot && !isZero) || this.hasStatus();
|
|
}
|
|
|
|
isHidden() {
|
|
const { showZero } = this.props;
|
|
const displayCount = this.getDisplayCount();
|
|
const isZero = this.isZero();
|
|
const isDot = this.isDot();
|
|
const isEmpty = displayCount === null || displayCount === undefined || displayCount === '';
|
|
return (isEmpty || (isZero && !showZero)) && !isDot;
|
|
}
|
|
|
|
renderStatusText(prefixCls: string) {
|
|
const { text } = this.props;
|
|
const hidden = this.isHidden();
|
|
return hidden || !text ? null : <span className={`${prefixCls}-status-text`}>{text}</span>;
|
|
}
|
|
|
|
renderDisplayComponent() {
|
|
const { count } = this.props;
|
|
const customNode = count as React.ReactElement<any>;
|
|
if (!customNode || typeof customNode !== 'object') {
|
|
return undefined;
|
|
}
|
|
return React.cloneElement(customNode, {
|
|
style: {
|
|
...this.getStyleWithOffset(),
|
|
...(customNode.props && customNode.props.style),
|
|
},
|
|
});
|
|
}
|
|
|
|
renderBadgeNumber(prefixCls: string, scrollNumberPrefixCls: string) {
|
|
const { status, count, color } = this.props;
|
|
|
|
const displayCount = this.getDisplayCount();
|
|
const isDot = this.isDot();
|
|
const hidden = this.isHidden();
|
|
|
|
const scrollNumberCls = classNames({
|
|
[`${prefixCls}-dot`]: isDot,
|
|
[`${prefixCls}-count`]: !isDot,
|
|
[`${prefixCls}-multiple-words`]:
|
|
!isDot && count && count.toString && count.toString().length > 1,
|
|
[`${prefixCls}-status-${status}`]: !!status,
|
|
[`${prefixCls}-status-${color}`]: isPresetColor(color),
|
|
});
|
|
|
|
let statusStyle: React.CSSProperties | undefined = this.getStyleWithOffset();
|
|
if (color && !isPresetColor(color)) {
|
|
statusStyle = statusStyle || {};
|
|
statusStyle.background = color;
|
|
}
|
|
|
|
return hidden ? null : (
|
|
<ScrollNumber
|
|
prefixCls={scrollNumberPrefixCls}
|
|
data-show={!hidden}
|
|
className={scrollNumberCls}
|
|
count={displayCount}
|
|
displayComponent={this.renderDisplayComponent()} // <Badge status="success" count={<Icon type="xxx" />}></Badge>
|
|
title={this.getScrollNumberTitle()}
|
|
style={statusStyle}
|
|
key="scrollNumber"
|
|
/>
|
|
);
|
|
}
|
|
|
|
renderBadge = ({ getPrefixCls, direction }: ConfigConsumerProps) => {
|
|
const {
|
|
prefixCls: customizePrefixCls,
|
|
scrollNumberPrefixCls: customizeScrollNumberPrefixCls,
|
|
children,
|
|
status,
|
|
text,
|
|
color,
|
|
...restProps
|
|
} = this.props;
|
|
const omitArr = [
|
|
'count',
|
|
'showZero',
|
|
'overflowCount',
|
|
'className',
|
|
'style',
|
|
'dot',
|
|
'offset',
|
|
'title',
|
|
];
|
|
|
|
const prefixCls = getPrefixCls('badge', customizePrefixCls);
|
|
const scrollNumberPrefixCls = getPrefixCls('scroll-number', customizeScrollNumberPrefixCls);
|
|
|
|
const scrollNumber = this.renderBadgeNumber(prefixCls, scrollNumberPrefixCls);
|
|
const statusText = this.renderStatusText(prefixCls);
|
|
|
|
const statusCls = classNames({
|
|
[`${prefixCls}-status-dot`]: this.hasStatus(),
|
|
[`${prefixCls}-status-${status}`]: !!status,
|
|
[`${prefixCls}-status-${color}`]: isPresetColor(color),
|
|
});
|
|
const statusStyle: React.CSSProperties = {};
|
|
if (color && !isPresetColor(color)) {
|
|
statusStyle.background = color;
|
|
}
|
|
|
|
// <Badge status="success" />
|
|
if (!children && this.hasStatus()) {
|
|
const styleWithOffset = this.getStyleWithOffset();
|
|
const statusTextColor = styleWithOffset && styleWithOffset.color;
|
|
return (
|
|
<span
|
|
{...omit(restProps, omitArr)}
|
|
className={this.getBadgeClassName(prefixCls, direction)}
|
|
style={styleWithOffset}
|
|
>
|
|
<span className={statusCls} style={statusStyle} />
|
|
<span style={{ color: statusTextColor }} className={`${prefixCls}-status-text`}>
|
|
{text}
|
|
</span>
|
|
</span>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<span {...omit(restProps, omitArr)} className={this.getBadgeClassName(prefixCls, direction)}>
|
|
{children}
|
|
<Animate
|
|
component=""
|
|
showProp="data-show"
|
|
transitionName={children ? `${prefixCls}-zoom` : ''}
|
|
transitionAppear
|
|
>
|
|
{scrollNumber}
|
|
</Animate>
|
|
{statusText}
|
|
</span>
|
|
);
|
|
};
|
|
|
|
render() {
|
|
return <ConfigConsumer>{this.renderBadge}</ConfigConsumer>;
|
|
}
|
|
}
|