-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathindex.tsx
More file actions
38 lines (35 loc) · 1.22 KB
/
index.tsx
File metadata and controls
38 lines (35 loc) · 1.22 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
import { NewPaneOptions, PaneDefinition } from '../types'
import solidUi from 'solid-ui'
import { NamedNode, sym } from 'rdflib'
import { MarkdownController } from './markdown.controller'
import { MarkdownView } from './markdown.view'
import { saveMarkdown } from './markdown.service'
const { icons, store } = 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) => {
const controller = new MarkdownController(subject.uri)
return MarkdownView(controller)
}
}
function createFileName (options: NewPaneOptions): NamedNode {
let uri = options.newBase
if (uri.endsWith('/')) {
uri = uri.slice(0, -1) + '.md'
}
return sym(uri)
}