({
async appOption(app) {
await app.openEmbed();
await app.navigate("https://www.amplenote.com/notes/plugins/" + app.context.pluginUUID);
},
async insertText(app) {
await app.context.replaceSelection(`<object data="plugin://${ app.context.pluginUUID }" data-aspect-ratio="1" />`);
return null;
},
async onEmbedCall(app, type, data) {
if (type === "load") {
const args = app.context.embedArgs;
if (args.length !== 1) return null
return atob(args[0]);
} else if (type === "change") {
const encodedData = btoa(data);
app.context.updateEmbedArgs(encodedData);
return true;
}
},
async renderEmbed(app) {
if (app.context.setEmbedHTML) {
app.context.setEmbedHTML(`
<div style="animation: amplenote-embed-spin 0.8s linear infinite; border: 3px solid rgba(133, 147, 163, 0.25); border-top-color: #8593A3; border-radius: 50%; box-sizing: border-box; height: 36px; width: 36px; position: fixed; top: 50%; left: 50%; margin: -18px 0 0 -18px;"></div>
<style>@keyframes amplenote-embed-spin { to { transform: rotate(360deg); } }</style>
`);
}
try {
const attachments = await app.getNoteAttachments(app.context.pluginUUID);
const attachment = attachments.find(attachment => attachment.name === "build.html.json");
if (!attachment) throw new Error("build.html.json attachment not found");
return this._getAttachmentContent(app, attachment.uuid);
} catch (error) {
return `<div><em>renderEmbed error:</em> ${ error.toString() }</div>`;
}
},
async _getAttachmentContent(app, attachmentUUID) {
const url = await app.getAttachmentURL(attachmentUUID);
const proxyURL = new URL("https://plugins.amplenote.com/cors-proxy");
proxyURL.searchParams.set("apiurl", url);
const response = await fetch(proxyURL);
return response.text();
}
})