Skip to content

Commit 2808423

Browse files
committed
feat[devtools-fusebox]: Expose "view source" callbacks as options
1 parent 5c32599 commit 2808423

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

packages/react-devtools-fusebox/src/frontend.d.ts

+26-18
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,44 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
export type MessagePayload =
9-
| null
10-
| string
11-
| number
12-
| boolean
13-
| {[key: string]: MessagePayload}
14-
| MessagePayload[];
15-
export type Message = {event: string; payload?: MessagePayload};
8+
export type MessagePayload = null | string | number | boolean | { [key: string]: MessagePayload } | MessagePayload[];
9+
export type Message = { event: string, payload?: MessagePayload };
1610

1711
export type WallListener = (message: Message) => void;
1812
export type Wall = {
19-
listen: (fn: WallListener) => Function;
20-
send: (event: string, payload?: MessagePayload) => void;
13+
listen: (fn: WallListener) => Function,
14+
send: (event: string, payload?: MessagePayload) => void,
2115
};
2216

2317
export type Bridge = {
24-
shutdown: () => void;
18+
shutdown: () => void,
2519
};
2620
export type Store = Object;
2721
export type BrowserTheme = 'dark' | 'light';
2822

2923
export function createBridge(wall: Wall): Bridge;
3024
export function createStore(bridge: Bridge): Store;
3125

26+
export type ViewElementSource = (
27+
source: Source,
28+
symbolicatedSource: Source | null,
29+
) => void;
30+
export type ViewAttributeSource = (
31+
id: number,
32+
path: Array<string | number>,
33+
) => void;
34+
export type CanViewElementSource = (
35+
source: Source,
36+
symbolicatedSource: Source | null,
37+
) => boolean;
38+
3239
export type InitializationOptions = {
33-
bridge: Bridge;
34-
store: Store;
35-
theme?: BrowserTheme;
40+
bridge: Bridge,
41+
store: Store,
42+
theme?: BrowserTheme,
43+
viewAttributeSourceFunction?: ViewAttributeSource,
44+
viewElementSourceFunction?: ViewElementSource,
45+
canViewElementSourceFunction?: CanViewElementSource,
3646
};
37-
export function initialize(
38-
node: Element | Document,
39-
options: InitializationOptions,
40-
): void;
47+
48+
export function initialize(node: Element | Document, options: InitializationOptions): void;

packages/react-devtools-fusebox/src/frontend.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import type {
1818
Wall,
1919
} from 'react-devtools-shared/src/frontend/types';
2020
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
21+
import type {
22+
ViewAttributeSource,
23+
ViewElementSource,
24+
CanViewElementSource,
25+
} from 'react-devtools-shared/src/devtools/views/DevTools';
2126

2227
type Config = {
2328
checkBridgeProtocolCompatibility?: boolean,
@@ -46,13 +51,23 @@ type InitializationOptions = {
4651
bridge: FrontendBridge,
4752
store: Store,
4853
theme?: BrowserTheme,
54+
viewAttributeSourceFunction?: ViewAttributeSource,
55+
viewElementSourceFunction?: ViewElementSource,
56+
canViewElementSourceFunction?: CanViewElementSource,
4957
};
5058

5159
export function initialize(
5260
contentWindow: Element | Document,
5361
options: InitializationOptions,
5462
): void {
55-
const {bridge, store, theme = 'light'} = options;
63+
const {
64+
bridge,
65+
store,
66+
theme = 'light',
67+
viewAttributeSourceFunction,
68+
viewElementSourceFunction,
69+
canViewElementSourceFunction,
70+
} = options;
5671
const root = createRoot(contentWindow);
5772

5873
root.render(
@@ -63,6 +78,9 @@ export function initialize(
6378
showTabBar={true}
6479
warnIfLegacyBackendDetected={true}
6580
enabledInspectedElementContextMenu={true}
81+
viewAttributeSourceFunction={viewAttributeSourceFunction}
82+
viewElementSourceFunction={viewElementSourceFunction}
83+
canViewElementSourceFunction={canViewElementSourceFunction}
6684
/>,
6785
);
6886
}

0 commit comments

Comments
 (0)