Skip to content

Commit e364a4e

Browse files
committed
Add docs about supporting custom renderers
1 parent 95b348b commit e364a4e

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

packages/debugger/README.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pnpm add @solid-devtools/debugger
2727
> **Warning**
2828
> This package changes extremely often, and is not meant to be used directly. Unless you know what you're doing, use the main package instead.
2929
30-
### Module overview
30+
## Module overview
3131

3232
The debugger is split into four submodules:
3333

@@ -48,33 +48,33 @@ The debugger needs to be setup before it can be used. To do that, import the `./
4848
```ts
4949
import '@solid-devtools/debugger/setup'
5050

51-
import { useDebugger } from '@solid-devtools/debugger/bundled' // or from '@solid-devtools/debugger'
51+
import {useDebugger} from '@solid-devtools/debugger/bundled' // or from '@solid-devtools/debugger'
5252
5353
const debug = useDebugger()
5454
```
5555

56-
### Using component locator
56+
## Using component locator
5757

5858
_Debugger feature inspired by [LocatorJS](https://www.locatorjs.com)_
5959

6060
Locator let's you locate components on the page, and go to their source code in your IDE. All you need to do is configure it by calling `setLocatorOptions` with some options.
6161

6262
```ts
63-
import { useDebugger } from '@solid-devtools/debugger' // or 'solid-devtools/setup'
63+
import {useDebugger} from '@solid-devtools/debugger' // or 'solid-devtools/setup'
6464
6565
const debug = useDebugger()
6666
debug.setLocatorOptions()
6767
```
6868

6969
It will not allow you to highlight hovered components on the page and reveal them in the IDE or the Chrome Extension. _(depending of if the extension panel is open or not)_
7070

71-
#### Locator Options
71+
### Locator Options
7272

7373
Not passing any options will enable the locator with <kbd>Alt</kbd> as the trigger key and no `targetIDE` selected.
7474

7575
Currently Locator allows for specifying these props:
7676

77-
##### `targetIDE`
77+
#### `targetIDE`
7878

7979
Choose in which IDE the component source code should be revealed.
8080

@@ -111,7 +111,7 @@ setLocatorOptions({
111111
})
112112
```
113113

114-
##### `key`
114+
#### `key`
115115

116116
Holding which key should enable the locator overlay? It's `"Alt"` by default — <kbd>Alt</kbd> on Windows, and <kbd>Option</kbd> or <kbd>⌥</kbd> on macOS.
117117

@@ -123,14 +123,41 @@ setLocatorOptions({
123123
})
124124
```
125125

126-
#### Using the Locator on the page
126+
### Using the Locator on the page
127127

128128
To activate the Locator module — you have to hold down the <kbd>Alt</kbd>/<kbd>Option</kbd> key and move your mouse around the page to highlight components and their different HTML Elements.
129129

130130
Clicking the component should take you to the component source code, given that you specified the [`targetIDE`](#targetIDE) option.
131131

132132
https://user-images.githubusercontent.com/24491503/174093606-a0d80331-021f-4d43-b0bb-e9a4041e1a26.mp4
133133

134+
## Supporting custom renderers
135+
136+
By default the debugger assumes you are using `"solid-js/web"` as jsx renderer and that the rendered elements are `HTMLElement`s.
137+
138+
If you are using a custom renderer—such as Three.js, Pixi.js, or Lightning.js—you need to provide the debugger with an `ElementInterface` implementation.
139+
140+
```ts
141+
import * as debug from '@solid-devtools/debugger/types'
142+
import {setElementInterface} from '@solid-devtools/debugger/setup' // or 'solid-devtools/setup'
143+
144+
/** ElementInterface implementation for DOM Element */
145+
let element_interface: debug.ElementInterface<Element> = {
146+
isElement: obj => obj instanceof Element,
147+
getElementAt: e => e.target as Element | null,
148+
getName: el => el.localName,
149+
getChildren: el => el.children,
150+
getParent: el => el.parentElement,
151+
getRect: el => el.getBoundingClientRect(),
152+
getLocation: el => {
153+
let attr = debug.getLocationAttr(el)
154+
return attr && debug.parseLocationString(attr) || null
155+
},
156+
}
157+
158+
setElementInterface(element_interface)
159+
```
160+
134161
## Changelog
135162

136163
See [CHANGELOG.md](./CHANGELOG.md).

0 commit comments

Comments
 (0)