Skip to content

Commit

Permalink
fix: 简化 Block 配置时的变量名
Browse files Browse the repository at this point in the history
  • Loading branch information
limaofeng committed Aug 26, 2021
1 parent e35d5b0 commit 7c2c54e
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 2,158 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"react-use": "^17.2.4",
"rollup-plugin-postcss": "^4.0.0",
"size-limit": "^5.0.1",
"sunmao": "^0.2.2",
"sunmao": "^0.2.4",
"tailwindcss": "npm:@tailwindcss/postcss7-compat",
"tsdx": "^0.14.1",
"tslib": "^2.3.0",
Expand Down
6 changes: 3 additions & 3 deletions src/components/aside/ConfigurationToolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Popover } from 'antd';
import React, { useCallback, useRef } from 'react';
import { ICustomizer } from 'sunmao';

import { ComponentPropertyType } from 'sunmao';
import { useDispatch, useSelector } from '../../hooks';
import FormPanel from '../../properties/DynaActionForm';
import { ActionType, UIActionType } from '../../reducers/actions';
Expand Down Expand Up @@ -47,12 +47,12 @@ function EditableZoom() {

function Guides() {
const ruler = useSelector((state) => state.features.ruler);
const customizer = useRef({
const customizer = useRef<ICustomizer>({
fields: [
{
name: 'ruler',
label: '标尺',
type: ComponentPropertyType.Boolean,
type: 'Boolean',
},
],
});
Expand Down
7 changes: 2 additions & 5 deletions src/components/scena/viewport/ScreenViewport.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CheckOutlined, DownOutlined } from '@ant-design/icons';
import { InputNumber, Popover } from 'antd';
import classnames from 'classnames';
import { isEqual } from 'lodash-es';
Expand Down Expand Up @@ -45,7 +44,7 @@ export function DeviceList(props: DeviceListProps) {
<ul>
{item.children.map((device: DeviceScreen) => (
<li key={device.id} onClick={handleClick(device)}>
{value.id === device.id && <CheckOutlined />}
{value.id === device.id && 'CheckOutlined'}
<span className="device-name">{device.name}</span>
<span className="device-size">{device.size.join('x')}</span>
</li>
Expand Down Expand Up @@ -122,9 +121,7 @@ function DeviceScreenPicker() {
</>
)}
</div>
<span className="screen-picker-more">
<DownOutlined />
</span>
<span className="screen-picker-more">DownOutlined</span>
</div>
</Popover>
<div className="screen-size">
Expand Down
12 changes: 6 additions & 6 deletions src/properties/DynaActionForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import classnames from 'classnames';
import isEqual from 'lodash/isEqual';
import React, { useEffect, useState } from 'react';
import { ComponentPropertyRendererSetting, ComponentPropertyType, IComponentProperty, IGroup, useSunmao } from 'sunmao';
import { ComponentPropertyRendererSetting, ICustomizer, IField, IGroup, useSunmao } from 'sunmao';

import { DEFAULT_GROUP_ID, ICustomizer } from '../typings';
import { DEFAULT_GROUP_ID } from '../typings';
import FormField from './FormField';
import FormFieldset from './FormFieldset';
import { useFormSelector, useFormState } from './FormStateContext';
Expand All @@ -19,7 +19,7 @@ interface DynaActionFormProps {

interface FormItemWrapperProps {
component: React.ComponentType<any>;
field: IComponentProperty;
field: IField;
defaultValue?: any;
size: string;
}
Expand Down Expand Up @@ -57,7 +57,7 @@ export const visibleFilter = (props: any) => {
interface PanelBodyProps {
group: string;
layout: 'Inline' | 'Stacked';
fields: IComponentProperty[];
fields: IField[];
value: any;
Form: any;
}
Expand All @@ -70,7 +70,7 @@ const PanelBody = (props: PanelBodyProps) => {
const { component, props = {} } = item.renderer as ComponentPropertyRendererSetting;
const ComponentForm = component as React.ComponentType<any>;
const lable = item.hiddenLabel ? '' : !item.multiple && item.label;
const valuePropName = item.type === ComponentPropertyType.Boolean ? 'checked' : undefined;
const valuePropName = item.type === 'Boolean' ? 'checked' : undefined;
return (
<Form.Item
key={`${group}-${item.name}`}
Expand All @@ -93,7 +93,7 @@ const PanelBody = (props: PanelBodyProps) => {
);
};

function getComponentClassName(item: IComponentProperty) {
function getComponentClassName(item: IField) {
if (typeof item.renderer.name === 'string') {
return `form-component-${item.renderer.name.toLowerCase()}`;
}
Expand Down
4 changes: 2 additions & 2 deletions src/properties/FormField.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import classnames from 'classnames';
import React from 'react';
import { IComponentProperty } from 'sunmao';
import { IField } from 'sunmao';

interface FormFieldProps {
field: IComponentProperty;
field: IField;
layout: 'Inline' | 'Stacked';
className?: string;
children: React.ReactElement;
Expand Down
7 changes: 1 addition & 6 deletions src/properties/combine/MultipleWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PlusOutlined } from '@ant-design/icons';
import React, { memo, useRef, useState } from 'react';

// import Sortable, { ISortableItem, SortableItemContentProps } from '../../sortable';
Expand Down Expand Up @@ -212,11 +211,7 @@ export function MultipleWrapper<T>(props: MultipleWrapperProps) {
<div className="multiple-wrapper">
<div className="multiple-wrapper-header">
<span className="title">{name || '多值配置'}</span>
{canAddItem && (
<a onClick={handleInsertRow}>
<PlusOutlined />
</a>
)}
{canAddItem && <a onClick={handleInsertRow}>PlusOutlined</a>}
</div>
{canSortItem ? (
{
Expand Down
6 changes: 3 additions & 3 deletions src/properties/combine/ObjectCombiner.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Form } from 'antd';
import { isEqual } from 'lodash-es';
import React, { useEffect } from 'react';
import { ComponentPropertyRendererSetting, ComponentPropertyType, IComponentProperty, useSunmao } from 'sunmao';
import { ComponentPropertyRendererSetting, useSunmao, IField } from 'sunmao';

import { FormItemWrapper, visibleFilter } from '../DynaActionForm';
import { getRenderer } from '../renderers';
Expand All @@ -10,7 +10,7 @@ interface ObjectCombinerProps {
value?: any;
onChange?: (value: any) => void;
className?: string;
fields: IComponentProperty[];
fields: IField[];
}

function ObjectCombiner(props: ObjectCombinerProps) {
Expand Down Expand Up @@ -38,7 +38,7 @@ function ObjectCombiner(props: ObjectCombinerProps) {
const { component, props = {} } = item.renderer as ComponentPropertyRendererSetting;
const ComponentForm = component as React.ComponentType<any>;
const lable = item.hiddenLabel ? '' : !item.multiple && item.label;
const valuePropName = item.type === ComponentPropertyType.Boolean ? 'checked' : undefined;
const valuePropName = item.type === 'Boolean' ? 'checked' : undefined;
return (
<Form.Item
className={`object-combiner-field-${item.name}`}
Expand Down
7 changes: 1 addition & 6 deletions src/properties/combine/WrapperComponentSelectItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { memo, MutableRefObject } from 'react';
import { CloseOutlined } from '@ant-design/icons';
import { IMultipleWrapperData } from './MultipleWrapper';
import { useReactComponent } from 'sunmao';
import { SortableHandler } from './WrapperItem';
Expand Down Expand Up @@ -35,11 +34,7 @@ function WrapperItem(props: WrapperItemProps) {
onChange({ ...data, componentId });
}}
/> */}
{canDelete && (
<a onClick={onDelete}>
<CloseOutlined />
</a>
)}
{canDelete && <a onClick={onDelete}>CloseOutlined</a>}
</div>
);
}
Expand Down
7 changes: 2 additions & 5 deletions src/properties/combine/WrapperItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CloseOutlined, EditOutlined } from '@ant-design/icons';
import Icon from '@asany/icons';
import { Checkbox, Input } from 'antd';
import React, { memo, MutableRefObject } from 'react';
Expand Down Expand Up @@ -91,15 +90,13 @@ function WrapperItem(props: WrapperItemProps) {

{canEdit && (
<a ref={itemRef} onClick={handleEditClick}>
<EditOutlined />
EditOutlined
</a>
)}
{canDelete && data.isPreset ? (
<Checkbox style={{ marginLeft: '6px' }} checked={!data.isDelete} onClick={onDelete} />
) : (
<a onClick={onDelete}>
<CloseOutlined />
</a>
<a onClick={onDelete}>CloseOutlined</a>
)}
</div>
</>
Expand Down
14 changes: 5 additions & 9 deletions src/properties/combine/WrapperPopoverContent.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React, { memo, useEffect, useState } from 'react';
import { CloseOutlined } from '@ant-design/icons';
import './style/WrapperPopoverContent.less';
import { IComponentProperty } from 'sunmao';
import { IField, ICustomizer } from 'sunmao';
import DynaActionForm from '../DynaActionForm';
import { ICustomizer } from '../../typings';

export interface PopoverFields<T> {
/** 传递 fields 或者 根据当前的 value 某些值获得 fields 的函数 */
fields: ((value: T) => IComponentProperty[]) | IComponentProperty[];
fields: ((value: T) => IField[]) | IField[];
}

export interface WrapperPopoverContentProps<T> extends PopoverFields<T> {
Expand All @@ -31,7 +29,7 @@ WrapperPopoverContent.defaultProps = {
function WrapperPopoverContent(props: WrapperPopoverContentProps<any>) {
const { contentRef, fields: fieldsProp, value, maxHeight, width, onClose, onChange } = props;

const [fields, setFields] = useState<IComponentProperty[]>([] as IComponentProperty[]);
const [fields, setFields] = useState<IField[]>([] as IField[]);

const [customizer, setCustomizer] = useState<ICustomizer>({
groups: [
Expand All @@ -45,7 +43,7 @@ function WrapperPopoverContent(props: WrapperPopoverContentProps<any>) {
});

useEffect(() => {
const currentFields: IComponentProperty[] = Array.isArray(fieldsProp) ? fieldsProp : fieldsProp(value);
const currentFields: IField[] = Array.isArray(fieldsProp) ? fieldsProp : fieldsProp(value);
setFields(currentFields);
setCustomizer({
groups: [
Expand All @@ -69,9 +67,7 @@ function WrapperPopoverContent(props: WrapperPopoverContentProps<any>) {
ref={contentRef}
>
<div className="popover-content__title">
<a onClick={onClose}>
<CloseOutlined />
</a>
<a onClick={onClose}>CloseOutlined</a>
</div>
{/* 使用 contentRef 中的组件
有弹出层的需要配置(如 select ) 基于 弹出层基于父组件而不是 body 上
Expand Down
28 changes: 9 additions & 19 deletions src/properties/renderers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { Radio, Select } from 'antd';
import React, { ComponentType } from 'react';
import Sunmao from 'sunmao';

import {
ComponentPropertyRenderer,
ComponentPropertyRendererSetting,
ComponentPropertyType,
IComponentProperty,
} from 'sunmao';
import { ComponentPropertyRenderer, ComponentPropertyRendererSetting, IField } from 'sunmao';
import MultipleWrapper from '../combine/MultipleWrapper';

const EmptyRenderer = () => <></>;
Expand All @@ -32,21 +27,16 @@ function crbc(component: ComponentType<any>, props: any = {}, name?: string) {
return { name, component: component || EmptyRenderer, props };
}

export function getDefaultRenderer(
sunmao: Sunmao,
library: string,
item: IComponentProperty
): ComponentPropertyRendererSetting {
export function getDefaultRenderer(sunmao: Sunmao, library: string, item: IField): ComponentPropertyRendererSetting {
switch (item.type) {
case ComponentPropertyType.Integer:
case 'Integer':
return cr(sunmao, `${library}.InputNumber`);
case ComponentPropertyType.Text:
case ComponentPropertyType.String:
case 'String':
return cr(sunmao, `${library}.Input`);
case ComponentPropertyType.Boolean:
case 'Boolean':
const comTemp = cr(sunmao, `${library}.Checkbox`);
return crbc(comTemp.component, { children: item.label }, comTemp.name);
case ComponentPropertyType.Enum:
case 'Enum':
const props: any = { style: { width: '100%' } };
if (item.enumeration) {
props.children = item.enumeration.values.map((v: any) => (
Expand All @@ -61,13 +51,13 @@ export function getDefaultRenderer(
}
}

function getBasisRenderer(sunmao: Sunmao, library: string, item: IComponentProperty): ComponentPropertyRenderer {
function getBasisRenderer(sunmao: Sunmao, library: string, item: IField): ComponentPropertyRenderer {
if (!item.renderer) {
return getDefaultRenderer(sunmao, library, item);
}
if (typeof item.renderer === 'string') {
switch (item.type) {
case ComponentPropertyType.Enum: // 枚举类型
case 'Enum': // 枚举类型
const props: any = { style: { width: '100%' } };
if (item.enumeration) {
props.children = item.enumeration.values.map((v: any) => (
Expand Down Expand Up @@ -95,7 +85,7 @@ function getBasisRenderer(sunmao: Sunmao, library: string, item: IComponentPrope
return crbc(item.renderer['component'] as any, item.renderer['props']);
}

export function getRenderer(sunmao: Sunmao, library: string, item: IComponentProperty): ComponentPropertyRenderer {
export function getRenderer(sunmao: Sunmao, library: string, item: IField): ComponentPropertyRenderer {
const render = getBasisRenderer(sunmao, library, item);
if (item.wrappers) {
if ((item as any).wrapperRender) {
Expand Down
31 changes: 0 additions & 31 deletions src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,9 @@ export interface IComponent {
props?: IComponentProperty[];
}

export interface IFieldGroup {
id: string;
name?: string;
visible?: boolean | VisibleFunc;
layout?: 'Inline' | 'Stacked';
}

export const DEFAULT_GROUP_ID = 'DEFAULT';
export const DEFAULT_TABPANE_ID = 'DEFAULT';

export interface ITabPane {
name: string;
visible?: boolean | VisibleFunc;
groups: string[] | IFieldGroup[];
customizer?: ICustomizer;
}

export interface ICustomizer {
/**
* 展示画框详情
*/
frame?: boolean;
dynamic?: boolean;
tabs?: ITabPane[];
/**
* 字段分组设置
*/
groups?: IFieldGroup[];
/**
* 配置字段
*/
fields: IComponentProperty[];
}

/**
* 工具位置: 头部左边, 头部右边, 左边头部, 左边底部
*/
Expand Down
11 changes: 4 additions & 7 deletions src/utils/BlockAside.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react';
import React, { useContext, useRef } from 'react';
import { ICustomizer, IFieldGroup } from 'sunmao';

// import DynaActionForm from '../../library-manager/DynaActionForm';
// import { ComponentPropertyType } from '../../library-manager/typings';

import FormPanel from '../properties/DynaActionForm';
// import { useSelector } from '../hooks';
import CurrentElementInformation from '../properties/CurrentElementInformation';
import { AsideTabPane, ComponentPropertyType, DEFAULT_GROUP_ID, ICustomizer, IFieldGroup } from '../typings';
import FormPanel from '../properties/DynaActionForm';
import { AsideTabPane, DEFAULT_GROUP_ID } from '../typings';

export const DynaActionFormContext = React.createContext<any>({});

Expand Down Expand Up @@ -43,7 +40,7 @@ export function buildAside(customizer: ICustomizer, namespace?: string) {
name: 'rect',
group: 'DEFAULT-rect',
renderer: CurrentElementInformation,
type: ComponentPropertyType.JSON,
type: 'JSON',
});
}

Expand Down
Loading

0 comments on commit 7c2c54e

Please sign in to comment.