|
@@ -87,7 +87,6 @@ export interface DragactProps {
|
|
|
placeholder?: Boolean
|
|
|
|
|
|
style?: React.CSSProperties
|
|
|
-
|
|
|
}
|
|
|
|
|
|
export interface mapLayout {
|
|
@@ -115,6 +114,7 @@ export interface GridItemProvided {
|
|
|
}
|
|
|
|
|
|
export class Dragact extends React.Component<DragactProps, DragactState> {
|
|
|
+
|
|
|
constructor(props: DragactProps) {
|
|
|
super(props)
|
|
|
this.onDrag = this.onDrag.bind(this)
|
|
@@ -122,7 +122,6 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
|
|
|
this.onDragEnd = this.onDragEnd.bind(this)
|
|
|
|
|
|
const layout = props.layout;
|
|
|
-
|
|
|
this.state = {
|
|
|
GridXMoving: 0,
|
|
|
GridYMoving: 0,
|
|
@@ -136,6 +135,7 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
|
|
|
mapLayout: undefined
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
onResizeStart = (layoutItem: GridItemEvent) => {
|
|
|
const { GridX, GridY, w, h } = layoutItem
|
|
|
if (this.state.mapLayout) {
|
|
@@ -151,6 +151,7 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
|
|
|
dragType: 'resize'
|
|
|
})
|
|
|
}
|
|
|
+ this.props.onDragStart && this.props.onDragStart(layoutItem);
|
|
|
}
|
|
|
|
|
|
onResizing = (layoutItem: GridItemEvent) => {
|
|
@@ -181,7 +182,6 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
|
|
|
|
|
|
onDragStart(bundles: GridItemEvent) {
|
|
|
const { GridX, GridY, w, h } = bundles
|
|
|
-
|
|
|
if (this.state.mapLayout) {
|
|
|
this.setState({
|
|
|
GridXMoving: GridX,
|
|
@@ -194,12 +194,10 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
|
|
|
dragType: 'drag'
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
- this.props.onDragStart && this.props.onDragStart(bundles)
|
|
|
+ this.props.onDragStart && this.props.onDragStart(bundles);
|
|
|
}
|
|
|
|
|
|
onDrag(layoutItem: GridItemEvent) {
|
|
|
-
|
|
|
const { GridY, UniqueKey } = layoutItem;
|
|
|
const moving = GridY - this.state.GridYMoving;
|
|
|
|
|
@@ -216,18 +214,16 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
|
|
|
}
|
|
|
|
|
|
onDragEnd(layoutItem: GridItemEvent) {
|
|
|
-
|
|
|
const { compacted, mapLayout } = compactLayout(this.state.layout, undefined, this.state.mapLayout)
|
|
|
-
|
|
|
this.setState({
|
|
|
placeholderShow: false,
|
|
|
layout: compacted,
|
|
|
mapLayout: mapLayout,
|
|
|
containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1], this.state.containerHeight)
|
|
|
})
|
|
|
-
|
|
|
this.props.onDragEnd && this.props.onDragEnd(layoutItem);
|
|
|
}
|
|
|
+
|
|
|
renderPlaceholder() {
|
|
|
if (!this.state.placeholderShow) return null
|
|
|
var { col, width, padding, rowHeight, margin, placeholder } = this.props
|
|
@@ -276,8 +272,7 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
|
|
|
mapLayout
|
|
|
})
|
|
|
}
|
|
|
- }
|
|
|
- if (this.props.layout.length < nextProps.layout.length) {//add
|
|
|
+ } else if (this.props.layout.length < nextProps.layout.length) {//add
|
|
|
var item;
|
|
|
for (const idx in nextProps.layout) {
|
|
|
const i = nextProps.layout[idx];
|
|
@@ -300,18 +295,24 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
|
|
|
mapLayout
|
|
|
})
|
|
|
}
|
|
|
+ } else {
|
|
|
+ this.recalculateLayout(nextProps.layout, nextProps.col);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ recalculateLayout = (layout: DragactLayoutItem[], col: number) => {
|
|
|
+ const corrected = correctLayout(layout, col)
|
|
|
+ const { compacted, mapLayout } = compactLayout(corrected, undefined, undefined);
|
|
|
+ this.setState({
|
|
|
+ layout: compacted,
|
|
|
+ mapLayout: mapLayout,
|
|
|
+ containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1], this.state.containerHeight, false)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
componentDidMount() {
|
|
|
setTimeout(() => {
|
|
|
- let layout = correctLayout(this.state.layout, this.props.col)
|
|
|
- const { compacted, mapLayout } = compactLayout(layout, undefined, this.state.mapLayout);
|
|
|
- this.setState({
|
|
|
- layout: compacted,
|
|
|
- mapLayout: mapLayout,
|
|
|
- containerHeight: getMaxContainerHeight(compacted, this.props.rowHeight, this.props.margin[1], this.state.containerHeight, false)
|
|
|
- })
|
|
|
+ this.recalculateLayout(this.state.layout, this.props.col)
|
|
|
}, 1);
|
|
|
}
|
|
|
|
|
@@ -350,6 +351,7 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
render() {
|
|
|
const {
|
|
|
width,
|
|
@@ -361,6 +363,7 @@ export class Dragact extends React.Component<DragactProps, DragactState> {
|
|
|
|
|
|
return (
|
|
|
<div
|
|
|
+
|
|
|
className={stringJoin('DraggerLayout', className + '')}
|
|
|
style={{
|
|
|
...style,
|