Skip to content

Add hostToolbarControl message for programmatic toolbar control via postMessage#146

Merged
danmarshall merged 7 commits into
mainfrom
copilot/add-hostrenderrequest-option
Nov 19, 2025
Merged

Add hostToolbarControl message for programmatic toolbar control via postMessage#146
danmarshall merged 7 commits into
mainfrom
copilot/add-hostrenderrequest-option

Conversation

Copilot AI commented Nov 19, 2025

Copy link
Copy Markdown
Contributor

Enables external applications to control toolbar UI elements via postMessage without coupling to the render request message.

Changes

New Message Type

Added HostToolbarControlMessage with commands:

  • showSource: boolean - Toggle source textarea visibility
  • showDownloadDialog: boolean - Trigger download popup programmatically
  • setFilename: string - Override download filename
  • showOrHideButtons: { tweak?: boolean; download?: boolean; restart?: boolean } - Control button visibility with a single object

Implementation

  • packages/common/src/messages.ts: Defined HostToolbarControlMessage interface
  • packages/toolbar/src/toolbar.tsx: Added control methods (setSourceVisibility(), showDownloadDialog(), showOrHideButtons())
  • packages/host/src/post-receive.ts: Handler for hostToolbarControl messages
  • packages/host-test/src/index.ts: Usage example

Usage

// Render content
iframe.contentWindow.postMessage({
  type: 'hostRenderRequest',
  title: 'Document',
  markdown: '# Content'
}, '*');

// Control toolbar independently
iframe.contentWindow.postMessage({
  type: 'hostToolbarControl',
  showSource: true,
  setFilename: 'custom-name',
  showOrHideButtons: {
    tweak: true,      // Show view source button
    download: true,   // Show download button
    restart: false    // Hide start over button
  },
  showDownloadDialog: true
}, '*');

Screenshots

Show source programmatically:

Trigger download dialog:

Hide all buttons:

Show all buttons:

Original prompt

We want a feature to be able to control various aspects of the host when using postmessage.

One idea is in message type hostRenderRequest : add an option for showSource which would tell the toolbar to have the textarea be visible. This is the primary feature request.

But another idea is to perhaps add a more generalizable message packet to control the toolbar.

Let me know which idea is preferable. For the latter, tell me what commands it might contain


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 19, 2025 18:56
…essage

Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>
Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>
Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>
Copilot AI changed the title [WIP] Add showSource option in hostRenderRequest message Add hostToolbarControl message for programmatic toolbar control via postMessage Nov 19, 2025
Copilot AI requested a review from danmarshall November 19, 2025 19:17
@danmarshall

Copy link
Copy Markdown
Collaborator

@copilot instead of a collection of methods for every button, lets have a single showOrHideButtons and then pass an object where keys are button names and boolean.

Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>

Copilot AI commented Nov 19, 2025

Copy link
Copy Markdown
Contributor Author

@copilot instead of a collection of methods for every button, lets have a single showOrHideButtons and then pass an object where keys are button names and boolean.

Refactored to use a single showOrHideButtons(buttons) method that accepts an object with button names as keys (tweak, download, restart). This makes the API more concise and easier to use when controlling multiple buttons. Commit: 2489d9e

Example:

toolbar.showOrHideButtons({
  tweak: true,
  download: true,
  restart: false
});

All buttons hidden

All buttons shown

@danmarshall

Copy link
Copy Markdown
Collaborator

@copilot let's rename tweak to source

Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>
@danmarshall
danmarshall marked this pull request as ready for review November 19, 2025 21:20
@danmarshall
danmarshall merged commit d308593 into main Nov 19, 2025
5 checks passed
@danmarshall
danmarshall deleted the copilot/add-hostrenderrequest-option branch November 19, 2025 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants