Skip to content

Commit

Permalink
Don't request content from da-admin (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlpauls authored Feb 14, 2024
1 parent 42a3297 commit adc18d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 90 deletions.
26 changes: 11 additions & 15 deletions blocks/edit/da-editor/da-editor.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
import { LitElement, html } from '../../../deps/lit/lit-core.min.js';
import getContent from '../utils/content.js';
import initProse from '../prose/index.js';
import getSheet from '../../shared/sheet.js';

const sheet = await getSheet('/blocks/edit/da-editor/da-editor.css');

// Milo Imports
const { getLibs } = await import('../../../scripts/utils.js');
const { loadIms } = await import(`${getLibs()}/utils/utils.js`);

export default class DaEditor extends LitElement {
static properties = {
path: {},
_content: {},
_contentLoaded: { state: true },
_imsLoaded: { state: false },
};

async getContent(path) {
this._contentLoaded = false;
this._content = await getContent(`${path}`);
this._contentLoaded = true;
this._path = path;
}

connectedCallback() {
super.connectedCallback();
this.shadowRoot.adoptedStyleSheets = [sheet];
this.shadowRoot.createRange = () => document.createRange();
loadIms().then(() => {
this._imsLoaded = true;
});
}

attributeChangedCallback(name, _old, value) {
super.attributeChangedCallback();
if (name !== 'path') return;
this.getContent(value);
this._path = value;
}

render() {
if (!this._content) return null;
if (!this._imsLoaded) return null;
return html`<div class="da-prose-mirror"></div>`;
}

updated() {
if (!this._content) return;
if (!this._imsLoaded) return;
const prose = this.shadowRoot.querySelector('.da-prose-mirror');
prose.innerHTML = '';
const content = document.createElement('div');
content.append(...this._content);
initProse({ editor: prose, path: this._path });
}
}
Expand Down
22 changes: 0 additions & 22 deletions blocks/edit/utils/content.js

This file was deleted.

53 changes: 0 additions & 53 deletions blocks/edit/utils/default-content.js

This file was deleted.

0 comments on commit adc18d9

Please sign in to comment.