Skip to content

Commit 6ec02ef

Browse files
megothArne Hassel
authored andcommitted
Added mintNew method
1 parent 83a4b82 commit 6ec02ef

3 files changed

Lines changed: 44 additions & 25 deletions

File tree

markdown/index.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
import * 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

56
const { S } = Surplus
7+
const { icons, store } = solidUi
68

79
export 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+
}

types.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ export interface PaneDefinition {
99
shouldGetFocus?: (subject: NamedNode) => boolean;
1010
requireQueryButton?: boolean;
1111
mintClass?: NamedNode;
12-
mintNew?: (options: NewPaneOptions) => Promise<NewPaneOptions & { newInstance: NamedNode }>;
13-
};
14-
interface NewPaneOptions {
12+
mintNew?: (options: NewPaneOptions) => Promise<NewPaneOptions & {newInstance: NamedNode}>;
13+
}
14+
15+
export interface NewPaneOptions {
1516
appPathSegment: string;
1617
div: HTMLDivElement;
1718
dom: HTMLDocument;
@@ -32,24 +33,10 @@ export interface ViewParams {
3233
store: IndexedFormula;
3334
visitNode: (node: NamedNode) => void;
3435
user?: NamedNode;
35-
};
36+
}
3637

3738
export interface RevampPaneDefinition {
3839
canHandle: (subject: NamedNode, store: IndexedFormula) => boolean;
3940
view: (params: ViewParams) => void;
4041
label: (subject: NamedNode, store: IndexedFormula) => string | null;
41-
};
42-
interface NewPaneOptions {
43-
appPathSegment: string;
44-
div: HTMLDivElement;
45-
dom: HTMLDocument;
46-
folder: NamedNode;
47-
iconEle: HTMLImageElement;
48-
me?: NamedNode;
49-
newBase: string;
50-
newInstance: NamedNode;
51-
noIndexHTML: boolean;
52-
noun: string;
53-
pane: PaneDefinition;
54-
refreshTarget: HTMLTableElement;
5542
}

typings/solid-ui/index.d.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
12
declare module 'solid-ui' {
2-
export type SolidUi = any
3+
export type SolidUi = {
4+
authn: any
5+
create: any
6+
icons: any
7+
ns: any
8+
pad: any
9+
store: any
10+
widgets: any
11+
}
312
const solidUi: SolidUi
4-
513
export default solidUi
614
}

0 commit comments

Comments
 (0)