Skip to content

Commit

Permalink
Libplug (#195)
Browse files Browse the repository at this point in the history
* Add context to what page is being edited

* Implement sendText
  • Loading branch information
auniverseaway authored Aug 17, 2024
1 parent 5ab5ff5 commit e7ef5bd
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions blocks/edit/da-library/da-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,33 @@ class DaLibrary extends LitElement {
}

getParts() {
const view = 'edit';
const [org, repo, ...path] = window.location.hash.replace('#/', '').split('/');
return { org, repo, ref: 'main', path: `/${path.join('/')}` };
return { view, org, repo, ref: 'main', path: `/${path.join('/')}` };
}

async handlePluginLoad({ target }) {
const channel = new MessageChannel();
channel.port1.onmessage = (e) => { console.log(e.data); };
this.getParts();
channel.port1.onmessage = (e) => {
if (e.data) {
const para = window.view.state.schema.text(e.data);
window.view.dispatch(window.view.state.tr.replaceSelectionWith(para));
}
};

if (!accessToken) {
const { initIms } = await import('../../shared/utils.js');
({ accessToken } = await initIms());
}

setTimeout(() => {
const message = { ready: true, project: this.getParts() };
const project = this.getParts();

const message = {
ready: true,
project,
context: project,
};
if (accessToken) message.token = accessToken;
target.contentWindow.postMessage(message, '*', [channel.port2]);
}, 750);
Expand Down

0 comments on commit e7ef5bd

Please sign in to comment.