Files
@ 26f84fc67ab1
Branch filter:
Location: light9/web/ResourceDisplay.ts - annotation
26f84fc67ab1
4.6 KiB
video/MP2T
start 2024 show
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 4556eebe5d73 | import { TextField } from "@material/mwc-textfield";
import debug from "debug";
import { css, html, LitElement, PropertyValues } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { NamedNode } from "n3";
import { getTopGraph } from "./RdfdbSyncedGraph";
import { SyncedGraph } from "./SyncedGraph";
export { Button } from "@material/mwc-button";
export { Dialog } from "@material/mwc-dialog";
export { TextField } from "@material/mwc-textfield";
const log = debug("rdisplay");
@customElement("resource-display")
export class ResourceDisplay extends LitElement {
graph!: SyncedGraph;
static styles = [
css`
:host {
display: inline-block;
}
a.resource {
color: inherit;
text-decoration: none;
}
.resource {
border: 1px solid #545454;
border-radius: 5px;
padding: 1px;
margin: 2px;
background: rgb(49, 49, 49);
display: inline-block;
text-shadow: 1px 1px 2px black;
}
.resource.minor {
background: none;
border: none;
}
.resource a {
color: rgb(150, 150, 255);
padding: 1px;
display: inline-block;
}
.resource.minor a {
text-decoration: none;
color: rgb(155, 155, 193);
padding: 0;
}
`,
];
render() {
let renameDialog = html``;
if (this.renameDialogOpen) {
renameDialog = html` <mwc-dialog id="renameDialog" open @closing=${this.onRenameClosing} @closed=${this.onRenameClosed}>
<p>
New label:
<mwc-textfield id="renameField" dialogInitialFocus .value=${this.renameTo}></mwc-textfield>
</p>
<mwc-button dialogAction="cancel" slot="secondaryAction">Cancel</mwc-button>
<mwc-button dialogAction="ok" slot="primaryAction">OK</mwc-button>
</mwc-dialog>`;
}
return html` <span class="${this.resClasses()}">
<a href="${this.href()}" id="uri"> <!-- type icon goes here -->${this.label}</a>
${this.rename ? html`<button @click=${this.onRename}>Rename</button>` : ""} </span
>${renameDialog}`;
//
}
@property() uri?: NamedNode;
@state() label: string = "";
@state() renameDialogOpen = false;
@state() renameTo = "";
@property({ type: Boolean }) rename: boolean = false;
@property({ type: Boolean }) noclick: boolean = false;
@property({ type: Boolean }) minor: boolean = false;
constructor() {
super();
getTopGraph().then((g) => {
this.graph = g;
this.onUri();
});
}
updated(changedProperties: PropertyValues) {
if (changedProperties.has("uri")) {
this.onUri();
}
}
private onUri() {
if (!this.graph) {
return; /*too soon, but getTopGraph will call us again*/
}
if (this.uri === undefined) {
this.label = "(unset)";
} else if (this.uri === null) {
throw 'use undefined please'
} else {
this.graph.runHandler(this.compile.bind(this, this.graph), `label for ${this.uri.id}`);
}
}
private compile(graph: SyncedGraph) {
if (this.uri === undefined) {
return;
} else {
this.label = this.graph.labelOrTail(this.uri);
}
}
private href(): string {
if (!this.uri || this.noclick) {
return "javascript:;";
}
return this.uri.value;
}
private resClasses() {
return this.minor ? "resource minor" : "resource";
}
private onRename() {
this.renameTo = this.label;
this.renameDialogOpen = true;
setTimeout(() => {
// I! 👏 know! 👏 the! 👏 element! 👏 I! 👏 want!
const inputEl = this.shadowRoot!.querySelector("#renameField")!.shadowRoot!.querySelector("input")! as HTMLInputElement;
inputEl.setSelectionRange(0, -1);
}, 100);
}
// move to SyncedGraph
private whatCtxHeldTheObj(subj: NamedNode, pred: NamedNode): NamedNode {
var ctxs = this.graph.contextsWithPattern(subj, pred, null);
if (ctxs.length != 1) {
throw new Error(`${ctxs.length} ${pred.id} stmts for ${subj.id}`);
}
return ctxs[0];
}
private onRenameClosing(ev: CustomEvent) {
this.renameTo = (this.shadowRoot!.querySelector("#renameField")! as TextField).value;
}
private onRenameClosed(ev: CustomEvent) {
this.renameDialogOpen = false;
if (ev.detail.action == "ok") {
var label = this.graph.Uri("rdfs:label");
if (this.uri === undefined) {
throw "lost uri";
}
const ctx = this.whatCtxHeldTheObj(this.uri, label);
this.graph.patchObject(this.uri, label, this.graph.Literal(this.renameTo), ctx);
}
this.renameTo = "";
}
}
|