-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathindex.ts
More file actions
96 lines (79 loc) · 2.85 KB
/
Copy pathindex.ts
File metadata and controls
96 lines (79 loc) · 2.85 KB
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
// IMPORTANT: must be the first import so window.SolidLogic / window.$rdf are
// defined before solid-ui / solid-panes prebuilt bundles are evaluated
// (they declare `solid-logic` and `rdflib` as UMD externals with
// root: "SolidLogic" / "$rdf").
import './globals'
import * as $rdf from 'rdflib'
import * as SolidLogic from 'solid-logic'
import type { RenderEnvironment } from 'pane-registry'
import'solid-ui/components/header'
import * as panes from 'solid-panes'
import { layout } from './layout'
import { theme } from './theme'
import versionInfo from './versionInfo'
import './styles/mash.css'
const global: any = window
global.panes = panes
global.mashlib = { versionInfo }
layout.init()
theme.init()
// Build a snapshot of the current render environment
const buildRenderEnvironment = (): RenderEnvironment => ({
layout: layout.get(),
layoutPreference: layout.getPreference(),
inputMode: layout.getInputMode(),
theme: theme.get(),
viewport: layout.getViewport()
})
// Inject or update the environment on the pane context
const syncEnvironmentToContext = async (_trigger?: Event | string) => {
const outliner = panes.getOutliner(document) as any
if (!outliner) {
return
}
if (!outliner.context) {
outliner.context = {}
}
panes.updateEnvironment(outliner, buildRenderEnvironment())
await panes.refreshUI(outliner)
}
// Keep environment in sync on layout/theme changes
window.addEventListener('mashlib:layoutchange', syncEnvironmentToContext)
window.addEventListener('mashlib:themechange', syncEnvironmentToContext)
global.panes.runDataBrowser = function (uri?:string|$rdf.NamedNode|null) {
// Set up cross-site proxy
const fetcher: any = $rdf.Fetcher
fetcher.crossSiteProxyTemplate = window.origin + '/xss/?uri={uri}'
// Add web monetization tag to page header
try {
const webMonetizationTag: HTMLElement = document.createElement('meta')
webMonetizationTag.setAttribute('name', 'monetization')
webMonetizationTag.setAttribute('content', `$${window.location.host}`)
document.head.appendChild(webMonetizationTag)
} catch {}
window.addEventListener('load', syncEnvironmentToContext)
// Authenticate the user
SolidLogic.authn.checkUser()
.then(() => {
// Avoid rdflib type identity clashes when workspace packages resolve different node_modules paths.
const storeForPanes = SolidLogic.solidLogicSingleton.store as unknown as Parameters<typeof panes.initMainPage>[0]
return panes.initMainPage(storeForPanes, uri)
})
.then(() => {
// Inject render environment into pane context after outliner exists
syncEnvironmentToContext('initMainPage')
})
.catch(() => undefined)
}
window.onpopstate = function (_event: any) {
global.document.outline.GotoSubject(
$rdf.sym(window.document.location.href),
true,
undefined,
true,
undefined
)
}
export {
versionInfo,
}