From 3b1a3cb18f2a19bc8e2b72488ef48fada0dc92bb Mon Sep 17 00:00:00 2001 From: Chris Millar Date: Sat, 17 Aug 2024 21:11:18 -0600 Subject: [PATCH] Libplug (#196) * Add context to what page is being edited * Implement sendText * Add close function * Minor fixes for plugins --- blocks/edit/da-library/da-library.js | 39 ++++++++++++++++++---------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/blocks/edit/da-library/da-library.js b/blocks/edit/da-library/da-library.js index 17fdf680..b4f28d51 100644 --- a/blocks/edit/da-library/da-library.js +++ b/blocks/edit/da-library/da-library.js @@ -17,6 +17,16 @@ const ICONS = [ let accessToken; +function closeLibrary() { + const palletePane = window.view.dom.nextElementSibling; + const existingPalette = palletePane.querySelector('da-library'); + if (existingPalette) { + existingPalette.remove(); + return true; + } + return false; +} + class DaLibrary extends LitElement { static properties = { _libraryList: { state: true }, @@ -39,10 +49,9 @@ class DaLibrary extends LitElement { handleLibSwitch(e) { const { target } = e; - const type = target.classList[0]; + const type = target.dataset.libraryName; target.closest('.palette-pane').classList.add('backward'); const toShow = this.shadowRoot.querySelector(`[data-library-type="${type}"]`); - this._title = toShow.dataset.libraryName; toShow.classList.remove('forward'); } @@ -89,10 +98,13 @@ class DaLibrary extends LitElement { async handlePluginLoad({ target }) { const channel = new MessageChannel(); channel.port1.onmessage = (e) => { - if (e.data) { - const para = window.view.state.schema.text(e.data); + if (e.data.action === 'sendText') { + const para = window.view.state.schema.text(e.data.details); window.view.dispatch(window.view.state.tr.replaceSelectionWith(para)); } + if (e.data.action === 'closeLibrary') { + closeLibrary(); + } }; if (!accessToken) { @@ -108,7 +120,7 @@ class DaLibrary extends LitElement { project, context: project, }; - if (accessToken) message.token = accessToken; + if (accessToken) message.token = accessToken.token; target.contentWindow.postMessage(message, '*', [channel.port2]); }, 750); } @@ -208,6 +220,7 @@ class DaLibrary extends LitElement { `; } + // http://localhost:6456/nx/sdk/demo.html renderPlugin(url) { return html`
@@ -254,7 +267,7 @@ class DaLibrary extends LitElement {