Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(Debug): Add CSSinJS debug panel #1974

Merged
merged 114 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
5a3e602
- debug stack added to mergeComponentVariables
miroslavstastny Sep 12, 2019
840c47e
wip: start ctrl + d and click for debugger
levithomason Sep 12, 2019
148b0a3
Merge branch 'feat/debug-panel' of github.com:stardust-ui/react into …
levithomason Sep 12, 2019
c55290c
-added DebugPanel component
Sep 13, 2019
1a463b8
wip: start fiber navigator
levithomason Sep 14, 2019
b523151
-added styles panel
Sep 15, 2019
cab06a2
-updated debug panel to cross the overriden values
Sep 16, 2019
15922ee
-added TODO for the merging of the styles
Sep 16, 2019
d256bd3
-split DebugPanel to more components
Sep 16, 2019
7b189c3
-added example usages for debug panel
Sep 16, 2019
57b8ee7
-added dock left and right options
Sep 16, 2019
ef02b71
-refactorings
Sep 16, 2019
f13294a
-extracted input styles
Sep 16, 2019
b74b17f
-remove DebugPanel from app
Sep 16, 2019
90db913
- save debug stack in mergeStyles and mergeComponentVariables
miroslavstastny Sep 16, 2019
a2684bb
-changed data structure
Sep 16, 2019
86dcbc1
improve debug selector
levithomason Sep 16, 2019
593f26d
fix lint errors
levithomason Sep 16, 2019
07b2c55
wire actual data into debug flow
levithomason Sep 16, 2019
8ff82a7
touch up styles
levithomason Sep 16, 2019
01dc2c6
-updated debug panel
Sep 16, 2019
018a1d7
Merge remote-tracking branch 'origin/feat/debug-panel' into feat/debu…
Sep 16, 2019
c45eb68
fix keys and return errors
levithomason Sep 16, 2019
686d18f
-updated styles on debug panel
Sep 17, 2019
8bad203
-ts error fixes
Sep 17, 2019
d13f4da
-final style changes
Sep 17, 2019
02b1326
-added design component in the index
Sep 17, 2019
8dff54a
- filter out empty style stack frames
miroslavstastny Sep 17, 2019
ae43a3c
-fixed bug for reversing variables object
Sep 17, 2019
6192a1f
fix double select bug, touch up styles
levithomason Sep 17, 2019
bea39e0
-added white backgorund on the icons
Sep 17, 2019
79af35f
-refactored variables and styles to use the same components
Sep 17, 2019
22ecf74
-added site variables in the debug data
Sep 17, 2019
3d6020f
-added select for style's slots
Sep 17, 2019
f3a170d
take document as prop
levithomason Sep 17, 2019
721ec94
-siteVariables displayed (only used)
Sep 17, 2019
e256efe
Merge branch 'feat/debug-panel' of github.com:stardust-ui/react into …
levithomason Sep 17, 2019
da88e65
Merge branch 'feat/debug-panel' of https://github.com/stardust-ui/rea…
Sep 17, 2019
bb1e638
improve slot selector
levithomason Sep 17, 2019
cee8786
improve slot selector layout
levithomason Sep 17, 2019
c24f491
select owner component
levithomason Sep 17, 2019
4a7c3f1
- add _debugId to style frames
miroslavstastny Sep 17, 2019
7aba0c8
-added comments and styles id
Sep 17, 2019
69b43ce
-gracefully handled undefined and null
Sep 18, 2019
e5c164b
fix parent traversal in select
levithomason Sep 18, 2019
f838747
add owner selector traversal
levithomason Sep 18, 2019
198c914
selectable fn components, hide selector on click, show panel for all …
levithomason Sep 18, 2019
7816414
- correctly save debug for components with a FocusZone (Menu)
miroslavstastny Sep 18, 2019
a6b8fbd
fix fiber nav instance
levithomason Sep 18, 2019
b362e7b
fix fiber nav react component
levithomason Sep 18, 2019
116878e
-replaced margin wtih padding
Sep 18, 2019
27dcac7
-handling empty site variables
Sep 18, 2019
d44163c
limit selection to stardust owners
levithomason Sep 18, 2019
8e34266
Merge branch 'feat/debug-panel' of github.com:stardust-ui/react into …
levithomason Sep 18, 2019
f20c696
remove css styles, separate fiber nav
levithomason Sep 18, 2019
3d0c535
-added activate debug selector prop on debug panel
Sep 18, 2019
0c7bb7f
-renamed prop
Sep 18, 2019
a863ddd
update styles, remove portal
levithomason Sep 18, 2019
a0551e8
-added close icon
Sep 18, 2019
9afa488
-fix
Sep 18, 2019
f8bb824
-refactoring
Sep 18, 2019
90fe054
fix some stuff
levithomason Sep 19, 2019
c44de16
merge and fix
levithomason Sep 19, 2019
e82a6ee
fix up more styles
levithomason Sep 19, 2019
e692084
-added DebugRect component
Sep 19, 2019
56aa6cc
- add _debugId to component variables frames
miroslavstastny Sep 19, 2019
aca54b8
- fix most of the failing UTs
miroslavstastny Sep 19, 2019
700c8a2
fix fiber nav domNode
levithomason Sep 19, 2019
0ed69b6
remove fiber nav window global
levithomason Sep 19, 2019
8b14be1
-site variabels are shown as object
Sep 19, 2019
582e878
-fix Provider tests
Sep 19, 2019
d8f7798
-fix site Variables
Sep 19, 2019
a602319
-site variables empty object fixes
Sep 19, 2019
b416937
-fixed bug on crashing when clicking on activate selecting
Sep 19, 2019
9727519
get ready for ........ can not say it...
levithomason Sep 19, 2019
e8a3d31
merge and fix
levithomason Sep 19, 2019
c26e751
- hoist _debugId to Theme object, add it to site variables frames
miroslavstastny Sep 19, 2019
6b0eea4
fix conflicts, make it uglier
levithomason Sep 20, 2019
a097308
tweak jsx navigator badges
levithomason Sep 20, 2019
1263c17
-fixed ts errors
Sep 23, 2019
250bf8f
-extracted more methods to utils
Sep 23, 2019
80571b8
-added interfaces for DebugPanelData and DebugPanelItem props
Sep 23, 2019
aa84b8e
-added filter tests
Sep 23, 2019
a20d977
-added tests for getValues
Sep 23, 2019
b165fab
-added test for removeNulls
Sep 23, 2019
c97e4aa
-used deepmerge in DebugPanelItem
Sep 23, 2019
0cfffbc
fix filter margin and selected item indent
levithomason Sep 23, 2019
e417591
-fixed issue with icon-clicks when debug panel is scrolled
Sep 24, 2019
ca6abef
Merge remote-tracking branch 'origin/master' into feat/debug-panel
miroslavstastny Sep 24, 2019
f0c55cf
- fix renderComponent after merge
miroslavstastny Sep 24, 2019
6179277
- store debug frames only if debugging is enabled
miroslavstastny Sep 25, 2019
a18fc58
factor out component viewer
levithomason Sep 25, 2019
542c358
Merge remote-tracking branch 'origin/master' into feat/debug-panel
miroslavstastny Sep 25, 2019
4c3ff6b
allow `window` accessing in Debug
miroslavstastny Sep 25, 2019
3010c7b
shallow clone instead of mutating in withDebugId
miroslavstastny Sep 25, 2019
79e93e7
remove old debug
miroslavstastny Sep 26, 2019
40f00cb
Merge remote-tracking branch 'origin/master' into feat/debug-panel
miroslavstastny Sep 26, 2019
944202f
fix UT import
miroslavstastny Sep 26, 2019
aea0d49
revert testing examples
miroslavstastny Sep 26, 2019
c9400b5
createTheme wrapper
miroslavstastny Sep 26, 2019
13585a9
added console function for opening the debug panel
Sep 26, 2019
87c4d31
-added isBrowser check
Sep 27, 2019
c584cb3
-clean up
Sep 30, 2019
695f5b4
-added typings to utils
Sep 30, 2019
d50fbfc
-added more typings
Sep 30, 2019
a4fbfda
-added comments on the helper functions
Sep 30, 2019
a7aa9c7
Merge remote-tracking branch 'origin/master' into feat/debug-panel
miroslavstastny Oct 9, 2019
2c223bd
Merge remote-tracking branch 'origin/master' into feat/debug-panel
miroslavstastny Oct 14, 2019
bf47bde
address (part of) PR comments
miroslavstastny Oct 14, 2019
d9bd25a
refactor tests
miroslavstastny Oct 15, 2019
e821f9e
address PR comments
miroslavstastny Oct 15, 2019
bacf4d1
Merge remote-tracking branch 'origin/master' into feat/debug-panel
miroslavstastny Oct 15, 2019
edcdee3
fix UTs
miroslavstastny Oct 15, 2019
fb3252c
changelog
miroslavstastny Oct 15, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Features
- Export `robot`, `tabs` and `plugs` icon to Teams theme @codepretty ([#2026](https://github.com/stardust-ui/react/pull/2026))
- Add CSSinJS debug panel @levithomason @miroslavstastny @mnajdova ([#1974](https://github.com/stardust-ui/react/pull/1974))

### Fixes
- Correctly handle RTL in `Alert` component @miroslavstastny ([#2018](https://github.com/stardust-ui/react/pull/2018))
Expand Down
7 changes: 5 additions & 2 deletions docs/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { hot } from 'react-hot-loader/root'
import { Provider, themes } from '@stardust-ui/react'
import { Provider, Debug, themes } from '@stardust-ui/react'

import { mergeThemes } from 'src/lib'
import { ThemeContext, ThemeContextData, themeContextDefaults } from './context/ThemeContext'
Expand Down Expand Up @@ -40,7 +40,10 @@ class App extends React.Component<any, ThemeContextData> {
})}
>
<PerfDataProvider>
<Routes />
<div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is required two have a wrapping element:

Suggested change
<div>
<>

nit

<Debug />
<Routes />
</div>
</PerfDataProvider>
</Provider>
</ThemeContext.Provider>
Expand Down
62 changes: 34 additions & 28 deletions docs/src/components/DocsLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Provider, themes, pxToRem } from '@stardust-ui/react'
import { Provider, themes, pxToRem, createTheme } from '@stardust-ui/react'
import AnchorJS from 'anchor-js'
import * as PropTypes from 'prop-types'
import * as React from 'react'
Expand Down Expand Up @@ -93,36 +93,42 @@ class DocsLayout extends React.Component<any, any> {
return (
<>
<Provider
theme={mergeThemes(themes.teamsDark, {
// adjust Teams' theme to Semantic UI's font size scheme
componentVariables: {
HierarchicalTreeItem: {
padding: `${pxToRem(7)} ${pxToRem(16)}`,
textDecoration: 'none',
fontSize: pxToRem(12),
fontWeight: 400,
color: '#ffffff80',

'& .active': {
fontWeight: 'bold',
theme={mergeThemes(
themes.teamsDark,
createTheme(
{
// adjust Teams' theme to Semantic UI's font size scheme
componentVariables: {
HierarchicalTreeItem: {
padding: `${pxToRem(7)} ${pxToRem(16)}`,
textDecoration: 'none',
fontSize: pxToRem(12),
fontWeight: 400,
color: '#ffffff80',

'& .active': {
fontWeight: 'bold',
},
},
},
},
},
componentStyles: {
HierarchicalTreeItem: {
root: ({ variables: v, props: p }) => ({
...(!p.items && treeItemStyle),
...(p.items && treeSectionStyle),
}),
},
HierarchicalTreeTitle: {
root: {
display: 'block',
width: '100%',
componentStyles: {
HierarchicalTreeItem: {
root: ({ variables: v, props: p }) => ({
...(!p.items && treeItemStyle),
...(p.items && treeSectionStyle),
}),
},
HierarchicalTreeTitle: {
root: {
display: 'block',
width: '100%',
},
},
},
},
},
})}
'DocsLayout',
),
)}
>
<Sidebar width={sidebarWidth} treeItemStyle={treeItemStyle} />
</Provider>
Expand Down
4 changes: 3 additions & 1 deletion docs/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const pkg = require('../../../../packages/react/package.json')
const componentMenu: ComponentMenuItem[] = require('docs/src/componentMenu')
const behaviorMenu: ComponentMenuItem[] = require('docs/src/behaviorMenu')

const componentsBlackList = ['Debug', 'Design']

class Sidebar extends React.Component<any, any> {
static propTypes = {
match: PropTypes.object.isRequired,
Expand Down Expand Up @@ -258,7 +260,7 @@ class Sidebar extends React.Component<any, any> {
const treeItemsByType = _.map(constants.typeOrder, nextType => {
const items = _.chain([...componentMenu, ...behaviorMenu])
.filter(({ type }) => type === nextType)
.filter(({ displayName }) => displayName !== 'Design')
.filter(({ displayName }) => !_.includes(componentsBlackList, displayName))
.map(info => ({
key: info.displayName.concat(nextType),
title: { content: info.displayName, as: NavLink, to: getComponentPathname(info) },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from 'react'
layershifter marked this conversation as resolved.
Show resolved Hide resolved
import { mergeThemes, callable, ComponentStyleFunctionParam, themes } from '@stardust-ui/react'
import * as _ from 'lodash'

/**
* Not a real performance test, just a temporary POC
*/
const providerMergeThemesPerf = () => {
const merged = mergeThemes(..._.times(100, n => themes.teams))
const resolvedStyles = _.mapValues(merged.componentStyles, (componentStyle, componentName) => {
const compVariables = _.get(merged.componentVariables, componentName, callable({}))(
merged.siteVariables,
)
const styleParam: ComponentStyleFunctionParam = {
displayName: componentName,
props: {},
variables: compVariables,
theme: merged,
rtl: false,
disableAnimations: false,
}
return _.mapValues(componentStyle, (partStyle, partName) => {
if (partName === '_debug') {
// TODO: fix in code, happens only with mergeThemes(singleTheme)
return undefined
}
if (typeof partStyle !== 'function') {
console.log(componentName, partStyle, partName)
Copy link
Member

@layershifter layershifter Sep 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will affect performance as console.log() is very slow.


Do you want to add this perf test at all?

}
return partStyle(styleParam)
})
})

return resolvedStyles
}

const MergeThemesPerf = () => {
const resolvedStyles = providerMergeThemesPerf()
delete resolvedStyles.Button.root._debug
return <pre>{JSON.stringify(resolvedStyles.Button.root, null, 2)}</pre>
}

export default MergeThemesPerf
16 changes: 16 additions & 0 deletions docs/src/examples/components/Provider/Performance/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react'

import ComponentPerfExample from 'docs/src/components/ComponentDoc/ComponentPerfExample'
import NonPublicSection from 'docs/src/components/ComponentDoc/NonPublicSection'

const Performance = () => (
<NonPublicSection title="Performance">
<ComponentPerfExample
title="Merge themes"
description="mergeThemes perf"
examplePath="components/Provider/Performance/ProviderMergeThemes.perf"
/>
</NonPublicSection>
)

export default Performance
2 changes: 2 additions & 0 deletions docs/src/examples/components/Provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import * as React from 'react'

import Types from './Types'
import Usage from './Usage'
import Performance from './Performance'

const ProviderExamples = () => (
<>
<Types />
<Usage />
<Performance />
</>
)

Expand Down
193 changes: 193 additions & 0 deletions packages/react/src/components/Debug/Debug.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
import keyboardKey from 'keyboard-key'
import * as PropTypes from 'prop-types'
import * as React from 'react'
import { toRefObject } from '@stardust-ui/react-component-ref'
import { EventListener } from '@stardust-ui/react-component-event-listener'

import { isBrowser } from '../../lib'
import { isEnabled as isDebugEnabled } from '../../lib/debug/debugEnabled'

import DebugPanel from './DebugPanel'
import FiberNavigator from './FiberNavigator'
import DebugRect from './DebugRect'

type DebugProps = {
/** Existing document the popup should add listeners. */
mountDocument?: Document
}

type DebugState = {
debugPanelPosition?: 'left' | 'right'
fiberNav: FiberNavigator
selectedFiberNav: FiberNavigator
isSelecting: boolean
}

const INITIAL_STATE: DebugState = {
fiberNav: null,
selectedFiberNav: null,
isSelecting: false,
}

class Debug extends React.Component<DebugProps, DebugState> {
state = INITIAL_STATE

static defaultProps = {
// eslint-disable-next-line no-undef
mountDocument: isBrowser() ? window.document : null,
}

static propTypes = {
mountDocument: PropTypes.object.isRequired,
}

constructor(p, s) {
super(p, s)
if (process.env.NODE_ENV !== 'production' && isDebugEnabled && isBrowser()) {
// eslint-disable-next-line no-undef
;(window as any).openDebugPanel = () => {
// eslint-disable-next-line no-undef
this.debugReactComponent((window as any).$r)
}
}
}

debugReactComponent = r => {
if (!r) {
console.error(
"No React component selected. Please select a Stardust component from the React's Component panel.",
)
return
}
if (!r._reactInternalFiber) {
console.error(
'React does not provide data for debugging for this component. Try selecting some Stardust component.',
)
return
}
if (!r.stardustDebug) {
console.error('Not a debuggable component. Try selecting some Stardust component.')
return
}

const fiberNav = FiberNavigator.fromFiber(r._reactInternalFiber)
this.setState({ fiberNav, isSelecting: false, selectedFiberNav: null })
}

debugDOMNode = domNode => {
let fiberNav = FiberNavigator.fromDOMNode(domNode)

if (!fiberNav) {
console.error('No fiber for dom node', domNode)
return
}

fiberNav = fiberNav.findOwner(fiber => fiber.stardustDebug)

if (fiberNav !== this.state.fiberNav) {
this.setState({ fiberNav })
}
}

handleKeyDown = e => {
const code = keyboardKey.getCode(e)

switch (code) {
case keyboardKey.Escape:
this.stopSelecting()
break

case keyboardKey.d:
if (e.altKey && e.shiftKey) {
this.startSelecting()
}
break
}
}

handleMouseMove = e => {
this.debugDOMNode(e.target)
}

handleStardustDOMNodeClick = e => {
e.preventDefault()
e.stopPropagation()

this.setState({ isSelecting: false })
}

startSelecting = () => {
const isSelecting = !this.state.isSelecting

this.setState({
...(!isSelecting && INITIAL_STATE),
isSelecting,
})
}

stopSelecting = () => {
this.setState(INITIAL_STATE)
}

selectFiber = selectedFiberNav => this.setState({ selectedFiberNav })

changeFiber = fiberNav => this.setState({ fiberNav })

positionRight = () => this.setState({ debugPanelPosition: 'right' })

positionLeft = () => this.setState({ debugPanelPosition: 'left' })

close = () => this.setState(INITIAL_STATE)

render() {
const { mountDocument } = this.props
const { fiberNav, selectedFiberNav, isSelecting, debugPanelPosition } = this.state

if (process.env.NODE_ENV !== 'production' && isDebugEnabled) {
return (
<>
<EventListener
targetRef={toRefObject(mountDocument.body)}
listener={this.handleKeyDown}
type="keydown"
/>
{isSelecting && (
<EventListener
targetRef={toRefObject(mountDocument.body)}
listener={this.handleMouseMove}
type="mousemove"
/>
)}
{isSelecting && fiberNav && fiberNav.domNode && (
<EventListener
targetRef={toRefObject(fiberNav.domNode)}
listener={this.handleStardustDOMNodeClick}
type="click"
/>
)}
{isSelecting && fiberNav && <DebugRect fiberNav={fiberNav} />}
{selectedFiberNav && <DebugRect fiberNav={selectedFiberNav} />}
{!isSelecting && fiberNav && fiberNav.instance && (
<DebugPanel
fiberNav={fiberNav}
onActivateDebugSelectorClick={this.startSelecting}
onClose={this.close}
// TODO: Integrate CSS in JS Styles for Host Components (DOM nodes)
// cssStyles={stylesForNode(stardustDOMNode)}
debugData={fiberNav.stardustDebug}
position={debugPanelPosition || 'right'}
onPositionLeft={this.positionLeft}
onPositionRight={this.positionRight}
onFiberChanged={this.changeFiber}
onFiberSelected={this.selectFiber}
/>
)}
</>
)
}

return null
}
}

export default Debug
Loading