2023-10-29 20:22:30 -04:00
|
|
|
import {LitElement, html} from './lit-all.min.js';
|
|
|
|
import * as tfrpc from '/static/tfrpc.js';
|
|
|
|
|
|
|
|
class TfWikiDocElement extends LitElement {
|
|
|
|
static get properties() {
|
|
|
|
return {
|
|
|
|
whoami: {type: String},
|
|
|
|
value: {type: Object},
|
|
|
|
blob: {type: String},
|
|
|
|
blob_original: {type: String},
|
2023-11-01 18:21:42 -04:00
|
|
|
blob_for_value: {type: String},
|
2023-10-29 20:22:30 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
async load_blob() {
|
|
|
|
this.blob = await tfrpc.rpc.get_blob(this.value?.blob);
|
|
|
|
this.blob_original = this.blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
on_edit(event) {
|
|
|
|
this.blob = event.srcElement.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
async publish() {
|
|
|
|
let id = await tfrpc.rpc.store_blob(this.blob);
|
|
|
|
this.dispatchEvent(new CustomEvent('publish', {
|
|
|
|
bubbles: true,
|
|
|
|
detail: {
|
|
|
|
id: id,
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2023-11-01 18:21:42 -04:00
|
|
|
let value = JSON.stringify(this.value);
|
|
|
|
if (this.blob_for_value != value) {
|
|
|
|
this.blob_for_value = value;
|
|
|
|
this.blob = undefined;
|
|
|
|
this.blob_original = undefined;
|
2023-10-29 20:22:30 -04:00
|
|
|
this.load_blob();
|
|
|
|
}
|
|
|
|
return html`
|
2023-11-01 19:39:34 -04:00
|
|
|
<div style="display: flex; flex-direction: row">
|
|
|
|
<textarea
|
|
|
|
style="flex: 1 1; min-height: 10em"
|
|
|
|
@input=${this.on_edit} .value=${this.blob ?? ''}></textarea>
|
|
|
|
<div style="flex: 1 1">${this.blob}</div>
|
|
|
|
</div>
|
2023-10-29 20:22:30 -04:00
|
|
|
<button ?disabled=${this.blob == this.blob_original} @click=${this.publish}>Publish</button>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define('tf-wiki-doc', TfWikiDocElement);
|