@imposium-hub/components 1.32.0 → 1.32.2
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}
|
|
@@ -17,7 +17,7 @@ interface ISliderFieldProps {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
interface ISliderFieldState {
|
|
20
|
-
|
|
20
|
+
tempValue : number;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
class SliderField extends React.PureComponent<ISliderFieldProps, ISliderFieldState> {
|
|
@@ -28,10 +28,8 @@ class SliderField extends React.PureComponent<ISliderFieldProps, ISliderFieldSta
|
|
|
28
28
|
|
|
29
29
|
super(props);
|
|
30
30
|
|
|
31
|
-
const inputValue = (props.value === null || props.value === undefined) ? props.defaultValue : props.value;
|
|
32
|
-
|
|
33
31
|
this.state = {
|
|
34
|
-
|
|
32
|
+
tempValue: null
|
|
35
33
|
};
|
|
36
34
|
}
|
|
37
35
|
|
|
@@ -40,11 +38,6 @@ class SliderField extends React.PureComponent<ISliderFieldProps, ISliderFieldSta
|
|
|
40
38
|
clearTimeout(this.updateTimeout);
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
private toggle() {
|
|
44
|
-
|
|
45
|
-
this.props.onChange(!this.props.value);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
41
|
private updateValue(val) {
|
|
49
42
|
|
|
50
43
|
this.props.onChange(val);
|
|
@@ -52,17 +45,18 @@ class SliderField extends React.PureComponent<ISliderFieldProps, ISliderFieldSta
|
|
|
52
45
|
|
|
53
46
|
private rangeInputChange(e) {
|
|
54
47
|
|
|
55
|
-
const {min, max, defaultValue } = this.props;
|
|
56
|
-
|
|
57
48
|
const inputVal = e.target.value;
|
|
58
49
|
const val = parseFloat(inputVal);
|
|
59
50
|
|
|
60
51
|
clearTimeout(this.updateTimeout);
|
|
61
52
|
|
|
62
53
|
this.setState({
|
|
63
|
-
|
|
54
|
+
tempValue: val
|
|
64
55
|
}, () => {
|
|
65
|
-
this.updateTimeout = setTimeout(() =>
|
|
56
|
+
this.updateTimeout = setTimeout(() => {
|
|
57
|
+
this.updateValue(val);
|
|
58
|
+
this.setState({tempValue: null});
|
|
59
|
+
}, 100);
|
|
66
60
|
});
|
|
67
61
|
}
|
|
68
62
|
|
|
@@ -73,19 +67,16 @@ class SliderField extends React.PureComponent<ISliderFieldProps, ISliderFieldSta
|
|
|
73
67
|
inputValue = (inputValue === '') ? 0 : parseFloat(inputValue);
|
|
74
68
|
|
|
75
69
|
if (inputValue >= min && inputValue <= max) {
|
|
76
|
-
|
|
77
|
-
this.setState({
|
|
78
|
-
inputValue
|
|
79
|
-
}, () => {
|
|
80
|
-
this.updateValue(inputValue);
|
|
81
|
-
});
|
|
70
|
+
this.updateValue(inputValue);
|
|
82
71
|
}
|
|
83
72
|
}
|
|
84
73
|
|
|
85
74
|
public render() {
|
|
86
75
|
|
|
87
|
-
const {label, width, min, max, step, defaultValue, tooltip, info, labelPosition} = this.props;
|
|
88
|
-
const {
|
|
76
|
+
const {label, width, min, max, step, defaultValue, value, tooltip, info, labelPosition} = this.props;
|
|
77
|
+
const { tempValue } = this.state;
|
|
78
|
+
|
|
79
|
+
const val = (tempValue !== null) ? tempValue : (value === null || value === undefined) ? defaultValue : value;
|
|
89
80
|
|
|
90
81
|
return <FieldWrapper
|
|
91
82
|
customClass = 'slider-field'
|
|
@@ -99,14 +90,14 @@ class SliderField extends React.PureComponent<ISliderFieldProps, ISliderFieldSta
|
|
|
99
90
|
type= 'range'
|
|
100
91
|
min={ min }
|
|
101
92
|
max= { max }
|
|
102
|
-
value = {
|
|
93
|
+
value = {val}
|
|
103
94
|
step= { step }/>
|
|
104
95
|
|
|
105
96
|
<input
|
|
106
97
|
className = 'val'
|
|
107
98
|
onChange = {(e) => this.numberInputChange(e)}
|
|
108
99
|
type = 'number'
|
|
109
|
-
value = {
|
|
100
|
+
value = {val} />
|
|
110
101
|
</FieldWrapper>;
|
|
111
102
|
}
|
|
112
103
|
}
|