2021-07-09 01:41:03 +08:00
|
|
|
import { containerDragResolve } from '../core/crossDrag';
|
|
|
|
import { containerFocusRemove } from '../core/focusHandler';
|
|
|
|
import { innerContainerDrag } from '../core/innerDrag';
|
|
|
|
import { NormalMarkLineRender } from '../core/markline';
|
|
|
|
import { IStoreData } from '../core/store/storetype';
|
|
|
|
import { wrapperMoveState } from './wrapperMove/event';
|
|
|
|
import { CSSProperties, PropsWithChildren, useMemo } from 'react';
|
|
|
|
import Blocks from './blocks';
|
|
|
|
import { containerResizer } from '../core/resizeHandler/containerResizer';
|
|
|
|
import React from 'react';
|
|
|
|
import UserConfig from '../config';
|
|
|
|
import styles from '../index.less';
|
|
|
|
import { getRealHeight } from '../core/transfer';
|
|
|
|
interface ContainerProps {
|
|
|
|
state: IStoreData;
|
|
|
|
context: 'edit' | 'preview';
|
|
|
|
config: UserConfig;
|
|
|
|
editContainerStyle?: CSSProperties;
|
|
|
|
previewContainerStyle?: CSSProperties;
|
|
|
|
}
|
|
|
|
function Container(props: PropsWithChildren<ContainerProps>) {
|
|
|
|
const { editContainerStyle, previewContainerStyle } = props;
|
2021-07-12 21:01:11 +08:00
|
|
|
const scaleState = props.config.getScaleState();
|
2021-07-09 01:41:03 +08:00
|
|
|
const transform = useMemo(() => {
|
|
|
|
if (props.context === 'edit') {
|
|
|
|
return `scale(${scaleState.value}) translate(${wrapperMoveState.needX}px, ${wrapperMoveState.needY}px)`;
|
|
|
|
} else {
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-07-12 21:01:11 +08:00
|
|
|
}, [props.context, scaleState]);
|
2021-07-09 01:41:03 +08:00
|
|
|
|
|
|
|
const bgColor = () => {
|
|
|
|
const isEdit = props.config.getStoreChanger().isEdit();
|
|
|
|
if (isEdit) {
|
|
|
|
return 'rgba(255,255,255,1)';
|
|
|
|
} else {
|
|
|
|
return props.state.globalState.containerColor;
|
|
|
|
}
|
|
|
|
};
|
2021-07-17 22:15:30 +08:00
|
|
|
|
2021-07-09 01:41:03 +08:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{props.context === 'edit' && (
|
|
|
|
<>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
height: `${props.state.container.height + 60}px`,
|
|
|
|
width: `${props.state.container.width}px`,
|
|
|
|
transform: `scale(${scaleState.value}) translate(${wrapperMoveState.needX}px, ${wrapperMoveState.needY}px)`,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div style={{ display: 'flex' }}>
|
|
|
|
<div
|
|
|
|
id="yh-container"
|
|
|
|
className={styles.yh_container}
|
|
|
|
style={{
|
|
|
|
height: `${props.state.container.height}px`,
|
|
|
|
width: `${props.state.container.width}px`,
|
|
|
|
backgroundColor: bgColor(),
|
|
|
|
position: 'relative',
|
|
|
|
overflow: 'hidden',
|
2022-01-04 12:15:09 +08:00
|
|
|
cursor: 'default',
|
2021-07-09 01:41:03 +08:00
|
|
|
...editContainerStyle,
|
|
|
|
}}
|
2021-07-12 21:01:11 +08:00
|
|
|
{...(props.context === 'edit' ? containerDragResolve(props.config) : null)}
|
|
|
|
{...(props.context === 'edit' ? innerContainerDrag(props.config) : null)}
|
|
|
|
{...(props.context === 'edit' ? containerFocusRemove(props.config) : null)}
|
2021-07-09 01:41:03 +08:00
|
|
|
>
|
2021-07-12 21:01:11 +08:00
|
|
|
{props.context === 'edit' && (
|
2021-07-27 15:38:29 +08:00
|
|
|
<NormalMarkLineRender config={props.config} iframe={false}></NormalMarkLineRender>
|
2021-07-12 21:01:11 +08:00
|
|
|
)}
|
2021-07-09 01:41:03 +08:00
|
|
|
{props.state.block.map((v) => {
|
|
|
|
return (
|
|
|
|
<Blocks
|
|
|
|
config={props.config}
|
|
|
|
key={v.id}
|
|
|
|
data={v}
|
|
|
|
context={props.context}
|
|
|
|
></Blocks>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
height: '50px',
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
width: `${props.state.container.width}px`,
|
|
|
|
}}
|
|
|
|
>
|
2021-07-16 20:30:47 +08:00
|
|
|
<div
|
2021-07-09 01:41:03 +08:00
|
|
|
style={{ fontSize: '20px', cursor: 's-resize' }}
|
2021-07-16 20:30:47 +08:00
|
|
|
onMouseDown={(e) => containerResizer.onMousedown(e, props.config)}
|
|
|
|
>
|
|
|
|
{props.config.getConfig().containerIcon}
|
|
|
|
</div>
|
2021-07-09 01:41:03 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{props.context === 'preview' && (
|
|
|
|
<div
|
|
|
|
id="yh-container-preview"
|
|
|
|
className={styles.yh_container_preview}
|
|
|
|
style={{
|
|
|
|
height: `${getRealHeight(props.state.container.height)}px`,
|
|
|
|
width: `100%`,
|
|
|
|
position: 'relative' as 'absolute' | 'relative',
|
|
|
|
overflow: 'hidden',
|
|
|
|
backgroundColor: bgColor(),
|
|
|
|
transform: transform,
|
|
|
|
...previewContainerStyle,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{props.state.block.map((v) => {
|
|
|
|
return (
|
|
|
|
<Blocks key={v.id} config={props.config} data={v} context={props.context}></Blocks>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
export default Container;
|