-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathindex.ts
More file actions
45 lines (41 loc) · 1.2 KB
/
index.ts
File metadata and controls
45 lines (41 loc) · 1.2 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
import { NewPaneOptions, PaneDefinition } from '../types'
import solidUi from 'solid-ui'
import { NamedNode, sym } from 'rdflib'
import { saveMarkdown } from './markdown.service'
import Vue from 'vue'
import App from './App.vue'
const { icons } = solidUi
export const Pane: PaneDefinition = {
icon: `${icons.iconBase}noun_79217.svg`,
name: 'MarkdownPane',
label: (subject: NamedNode) => subject.uri.endsWith('.md') ? 'Handle markdown file' : null,
mintNew: function (options: NewPaneOptions) {
const newInstance = createFileName(options)
return saveMarkdown(newInstance.uri, '# This is your markdown file\n\nHere be stuff!')
.then((): NewPaneOptions => ({
newInstance,
...options
}))
.catch((err: any) => {
console.error('Error creating new instance of markdown file', err)
return options
})
},
render: (subject: NamedNode) => {
return new Vue({
el: '#MarkdownApp',
render: h => h(App, {
props: {
subject
}
})
}).$el
}
}
function createFileName (options: NewPaneOptions): NamedNode {
let uri = options.newBase
if (uri.endsWith('/')) {
uri = uri.slice(0, -1) + '.md'
}
return sym(uri)
}