-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.ts
59 lines (48 loc) · 1.04 KB
/
main.ts
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
import Alpine from 'alpinejs';
import { marked } from 'marked';
declare global {
interface Window {
Alpine: typeof Alpine;
}
}
window.Alpine = Alpine;
Alpine.data('question', () => ({
summarise: '',
problem: '',
solving: '',
expectation: '',
markup: '',
markdown() {
const combined = [
`# ${this.summarise}`,
'## The Problem',
this.problem,
'## What I tried',
this.solving,
'## What I expect to happen',
this.expectation,
].join('\n\n');
return combined;
},
init() {},
output() {
const html = marked.parse(this.markdown());
return html;
},
copy() {
navigator.clipboard.writeText(this.markdown());
},
preview() {
this.markup = this.output();
},
resize(event: {
target: { style: { height: string }; scrollHeight: number };
}) {
const MIN_HEIGHT = Number(event.target.style.height.replace('px', ''));
event.target.style.height = `${Math.max(
MIN_HEIGHT,
event.target.scrollHeight,
)}px`;
},
}));
Alpine.start();