@imposium-hub/components 1.32.0 → 1.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import Moveable from 'react-moveable';
|
|
3
|
+
import hotkeys from 'hotkeys-js';
|
|
3
4
|
import TextLayer from './TextLayer';
|
|
4
5
|
|
|
5
6
|
interface ICompositionRendererLayerProps {
|
|
@@ -11,7 +12,11 @@ interface ICompositionRendererLayerProps {
|
|
|
11
12
|
onUpdate(l : any) : void;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
interface ICompositionRendererLayerState {
|
|
16
|
+
lockRatio : boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class CompositionRendererLayer extends React.PureComponent<ICompositionRendererLayerProps, ICompositionRendererLayerState> {
|
|
15
20
|
|
|
16
21
|
private evtHandlers;
|
|
17
22
|
private moveable;
|
|
@@ -26,10 +31,43 @@ class CompositionRendererLayer extends React.PureComponent<ICompositionRendererL
|
|
|
26
31
|
onDrag: (e) => this.handleDrag(e),
|
|
27
32
|
onResize: (e) => this.handleResize(e),
|
|
28
33
|
onRotate: (e) => this.handleRotate(e),
|
|
29
|
-
onClick: (e) => this.layerClicked(e)
|
|
34
|
+
onClick: (e) => this.layerClicked(e),
|
|
35
|
+
onShift: (e) => this.onShift(e),
|
|
36
|
+
onLeft: (e) => this.move(e, -1, 0),
|
|
37
|
+
onRight: (e) => this.move(e, 1, 0),
|
|
38
|
+
onUp: (e) => this.move(e, 0, -1),
|
|
39
|
+
onDown: (e) => this.move(e, 0, 1),
|
|
30
40
|
};
|
|
31
41
|
|
|
32
42
|
this.moveable = React.createRef();
|
|
43
|
+
|
|
44
|
+
this.state = {
|
|
45
|
+
lockRatio: false
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private move(e, x, y) {
|
|
50
|
+
|
|
51
|
+
if (this.props.selected) {
|
|
52
|
+
const shiftX = (e.shiftKey) ? x * 10 : x;
|
|
53
|
+
const shiftY = (e.shiftKey) ? y * 10 : y;
|
|
54
|
+
|
|
55
|
+
const newLayer = {...this.props.layer};
|
|
56
|
+
newLayer.x = newLayer.x + shiftX;
|
|
57
|
+
newLayer.y = newLayer.y + shiftY;
|
|
58
|
+
|
|
59
|
+
this.props.onUpdate(newLayer);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private onShift(e) {
|
|
64
|
+
|
|
65
|
+
if (e.key === 'Shift' && e.keyCode === 16 && this.props.selected) {
|
|
66
|
+
const lockRatio = (e.type === 'keydown') ? true : false;
|
|
67
|
+
this.setState({
|
|
68
|
+
lockRatio
|
|
69
|
+
});
|
|
70
|
+
}
|
|
33
71
|
}
|
|
34
72
|
|
|
35
73
|
public componentDidUpdate() {
|
|
@@ -40,6 +78,24 @@ class CompositionRendererLayer extends React.PureComponent<ICompositionRendererL
|
|
|
40
78
|
}
|
|
41
79
|
}
|
|
42
80
|
|
|
81
|
+
public componentDidMount() {
|
|
82
|
+
|
|
83
|
+
hotkeys('*', {keyup: true}, this.evtHandlers.onShift);
|
|
84
|
+
hotkeys('left, shift+left', this.evtHandlers.onLeft);
|
|
85
|
+
hotkeys('right, shift+right', this.evtHandlers.onRight);
|
|
86
|
+
hotkeys('up, shift+up', this.evtHandlers.onUp);
|
|
87
|
+
hotkeys('down, shift+down', this.evtHandlers.onDown);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public componentWillUnmount() {
|
|
91
|
+
|
|
92
|
+
hotkeys.unbind('*', this.evtHandlers.onShift);
|
|
93
|
+
hotkeys.unbind('left, shift+left', this.evtHandlers.onLeft);
|
|
94
|
+
hotkeys.unbind('right, shift+right', this.evtHandlers.onRight);
|
|
95
|
+
hotkeys.unbind('up, shift+up', this.evtHandlers.onUp);
|
|
96
|
+
hotkeys.unbind('down, shift+down', this.evtHandlers.onDown);
|
|
97
|
+
}
|
|
98
|
+
|
|
43
99
|
private handleDrag(e) {
|
|
44
100
|
|
|
45
101
|
const newLayer = {...this.props.layer};
|
|
@@ -51,9 +107,13 @@ class CompositionRendererLayer extends React.PureComponent<ICompositionRendererL
|
|
|
51
107
|
|
|
52
108
|
private handleResize(e) {
|
|
53
109
|
|
|
110
|
+
const {drag: {beforeDelta}, width, height} = e;
|
|
111
|
+
|
|
54
112
|
const newLayer = {...this.props.layer};
|
|
55
|
-
newLayer.width = Math.round(
|
|
56
|
-
newLayer.height = Math.round(
|
|
113
|
+
newLayer.width = Math.round(width);
|
|
114
|
+
newLayer.height = Math.round(height);
|
|
115
|
+
newLayer.x = Math.round(newLayer.x + beforeDelta[0]);
|
|
116
|
+
newLayer.y = Math.round(newLayer.y + beforeDelta[1]);
|
|
57
117
|
|
|
58
118
|
this.props.onUpdate(newLayer);
|
|
59
119
|
}
|
|
@@ -95,6 +155,7 @@ class CompositionRendererLayer extends React.PureComponent<ICompositionRendererL
|
|
|
95
155
|
public render() {
|
|
96
156
|
|
|
97
157
|
const { selected, layer } = this.props;
|
|
158
|
+
const { lockRatio } = this.state;
|
|
98
159
|
|
|
99
160
|
const layerClass = `comp-layer-${layer.id}`;
|
|
100
161
|
const layerStyle : any = {
|
|
@@ -114,6 +175,7 @@ class CompositionRendererLayer extends React.PureComponent<ICompositionRendererL
|
|
|
114
175
|
onResizeEnd = {this.evtHandlers.onResizeEnd}
|
|
115
176
|
onRotate = {this.evtHandlers.onRotate}
|
|
116
177
|
onRotateEnd = {this.evtHandlers.onRotateEnd}
|
|
178
|
+
keepRatio = {lockRatio}
|
|
117
179
|
resizable = {true}
|
|
118
180
|
rotatable = {true}
|
|
119
181
|
origin = {false}
|