GeezerVison is showing github.com — Disable view-source button in standalone mode if no project roots are… · react/react@9a05e0b
File treeExpand file treeCollapse file tree Open diff view settings packages/react-devtools-core/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-core/src/standalone.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -85,7 +85,6 @@ function reload() { | 85 | 85 | root.render( | 86 | 86 | createElement(DevTools, { | 87 | 87 | bridge: ((bridge: any): FrontendBridge), | 88 | | - isBrowserMode: false, | 89 | 88 | showTabBar: true, | 90 | 89 | store: ((store: any): Store), | 91 | 90 | warnIfLegacyBackendDetected: true, | @@ -172,7 +171,10 @@ function initialize(socket: WebSocket) { | 172 | 171 | socket.close(); | 173 | 172 | }); | 174 | 173 |
| 175 | | - store = new Store(bridge, { supportsNativeInspection: false }); | | 174 | + store = new Store(bridge, { | | 175 | + supportsNativeInspection: false, | | 176 | + supportsViewSource: projectRoots.length > 0, | | 177 | + }); | 176 | 178 |
| 177 | 179 | log('Connected'); | 178 | 180 | reload(); | |
Collapse file Copy file name to clipboardExpand all lines: src/devtools/store.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,6 +49,7 @@ type Config = {| | 49 | 49 | supportsNativeInspection?: boolean, | 50 | 50 | supportsReloadAndProfile?: boolean, | 51 | 51 | supportsProfiling?: boolean, | | 52 | + supportsViewSource?: boolean, | 52 | 53 | |}; | 53 | 54 |
| 54 | 55 | export type Capabilities = {| | @@ -124,6 +125,7 @@ export default class Store extends EventEmitter<{| | 124 | 125 | _supportsNativeInspection: boolean = false; | 125 | 126 | _supportsProfiling: boolean = false; | 126 | 127 | _supportsReloadAndProfile: boolean = false; | | 128 | + _supportsViewSource: boolean = true; | 127 | 129 |
| 128 | 130 | // Total number of visible elements (within all roots). | 129 | 131 | // Used for windowing purposes. | @@ -155,13 +157,15 @@ export default class Store extends EventEmitter<{| | 155 | 157 | supportsNativeInspection, | 156 | 158 | supportsProfiling, | 157 | 159 | supportsReloadAndProfile, | | 160 | + supportsViewSource, | 158 | 161 | } = config; | 159 | 162 | if (supportsCaptureScreenshots) { | 160 | 163 | this._supportsCaptureScreenshots = true; | 161 | 164 | this._captureScreenshots = | 162 | 165 | localStorageGetItem(LOCAL_STORAGE_CAPTURE_SCREENSHOTS_KEY) === 'true'; | 163 | 166 | } | 164 | 167 | this._supportsNativeInspection = supportsNativeInspection !== false; | | 168 | + this._supportsViewSource = supportsViewSource !== false; | 165 | 169 | if (supportsProfiling) { | 166 | 170 | this._supportsProfiling = true; | 167 | 171 | } | @@ -361,6 +365,10 @@ export default class Store extends EventEmitter<{| | 361 | 365 | return this._supportsReloadAndProfile && this._isBackendStorageAPISupported; | 362 | 366 | } | 363 | 367 |
| | 368 | + get supportsViewSource(): boolean { | | 369 | + return this._supportsViewSource; | | 370 | + } | | 371 | + | 364 | 372 | containsElement(id: number): boolean { | 365 | 373 | return this._idToElement.get(id) != null; | 366 | 374 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/devtools/views/Components/Components.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,7 +13,7 @@ import { SettingsModalContextController } from 'src/devtools/views/Settings/Sett | 13 | 13 |
| 14 | 14 | import styles from './Components.css'; | 15 | 15 |
| 16 | | -function Components({ isBrowserMode }: {| isBrowserMode?: boolean |}) { | | 16 | +function Components(_: {||}) { | 17 | 17 | // TODO Flex wrappers below should be user resizable. | 18 | 18 | return ( | 19 | 19 | <SettingsModalContextController> | @@ -26,7 +26,7 @@ function Components({ isBrowserMode }: {| isBrowserMode?: boolean |}) { | 26 | 26 | <div className={styles.SelectedElementWrapper}> | 27 | 27 | <NativeStyleContextController> | 28 | 28 | <Suspense fallback={<Loading />}> | 29 | | - <SelectedElement isBrowserMode={isBrowserMode} /> | | 29 | + <SelectedElement /> | 30 | 30 | </Suspense> | 31 | 31 | </NativeStyleContextController> | 32 | 32 | </div> | |
Collapse file Copy file name to clipboardExpand all lines: src/devtools/views/Components/SelectedElement.js +13-13Lines changed: 13 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,11 +30,9 @@ import type { GetInspectedElementPath } from './InspectedElementContext'; | 30 | 30 | import type { Element, InspectedElement } from './types'; | 31 | 31 | import type { ElementType } from 'src/types'; | 32 | 32 |
| 33 | | -export type Props = {| | 34 | | - isBrowserMode?: boolean, | 35 | | -|}; | | 33 | +export type Props = {||}; | 36 | 34 |
| 37 | | -export default function SelectedElement({ isBrowserMode }: Props) { | | 35 | +export default function SelectedElement(_: Props) { | 38 | 36 | const { inspectedElementID } = useContext(TreeStateContext); | 39 | 37 | const dispatch = useContext(TreeDispatcherContext); | 40 | 38 | const { isFileLocationRequired, viewElementSourceFunction } = useContext( | @@ -188,7 +186,7 @@ export default function SelectedElement({ isBrowserMode }: Props) { | 188 | 186 | <ButtonIcon type="suspend" /> | 189 | 187 | </Toggle> | 190 | 188 | )} | 191 | | - {isBrowserMode && ( | | 189 | + {store.supportsNativeInspection && ( | 192 | 190 | <Button | 193 | 191 | className={styles.IconButton} | 194 | 192 | onClick={highlightElement} | @@ -204,14 +202,16 @@ export default function SelectedElement({ isBrowserMode }: Props) { | 204 | 202 | > | 205 | 203 | <ButtonIcon type="log-data" /> | 206 | 204 | </Button> | 207 | | - <Button | 208 | | - className={styles.IconButton} | 209 | | - disabled={!canViewSource} | 210 | | - onClick={viewSource} | 211 | | - title="View source for this element" | 212 | | - > | 213 | | - <ButtonIcon type="view-source" /> | 214 | | - </Button> | | 205 | + {store.supportsViewSource && ( | | 206 | + <Button | | 207 | + className={styles.IconButton} | | 208 | + disabled={!canViewSource} | | 209 | + onClick={viewSource} | | 210 | + title="View source for this element" | | 211 | + > | | 212 | + <ButtonIcon type="view-source" /> | | 213 | + </Button> | | 214 | + )} | 215 | 215 | </div> | 216 | 216 |
| 217 | 217 | {inspectedElement === null && ( | |
Collapse file Copy file name to clipboardExpand all lines: src/devtools/views/DevTools.js +1-6Lines changed: 1 addition & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,7 +37,6 @@ export type Props = {| | 37 | 37 | bridge: FrontendBridge, | 38 | 38 | browserTheme?: BrowserTheme, | 39 | 39 | defaultTab?: TabID, | 40 | | - isBrowserMode?: boolean, | 41 | 40 | showTabBar?: boolean, | 42 | 41 | store: Store, | 43 | 42 | warnIfLegacyBackendDetected?: boolean, | @@ -78,7 +77,6 @@ export default function DevTools({ | 78 | 77 | browserTheme = 'light', | 79 | 78 | defaultTab = 'components', | 80 | 79 | componentsPortalContainer, | 81 | | - isBrowserMode = true, | 82 | 80 | overrideTab, | 83 | 81 | profilerPortalContainer, | 84 | 82 | settingsPortalContainer, | @@ -135,10 +133,7 @@ export default function DevTools({ | 135 | 133 | className={styles.TabContent} | 136 | 134 | hidden={tab !== 'components'} | 137 | 135 | > | 138 | | - <Components | 139 | | - isBrowserMode={isBrowserMode} | 140 | | - portalContainer={componentsPortalContainer} | 141 | | - /> | | 136 | + <Components portalContainer={componentsPortalContainer} /> | 142 | 137 | </div> | 143 | 138 | <div | 144 | 139 | className={styles.TabContent} | |
|