|
| 1 | +/* Tabbed view of anything |
| 2 | + ** |
| 3 | + ** data-driven |
| 4 | + ** |
| 5 | + */ |
| 6 | +import { DataBrowserContext, PaneDefinition } from 'pane-registry' |
| 7 | +import { NamedNode } from 'rdflib' |
| 8 | +import { icons, ns, tabs, widgets } from 'solid-ui' |
| 9 | + |
| 10 | +const TabbedPane: PaneDefinition = { |
| 11 | + icon: icons.iconBase + 'noun_688606.svg', |
| 12 | + |
| 13 | + name: 'tabbed', |
| 14 | + |
| 15 | + audience: [ns.solid('PowerUser')], |
| 16 | + |
| 17 | + // Does the subject deserve this pane? |
| 18 | + label: (subject, context) => { |
| 19 | + const kb = context.session.store |
| 20 | + const typeURIs = kb.findTypeURIs(subject) |
| 21 | + if (ns.meeting('Cluster').uri in typeURIs) { |
| 22 | + return 'Tabbed' |
| 23 | + } |
| 24 | + return null |
| 25 | + }, |
| 26 | + |
| 27 | + render: (subject, context) => { |
| 28 | + const dom = context.dom |
| 29 | + const store = context.session.store |
| 30 | + const div = dom.createElement('div') |
| 31 | + |
| 32 | + ;(async () => { |
| 33 | + // @@ TODO Remove casting of kb.fetcher.load |
| 34 | + await (store.fetcher.load as any)(subject) |
| 35 | + |
| 36 | + div.appendChild(tabs.tabWidget({ |
| 37 | + dom, |
| 38 | + subject, |
| 39 | + predicate: store.any(subject, ns.meeting('predicate')) || ns.meeting('toolList'), |
| 40 | + ordered: true, |
| 41 | + orientation: store.anyValue(subject, ns.meeting('orientation')) || 0, |
| 42 | + renderMain: prepareRenderMainFn(context), |
| 43 | + renderTab: prepareRenderTabFn(subject, context), |
| 44 | + backgroundColor: store.anyValue(subject, ns.ui('backgroundColor')) || '#ddddcc' |
| 45 | + })) |
| 46 | + })() |
| 47 | + return div |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +function prepareRenderTabFn (subject: NamedNode, context: DataBrowserContext): (div, item) => void { |
| 52 | + const predicate = context.session.store.the(subject, ns.meeting('predicate')) |
| 53 | + return (div, item) => { |
| 54 | + div.appendChild(widgets.personTR(context.dom, predicate, item, {})) |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +function prepareRenderMainFn (context: DataBrowserContext): (containerDiv, item) => void { |
| 59 | + return (containerDiv, item) => { |
| 60 | + containerDiv.innerHTML = '' |
| 61 | + const table = containerDiv.appendChild(context.dom.createElement('table')) |
| 62 | + ;(context.getOutliner(context.dom) as any).GotoSubject(item, true, null, false, undefined, table) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +export default TabbedPane |
0 commit comments