0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-08 07:50:44 -05:00
penpot-plugins/docs/plugin-usage.md
2024-02-16 13:48:38 +01:00

759 B

Open UI:

penpot.ui.open('Plugin name', 'http://localhost:4201', {
  width: 500,
  height: 600,
});

Messages

Receive message from iframe:

penpot.ui.onMessage((message) => {
  penpot.log('Received message:', message);
});

Send message from iframe:

parent.postMessage({ content: 'text' }, '*');

Send message from plugin

penpot.ui.sendMessage({ type: 'hello' });

Send message from plugin:

window.addEventListener('message', function (event) {
  console.log('Message received from plugin: ', event.data);
});

Events

Current events pagechange and filechange.

const event = (page) => {
  penpot.log(page.name);
};

penpot.on('pagechange', event);

penpot.off('pagechange', event);