更新 Schema 配置

This commit is contained in:
2betop 2020-09-09 11:23:41 +08:00
parent 5ae8fb6b85
commit 7b6d4943de
16 changed files with 180 additions and 45 deletions

View File

@ -9,6 +9,8 @@ import {ButtonToolbarSchema} from './renderers/ButtonToolbar';
import {CardSchema} from './renderers/Card';
import {CardsSchema} from './renderers/Cards';
import {FormSchema} from './renderers/Form';
import {CarouselSchema} from './renderers/Carousel';
import {ChartSchema} from './renderers/Chart';
// 每加个类型,这补充一下。
export type SchemaType =
@ -25,7 +27,9 @@ export type SchemaType =
| 'button-group'
| 'button-toolbar'
| 'card'
| 'cards';
| 'cards'
| 'carousel'
| 'chart';
export type SchemaObject =
| PageSchema
@ -38,7 +42,9 @@ export type SchemaObject =
| ButtonGroupSchema
| ButtonToolbarSchema
| CardSchema
| CardsSchema;
| CardsSchema
| CarouselSchema
| ChartSchema;
export type SchemaCollection = SchemaObject | Array<SchemaObject> | SchemaTpl;
@ -181,9 +187,9 @@ export type SchemaSchema = string;
*/
export type SchemaIcon = string;
export type TokenizeableString = string;
export type SchemaTokenizeableString = string;
export type SchemaUrlPath = TokenizeableString;
export type SchemaUrlPath = SchemaTokenizeableString;
export type SchemaTooltip =
| string
@ -199,6 +205,8 @@ export type SchemaTooltip =
content: string;
};
export type SchemaFunction = string | Function;
export interface BaseSchema {
$schema?: SchemaSchema;
type: SchemaType;

View File

@ -283,7 +283,7 @@ import {
SchemaReload,
SchemaTooltip,
SchemaTpl
} from '../Schemas';
} from '../Schema';
export interface ActionProps
extends ButtonSchema,

View File

@ -1,7 +1,7 @@
import {Renderer, RendererProps} from '../factory';
import React from 'react';
import Alert, {AlertProps} from '../components/Alert2';
import {BaseSchema, SchemaCollection} from '../Schemas';
import {BaseSchema, SchemaCollection} from '../Schema';
/**
* Alert https://baidu.gitee.io/amis/docs/components/alert

View File

@ -5,7 +5,7 @@ import {autobind} from '../utils/helper';
import {Icon} from '../components/icons';
import {resolveVariable} from '../utils/tpl-builtin';
import {filter} from '../utils/tpl';
import {BaseSchema, SchemaUrlPath} from '../Schemas';
import {BaseSchema, SchemaUrlPath} from '../Schema';
/**
* Audio https://baidu.gitee.io/amis/docs/components/audio

View File

@ -1,7 +1,7 @@
import React from 'react';
import ButtonGroup from './Form/ButtonGroup';
import {Renderer} from '../factory';
import {BaseSchema, SchemaClassName, SchemaExpression} from '../Schemas';
import {BaseSchema, SchemaClassName, SchemaExpression} from '../Schema';
import {ActionSchema} from './Action';
/**

View File

@ -1,6 +1,6 @@
import React from 'react';
import {Renderer, RendererProps} from '../factory';
import {BaseSchema} from '../Schemas';
import {BaseSchema} from '../Schema';
import {ActionSchema} from './Action';
/**

View File

@ -20,11 +20,11 @@ import {
SchemaExpression,
SchemaTpl,
SchemaUrlPath
} from '../Schemas';
} from '../Schema';
import {ActionSchema} from './Action';
/**
* Card https://baidu.gitee.io/amis/docs/components/card
* Card https://baidu.gitee.io/amis/docs/components/card
*/
export interface CardSchema extends BaseSchema {
/**

View File

@ -22,11 +22,11 @@ import {
SchemaExpression,
SchemaTpl,
TokenizeableString
} from '../Schemas';
} from '../Schema';
import {CardSchema} from './Card';
/**
* Card https://baidu.gitee.io/amis/docs/components/card
* Cards https://baidu.gitee.io/amis/docs/components/card
*/
export interface CardsSchema extends BaseSchema {
/**

View File

@ -13,6 +13,71 @@ import {
isArrayChildrenModified
} from '../utils/helper';
import {Icon} from '../components/icons';
import {BaseSchema, SchemaName, SchemaObject, SchemaTpl} from '../Schema';
/**
* Carousel https://baidu.gitee.io/amis/docs/components/carousel
*/
export interface CarouselSchema extends BaseSchema {
/**
*
*/
type: 'carousel';
/**
*
*/
auto?: boolean;
/**
*
*/
interval?: number;
/**
*
*/
duration?: number;
/**
*
*/
width?: number;
/**
*
*/
height?: number;
controlsTheme?: 'light' | 'dark';
/**
*
*/
placeholder?: string;
/**
*
*/
controls?: Array<'dots' | 'arrows'>;
/**
*
*/
animation?: 'fade' | 'slide';
/**
*
*/
itemSchema?: SchemaObject | SchemaTpl;
name?: SchemaName;
/**
*
*/
options?: Array<any>;
}
const animationStyles: {
[propName: string]: string;
@ -22,18 +87,8 @@ const animationStyles: {
[EXITING]: 'out'
};
export interface CarouselProps extends RendererProps {
className?: string;
auto?: boolean;
export interface CarouselProps extends RendererProps, CarouselSchema {
value?: any;
placeholder?: any;
width?: number;
height?: number;
controls: string[];
interval: number;
duration: number;
controlsTheme: 'light' | 'dark';
animation: 'fade' | 'slide';
}
export interface CarouselState {
@ -74,8 +129,8 @@ const defaultSchema = {
export class Carousel extends React.Component<CarouselProps, CarouselState> {
wrapperRef: React.RefObject<HTMLDivElement> = React.createRef();
intervalTimeout: NodeJS.Timer;
durationTimeout: NodeJS.Timer;
intervalTimeout: NodeJS.Timer | number;
durationTimeout: NodeJS.Timer | number;
static defaultProps: Pick<
CarouselProps,
@ -212,8 +267,8 @@ export class Carousel extends React.Component<CarouselProps, CarouselState> {
@autobind
clearAutoTimeout() {
clearTimeout(this.intervalTimeout);
clearTimeout(this.durationTimeout);
clearTimeout(this.intervalTimeout as number);
clearTimeout(this.durationTimeout as number);
}
renderDots() {
@ -293,8 +348,8 @@ export class Carousel extends React.Component<CarouselProps, CarouselState> {
width ? (carouselStyles.width = width + 'px') : '';
height ? (carouselStyles.height = height + 'px') : '';
const [dots, arrows] = [
controls.indexOf('dots') > -1,
controls.indexOf('arrows') > -1
controls!.indexOf('dots') > -1,
controls!.indexOf('arrows') > -1
];
const animationName = nextAnimation || animation;
@ -338,7 +393,7 @@ export class Carousel extends React.Component<CarouselProps, CarouselState> {
data,
isObject(option)
? option
: {item: option, [name]: option}
: {item: option, [name!]: option}
)
}
)}

View File

@ -12,18 +12,90 @@ import {isApiOutdated, isEffectiveApi} from '../utils/api';
import {ScopedContext, IScopedContext} from '../Scoped';
import {createObject} from '../utils/helper';
import Spinner from '../components/Spinner';
import {
BaseSchema,
SchemaApi,
SchemaExpression,
SchemaFunction,
SchemaName,
SchemaTokenizeableString
} from '../Schema';
import {ActionSchema} from './Action';
export interface ChartProps extends RendererProps {
/**
* Chart https://baidu.gitee.io/amis/docs/components/carousel
*/
export interface ChartSchema extends BaseSchema {
/**
* chart
*/
type: 'chart';
/**
*
*/
api?: SchemaApi;
/**
*
* @deprecated api sendOn
*/
initFetch?: boolean;
/**
*
* @deprecated api.sendOn
*/
initFetchOn?: SchemaExpression;
/**
* echart的config
*/
config?: any;
/**
*
*/
width?: number;
/**
*
*/
height?: number;
/**
*
*/
interval?: number;
name?: SchemaName;
/**
* style样式
*/
style?: {
[propName: string]: any;
};
dataFilter?: SchemaFunction;
source?: SchemaTokenizeableString;
/**
*
*/
clickAction?: ActionSchema;
/**
* true.
*/
replaceChartOption?: boolean;
}
export interface ChartProps extends RendererProps, ChartSchema {
chartRef?: (echart: any) => void;
onDataFilter?: (config: any, echarts: any) => any;
dataFilter?: string;
api?: Api;
source?: string;
config?: object;
initFetch?: boolean;
store: IServiceStore;
clickAction?: Action;
replaceChartOption: boolean;
}
export class Chart extends React.Component<ChartProps> {
static defaultProps: Partial<ChartProps> = {

View File

@ -35,7 +35,7 @@ import {isAlive} from 'mobx-state-tree';
import {asFormItem} from './Item';
import {SimpleMap} from '../../utils/SimpleMap';
import {trace} from 'mobx';
import {BaseSchema, SchemaApi, SchemaDefaultData} from '../../Schemas';
import {BaseSchema, SchemaApi, SchemaDefaultData} from '../../Schema';
import {ActionSchema} from '../Action';
/**

View File

@ -27,7 +27,7 @@ import {
SchemaApi,
SchemaExpression,
SchemaName
} from '../Schemas';
} from '../Schema';
import {SchemaRemark} from './Remark';
/**

View File

@ -6,7 +6,7 @@ import TooltipWrapper from '../components/TooltipWrapper';
import {filter} from '../utils/tpl';
import {themeable} from '../theme';
import {Icon} from '../components/icons';
import {BaseSchema, SchemaIcon, SchemaTpl} from '../Schemas';
import {BaseSchema, SchemaIcon, SchemaTpl} from '../Schema';
/**
*

View File

@ -4,7 +4,7 @@ import {filter} from '../utils/tpl';
import cx from 'classnames';
import {anyChanged} from '../utils/helper';
import {escapeHtml} from '../utils/tpl-builtin';
import {BaseSchema, SchemaTpl} from '../Schemas';
import {BaseSchema, SchemaTpl} from '../Schema';
/**
* tpl

View File

@ -1,4 +1,4 @@
import {SchemaApiObject} from './Schemas';
import {SchemaApiObject} from './Schema';
export interface ApiObject extends SchemaApiObject {
config?: {

View File

@ -419,7 +419,7 @@ export function pickValues(names: string, data: object) {
return ret;
}
export const resolveVariable = (path: string, data: any = {}): any => {
export const resolveVariable = (path?: string, data: any = {}): any => {
if (!path) {
return undefined;
}