annotate web/RdfdbSyncedGraph.ts @ 2376:4556eebe5d73

topdir reorgs; let pdm have its src/ dir; separate vite area from light9/
author drewp@bigasterisk.com
date Sun, 12 May 2024 19:02:10 -0700
parents light9/web/RdfdbSyncedGraph.ts@06bf6dae8e64
children f2b3cfcc23d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2074
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
1 import debug from "debug";
2268
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
2 import { LitElement, css, html } from "lit";
2074
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
3 import { customElement, property } from "lit/decorators.js";
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
4 import { SyncedGraph } from "./SyncedGraph";
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
5
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
6 const log = debug("syncedgraph-el");
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
7
2268
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
8 // Contains a SyncedGraph. Displays as little status box.
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
9 // Put one element on your page and use getTopGraph everywhere.
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
10 @customElement("rdfdb-synced-graph")
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
11 export class RdfdbSyncedGraph extends LitElement {
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
12 @property() graph: SyncedGraph;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
13 @property() status: string;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
14 @property() testGraph = false;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
15 static styles = [
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
16 css`
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
17 :host {
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
18 display: inline-block;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
19 border: 1px solid gray;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
20 min-width: 22em;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
21 background: #05335a;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
22 color: #4fc1d4;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
23 }
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
24 `,
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
25 ];
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
26 render() {
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
27 return html`graph: ${this.status}`;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
28 }
2074
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
29
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
30 constructor() {
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
31 super();
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
32 this.status = "startup";
2087
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
33 const prefixes = new Map<string, string>([
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
34 ["", "http://light9.bigasterisk.com/"],
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
35 ["dev", "http://light9.bigasterisk.com/device/"],
2270
b51c74da9d35 more cleanup- mixed up with other commits
drewp@bigasterisk.com
parents: 2268
diff changeset
36 ["effect", "http://light9.bigasterisk.com/effect/"],
2087
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
37 ["rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"],
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
38 ["rdfs", "http://www.w3.org/2000/01/rdf-schema#"],
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
39 ["xsd", "http://www.w3.org/2001/XMLSchema#"],
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
40 ]);
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
41 this.graph = new SyncedGraph(
2372
06bf6dae8e64 reorg tools into light9/web/ and a single vite instance
drewp@bigasterisk.com
parents: 2270
diff changeset
42 this.testGraph ? "unused" : "/service/rdfdb/syncedGraph",
2087
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
43 prefixes,
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
44 (s: string) => {
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
45 this.status = s;
2268
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
46 }
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
47 );
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
48 setTopGraph(this.graph);
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
49 }
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
50 }
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
51
2268
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
52 // todo: consider if this has anything to contribute:
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
53 // https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
54 let setTopGraph: (sg: SyncedGraph) => void;
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
55 (window as any).topSyncedGraph = new Promise<SyncedGraph>((res, rej) => {
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
56 setTopGraph = res;
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
57 });
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
58
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
59 export async function getTopGraph(): Promise<SyncedGraph> {
2074
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
60 const s = (window as any).topSyncedGraph;
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
61 return await s;
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
62 }