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.
Files changed (204) hide show
  1. package/LICENSE +21 -0
  2. package/client.d.ts +2 -0
  3. package/dist/client/app/App.vue +84 -21
  4. package/dist/client/app/assets/histoire-text-dark.svg +89 -0
  5. package/dist/client/app/assets/histoire-text.svg +89 -0
  6. package/dist/client/app/assets/histoire.svg +51 -0
  7. package/dist/client/app/codegen/serialize-js.d.ts +1 -0
  8. package/dist/client/app/codegen/serialize-js.js +113 -0
  9. package/dist/client/app/codegen/serialize-js.ts +119 -0
  10. package/dist/client/app/codegen/util.d.ts +10 -0
  11. package/dist/client/app/codegen/util.js +70 -0
  12. package/dist/client/app/codegen/util.ts +79 -0
  13. package/dist/client/app/codegen/vue3.d.ts +2 -0
  14. package/dist/client/app/codegen/vue3.js +238 -0
  15. package/dist/client/app/codegen/vue3.ts +240 -0
  16. package/dist/client/app/components/HomeView.vue +15 -1
  17. package/dist/client/app/components/StoryControls.vue +7 -2
  18. package/dist/client/app/components/StoryList.vue +20 -13
  19. package/dist/client/app/components/StoryListFolder.vue +87 -0
  20. package/dist/client/app/components/StoryListItem.vue +38 -12
  21. package/dist/client/app/components/StorySourceCode.vue +121 -0
  22. package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
  23. package/dist/client/app/components/StoryVariantListItem.vue +46 -0
  24. package/dist/client/app/components/StoryVariantSingleView.vue +145 -15
  25. package/dist/client/app/components/StoryView.vue +88 -54
  26. package/dist/client/app/components/app/AppHeader.vue +56 -0
  27. package/dist/client/app/components/app/AppLogo.vue +24 -0
  28. package/dist/client/app/components/base/BaseEmpty.vue +1 -1
  29. package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
  30. package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
  31. package/dist/client/app/components/exposed/Story.vue +23 -58
  32. package/dist/client/app/components/exposed/Variant.vue +24 -47
  33. package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
  34. package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  35. package/dist/client/app/components/search/SearchItem.vue +110 -0
  36. package/dist/client/app/components/search/SearchModal.vue +179 -0
  37. package/dist/client/app/composable/variant.js +0 -1
  38. package/dist/client/app/composable/variant.ts +20 -0
  39. package/dist/client/app/global-components.js +0 -1
  40. package/dist/client/app/global-components.ts +10 -0
  41. package/dist/client/app/index.d.ts +1 -0
  42. package/dist/client/app/index.js +10 -2
  43. package/dist/client/app/index.ts +24 -0
  44. package/dist/client/app/router.js +0 -1
  45. package/dist/client/app/router.ts +17 -0
  46. package/dist/client/app/sandbox.d.ts +1 -0
  47. package/dist/client/app/sandbox.js +53 -0
  48. package/dist/client/app/sandbox.ts +60 -0
  49. package/dist/client/app/stores/story.d.ts +167 -50
  50. package/dist/client/app/stores/story.js +33 -16
  51. package/dist/client/app/stores/story.ts +58 -0
  52. package/dist/client/app/style/floating-vue.css +31 -0
  53. package/dist/client/app/style/main.css +17 -2
  54. package/dist/client/app/style/sandbox.css +14 -0
  55. package/dist/client/app/types.d.ts +36 -4
  56. package/dist/client/app/types.js +0 -1
  57. package/dist/client/app/types.ts +59 -0
  58. package/dist/client/app/util/config.d.ts +3 -0
  59. package/dist/client/app/util/config.js +4 -0
  60. package/dist/client/app/util/config.ts +6 -0
  61. package/dist/client/app/util/const.d.ts +1 -0
  62. package/dist/client/app/util/const.js +1 -0
  63. package/dist/client/app/util/const.ts +1 -0
  64. package/dist/client/app/util/dark.d.ts +2 -0
  65. package/dist/client/app/util/dark.js +3 -0
  66. package/dist/client/app/util/dark.ts +4 -0
  67. package/dist/client/app/util/env.d.ts +1 -0
  68. package/dist/client/app/util/env.js +1 -0
  69. package/dist/client/app/util/env.ts +1 -0
  70. package/dist/client/app/util/keyboard.d.ts +8 -0
  71. package/dist/client/app/util/keyboard.js +82 -0
  72. package/dist/client/app/util/keyboard.ts +99 -0
  73. package/dist/client/app/util/mapping.d.ts +3 -0
  74. package/dist/client/app/util/mapping.js +39 -0
  75. package/dist/client/app/util/mapping.ts +41 -0
  76. package/dist/client/app/util/tooltip.d.ts +6 -0
  77. package/dist/client/app/util/tooltip.js +11 -0
  78. package/dist/client/app/util/tooltip.ts +13 -0
  79. package/dist/client/index.d.ts +8 -0
  80. package/dist/client/index.js +3 -0
  81. package/dist/client/index.ts +12 -0
  82. package/dist/client/server/Story.server.vue +65 -0
  83. package/dist/client/server/Variant.server.vue +50 -0
  84. package/dist/client/server/index.d.ts +2 -0
  85. package/dist/client/server/index.js +25 -0
  86. package/dist/client/server/index.ts +29 -0
  87. package/dist/client/shim.d.ts +5 -0
  88. package/dist/node/alias.js +0 -1
  89. package/dist/node/bin.js +8 -3
  90. package/dist/node/build.d.ts +2 -0
  91. package/dist/node/build.js +71 -0
  92. package/dist/node/collect.d.ts +12 -0
  93. package/dist/node/collect.js +65 -0
  94. package/dist/node/colors.d.ts +286 -0
  95. package/dist/node/colors.js +324 -0
  96. package/dist/node/commands/build.d.ts +1 -0
  97. package/dist/node/commands/build.js +10 -0
  98. package/dist/node/commands/dev.d.ts +1 -1
  99. package/dist/node/commands/dev.js +45 -13
  100. package/dist/node/config.d.ts +112 -1
  101. package/dist/node/config.js +124 -2
  102. package/dist/node/context.d.ts +13 -0
  103. package/dist/node/context.js +12 -2
  104. package/dist/node/dom/dom-keys.d.ts +4 -0
  105. package/dist/node/dom/dom-keys.js +223 -0
  106. package/dist/node/dom/env.d.ts +5 -0
  107. package/dist/node/dom/env.js +22 -0
  108. package/dist/node/index.d.ts +2 -0
  109. package/dist/node/index.js +2 -2
  110. package/dist/node/plugin.d.ts +8 -2
  111. package/dist/node/plugin.js +150 -22
  112. package/dist/node/server.d.ts +4 -1
  113. package/dist/node/server.js +80 -21
  114. package/dist/node/stories.d.ts +8 -9
  115. package/dist/node/stories.js +42 -23
  116. package/dist/node/tree.d.ts +19 -0
  117. package/dist/node/tree.js +54 -0
  118. package/dist/node/types.d.ts +38 -0
  119. package/dist/node/types.js +1 -0
  120. package/dist/style.css +610 -53
  121. package/package.json +45 -25
  122. package/scripts/copy.mjs +11 -0
  123. package/src/client/app/App.vue +84 -21
  124. package/src/client/app/assets/histoire-text-dark.svg +89 -0
  125. package/src/client/app/assets/histoire-text.svg +89 -0
  126. package/src/client/app/assets/histoire.svg +51 -0
  127. package/src/client/app/codegen/serialize-js.ts +119 -0
  128. package/src/client/app/codegen/util.ts +79 -0
  129. package/src/client/app/codegen/vue3.ts +240 -0
  130. package/src/client/app/components/HomeView.vue +15 -1
  131. package/src/client/app/components/StoryControls.vue +7 -2
  132. package/src/client/app/components/StoryList.vue +20 -13
  133. package/src/client/app/components/StoryListFolder.vue +87 -0
  134. package/src/client/app/components/StoryListItem.vue +38 -12
  135. package/src/client/app/components/StorySourceCode.vue +121 -0
  136. package/src/client/app/components/StoryVariantGridItem.vue +32 -17
  137. package/src/client/app/components/StoryVariantListItem.vue +46 -0
  138. package/src/client/app/components/StoryVariantSingleView.vue +145 -15
  139. package/src/client/app/components/StoryView.vue +88 -54
  140. package/src/client/app/components/app/AppHeader.vue +56 -0
  141. package/src/client/app/components/app/AppLogo.vue +24 -0
  142. package/src/client/app/components/base/BaseEmpty.vue +1 -1
  143. package/src/client/app/components/base/BaseListItemLink.vue +55 -0
  144. package/src/client/app/components/base/BaseSplitPane.vue +57 -21
  145. package/src/client/app/components/exposed/Story.vue +23 -58
  146. package/src/client/app/components/exposed/Variant.vue +24 -47
  147. package/src/client/app/components/misc/HatchedPattern.vue +25 -0
  148. package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  149. package/src/client/app/components/search/SearchItem.vue +110 -0
  150. package/src/client/app/components/search/SearchModal.vue +179 -0
  151. package/src/client/app/index.ts +10 -1
  152. package/src/client/app/sandbox.ts +60 -0
  153. package/src/client/app/stores/story.ts +39 -15
  154. package/src/client/app/style/floating-vue.css +31 -0
  155. package/src/client/app/style/main.css +17 -2
  156. package/src/client/app/style/sandbox.css +14 -0
  157. package/src/client/app/types.ts +42 -4
  158. package/src/client/app/util/config.ts +6 -0
  159. package/src/client/app/util/const.ts +1 -0
  160. package/src/client/app/util/dark.ts +4 -0
  161. package/src/client/app/util/env.ts +1 -0
  162. package/src/client/app/util/keyboard.ts +99 -0
  163. package/src/client/app/util/mapping.ts +41 -0
  164. package/src/client/app/util/tooltip.ts +13 -0
  165. package/src/client/index.ts +12 -0
  166. package/src/client/server/Story.server.vue +65 -0
  167. package/src/client/server/Variant.server.vue +50 -0
  168. package/src/client/server/index.ts +29 -0
  169. package/src/node/bin.ts +9 -2
  170. package/src/node/build.ts +80 -0
  171. package/src/node/collect.ts +78 -0
  172. package/src/node/colors.ts +340 -0
  173. package/src/node/commands/build.ts +12 -0
  174. package/src/node/commands/dev.ts +49 -12
  175. package/src/node/config.ts +240 -1
  176. package/src/node/context.ts +21 -1
  177. package/src/node/dom/dom-keys.ts +227 -0
  178. package/src/node/dom/env.ts +26 -0
  179. package/src/node/index.ts +2 -0
  180. package/src/node/plugin.ts +155 -22
  181. package/src/node/server.ts +95 -20
  182. package/src/node/stories.ts +53 -31
  183. package/src/node/tree.spec.ts +28 -0
  184. package/src/node/tree.ts +88 -0
  185. package/src/node/types.ts +40 -0
  186. package/tailwind.config.cjs +41 -1
  187. package/tsconfig.json +2 -1
  188. package/dist/client/app/components/StoryVariantItem.vue +0 -29
  189. package/dist/client/app/composable/variant.js.map +0 -1
  190. package/dist/client/app/global-components.js.map +0 -1
  191. package/dist/client/app/index.js.map +0 -1
  192. package/dist/client/app/router.js.map +0 -1
  193. package/dist/client/app/stores/story.js.map +0 -1
  194. package/dist/client/app/types.js.map +0 -1
  195. package/dist/node/alias.js.map +0 -1
  196. package/dist/node/bin.js.map +0 -1
  197. package/dist/node/commands/dev.js.map +0 -1
  198. package/dist/node/config.js.map +0 -1
  199. package/dist/node/context.js.map +0 -1
  200. package/dist/node/index.js.map +0 -1
  201. package/dist/node/plugin.js.map +0 -1
  202. package/dist/node/server.js.map +0 -1
  203. package/dist/node/stories.js.map +0 -1
  204. 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>
@@ -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 addStory (story: Story) {
10
- const existing = stories.value.find(s => s.id === story.id)
11
- if (existing) {
12
- Object.assign(existing, story)
13
- return existing
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 removeStory (story: Story) {
20
- const index = stories.value.findIndex(s => s.id === story.id)
21
- if (index !== -1) {
22
- stories.value.splice(index, 1)
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
- const currentStory = computed(() => stories.value.find(s => s.id === router.currentRoute.value.params.storyId))
46
+ watch(currentStory, () => {
47
+ openFileFolders(currentStory.value.file.path)
48
+ })
27
49
 
28
50
  return {
29
51
  stories,
30
- addStory,
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
 
@@ -0,0 +1,14 @@
1
+ body {
2
+ margin: 0;
3
+ }
4
+
5
+ html,
6
+ body,
7
+ #app {
8
+ font-family: 'Lato', sans-serif;
9
+ font-size: 14px;
10
+ }
11
+
12
+ .htw-sandbox-hidden {
13
+ display: none;
14
+ }
@@ -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
- initState: () => any
19
- slots: () => Readonly<any>
20
- state: any
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,4 @@
1
+ import { useDark, useToggle } from '@vueuse/core'
2
+
3
+ export const isDark = useDark({ valueDark: 'htw-dark' })
4
+ export const toggleDark = useToggle(isDark)
@@ -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
+ }