Files
dooring/packages/dooringx-example/src/plugin/formComponents/animateControl.tsx

365 lines
11 KiB
TypeScript
Raw Normal View History

2021-08-11 17:16:22 +08:00
import React, { useMemo } from 'react';
2021-08-09 14:39:49 +08:00
import { UserConfig, deepCopy, createUid } from 'dooringx-lib';
2021-08-06 21:41:31 +08:00
import { Col, Row, Select, InputNumber, Button } from 'antd';
2021-07-10 19:35:06 +08:00
import { FormMap, FormBaseType } from '../formTypes';
import { CreateOptionsRes } from 'dooringx-lib/dist/core/components/formTypes';
2021-08-06 21:41:31 +08:00
import { AnimateItem, IBlockType, IStoreData } from 'dooringx-lib/dist/core/store/storetype';
2021-07-10 19:35:06 +08:00
export interface FormAnimateControlType extends FormBaseType {}
interface AnimateControlProps {
data: CreateOptionsRes<FormMap, 'animateControl'>;
current: IBlockType;
config: UserConfig;
}
//类型待修改
const animateCategory: Record<string, string> = {
'': '无',
animate__bounce: 'bounce',
animate__flash: 'flash',
animate__pulse: 'pulse',
animate__rubberBand: 'rubberBand',
animate__shakeX: 'shakeX',
animate__shakeY: 'shakeY',
animate__headShake: 'headShake',
animate__swing: 'swing',
animate__tada: 'tada',
animate__wobble: 'wobble',
animate__jello: 'jello',
animate__heartBeat: 'heartBeat',
animate__backInDown: 'backInDown',
animate__backInLeft: 'backInLeft',
animate__backInRight: 'backInRight',
animate__backInUp: 'backInUp',
animate__backOutDown: 'backOutDown',
animate__backOutLeft: 'backOutLeft',
animate__backOutRight: 'backOutRight',
animate__backOutUp: 'backOutUp',
animate__bounceIn: 'bounceIn',
animate__bounceInDown: 'bounceInDown',
animate__bounceInLeft: 'bounceInLeft',
animate__bounceInRight: 'bounceInRight',
animate__bounceInUp: 'bounceInUp',
animate__bounceOut: 'bounceOut',
animate__bounceOutDown: 'bounceOutDown',
animate__bounceOutLeft: 'bounceOutLeft',
animate__bounceOutRight: 'bounceOutRight',
animate__bounceOutUp: 'bounceOutUp',
animate__fadeIn: 'fadeIn',
animate__fadeInDown: 'fadeInDown',
animate__fadeInDownBig: 'fadeInDownBig',
animate__fadeInLeft: 'fadeInLeft',
animate__fadeInLeftBig: 'fadeInLeftBig',
animate__fadeInRight: 'fadeInRight',
animate__fadeInRightBig: 'fadeInRightBig',
animate__fadeInUp: 'fadeInUp',
animate__fadeInUpBig: 'fadeInUpBig',
animate__fadeInTopLeft: 'fadeInTopLeft',
animate__fadeInTopRight: 'fadeInTopRight',
animate__fadeInBottomLeft: 'fadeInBottomLeft',
animate__fadeInBottomRight: 'fadeInBottomRight',
animate__fadeOut: 'fadeOut',
animate__fadeOutDown: 'fadeOutDown',
animate__fadeOutDownBig: 'fadeOutDownBig',
animate__fadeOutLeft: 'fadeOutLeft',
animate__fadeOutLeftBig: 'fadeOutLeftBig',
animate__fadeOutRight: 'fadeOutRight',
animate__fadeOutRightBig: 'fadeOutRightBig',
animate__fadeOutUp: 'fadeOutUp',
animate__fadeOutUpBig: 'fadeOutUpBig',
animate__fadeOutTopLeft: 'fadeOutTopLeft',
animate__fadeOutTopRight: 'fadeOutTopRight',
animate__fadeOutBottomRight: 'fadeOutBottomRight',
animate__fadeOutBottomLeft: 'fadeOutBottomLeft',
animate__flip: 'flip',
animate__flipInX: 'flipInX',
animate__flipInY: 'flipInY',
animate__flipOutX: 'flipOutX',
animate__flipOutY: 'flipOutY',
animate__lightSpeedInRight: 'lightSpeedInRight',
animate__lightSpeedInLeft: 'lightSpeedInLeft',
animate__lightSpeedOutRight: 'lightSpeedOutRight',
animate__lightSpeedOutLeft: 'lightSpeedOutLeft',
animate__rotateIn: 'rotateIn',
animate__rotateInDownLeft: 'rotateInDownLeft',
animate__rotateInDownRight: 'rotateInDownRight',
animate__rotateInUpLeft: 'rotateInUpLeft',
animate__rotateInUpRight: 'rotateInUpRight',
animate__rotateOut: 'rotateOut',
animate__rotateOutDownLeft: 'rotateOutDownLeft',
animate__rotateOutDownRight: 'rotateOutDownRight',
animate__rotateOutUpLeft: 'rotateOutUpLeft',
animate__rotateOutUpRight: 'rotateOutUpRight',
animate__hinge: 'hinge',
animate__jackInTheBox: 'jackInTheBox',
animate__rollIn: 'rollIn',
animate__rollOut: 'rollOut',
animate__zoomIn: 'zoomIn',
animate__zoomInDown: 'zoomInDown',
animate__zoomInLeft: 'zoomInLeft',
animate__zoomInRight: 'zoomInRight',
animate__zoomInUp: 'zoomInUp',
animate__zoomOut: 'zoomOut',
animate__zoomOutDown: 'zoomOutDown',
animate__zoomOutLeft: 'zoomOutLeft',
animate__zoomOutRight: 'zoomOutRight',
animate__zoomOutUp: 'zoomOutUp',
animate__slideInDown: 'slideInDown',
animate__slideInLeft: 'slideInLeft',
animate__slideInRight: 'slideInRight',
animate__slideInUp: 'slideInUp',
animate__slideOutDown: 'slideOutDown',
animate__slideOutLeft: 'slideOutLeft',
animate__slideOutRight: 'slideOutRight',
};
2021-08-06 21:41:31 +08:00
const repeat = ['1', '2', '3', '4', '5', 'infinite'];
2021-07-10 19:35:06 +08:00
2021-08-09 14:39:49 +08:00
const timeFunction: Record<string, string> = {
2021-08-06 21:41:31 +08:00
: 'linear',
2022-01-28 18:05:29 +08:00
: 'ease-in',
2021-08-06 21:41:31 +08:00
};
2021-07-10 19:35:06 +08:00
2021-08-11 17:16:22 +08:00
let lastAnimate: AnimateItem[] = [];
let isOmit = false;
2022-01-26 18:04:46 +08:00
const padding = 10;
2021-08-11 17:16:22 +08:00
2021-08-06 21:41:31 +08:00
function AnimateControl(props: AnimateControlProps) {
const store = props.config.getStore();
2021-08-11 17:16:22 +08:00
const animate = useMemo(() => {
2021-08-16 11:35:04 +08:00
if (isOmit || props.config.waitAnimate) {
2021-08-11 17:16:22 +08:00
return lastAnimate;
}
lastAnimate = props.current.animate;
return props.current.animate;
}, [props.current.animate]);
2021-07-10 19:35:06 +08:00
return (
<>
2021-08-06 21:41:31 +08:00
{animate.map((v, i) => {
return (
2022-01-26 18:04:46 +08:00
<div key={v.uid} style={{ borderBottom: '1px dotted #9e9e9e' }}>
<Row style={{ padding: padding, alignItems: 'center' }}>
2021-08-09 14:39:49 +08:00
<Col span={5}>:</Col>
<Col span={7}>
<Select
value={animate[i].animationName}
style={{ width: '100%' }}
onChange={(d) => {
const cloneData: IStoreData = deepCopy(store.getData());
cloneData.block.forEach((w) => {
if (w.id === props.current.id) {
w.animate.forEach((f) => {
if (f.uid === v.uid) {
f.animationName = d;
}
});
}
});
store.setData(cloneData);
}}
>
2021-08-06 21:41:31 +08:00
{Object.keys(animateCategory).map((v, i) => {
return (
<Select.Option key={i} value={animateCategory[v]}>
{animateCategory[v]}
</Select.Option>
);
})}
</Select>
</Col>
2021-08-09 14:39:49 +08:00
<Col span={5} style={{ paddingLeft: '10px' }}>
:
</Col>
<Col span={7}>
<InputNumber
style={{ width: '100%' }}
2021-08-11 17:16:22 +08:00
step="0.1"
2021-08-09 14:39:49 +08:00
value={animate[i].animationDuration}
formatter={(value) => `${value}s`}
min={0}
onChange={(d) => {
const cloneData: IStoreData = deepCopy(store.getData());
cloneData.block.forEach((w) => {
if (w.id === props.current.id) {
w.animate.forEach((f) => {
if (f.uid === v.uid) {
f.animationDuration = d;
}
});
}
});
store.setData(cloneData);
}}
/>
2021-08-06 21:41:31 +08:00
</Col>
</Row>
2022-01-26 18:04:46 +08:00
<Row style={{ padding: padding, alignItems: 'center' }}>
2021-08-09 14:39:49 +08:00
<Col span={5}>:</Col>
<Col span={7}>
<InputNumber
style={{ width: '100%' }}
value={animate[i].animationDelay}
formatter={(value) => `${value}s`}
min={0}
2021-08-11 17:16:22 +08:00
step="0.1"
2021-08-09 14:39:49 +08:00
onChange={(d) => {
const cloneData: IStoreData = deepCopy(store.getData());
cloneData.block.forEach((w) => {
if (w.id === props.current.id) {
w.animate.forEach((f) => {
if (f.uid === v.uid) {
f.animationDelay = d;
}
});
}
});
store.setData(cloneData);
}}
/>
2021-08-06 21:41:31 +08:00
</Col>
2021-08-09 14:39:49 +08:00
<Col span={5} style={{ paddingLeft: '10px' }}>
:
</Col>
<Col span={7}>
<Select
value={animate[i].animationIterationCount}
style={{ width: '100%' }}
onChange={(d) => {
const cloneData: IStoreData = deepCopy(store.getData());
cloneData.block.forEach((w) => {
if (w.id === props.current.id) {
w.animate.forEach((f) => {
if (f.uid === v.uid) {
f.animationIterationCount = d;
}
});
}
});
store.setData(cloneData);
}}
>
2021-08-06 21:41:31 +08:00
{repeat.map((v, i) => {
return (
<Select.Option key={i} value={v}>
{v}
</Select.Option>
);
})}
</Select>
</Col>
</Row>
2022-01-26 18:04:46 +08:00
<Row style={{ padding: padding, alignItems: 'center' }}>
2021-08-09 14:39:49 +08:00
<Col span={5}>:</Col>
<Col span={7}>
<Select
value={animate[i].animationTimingFunction}
style={{ width: '100%' }}
onChange={(d) => {
const cloneData: IStoreData = deepCopy(store.getData());
cloneData.block.forEach((w) => {
if (w.id === props.current.id) {
w.animate.forEach((f) => {
if (f.uid === v.uid) {
f.animationTimingFunction = d;
}
});
}
});
store.setData(cloneData);
}}
>
{Object.keys(timeFunction).map((v, i) => {
2021-08-06 21:41:31 +08:00
return (
2021-08-09 14:39:49 +08:00
<Select.Option key={i} value={timeFunction[v]}>
2021-08-06 21:41:31 +08:00
{v}
</Select.Option>
);
})}
</Select>
</Col>
2021-08-09 14:39:49 +08:00
<Col style={{ justifyContent: 'flex-end', flex: 1, textAlign: 'end' }}>
2021-08-06 21:41:31 +08:00
<Button
danger
onClick={() => {
const cloneData: IStoreData = deepCopy(store.getData());
cloneData.block.map((v) => {
if (v.id === props.current.id) {
v.animate.splice(i, 1);
}
});
store.setData(cloneData);
}}
>
</Button>
</Col>
</Row>
</div>
);
})}
2021-07-10 19:35:06 +08:00
2022-01-26 18:04:46 +08:00
<Row style={{ padding: padding, justifyContent: 'space-around' }}>
2021-08-09 14:39:49 +08:00
{animate.length > 0 && (
<Button
2022-01-28 18:05:29 +08:00
onClick={async () => {
2021-08-11 17:16:22 +08:00
if (!isOmit) {
isOmit = true;
const cacheProps = animate;
2022-01-29 17:59:59 +08:00
await props.config.timelineNeedleConfig.resetFunc(false);
2021-08-16 11:35:04 +08:00
const data: IStoreData = deepCopy(store.getData());
2022-01-28 18:05:29 +08:00
props.config.waitAnimate = true;
2021-08-09 14:39:49 +08:00
data.block.forEach((v) => {
if (v.id === props.current.id) {
2021-08-11 17:16:22 +08:00
v.animate = [];
2021-08-09 14:39:49 +08:00
}
});
2022-01-29 17:59:59 +08:00
props.config.timelineNeedleConfig.status = 'pause';
2021-08-16 11:35:04 +08:00
store.setData(data);
2021-08-11 17:16:22 +08:00
setTimeout(() => {
2021-08-16 11:35:04 +08:00
const clone: IStoreData = deepCopy(store.getData());
clone.block.forEach((v) => {
2021-08-11 17:16:22 +08:00
if (v.id === props.current.id) {
v.animate = cacheProps;
}
});
isOmit = false;
2021-08-16 11:35:04 +08:00
props.config.waitAnimate = false;
2022-01-28 18:05:29 +08:00
props.config.timelineNeedleConfig.status = 'start';
2021-08-16 11:35:04 +08:00
store.setData(clone);
store.cleanLast();
2021-08-11 17:16:22 +08:00
});
}
2021-08-09 14:39:49 +08:00
}}
>
</Button>
)}
2021-08-06 21:41:31 +08:00
<Button
onClick={() => {
const cloneData: IStoreData = deepCopy(store.getData());
const newItem: AnimateItem = {
2021-08-09 14:39:49 +08:00
uid: createUid(),
animationName: 'bounce',
animationDelay: 0,
animationDuration: 1,
2021-08-06 21:41:31 +08:00
animationTimingFunction: 'linear',
2021-08-09 14:39:49 +08:00
animationIterationCount: '1',
2021-08-06 21:41:31 +08:00
};
2021-08-09 14:39:49 +08:00
cloneData.block.forEach((v) => {
2021-08-06 21:41:31 +08:00
if (v.id === props.current.id) {
v.animate.push(newItem);
2021-07-10 19:35:06 +08:00
}
2021-08-06 21:41:31 +08:00
});
store.setData(cloneData);
}}
>
</Button>
2021-07-10 19:35:06 +08:00
</Row>
</>
);
}
export default AnimateControl;