Ah – so edits are allowed only on the same tick as the event that triggered your callback. If you want to do something asynchronous, you need to first call editDocument
and then do your async operation so that XD knows to hold the document open longer.
For example:
editButton.onclick = (e) => {
require("application").editDocument(() => {
const value = await doAsync();
try {
scenegraph.root.pluginData = { value };
} catch (ex) {
console.log("Failed", ex);
}
});
}