0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-03-11 23:31:23 -05:00

fix(contrast-plugin): update colors when shape change

This commit is contained in:
Juanfran 2024-07-22 13:13:33 +02:00
parent 2138985f9f
commit 8ce04d38a1
2 changed files with 25 additions and 2 deletions

View file

@ -14,14 +14,37 @@ penpot.ui.onMessage<PluginUIEvent>((message) => {
selection: penpot.getSelectedShapes(),
},
});
initEvents();
}
});
penpot.on('selectionchange', () => {
const shapes = penpot.getSelectedShapes();
sendMessage({ type: 'selection', content: shapes });
initEvents();
});
let listeners: symbol[] = [];
function initEvents() {
listeners.forEach((listener) => {
penpot.off(listener);
});
listeners = penpot.selection.map((shape) => {
return penpot.on(
'shapechange',
() => {
const shapes = penpot.getSelectedShapes();
sendMessage({ type: 'selection', content: shapes });
},
{ shapeId: shape.id }
);
});
}
penpot.on('themechange', () => {
const theme = penpot.getTheme();
sendMessage({ type: 'theme', content: theme });

View file

@ -65,11 +65,11 @@ export interface Penpot
*
* The following are the posible event types:
* - pagechange: event emitted when the current page changes. The callback will receive the new page.
* - shapechanged: event emitted when the shape changes. This event requires to send inside the `props` object the shape
* - shapechange: event emitted when the shape changes. This event requires to send inside the `props` object the shape
* that will be observed. For example:
* ```javascript
* // Observe the current selected shape
* penpot.on('shapechanged', (shape) => console.log(shape.name), { shapeId: penpot.selection[0].id });
* penpot.on('shapechange', (shape) => console.log(shape.name), { shapeId: penpot.selection[0].id });
* ```
* - selectionchange: event emitted when the current selection changes. The callback will receive the list of ids for the new selection
* - themechange: event emitted when the user changes its theme. The callback will receive the new theme (currentlly: either `dark` or `light`)