11import * as Surplus from 'surplus'
2- import { PaneDefinition } from '../types'
3- // import data from 'surplus-mixin-data'
2+ import { NewPaneOptions , PaneDefinition } from '../types'
3+ import solidUi from 'solid-ui'
4+ import { NamedNode , sym } from 'rdflib'
45
56const { S } = Surplus
7+ const { icons, store } = solidUi
68
79export const Pane : PaneDefinition = {
8- icon : 'crazy/url/icon. svg' ,
10+ icon : ` ${ icons . iconBase } noun_15177. svg` ,
911 name : 'MarkdownPane' ,
10- label : ( ) => 'Handle markdown file' ,
11- render : ( _subject : any , dom : HTMLDocument ) => {
12+ label : ( subject : NamedNode ) => subject . uri . endsWith ( '.md' ) ? 'Handle markdown file' : null ,
13+ mintNew : function ( options : NewPaneOptions ) {
14+ const newInstance = createFileName ( options )
15+ return store . fetcher . webOperation ( 'PUT' , newInstance , {
16+ data : '# This is your markdown file\n\nHere be stuff!' ,
17+ contentType : 'text/markdown; charset=UTF-8'
18+ } )
19+ . then ( ( ) => ( {
20+ newInstance,
21+ ...options
22+ } ) )
23+ . catch ( ( err : any ) => {
24+ console . error ( 'Error creating new instance of markdown file' , err )
25+ } )
26+ } ,
27+ render : ( ) => {
1228 let counter = 0
1329 let counterData = S . data ( counter )
1430 const incr = ( ) => {
@@ -22,3 +38,11 @@ export const Pane: PaneDefinition = {
2238 </ div >
2339 }
2440}
41+
42+ function createFileName ( options : NewPaneOptions ) : NamedNode {
43+ let uri = options . newBase
44+ if ( uri . endsWith ( '/' ) ) {
45+ uri = uri . slice ( 0 , - 1 ) + '.md'
46+ }
47+ return sym ( uri )
48+ }
0 commit comments