Skip to content

Fixed scrolling when QuickLook is opened in Elements panel #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions resources/debugger/components/elements/element-tree-item.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import styled from 'react-emotion'
import { css } from 'emotion'
import QuickLook from './quick-look'
import { selectElement } from '../../redux/ducks/elements'
import { ButtonToggle } from '../value/log-element'

const mapStateToProps = state => ({
selectedElement: state.elements.selectedElement,
})

const Element = styled.ul`
padding: 0 0 0 2rem;
list-style: none;
Expand Down Expand Up @@ -56,12 +62,11 @@ const OffsetButtonToggle = styled(ButtonToggle)`
top: 0.3rem;
`

export default class ElementTreeItem extends Component {
class ElementTreeItem extends Component {
constructor() {
super()
this.state = {
expanded: false,
quickLook: false,
}
}

Expand All @@ -82,13 +87,11 @@ export default class ElementTreeItem extends Component {
if (e.isDefaultPrevented() || this.props.element.id === '?') {
return
}
this.setState({
quickLook: !this.state.quickLook,
})
this.props.dispatch(selectElement(this.props.element.id))
}}
hasInfo={this.props.element.id !== '?'}
>
&lt;{this.renderElementName()}{expanded ? '>' : ' />'} {this.state.quickLook && <QuickLook element={this.props.element} />}
&lt;{this.renderElementName()}{expanded ? '>' : ' />'} {this.props.selectedElement === this.props.element.id && <QuickLook element={this.props.element} />}
</WrapElement>
)
}
Expand All @@ -109,7 +112,7 @@ export default class ElementTreeItem extends Component {
<span>
{this.renderQuickLook(true)}
{element.children.map((e, i) => (
<ElementTreeItem key={element.id + i} element={e} />
<ElementTreeItemWrapper key={element.id + i} element={e} />
))}
<WrapElement>&lt;/{this.renderElementName(true)}&gt;</WrapElement>
</span>
Expand Down Expand Up @@ -139,4 +142,9 @@ ElementTreeItem.propTypes = {
class: PropTypes.string,
name: PropTypes.string,
}).isRequired,
selectedElement: PropTypes.string,
dispatch: PropTypes.func.isRequired,
}

const ElementTreeItemWrapper = connect(mapStateToProps)(ElementTreeItem)
export default ElementTreeItemWrapper
11 changes: 0 additions & 11 deletions resources/debugger/components/elements/quick-look.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ const Wrapper = styled.div`
}
`

const Overlay = styled.div`
position: fixed;
width: 100vw;
height: calc(100vh - 30px);
cursor: auto;
top: 30px;
left: 0;
z-index: 8;
`

class QuickLook extends Component {
componentDidMount() {
if (!this.props.element.meta) {
Expand All @@ -77,7 +67,6 @@ class QuickLook extends Component {
render() {
return (
<div>
<Overlay />
<Wrapper onClick={e => e.preventDefault()}>
{!this.props.element.meta ? (
<Loading>Loading...</Loading>
Expand Down
1 change: 1 addition & 0 deletions resources/debugger/components/list-element.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const ButtonFilter = styled(Filter)`
export const Wrapper = styled.div`
flex: 1;
overflow: hidden;
height: 100vh;
`

export const ListInner = styled.ul`
Expand Down
14 changes: 14 additions & 0 deletions resources/debugger/redux/ducks/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import {
const FETCH_TREE = 'elements/FETCH_TREE'
const FETCH_PAGE_METADATA = 'elements/FETCH_PAGE_METADATA'
const FETCH_LAYER_METADATA = 'elements/FETCH_LAYER_METADATA'
const SELECT_ELEMENT = 'elements/SELECT_ELEMENT'

const initialState = {
loading: true,
tree: [],
selectedElement: '',
}

const handlers = {}
Expand Down Expand Up @@ -127,6 +129,18 @@ handlers[SET_LAYER_METADATA] = (state, { payload }) => ({
})),
})

export const selectElement = id => ({
type: SELECT_ELEMENT,
payload: {
id,
},
})

handlers[SELECT_ELEMENT] = (state, { payload }) => ({
...state,
selectedElement: payload.id,
})

export default function(state = initialState, action) {
if (handlers[action.type]) {
return handlers[action.type](state, action)
Expand Down
12 changes: 12 additions & 0 deletions webpack.skpm.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-not-accumulator-reassign/no-not-accumulator-reassign */
const webpack = require('webpack')
const path = require('path')

module.exports = config => {
config.resolve.extensions = ['.sketch.js', '.js', '.jsx']
Expand Down Expand Up @@ -29,6 +30,17 @@ module.exports = config => {
},
],
})
config.module.rules.push({
test: /\.jsx?$/,
include: [path.resolve(__dirname, 'node_modules/cocoascript-class')],
use: {
loader: 'babel-loader',
options: {
babelrc: false,
presets: ['babel-preset-airbnb'],
},
},
})

config.plugins.push(
new webpack.DefinePlugin({
Expand Down