-
-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathApp.vue
More file actions
207 lines (184 loc) · 5.4 KB
/
Copy pathApp.vue
File metadata and controls
207 lines (184 loc) · 5.4 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<script lang="ts">
export default {
name: 'HistoireApp',
}
</script>
<script lang="ts" setup>
import type { StoryFile, Tree } from './types'
import { useTitle } from '@vueuse/core'
import { onUpdate, files as rawFiles, tree as rawTree } from 'virtual:$histoire-stories'
import { computed, onMounted, ref, watch } from 'vue'
import AppActions from './components/app/AppActions.vue'
import AppHeader from './components/app/AppHeader.vue'
import Breadcrumb from './components/app/Breadcrumb.vue'
import InitialLoading from './components/app/InitialLoading.vue'
import TopBar from './components/app/TopBar.vue'
import BaseSplitPane from './components/base/BaseSplitPane.vue'
import CommandPromptsModal from './components/command/CommandPromptsModal.vue'
import LayoutModal from './components/layout/LayoutModal.vue'
import SearchModal from './components/search/SearchModal.vue'
import GenericMountStory from './components/story/GenericMountStory.vue'
import StoryList from './components/tree/StoryList.vue'
import { useCommandStore } from './stores/command'
import { useLayoutStore } from './stores/layout'
import { useStoryStore } from './stores/story'
import { histoireConfig } from './util/config'
import { onKeyboardShortcut } from './util/keyboard'
import { mapFile } from './util/mapping'
import { isMobile } from './util/responsive'
const files = ref<StoryFile[]>(rawFiles.map(file => mapFile(file)))
const tree = ref<Tree>(rawTree)
onUpdate((newFiles: StoryFile[], newTree: Tree) => {
loading.value = false
files.value = newFiles.map((file) => {
const existingFile = files.value.find(f => f.id === file.id)
return mapFile(file, existingFile)
})
tree.value = newTree
})
const stories = computed(() => files.value.reduce((acc, file) => {
acc.push(file.story)
return acc
}, []))
// Store
const storyStore = useStoryStore()
watch(stories, (value) => {
storyStore.setStories(value)
}, {
immediate: true,
})
useTitle(computed(() => {
if (storyStore.currentStory) {
let title = storyStore.currentStory.title
if (storyStore.currentVariant) {
title += ` › ${storyStore.currentVariant.title}`
}
return `${title} | ${histoireConfig.theme.title}`
}
return histoireConfig.theme.title
}))
const loadSearch = ref(false)
const isSearchOpen = ref(false)
const isLayoutOpen = ref(false)
watch(isSearchOpen, (value) => {
if (value) {
loadSearch.value = true
}
})
onKeyboardShortcut(['ctrl+k', 'meta+k'], (event) => {
isSearchOpen.value = true
event.preventDefault()
})
onKeyboardShortcut(['ctrl+shift+l', 'meta+shift+l'], (event) => {
isLayoutOpen.value = !isLayoutOpen.value
event.preventDefault()
})
const loading = ref(false)
if (import.meta.hot && !rawFiles.length) {
loading.value = true
import.meta.hot.on('histoire:all-stories-loaded', () => {
loading.value = false
})
}
const mounted = ref(false)
onMounted(() => {
mounted.value = true
})
const commandStore = useCommandStore()
const layoutStore = useLayoutStore()
</script>
<template>
<div
v-if="storyStore.currentStory"
class="histoire-app htw-hidden"
>
<GenericMountStory
:key="storyStore.currentStory.id"
:story="storyStore.currentStory"
/>
</div>
<div
class="htw-h-screen htw-bg-gray-100 dark:htw-bg-gray-750 dark:htw-text-gray-100"
:style="{
// Prevent flash of content
opacity: mounted ? 1 : 0,
}"
>
<div
v-if="isMobile"
class="htw-h-full htw-flex htw-flex-col htw-divide-y htw-divide-gray-100 dark:htw-divide-gray-800"
>
<div class="htw-flex htw-items-center htw-gap-2 htw-pr-4">
<AppHeader class="htw-flex-1" />
<AppActions
class="htw-flex-none"
@layout="isLayoutOpen = true"
@search="isSearchOpen = true"
/>
</div>
<Breadcrumb
:tree="tree"
:stories="stories"
/>
<RouterView class="htw-grow" />
</div>
<BaseSplitPane
v-else-if="layoutStore.settings.storyListVisible"
save-id="main-horiz"
:min="5"
:max="50"
:default-split="15"
class="htw-h-full"
>
<template #first>
<div class="htw-flex htw-flex-col htw-h-full htw-bg-gray-100 dark:htw-bg-gray-750 __histoire-pane-shadow-from-right">
<AppHeader class="htw-flex-none" />
<StoryList
:tree="tree"
:stories="stories"
class="htw-flex-1"
/>
</div>
</template>
<template #last>
<div class="htw-flex htw-flex-col htw-h-full">
<TopBar
@layout="isLayoutOpen = true"
@search="isSearchOpen = true"
/>
<RouterView class="htw-flex-1 htw-min-h-0" />
</div>
</template>
</BaseSplitPane>
<div
v-else
class="htw-h-full htw-flex htw-flex-col"
>
<TopBar
@layout="isLayoutOpen = true"
@search="isSearchOpen = true"
/>
<RouterView class="htw-flex-1 htw-min-h-0" />
</div>
<LayoutModal
v-if="!isMobile"
:shown="isLayoutOpen"
@close="isLayoutOpen = false"
/>
<SearchModal
v-if="loadSearch"
:shown="isSearchOpen"
@close="isSearchOpen = false"
/>
<CommandPromptsModal
v-if="__HISTOIRE_DEV__"
:shown="commandStore.showPromptsModal"
@close="commandStore.showPromptsModal = false"
/>
</div>
<transition name="__histoire-fade">
<InitialLoading
v-if="loading"
/>
</transition>
</template>