Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions docs/documentation/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ const client = Client({
});
```

### Debug Panel options

You can use the `hidePanel` option to hide the panel by default when the client loads. The `hideButton` option removes the toggle button on the side of the panel which means you can only use the keyboard shortcut to toggle its visibility.

```js
const client = Client({
// ...
debug: {
// ...
hidePanel: true/false,
hideButton: true/false
},
});
```

### Custom metadata in game logs

It can sometimes be helpful to surface some metadata during a move.
Expand Down
18 changes: 18 additions & 0 deletions src/client/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,24 @@ describe('start / stop', () => {
jest.resetAllMocks();
});

test('hide panel by default', () => {
const client = Client({ game: {}, debug: { hidePanel: true } });
expect(() => {
client.start();
client.stop();
}).not.toThrow();
expect(error).not.toHaveBeenCalled();
});

test('remove debug panel button', () => {
const client = Client({ game: {}, debug: { hideButton: true } });
expect(() => {
client.start();
client.stop();
}).not.toThrow();
expect(error).not.toHaveBeenCalled();
});

test('mount on custom element', () => {
const el = document.createElement('div');
const client = Client({ game: {}, debug: { target: el } });
Expand Down
2 changes: 2 additions & 0 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type Action =
export interface DebugOpt {
target?: HTMLElement;
impl?: typeof Debug;
hidePanel?: boolean;
hideButton?: boolean;
}

/**
Expand Down
9 changes: 8 additions & 1 deletion src/client/debug/Debug.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
visible = !visible;
}

let visible = true;
const debugOpt = $clientManager.client.debugOpt
let visible = !debugOpt || !debugOpt.hidePanel;
const showToggleButton = !debugOpt || !debugOpt.hideButton

function Keypress(e) {
if (e.key == '.') {
ToggleVisibility();
Expand Down Expand Up @@ -180,6 +183,7 @@

<section aria-label="boardgame.io Debug Panel" class="debug-panel">
{#if !visible}
{#if showToggleButton}
<button
on:click={ToggleVisibility}
class="visibility-toggle opener"
Expand All @@ -191,8 +195,10 @@
<Chevron />
</span>
</button>
{/if}
{:else}
<div transition:fly={{ x: 400, ...transitionOpts }} class="panel">
{#if showToggleButton}
<button
on:click={ToggleVisibility}
class="visibility-toggle closer"
Expand All @@ -204,6 +210,7 @@
<Chevron />
</span>
</button>
{/if}
<Menu on:change={MenuChange} {panes} {pane} />
<div
bind:this={paneDiv}
Expand Down