Skip to content
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

[DevTools] Expose "view source" options to Fusebox integration #28973

Merged
merged 1 commit into from
May 7, 2024
Merged
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
49 changes: 31 additions & 18 deletions packages/react-devtools-fusebox/src/frontend.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,49 @@
* LICENSE file in the root directory of this source tree.
*/

export type MessagePayload =
| null
| string
| number
| boolean
| {[key: string]: MessagePayload}
| MessagePayload[];
export type Message = {event: string; payload?: MessagePayload};
export type MessagePayload = null | string | number | boolean | { [key: string]: MessagePayload } | MessagePayload[];
export type Message = { event: string, payload?: MessagePayload };

export type WallListener = (message: Message) => void;
export type Wall = {
listen: (fn: WallListener) => Function;
send: (event: string, payload?: MessagePayload) => void;
listen: (fn: WallListener) => Function,
send: (event: string, payload?: MessagePayload) => void,
};

export type Bridge = {
shutdown: () => void;
shutdown: () => void,
};
export type Store = Object;
export type BrowserTheme = 'dark' | 'light';

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

export type Source = {
sourceURL: string,
line: number,
column: number,
};
export type ViewElementSource = (
source: Source,
symbolicatedSource: Source | null,
) => void;
export type ViewAttributeSource = (
id: number,
path: Array<string | number>,
) => void;
export type CanViewElementSource = (
source: Source,
symbolicatedSource: Source | null,
) => boolean;

export type InitializationOptions = {
bridge: Bridge;
store: Store;
theme?: BrowserTheme;
bridge: Bridge,
store: Store,
theme?: BrowserTheme,
viewAttributeSourceFunction?: ViewAttributeSource,
viewElementSourceFunction?: ViewElementSource,
canViewElementSourceFunction?: CanViewElementSource,
};
export function initialize(
node: Element | Document,
options: InitializationOptions,
): void;

export function initialize(node: Element | Document, options: InitializationOptions): void;
20 changes: 19 additions & 1 deletion packages/react-devtools-fusebox/src/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import type {
Wall,
} from 'react-devtools-shared/src/frontend/types';
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
import type {
ViewAttributeSource,
ViewElementSource,
CanViewElementSource,
} from 'react-devtools-shared/src/devtools/views/DevTools';

type Config = {
checkBridgeProtocolCompatibility?: boolean,
Expand Down Expand Up @@ -46,13 +51,23 @@ type InitializationOptions = {
bridge: FrontendBridge,
store: Store,
theme?: BrowserTheme,
viewAttributeSourceFunction?: ViewAttributeSource,
viewElementSourceFunction?: ViewElementSource,
canViewElementSourceFunction?: CanViewElementSource,
};

export function initialize(
contentWindow: Element | Document,
options: InitializationOptions,
): void {
const {bridge, store, theme = 'light'} = options;
const {
bridge,
store,
theme = 'light',
viewAttributeSourceFunction,
viewElementSourceFunction,
canViewElementSourceFunction,
} = options;
const root = createRoot(contentWindow);

root.render(
Expand All @@ -63,6 +78,9 @@ export function initialize(
showTabBar={true}
warnIfLegacyBackendDetected={true}
enabledInspectedElementContextMenu={true}
viewAttributeSourceFunction={viewAttributeSourceFunction}
viewElementSourceFunction={viewElementSourceFunction}
canViewElementSourceFunction={canViewElementSourceFunction}
/>,
);
}