histoire 0.0.0 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/client.d.ts +2 -0
- package/dist/client/app/App.vue +84 -21
- package/dist/client/app/assets/histoire-text-dark.svg +89 -0
- package/dist/client/app/assets/histoire-text.svg +89 -0
- package/dist/client/app/assets/histoire.svg +51 -0
- package/dist/client/app/codegen/serialize-js.d.ts +1 -0
- package/dist/client/app/codegen/serialize-js.js +113 -0
- package/dist/client/app/codegen/serialize-js.ts +119 -0
- package/dist/client/app/codegen/util.d.ts +10 -0
- package/dist/client/app/codegen/util.js +70 -0
- package/dist/client/app/codegen/util.ts +79 -0
- package/dist/client/app/codegen/vue3.d.ts +2 -0
- package/dist/client/app/codegen/vue3.js +238 -0
- package/dist/client/app/codegen/vue3.ts +240 -0
- package/dist/client/app/components/HomeView.vue +15 -1
- package/dist/client/app/components/StoryControls.vue +7 -2
- package/dist/client/app/components/StoryList.vue +20 -13
- package/dist/client/app/components/StoryListFolder.vue +87 -0
- package/dist/client/app/components/StoryListItem.vue +38 -12
- package/dist/client/app/components/StorySourceCode.vue +121 -0
- package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
- package/dist/client/app/components/StoryVariantListItem.vue +46 -0
- package/dist/client/app/components/StoryVariantSingleView.vue +145 -15
- package/dist/client/app/components/StoryView.vue +88 -54
- package/dist/client/app/components/app/AppHeader.vue +56 -0
- package/dist/client/app/components/app/AppLogo.vue +24 -0
- package/dist/client/app/components/base/BaseEmpty.vue +1 -1
- package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
- package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
- package/dist/client/app/components/exposed/Story.vue +23 -58
- package/dist/client/app/components/exposed/Variant.vue +24 -47
- package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
- package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
- package/dist/client/app/components/search/SearchItem.vue +110 -0
- package/dist/client/app/components/search/SearchModal.vue +179 -0
- package/dist/client/app/composable/variant.js +0 -1
- package/dist/client/app/composable/variant.ts +20 -0
- package/dist/client/app/global-components.js +0 -1
- package/dist/client/app/global-components.ts +10 -0
- package/dist/client/app/index.d.ts +1 -0
- package/dist/client/app/index.js +10 -2
- package/dist/client/app/index.ts +24 -0
- package/dist/client/app/router.js +0 -1
- package/dist/client/app/router.ts +17 -0
- package/dist/client/app/sandbox.d.ts +1 -0
- package/dist/client/app/sandbox.js +53 -0
- package/dist/client/app/sandbox.ts +60 -0
- package/dist/client/app/stores/story.d.ts +167 -50
- package/dist/client/app/stores/story.js +33 -16
- package/dist/client/app/stores/story.ts +58 -0
- package/dist/client/app/style/floating-vue.css +31 -0
- package/dist/client/app/style/main.css +17 -2
- package/dist/client/app/style/sandbox.css +14 -0
- package/dist/client/app/types.d.ts +36 -4
- package/dist/client/app/types.js +0 -1
- package/dist/client/app/types.ts +59 -0
- package/dist/client/app/util/config.d.ts +3 -0
- package/dist/client/app/util/config.js +4 -0
- package/dist/client/app/util/config.ts +6 -0
- package/dist/client/app/util/const.d.ts +1 -0
- package/dist/client/app/util/const.js +1 -0
- package/dist/client/app/util/const.ts +1 -0
- package/dist/client/app/util/dark.d.ts +2 -0
- package/dist/client/app/util/dark.js +3 -0
- package/dist/client/app/util/dark.ts +4 -0
- package/dist/client/app/util/env.d.ts +1 -0
- package/dist/client/app/util/env.js +1 -0
- package/dist/client/app/util/env.ts +1 -0
- package/dist/client/app/util/keyboard.d.ts +8 -0
- package/dist/client/app/util/keyboard.js +82 -0
- package/dist/client/app/util/keyboard.ts +99 -0
- package/dist/client/app/util/mapping.d.ts +3 -0
- package/dist/client/app/util/mapping.js +39 -0
- package/dist/client/app/util/mapping.ts +41 -0
- package/dist/client/app/util/tooltip.d.ts +6 -0
- package/dist/client/app/util/tooltip.js +11 -0
- package/dist/client/app/util/tooltip.ts +13 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.ts +12 -0
- package/dist/client/server/Story.server.vue +65 -0
- package/dist/client/server/Variant.server.vue +50 -0
- package/dist/client/server/index.d.ts +2 -0
- package/dist/client/server/index.js +25 -0
- package/dist/client/server/index.ts +29 -0
- package/dist/client/shim.d.ts +5 -0
- package/dist/node/alias.js +0 -1
- package/dist/node/bin.js +8 -3
- package/dist/node/build.d.ts +2 -0
- package/dist/node/build.js +71 -0
- package/dist/node/collect.d.ts +12 -0
- package/dist/node/collect.js +65 -0
- package/dist/node/colors.d.ts +286 -0
- package/dist/node/colors.js +324 -0
- package/dist/node/commands/build.d.ts +1 -0
- package/dist/node/commands/build.js +10 -0
- package/dist/node/commands/dev.d.ts +1 -1
- package/dist/node/commands/dev.js +45 -13
- package/dist/node/config.d.ts +112 -1
- package/dist/node/config.js +124 -2
- package/dist/node/context.d.ts +13 -0
- package/dist/node/context.js +12 -2
- package/dist/node/dom/dom-keys.d.ts +4 -0
- package/dist/node/dom/dom-keys.js +223 -0
- package/dist/node/dom/env.d.ts +5 -0
- package/dist/node/dom/env.js +22 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +2 -2
- package/dist/node/plugin.d.ts +8 -2
- package/dist/node/plugin.js +150 -22
- package/dist/node/server.d.ts +4 -1
- package/dist/node/server.js +80 -21
- package/dist/node/stories.d.ts +8 -9
- package/dist/node/stories.js +42 -23
- package/dist/node/tree.d.ts +19 -0
- package/dist/node/tree.js +54 -0
- package/dist/node/types.d.ts +38 -0
- package/dist/node/types.js +1 -0
- package/dist/style.css +610 -53
- package/package.json +45 -25
- package/scripts/copy.mjs +11 -0
- package/src/client/app/App.vue +84 -21
- package/src/client/app/assets/histoire-text-dark.svg +89 -0
- package/src/client/app/assets/histoire-text.svg +89 -0
- package/src/client/app/assets/histoire.svg +51 -0
- package/src/client/app/codegen/serialize-js.ts +119 -0
- package/src/client/app/codegen/util.ts +79 -0
- package/src/client/app/codegen/vue3.ts +240 -0
- package/src/client/app/components/HomeView.vue +15 -1
- package/src/client/app/components/StoryControls.vue +7 -2
- package/src/client/app/components/StoryList.vue +20 -13
- package/src/client/app/components/StoryListFolder.vue +87 -0
- package/src/client/app/components/StoryListItem.vue +38 -12
- package/src/client/app/components/StorySourceCode.vue +121 -0
- package/src/client/app/components/StoryVariantGridItem.vue +32 -17
- package/src/client/app/components/StoryVariantListItem.vue +46 -0
- package/src/client/app/components/StoryVariantSingleView.vue +145 -15
- package/src/client/app/components/StoryView.vue +88 -54
- package/src/client/app/components/app/AppHeader.vue +56 -0
- package/src/client/app/components/app/AppLogo.vue +24 -0
- package/src/client/app/components/base/BaseEmpty.vue +1 -1
- package/src/client/app/components/base/BaseListItemLink.vue +55 -0
- package/src/client/app/components/base/BaseSplitPane.vue +57 -21
- package/src/client/app/components/exposed/Story.vue +23 -58
- package/src/client/app/components/exposed/Variant.vue +24 -47
- package/src/client/app/components/misc/HatchedPattern.vue +25 -0
- package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
- package/src/client/app/components/search/SearchItem.vue +110 -0
- package/src/client/app/components/search/SearchModal.vue +179 -0
- package/src/client/app/index.ts +10 -1
- package/src/client/app/sandbox.ts +60 -0
- package/src/client/app/stores/story.ts +39 -15
- package/src/client/app/style/floating-vue.css +31 -0
- package/src/client/app/style/main.css +17 -2
- package/src/client/app/style/sandbox.css +14 -0
- package/src/client/app/types.ts +42 -4
- package/src/client/app/util/config.ts +6 -0
- package/src/client/app/util/const.ts +1 -0
- package/src/client/app/util/dark.ts +4 -0
- package/src/client/app/util/env.ts +1 -0
- package/src/client/app/util/keyboard.ts +99 -0
- package/src/client/app/util/mapping.ts +41 -0
- package/src/client/app/util/tooltip.ts +13 -0
- package/src/client/index.ts +12 -0
- package/src/client/server/Story.server.vue +65 -0
- package/src/client/server/Variant.server.vue +50 -0
- package/src/client/server/index.ts +29 -0
- package/src/node/bin.ts +9 -2
- package/src/node/build.ts +80 -0
- package/src/node/collect.ts +78 -0
- package/src/node/colors.ts +340 -0
- package/src/node/commands/build.ts +12 -0
- package/src/node/commands/dev.ts +49 -12
- package/src/node/config.ts +240 -1
- package/src/node/context.ts +21 -1
- package/src/node/dom/dom-keys.ts +227 -0
- package/src/node/dom/env.ts +26 -0
- package/src/node/index.ts +2 -0
- package/src/node/plugin.ts +155 -22
- package/src/node/server.ts +95 -20
- package/src/node/stories.ts +53 -31
- package/src/node/tree.spec.ts +28 -0
- package/src/node/tree.ts +88 -0
- package/src/node/types.ts +40 -0
- package/tailwind.config.cjs +41 -1
- package/tsconfig.json +2 -1
- package/dist/client/app/components/StoryVariantItem.vue +0 -29
- package/dist/client/app/composable/variant.js.map +0 -1
- package/dist/client/app/global-components.js.map +0 -1
- package/dist/client/app/index.js.map +0 -1
- package/dist/client/app/router.js.map +0 -1
- package/dist/client/app/stores/story.js.map +0 -1
- package/dist/client/app/types.js.map +0 -1
- package/dist/node/alias.js.map +0 -1
- package/dist/node/bin.js.map +0 -1
- package/dist/node/commands/dev.js.map +0 -1
- package/dist/node/config.js.map +0 -1
- package/dist/node/context.js.map +0 -1
- package/dist/node/index.js.map +0 -1
- package/dist/node/plugin.js.map +0 -1
- package/dist/node/server.js.map +0 -1
- package/dist/node/stories.js.map +0 -1
- package/src/client/app/components/StoryVariantItem.vue +0 -29
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { useFocus } from '@vueuse/core'
|
|
3
|
+
import { computed, ref, watch } from 'vue'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
import { useStoryStore } from '../../stores/story'
|
|
6
|
+
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
7
|
+
import type { SearchResult, Story, Variant } from '../../types'
|
|
8
|
+
import SearchItem from './SearchItem.vue'
|
|
9
|
+
|
|
10
|
+
const props = defineProps({
|
|
11
|
+
shown: {
|
|
12
|
+
type: Boolean,
|
|
13
|
+
default: false,
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const emit = defineEmits({
|
|
18
|
+
close: () => true,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
function close () {
|
|
22
|
+
emit('close')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Autofocus
|
|
26
|
+
|
|
27
|
+
const input = ref<HTMLInputElement>()
|
|
28
|
+
const { focused } = useFocus({
|
|
29
|
+
target: input,
|
|
30
|
+
initialValue: true,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
watch(() => props.shown, value => {
|
|
34
|
+
if (value) {
|
|
35
|
+
requestAnimationFrame(() => {
|
|
36
|
+
focused.value = true
|
|
37
|
+
input.value.select()
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// Search
|
|
43
|
+
|
|
44
|
+
const search = ref('')
|
|
45
|
+
|
|
46
|
+
const storyStore = useStoryStore()
|
|
47
|
+
|
|
48
|
+
function storyResultFactory (story: Story, rank: number): SearchResult {
|
|
49
|
+
return {
|
|
50
|
+
kind: 'story',
|
|
51
|
+
rank,
|
|
52
|
+
id: story.id,
|
|
53
|
+
title: story.title,
|
|
54
|
+
route: {
|
|
55
|
+
name: 'story',
|
|
56
|
+
params: {
|
|
57
|
+
storyId: story.id,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
path: story.file.path.slice(0, -1),
|
|
61
|
+
icon: story.icon,
|
|
62
|
+
iconColor: story.iconColor,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function variantResultFactory (story: Story, variant: Variant, rank: number): SearchResult {
|
|
67
|
+
return {
|
|
68
|
+
kind: 'variant',
|
|
69
|
+
rank,
|
|
70
|
+
id: variant.id,
|
|
71
|
+
title: variant.title,
|
|
72
|
+
route: {
|
|
73
|
+
name: 'story',
|
|
74
|
+
params: {
|
|
75
|
+
storyId: story.id,
|
|
76
|
+
},
|
|
77
|
+
query: {
|
|
78
|
+
variantId: variant.id,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
path: [...story.file.path ?? [], story.title],
|
|
82
|
+
icon: variant.icon,
|
|
83
|
+
iconColor: variant.iconColor,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const results = computed(() => {
|
|
88
|
+
const list: SearchResult[] = []
|
|
89
|
+
if (search.value) {
|
|
90
|
+
const s = search.value.toLowerCase()
|
|
91
|
+
for (const story of storyStore.stories) {
|
|
92
|
+
const storyMatched = story.title.toLowerCase().includes(s)
|
|
93
|
+
let storyPathMatched = false
|
|
94
|
+
if (storyMatched || (storyPathMatched = story.file.path.some(p => p.toLowerCase().includes(s)))) {
|
|
95
|
+
list.push(storyResultFactory(story, storyMatched ? 1 : 4))
|
|
96
|
+
}
|
|
97
|
+
for (const variant of story.variants) {
|
|
98
|
+
const variantMatched = variant.title.toLowerCase().includes(s)
|
|
99
|
+
if (storyMatched || storyPathMatched || variantMatched) {
|
|
100
|
+
list.push(variantResultFactory(story, variant, variantMatched ? 2 : storyMatched ? 3 : 5))
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return list.sort((a, b) => a.rank - b.rank)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
// Selection
|
|
109
|
+
|
|
110
|
+
const selectedIndex = ref(0)
|
|
111
|
+
|
|
112
|
+
watch(results, () => {
|
|
113
|
+
selectedIndex.value = 0
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
function selectNext () {
|
|
117
|
+
selectedIndex.value++
|
|
118
|
+
if (selectedIndex.value > results.value.length - 1) {
|
|
119
|
+
selectedIndex.value = 0
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function selectPrevious () {
|
|
124
|
+
selectedIndex.value--
|
|
125
|
+
if (selectedIndex.value < 0) {
|
|
126
|
+
selectedIndex.value = results.value.length - 1
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<template>
|
|
132
|
+
<div
|
|
133
|
+
v-show="shown"
|
|
134
|
+
class="htw-fixed htw-inset-0 htw-bg-white/80 dark:htw-bg-gray-700/80"
|
|
135
|
+
>
|
|
136
|
+
<div
|
|
137
|
+
class="htw-absolute htw-inset-0"
|
|
138
|
+
@click="close()"
|
|
139
|
+
/>
|
|
140
|
+
<div class="htw-bg-white dark:htw-bg-gray-700 md:htw-mt-16 md:htw-mx-auto htw-w-screen htw-max-w-[512px] htw-shadow-xl htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded-lg htw-relative htw-divide-y htw-divide-gray-200 dark:htw-divide-gray-850">
|
|
141
|
+
<div
|
|
142
|
+
class="htw-flex htw-items-center htw-gap-4 htw-pl-6 htw-border htw-border-transparent focus-visible:htw-border-primary-500"
|
|
143
|
+
@click="focused = true"
|
|
144
|
+
>
|
|
145
|
+
<Icon
|
|
146
|
+
icon="carbon:search"
|
|
147
|
+
class="flex-none htw-w-5 htw-h-5"
|
|
148
|
+
/>
|
|
149
|
+
|
|
150
|
+
<input
|
|
151
|
+
ref="input"
|
|
152
|
+
v-model="search"
|
|
153
|
+
placeholder="Search for stories, variants..."
|
|
154
|
+
class="htw-bg-transparent htw-w-full htw-flex-1 htw-pl-0 htw-pr-6 htw-py-4 htw-outline-none"
|
|
155
|
+
@keydown.down="selectNext()"
|
|
156
|
+
@keydown.up="selectPrevious()"
|
|
157
|
+
@keydown.escape="close()"
|
|
158
|
+
>
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<BaseEmpty v-if="search && !results.length">
|
|
162
|
+
No results
|
|
163
|
+
</BaseEmpty>
|
|
164
|
+
|
|
165
|
+
<div
|
|
166
|
+
v-else-if="results.length"
|
|
167
|
+
class="htw-max-h-[400px] htw-overflow-y-auto htw-rounded-b-lg"
|
|
168
|
+
>
|
|
169
|
+
<SearchItem
|
|
170
|
+
v-for="(result, index) of results"
|
|
171
|
+
:key="`${result.kind}-${result.id}`"
|
|
172
|
+
:result="result"
|
|
173
|
+
:selected="index === selectedIndex"
|
|
174
|
+
@close="close()"
|
|
175
|
+
/>
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
</template>
|
package/src/client/app/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import '$histoire-theme'
|
|
1
2
|
import '../../style.css'
|
|
2
3
|
|
|
3
4
|
import { createApp } from 'vue'
|
|
@@ -9,7 +10,15 @@ import { router } from './router'
|
|
|
9
10
|
|
|
10
11
|
const app = createApp(App)
|
|
11
12
|
app.use(createPinia())
|
|
12
|
-
app.use(FloatingVue
|
|
13
|
+
app.use(FloatingVue, {
|
|
14
|
+
overflowPadding: 4,
|
|
15
|
+
arrowPadding: 8,
|
|
16
|
+
themes: {
|
|
17
|
+
dropdown: {
|
|
18
|
+
computeTransformOrigin: true,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
})
|
|
13
22
|
app.use(router)
|
|
14
23
|
registerGlobalComponents(app)
|
|
15
24
|
app.mount('#app')
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import './style/sandbox.css'
|
|
2
|
+
import { parseQuery } from 'vue-router'
|
|
3
|
+
import { computed, createApp, h, ref, toRaw, watch } from 'vue'
|
|
4
|
+
import { createPinia } from 'pinia'
|
|
5
|
+
import { registerGlobalComponents } from './global-components'
|
|
6
|
+
import SandboxVue3 from './components/sandbox/SandboxVue3.vue'
|
|
7
|
+
import type { StoryFile } from './types'
|
|
8
|
+
import { mapFile } from './util/mapping'
|
|
9
|
+
// @ts-expect-error virtual module
|
|
10
|
+
import { files } from '$histoire-stories'
|
|
11
|
+
import { STATE_SYNC } from './util/const.js'
|
|
12
|
+
|
|
13
|
+
const query = parseQuery(window.location.search)
|
|
14
|
+
const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
|
|
15
|
+
|
|
16
|
+
const app = createApp({
|
|
17
|
+
setup () {
|
|
18
|
+
const story = computed(() => file.value.story)
|
|
19
|
+
const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId))
|
|
20
|
+
|
|
21
|
+
window.addEventListener('message', event => {
|
|
22
|
+
if (event.data?.type === STATE_SYNC) {
|
|
23
|
+
Object.assign(variant.value.state, event.data.state)
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
watch(() => variant.value.state, value => {
|
|
28
|
+
window.parent?.postMessage({
|
|
29
|
+
type: STATE_SYNC,
|
|
30
|
+
state: toRaw(value),
|
|
31
|
+
})
|
|
32
|
+
}, {
|
|
33
|
+
deep: true,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
story,
|
|
38
|
+
variant,
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
render () {
|
|
43
|
+
return [
|
|
44
|
+
h('div', { class: 'htw-sandbox-hidden' }, [
|
|
45
|
+
h(file.value.component, {
|
|
46
|
+
story: file.value.story,
|
|
47
|
+
}),
|
|
48
|
+
]),
|
|
49
|
+
this.story && this.variant
|
|
50
|
+
? h(SandboxVue3, {
|
|
51
|
+
story: this.story,
|
|
52
|
+
variant: this.variant,
|
|
53
|
+
})
|
|
54
|
+
: null,
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
app.use(createPinia())
|
|
59
|
+
registerGlobalComponents(app)
|
|
60
|
+
app.mount('#app')
|
|
@@ -1,34 +1,58 @@
|
|
|
1
1
|
import { defineStore } from 'pinia'
|
|
2
|
-
import { computed, ref } from 'vue'
|
|
2
|
+
import { computed, reactive, ref, watch } from 'vue'
|
|
3
3
|
import { router } from '../router'
|
|
4
4
|
import { Story } from '../types'
|
|
5
5
|
|
|
6
6
|
export const useStoryStore = defineStore('story', () => {
|
|
7
7
|
const stories = ref<Story[]>([])
|
|
8
|
+
function setStories (value: Story[]) {
|
|
9
|
+
stories.value = value
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const currentStory = computed(() => stories.value.find(s => s.id === router.currentRoute.value.params.storyId))
|
|
13
|
+
|
|
14
|
+
const currentVariant = computed(() => currentStory.value?.variants.find(v => v.id === router.currentRoute.value.query.variantId))
|
|
15
|
+
|
|
16
|
+
const openedFolders = ref(new Map() as Map<string, boolean>)
|
|
17
|
+
|
|
18
|
+
function getStringPath (path: Array<string>) {
|
|
19
|
+
return path.join('␜')
|
|
20
|
+
}
|
|
8
21
|
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
function toggleFolder (path: Array<string>, force?: boolean) {
|
|
23
|
+
const stringPath = getStringPath(path)
|
|
24
|
+
|
|
25
|
+
if (force === undefined) {
|
|
26
|
+
force = !openedFolders.value.get(stringPath)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (force) {
|
|
30
|
+
openedFolders.value.set(stringPath, true)
|
|
31
|
+
} else {
|
|
32
|
+
openedFolders.value.delete(stringPath)
|
|
14
33
|
}
|
|
15
|
-
stories.value.push(story)
|
|
16
|
-
return story
|
|
17
34
|
}
|
|
18
35
|
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
function isFolderOpened (path: Array<string>) {
|
|
37
|
+
return openedFolders.value.get(getStringPath(path))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function openFileFolders (path: Array<string>) {
|
|
41
|
+
for (let pathLength = 1; pathLength < path.length; pathLength++) {
|
|
42
|
+
toggleFolder(path.slice(0, pathLength), true)
|
|
23
43
|
}
|
|
24
44
|
}
|
|
25
45
|
|
|
26
|
-
|
|
46
|
+
watch(currentStory, () => {
|
|
47
|
+
openFileFolders(currentStory.value.file.path)
|
|
48
|
+
})
|
|
27
49
|
|
|
28
50
|
return {
|
|
29
51
|
stories,
|
|
30
|
-
|
|
31
|
-
removeStory,
|
|
52
|
+
setStories,
|
|
32
53
|
currentStory,
|
|
54
|
+
currentVariant,
|
|
55
|
+
isFolderOpened,
|
|
56
|
+
toggleFolder,
|
|
33
57
|
}
|
|
34
58
|
})
|
|
@@ -1 +1,32 @@
|
|
|
1
1
|
/* @TODO custom themes */
|
|
2
|
+
|
|
3
|
+
.v-popper {
|
|
4
|
+
line-height: 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.v-popper--theme-dropdown {
|
|
8
|
+
.htw-dark & {
|
|
9
|
+
.v-popper__inner {
|
|
10
|
+
@apply htw-bg-gray-700 htw-border-gray-850 htw-text-gray-100;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.v-popper__arrow-inner {
|
|
14
|
+
@apply htw-border-gray-700;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.v-popper__arrow-outer {
|
|
18
|
+
@apply htw-border-gray-850;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&.v-popper__popper--show-from .v-popper__wrapper {
|
|
23
|
+
transform: scale(.75);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
&.v-popper__popper--show-to .v-popper__wrapper {
|
|
27
|
+
transform: none;
|
|
28
|
+
transition: transform .15s cubic-bezier(0, 1, .5, 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
@@ -11,16 +11,31 @@
|
|
|
11
11
|
border-color: #e5e7eb;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
a
|
|
14
|
+
a,
|
|
15
|
+
input,
|
|
16
|
+
button {
|
|
15
17
|
color: inherit;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
a {
|
|
16
21
|
text-decoration: inherit;
|
|
17
22
|
}
|
|
18
23
|
|
|
24
|
+
input {
|
|
25
|
+
font-family: inherit;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
a,
|
|
29
|
+
button {
|
|
30
|
+
user-select: none;
|
|
31
|
+
}
|
|
32
|
+
|
|
19
33
|
@tailwind base;
|
|
20
34
|
@tailwind components;
|
|
21
35
|
@tailwind utilities;
|
|
22
36
|
|
|
23
|
-
body
|
|
37
|
+
body,
|
|
38
|
+
pre {
|
|
24
39
|
margin: 0;
|
|
25
40
|
}
|
|
26
41
|
|
package/src/client/app/types.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import type { RouteLocationRaw } from 'vue-router'
|
|
2
|
+
|
|
3
|
+
export interface StoryFile {
|
|
4
|
+
id: string
|
|
5
|
+
framework: string
|
|
6
|
+
component: any
|
|
7
|
+
story: Story
|
|
8
|
+
path: string[]
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
export interface Story {
|
|
2
12
|
id: string
|
|
3
13
|
title: string
|
|
@@ -8,14 +18,42 @@ export interface Story {
|
|
|
8
18
|
type: 'grid'
|
|
9
19
|
width: number
|
|
10
20
|
}
|
|
21
|
+
icon?: string
|
|
22
|
+
iconColor?: string
|
|
23
|
+
file?: StoryFile
|
|
11
24
|
lastSelectedVariant?: Variant
|
|
12
|
-
mountTime: number
|
|
13
25
|
}
|
|
14
26
|
|
|
15
27
|
export interface Variant {
|
|
16
28
|
id: string
|
|
17
29
|
title: string
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
icon?: string
|
|
31
|
+
iconColor?: string
|
|
32
|
+
initState?: () => any
|
|
33
|
+
slots?: () => Readonly<any>
|
|
34
|
+
state?: any
|
|
35
|
+
source?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type TreeLeaf = {
|
|
39
|
+
title: string
|
|
40
|
+
index: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type TreeFolder = {
|
|
44
|
+
title: string
|
|
45
|
+
children: (TreeFolder | TreeLeaf)[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type Tree = (TreeFolder | TreeLeaf)[]
|
|
49
|
+
|
|
50
|
+
export interface SearchResult {
|
|
51
|
+
kind: 'story' | 'variant'
|
|
52
|
+
rank: number
|
|
53
|
+
id: string
|
|
54
|
+
title: string
|
|
55
|
+
route: RouteLocationRaw
|
|
56
|
+
path?: string[]
|
|
57
|
+
icon?: string
|
|
58
|
+
iconColor?: string
|
|
21
59
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HistoireConfig } from '../../../node/config'
|
|
2
|
+
// @ts-expect-error virtual module
|
|
3
|
+
import { config as configRaw, logos as logosRaw } from '$histoire-config'
|
|
4
|
+
|
|
5
|
+
export const histoireConfig: HistoireConfig = configRaw
|
|
6
|
+
export const customLogos: HistoireConfig['theme']['logo'] = logosRaw
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const STATE_SYNC = '__histoire:state-sync'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isMac = navigator.platform.toLowerCase().includes('mac')
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useEventListener } from '@vueuse/core'
|
|
2
|
+
import { isRef, Ref } from 'vue'
|
|
3
|
+
import { isMac } from './env.js'
|
|
4
|
+
|
|
5
|
+
export type KeyboardShortcut = string[]
|
|
6
|
+
|
|
7
|
+
export type KeyboardHandler = (event: KeyboardEvent) => unknown
|
|
8
|
+
|
|
9
|
+
export interface KeyboardShortcutOptions {
|
|
10
|
+
event?: 'keyup' | 'keydown' | 'keypress'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function onKeyboardShortcut (shortcut: KeyboardShortcut | Ref<KeyboardShortcut>, handler: KeyboardHandler, options: KeyboardShortcutOptions = {}) {
|
|
14
|
+
useEventListener(options.event ?? 'keydown', event => {
|
|
15
|
+
if (isMatchingShortcut(isRef(shortcut) ? shortcut.value : shortcut)) {
|
|
16
|
+
handler(event)
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const modifiers: { [i: string]: { key: string, pressed: boolean } } = {
|
|
22
|
+
ctrl: { key: 'Control', pressed: false },
|
|
23
|
+
alt: { key: 'Alt', pressed: false },
|
|
24
|
+
shift: { key: 'Shift', pressed: false },
|
|
25
|
+
meta: { key: 'Meta', pressed: false },
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const pressedKeys = new Set<string>()
|
|
29
|
+
|
|
30
|
+
window.addEventListener('keydown', event => {
|
|
31
|
+
for (const i in modifiers) {
|
|
32
|
+
const mod = modifiers[i]
|
|
33
|
+
if (mod.key === event.key) {
|
|
34
|
+
mod.pressed = true
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
pressedKeys.add(event.key.toLocaleLowerCase())
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
window.addEventListener('keyup', event => {
|
|
42
|
+
requestAnimationFrame(() => {
|
|
43
|
+
pressedKeys.clear()
|
|
44
|
+
for (const i in modifiers) {
|
|
45
|
+
const mod = modifiers[i]
|
|
46
|
+
if (mod.key === event.key) {
|
|
47
|
+
mod.pressed = false
|
|
48
|
+
break
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
window.addEventListener('blur', () => {
|
|
55
|
+
pressedKeys.clear()
|
|
56
|
+
for (const i in modifiers) {
|
|
57
|
+
const mod = modifiers[i]
|
|
58
|
+
mod.pressed = false
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
function isMatchingShortcut (shortcut: KeyboardShortcut): boolean {
|
|
63
|
+
for (const combination of shortcut) {
|
|
64
|
+
if (isMatchingCombination(combination.toLowerCase())) {
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function isMatchingCombination (combination: string): boolean {
|
|
72
|
+
const splitted = combination.split('+').map(key => key.trim())
|
|
73
|
+
const targetKey = splitted.pop()
|
|
74
|
+
for (const mod in modifiers) {
|
|
75
|
+
const containsMod = splitted.includes(mod)
|
|
76
|
+
const isPressed = modifiers[mod].pressed
|
|
77
|
+
if (containsMod !== isPressed) {
|
|
78
|
+
return false
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return pressedKeys.has(targetKey)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function formatKey (key: string) {
|
|
85
|
+
key = key.toLowerCase()
|
|
86
|
+
if (key === 'ctrl') {
|
|
87
|
+
return isMac ? '^' : 'Ctrl'
|
|
88
|
+
}
|
|
89
|
+
if (key === 'alt') {
|
|
90
|
+
return isMac ? '⎇' : 'Alt'
|
|
91
|
+
}
|
|
92
|
+
if (key === 'shift') {
|
|
93
|
+
return '⇧'
|
|
94
|
+
}
|
|
95
|
+
if (key === 'meta') {
|
|
96
|
+
return '⌘'
|
|
97
|
+
}
|
|
98
|
+
return key.charAt(0).toUpperCase() + key.substring(1).toLowerCase()
|
|
99
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { markRaw } from 'vue'
|
|
2
|
+
import type { StoryFile, Variant } from '../types'
|
|
3
|
+
|
|
4
|
+
export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
|
|
5
|
+
const result: StoryFile = {
|
|
6
|
+
...file,
|
|
7
|
+
component: markRaw(file.component),
|
|
8
|
+
story: {
|
|
9
|
+
...file.story,
|
|
10
|
+
title: file.story.title,
|
|
11
|
+
file: markRaw(file),
|
|
12
|
+
variants: file.story.variants.map(v => mapVariant(v)),
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (existingFile) {
|
|
17
|
+
for (const index in result.story.variants) {
|
|
18
|
+
const variant = result.story.variants[index]
|
|
19
|
+
const existingVariant = existingFile.story.variants[index]
|
|
20
|
+
if (existingVariant) {
|
|
21
|
+
if (existingVariant.state) Object.assign(variant.state, existingVariant.state)
|
|
22
|
+
if (existingVariant.initState) variant.initState = existingVariant.initState
|
|
23
|
+
if (existingVariant.slots) variant.slots = existingVariant.slots
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (existingFile.story.lastSelectedVariant) {
|
|
27
|
+
result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return result
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function mapVariant (variant: Variant): Variant {
|
|
35
|
+
return {
|
|
36
|
+
...variant,
|
|
37
|
+
state: {},
|
|
38
|
+
initState: null,
|
|
39
|
+
slots: () => ({}),
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isMac } from './env.js'
|
|
2
|
+
import { formatKey } from './keyboard.js'
|
|
3
|
+
|
|
4
|
+
export function makeTooltip (descriptionHtml: string, keyboardShortcut: ({ isMac: boolean }) => string) {
|
|
5
|
+
return {
|
|
6
|
+
content: `<div>${descriptionHtml}</div><div class="htw-flex htw-items-center htw-gap-1 htw-mt-2 htw-text-sm">${genKeyboardShortcutHtml(keyboardShortcut({ isMac }))}</div>`,
|
|
7
|
+
html: true,
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function genKeyboardShortcutHtml (shortcut: string) {
|
|
12
|
+
return shortcut.split('+').map(k => k.trim()).map(key => `<span class="htw-bg-gray-500 htw-border-b-2 htw-border-gray-600 htw-px-1 htw-rounded-sm">${formatKey(key)}</span>`).join('')
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { App } from 'vue'
|
|
2
|
+
import type { Story, Variant } from './app/types.js'
|
|
3
|
+
|
|
4
|
+
export type Vue3StorySetupHandler = (payload: {
|
|
5
|
+
app: App
|
|
6
|
+
story: Story
|
|
7
|
+
variant: Variant
|
|
8
|
+
}) => Promise<void> | void
|
|
9
|
+
|
|
10
|
+
export function defineVue3StorySetup (handler: Vue3StorySetupHandler): Vue3StorySetupHandler {
|
|
11
|
+
return handler
|
|
12
|
+
}
|