Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
Specify accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
Ragg authored and Ragg committed Jul 16, 2017
1 parent c262c58 commit 6445829
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/frontend/modules/Portal/Portal.tsx
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import * as ReactDOM from 'react-dom'

export default class Portal {
private root: Element
public root: Element
private mounted: boolean = false
private mountedComponent: React.Component<any, any>|null

Expand Down
24 changes: 14 additions & 10 deletions src/frontend/views/KeyframeEditor/_DelirValueInput.tsx
Expand Up @@ -20,15 +20,15 @@ interface DelirValueInputProps {

export default class DelirValueInput extends Component<DelirValueInputProps, any>
{
static propTypes = {
public static propTypes = {
descriptors: PropTypes.arrayOf(
PropTypes.instanceOf(Delir.TypeDescriptor)
),
value: PropTypes.any,
onChange: PropTypes.func.isRequired,
}

refs: {
public refs: {
input: DragNumberInput,
propX: DragNumberInput,
propY: DragNumberInput,
Expand All @@ -48,18 +48,18 @@ export default class DelirValueInput extends Component<DelirValueInputProps, any
colorPickerDropdown: Dropdown
}

state = {
public state = {
value: this.props.value,
}

componentWillReceiveProps(nextProps: Readonly<DelirValueInputProps>, nextContext: any)
public componentWillReceiveProps(nextProps: Readonly<DelirValueInputProps>, nextContext: any)
{
if (this.props.value !== nextProps.value) {
setTimeout(() => this.setState({value: nextProps.value}), 0)
}
}

valueChanged = () =>
private valueChanged = () =>
{
const {descriptor} = this.props

Expand Down Expand Up @@ -137,29 +137,33 @@ export default class DelirValueInput extends Component<DelirValueInputProps, any
}
}

onFocusTextInput = (e: React.FocusEvent<HTMLInputElement>) => {
private onFocusTextInput = (e: React.FocusEvent<HTMLInputElement>) =>
{
e.preventDefault()
e.stopPropagation()
this.refs.textInputDropdown.show()
this.refs.textArea.focus()
}

onKeydownTextArea = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
private onKeydownTextArea = (e: React.KeyboardEvent<HTMLTextAreaElement>) =>
{
if ((e.metaKey === true || e.ctrlKey === true) && e.key === 'Enter') {
this.refs.textInputDropdown.hide()
this.valueChanged()
}
}

openColorPicker = (e: React.MouseEvent<HTMLButtonElement>) => {
private openColorPicker = (e: React.MouseEvent<HTMLButtonElement>) =>
{
const {colorPickerDropdown} = this.refs
colorPickerDropdown.show()

e.preventDefault()
e.stopPropagation()
}

closeColorPicker = (e: React.KeyboardEvent<HTMLDivElement>) => {
private closeColorPicker = (e: React.KeyboardEvent<HTMLDivElement>) =>
{
const {colorPickerDropdown} = this.refs
colorPickerDropdown.hide()
this.valueChanged()
Expand All @@ -168,7 +172,7 @@ export default class DelirValueInput extends Component<DelirValueInputProps, any
e.stopPropagation()
}

render()
public render()
{
const {props: {descriptor, assets}, state: {value}} = this
let component: JSX.Element[] = []
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/views/StatusBar/StatusBar.tsx
Expand Up @@ -27,13 +27,13 @@ export default class StatusBar extends React.Component<null, State>
})
}

openFeedback = (e) =>
public openFeedback = (e) =>
{
remote.shell.openExternal('https://goo.gl/forms/dDy7HWgPuAiOFaSn1')
e.preventDefault()
}

render()
public render()
{
return (
<Pane className='view-status' resizable={false} allowFocus={false}>
Expand Down
29 changes: 15 additions & 14 deletions src/frontend/views/components/drag-number-input.tsx
Expand Up @@ -23,7 +23,7 @@ interface DragNumberInputState {

export default class DragNumberInput extends React.Component<DragNumberInputProps, DragNumberInputState>
{
static propTypes = {
public static propTypes = {
className: PropTypes.string,
data: PropTypes.object,
min: PropTypes.number,
Expand All @@ -36,34 +36,35 @@ export default class DragNumberInput extends React.Component<DragNumberInputProp
doubleClickToEdit: PropTypes.bool,
}

static defaultProps = {
public static defaultProps = {
allowFloat: false,
disabled: false,
doubleClickToEdit: false,
}

refs: {
public refs: {
input: HTMLInputElement
}

state = {
public state = {
value: this.props.value != null ? this.props.value : 0,
valueChanged: false,
}

get value(): number { return +this.state.value }
public get value(): number { return +this.state.value }

componentDidMount()
public componentDidMount()
{
this.refs.input.onpointerlockerror = e => console.error(e)
}

componentWillReceiveProps(nextProps: DragNumberInputProps)
public componentWillReceiveProps(nextProps: DragNumberInputProps)
{
this.setState({value: nextProps.value})
}

onKeyDown = (e: KeyboardEvent) => {
private onKeyDown = (e: KeyboardEvent) =>
{
const {onChange} = this.props
const {input} = this.refs

Expand All @@ -84,22 +85,22 @@ export default class DragNumberInput extends React.Component<DragNumberInputProp
}
}

onBlur = (e: FocusEvent) =>
private onBlur = (e: FocusEvent) =>
{
const value = this._parseValue(this.refs.input.value)
this.props.onChange && this.props.onChange(value)
this.setState({value})
}

onMouseDown = (e: React.MouseEvent<HTMLSpanElement>) =>
private onMouseDown = (e: React.MouseEvent<HTMLSpanElement>) =>
{
// MouseEvent#movement is buggy on Windows. Disable modification by drag.
if (Platform.isWindows()) return

e.currentTarget.requestPointerLock()
}

onMouseMove = (event: React.MouseEvent<HTMLSpanElement>) =>
private onMouseMove = (event: React.MouseEvent<HTMLSpanElement>) =>
{
// MouseEvent#movement is buggy on Windows. Disable modification by drag.
if (Platform.isWindows()) return
Expand All @@ -119,7 +120,7 @@ export default class DragNumberInput extends React.Component<DragNumberInputProp
this.setState({value: this._parseValue(value)})
}

onMouseUp = (e: React.MouseEvent<HTMLSpanElement>) =>
private onMouseUp = (e: React.MouseEvent<HTMLSpanElement>) =>
{
// MouseEvent#movement is buggy on Windows. Disable modification by drag.
if (Platform.isWindows()) return
Expand All @@ -132,7 +133,7 @@ export default class DragNumberInput extends React.Component<DragNumberInputProp
}

// TODO: parse and calculate expression
valueChanged = (e: React.ChangeEvent<HTMLInputElement>) =>
private valueChanged = (e: React.ChangeEvent<HTMLInputElement>) =>
{
this.setState({value: e.target.value})
}
Expand All @@ -151,7 +152,7 @@ export default class DragNumberInput extends React.Component<DragNumberInputProp
return value
}

render()
public render()
{
return (
<input
Expand Down
31 changes: 20 additions & 11 deletions src/frontend/views/components/dropdown.tsx
Expand Up @@ -17,30 +17,39 @@ interface DropdownState {
}

export default class Dropdown extends PureComponent<DropdownProps, DropdownState> {
static propTypes = {
public static propTypes = {
shownInitial: PropTypes.bool,
className: PropTypes.string,
}

static defaultProps = {
public static defaultProps = {
shownInitial: false,
}

refs: {
public refs: {
inspector: HTMLDivElement
}

state = {
public state = {
show: this.props.shownInitial
}

private _portal: Portal = new Portal()

show = () => this.setState({show: true})
public show = () =>
{
this.setState({show: true})
}

hide = () => this.setState({show: false})
public hide = () =>
{
this.setState({show: false})
}

toggle = () => this.setState({show: !this.state.show})
public toggle = () =>
{
this.setState({show: !this.state.show})
}

private hideOnOutsideClicked = (e: MouseEvent) =>
{
Expand All @@ -52,18 +61,18 @@ export default class Dropdown extends PureComponent<DropdownProps, DropdownState
}
}

componentDidMount = () =>
public componentDidMountg()
{
window.addEventListener('click', this.hideOnOutsideClicked, true)
}

componentWillUnmount = () =>
public componentWillUnmountg()
{
window.removeEventListener('click', this.hideOnOutsideClicked, true)
this._portal.unmount()
}

componentDidUpdate = () =>
public componentDidUpdateg()
{
const {props: {className, children}, state: {show}} = this
const {left, top} = this.refs.inspector.getBoundingClientRect()
Expand All @@ -80,7 +89,7 @@ export default class Dropdown extends PureComponent<DropdownProps, DropdownState
))
}

render()
public render()
{
return (
<div ref='inspector' className={s.dropdownInspector} />
Expand Down

0 comments on commit 6445829

Please sign in to comment.