-
-
Notifications
You must be signed in to change notification settings - Fork 253
Expand file tree
/
Copy pathapp.ts
More file actions
125 lines (111 loc) · 3.15 KB
/
app.ts
File metadata and controls
125 lines (111 loc) · 3.15 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { goToSnippet } from '@/composable'
import { platform, store } from '@/electron'
import type { MarkdownSettings } from '@shared/types/main/store'
import type {
CodePreviewSettings,
EditorSettings,
ScreenshotSettings,
State,
Theme
} from '@shared/types/renderer/store/app'
import { defineStore } from 'pinia'
import { version } from '../../../package.json'
export const EDITOR_DEFAULTS: EditorSettings = {
fontFamily: 'SF Mono, Consolas, Menlo, Ubuntu Mono, monospace',
fontSize: 12,
tabSize: 2,
wrap: true,
trailingComma: 'none',
semi: false,
singleQuote: true,
highlightLine: false,
highlightGutter: false,
matchBrackets: false,
showFragments: false
}
const SCREENSHOT_DEFAULTS: ScreenshotSettings = {
background: false,
gradient: ['#D02F98', '#9439CA'],
darkMode: true,
width: 600
}
const CODE_PREVIEW_DEFAULTS: CodePreviewSettings = {
darkMode: false
}
const MARKDOWN_DEFAULTS: MarkdownSettings = {
presentationScale: 1.3,
codeRenderer: 'highlight.js'
}
const HISTORY_LIMIT = 50
export const useAppStore = defineStore('app', {
state: (): State => ({
isInit: false,
isSponsored: import.meta.env.VITE_SPONSORED === 'true',
theme: 'light:github',
showTags: true,
showModal: false,
sizes: {
titlebar: 15,
sidebar: 180,
snippetList: 250,
codePreviewHeight: 200,
editor: {
titleHeight: 34,
fragmentsHeight: 25,
tagsHeight: 40,
descriptionHeight: 58,
footerHeight: 30
}
},
editor: EDITOR_DEFAULTS,
screenshot: SCREENSHOT_DEFAULTS,
codePreview: CODE_PREVIEW_DEFAULTS,
markdown: MARKDOWN_DEFAULTS,
selectedPreferencesMenu: 'storage',
selectedDevtoolsMenu: 'textTools.caseConverter',
language: store.preferences.get('language'),
history: [],
historyIndex: 0,
version,
platform: platform()
}),
getters: {
isLightTheme: state => !!state.theme.match(/^light/)
},
actions: {
setTheme (theme: Theme) {
this.theme = theme
store.preferences.set('theme', theme)
store.preferences.set('editor', { ...this.editor })
},
resetEditorSettings () {
this.editor = EDITOR_DEFAULTS
},
isEditorSettingsValid (settings: EditorSettings) {
const defaults = Object.keys(EDITOR_DEFAULTS)
const toCompare = Object.keys(settings)
return defaults.every(i => toCompare.includes(i))
},
setLang (lang: string) {
this.language = lang
store.preferences.set('language', lang)
},
addToHistory (snippetId: string) {
if (!snippetId) return
if (this.history[this.history.length - 1] === snippetId) return
if (this.history.length === HISTORY_LIMIT) this.history.shift()
this.history.push(snippetId)
this.historyIndex = this.history.length - 1
},
historyBack () {
if (this.historyIndex === 0) return
this.historyIndex = this.historyIndex - 1
goToSnippet(this.history[this.historyIndex])
},
historyForward () {
if (this.historyIndex === this.history.length - 1) return
this.historyIndex = this.historyIndex + 1
goToSnippet(this.history[this.historyIndex])
}
}
})