mirror of
https://github.com/penpot/penpot-plugins.git
synced 2025-01-08 07:50:44 -05:00
1 KiB
1 KiB
Open UI:
penpot.ui.open('Plugin name', 'http://localhost:4201', {
width: 500,
height: 600,
});
Get state:
// file file state
penpot.ui.getFileState();
// file page state
penpot.ui.getPageState();
// selection id
penpot.ui.getSelection();
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
, filechange
and selectionchange
.
const event = (page) => {
penpot.log(page.name);
};
penpot.on('pagechange', event);
penpot.off('pagechange', event);
Requests
Same as the browser fetch API.
penpot.fetch('http://example.com/movies.json');