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
@@ -1,25 +1,27 @@
1
1
  <script lang="ts" setup>
2
2
  import { useStoryStore } from '../stores/story'
3
3
  import BaseSplitPane from './base/BaseSplitPane.vue'
4
- import StoryVariantItem from './StoryVariantItem.vue'
4
+ import StoryVariantListItem from './StoryVariantListItem.vue'
5
5
  import StoryVariantGridItem from './StoryVariantGridItem.vue'
6
6
  import { computed, watch } from 'vue'
7
7
  import { useRoute, useRouter } from 'vue-router'
8
8
  import StoryVariantSingleView from './StoryVariantSingleView.vue'
9
9
  import BaseEmpty from './base/BaseEmpty.vue'
10
10
  import StoryControls from './StoryControls.vue'
11
+ import StorySourceCode from './StorySourceCode.vue'
11
12
 
12
13
  const storyStore = useStoryStore()
13
14
 
14
- // Selected variant
15
-
15
+ const router = useRouter()
16
16
  const route = useRoute()
17
17
 
18
- const currentVariant = computed(() => storyStore.currentStory?.variants.find(v => v.id === route.query.variantId))
18
+ // Selected variant
19
+
20
+ const hasSingleVariant = computed(() => (storyStore.currentStory?.variants.length === 1))
19
21
 
20
22
  // Restore variant selection
21
23
 
22
- watch(currentVariant, value => {
24
+ watch(() => storyStore.currentVariant, value => {
23
25
  if (value) {
24
26
  storyStore.currentStory.lastSelectedVariant = value
25
27
  }
@@ -27,19 +29,30 @@ watch(currentVariant, value => {
27
29
  immediate: true,
28
30
  })
29
31
 
30
- const router = useRouter()
32
+ watch(() => [storyStore.currentStory, storyStore.currentVariant], () => {
33
+ if (!storyStore.currentVariant) {
34
+ if (storyStore.currentStory?.lastSelectedVariant) {
35
+ setVariant(storyStore.currentStory.lastSelectedVariant.id)
36
+ return
37
+ }
31
38
 
32
- watch(() => storyStore.currentStory, () => {
33
- if (!currentVariant.value && storyStore.currentStory?.lastSelectedVariant) {
34
- router.replace({
35
- ...route,
36
- query: {
37
- ...route.query,
38
- variantId: storyStore.currentStory.lastSelectedVariant.id,
39
- },
40
- })
39
+ if (storyStore.currentStory?.variants.length === 1) {
40
+ setVariant(storyStore.currentStory.variants[0].id)
41
+ }
41
42
  }
43
+ }, {
44
+ immediate: true,
42
45
  })
46
+
47
+ function setVariant (variantId: string) {
48
+ router.replace({
49
+ ...route,
50
+ query: {
51
+ ...route.query,
52
+ variantId,
53
+ },
54
+ })
55
+ }
43
56
  </script>
44
57
 
45
58
  <template>
@@ -49,7 +62,6 @@ watch(() => storyStore.currentStory, () => {
49
62
 
50
63
  <div
51
64
  v-else
52
- :key="storyStore.currentStory.mountTime"
53
65
  class="htw-h-full"
54
66
  >
55
67
  <BaseSplitPane
@@ -60,10 +72,10 @@ watch(() => storyStore.currentStory, () => {
60
72
  class="htw-h-full"
61
73
  >
62
74
  <template #first>
63
- <div class="htw-bg-gray-50 htw-h-full">
75
+ <div class="htw-bg-gray-50 htw-h-full dark:htw-bg-gray-750">
64
76
  <div
65
77
  v-if="storyStore.currentStory.layout.type === 'grid'"
66
- class="htw-bg-gray-50 htw-h-full htw-overflow-y-auto"
78
+ class="htw-h-full htw-overflow-y-auto"
67
79
  >
68
80
  <div
69
81
  class="htw-grid htw-gap-4 htw-m-4"
@@ -80,52 +92,74 @@ watch(() => storyStore.currentStory, () => {
80
92
  </div>
81
93
  </div>
82
94
 
83
- <BaseSplitPane
84
- v-else-if="storyStore.currentStory.layout.type === 'single'"
85
- save-id="story-single-main-split"
86
- :min="5"
87
- :max="40"
88
- :default-split="17"
89
- >
90
- <template #first>
91
- <div class="htw-bg-white htw-h-full htw-overflow-y-auto">
92
- <StoryVariantItem
93
- v-for="(variant, index) of storyStore.currentStory.variants"
94
- :key="index"
95
- :variant="variant"
96
- />
97
- </div>
98
- </template>
99
-
100
- <template #last>
101
- <div
102
- v-if="currentVariant"
103
- class="htw-p-2 htw-h-full"
104
- >
105
- <StoryVariantSingleView
106
- :variant="currentVariant"
107
- :story="storyStore.currentStory"
108
- />
109
- </div>
110
- </template>
111
- </BaseSplitPane>
95
+ <template v-else-if="storyStore.currentStory.layout.type === 'single'">
96
+ <div
97
+ v-if="hasSingleVariant && storyStore.currentVariant"
98
+ class="htw-p-2 htw-h-full"
99
+ >
100
+ <StoryVariantSingleView
101
+ :variant="storyStore.currentVariant"
102
+ :story="storyStore.currentStory"
103
+ />
104
+ </div>
105
+ <BaseSplitPane
106
+ v-else
107
+ save-id="story-single-main-split"
108
+ :min="5"
109
+ :max="40"
110
+ :default-split="17"
111
+ >
112
+ <template #first>
113
+ <div class="htw-h-full htw-overflow-y-auto">
114
+ <StoryVariantListItem
115
+ v-for="(variant, index) of storyStore.currentStory.variants"
116
+ :key="index"
117
+ :variant="variant"
118
+ />
119
+ </div>
120
+ </template>
121
+ <template #last>
122
+ <div
123
+ v-if="storyStore.currentVariant"
124
+ class="htw-p-2 htw-h-full"
125
+ >
126
+ <StoryVariantSingleView
127
+ :variant="storyStore.currentVariant"
128
+ :story="storyStore.currentStory"
129
+ />
130
+ </div>
131
+ </template>
132
+ </BaseSplitPane>
133
+ </template>
112
134
  </div>
113
135
  </template>
114
136
 
115
137
  <template #last>
116
- <BaseEmpty v-if="!currentVariant">
138
+ <BaseEmpty v-if="!storyStore.currentVariant">
117
139
  <span>Select a variant</span>
118
140
  </BaseEmpty>
119
141
 
120
- <div
142
+ <BaseSplitPane
121
143
  v-else
144
+ save-id="story-sidepane"
145
+ orientation="portrait"
122
146
  class="htw-h-full"
123
147
  >
124
- <StoryControls
125
- :story="storyStore.currentStory"
126
- :variant="currentVariant"
127
- />
128
- </div>
148
+ <template #first>
149
+ <StoryControls
150
+ :story="storyStore.currentStory"
151
+ :variant="storyStore.currentVariant"
152
+ class="htw-h-full htw-overflow-auto"
153
+ />
154
+ </template>
155
+
156
+ <template #last>
157
+ <StorySourceCode
158
+ :variant="storyStore.currentVariant"
159
+ class="htw-h-full"
160
+ />
161
+ </template>
162
+ </BaseSplitPane>
129
163
  </template>
130
164
  </BaseSplitPane>
131
165
  </div>
@@ -0,0 +1,56 @@
1
+ <script setup lang="ts">
2
+ import { Icon } from '@iconify/vue'
3
+ import { computed } from 'vue'
4
+ import AppLogo from './AppLogo.vue'
5
+ import { isDark, toggleDark } from '../../util/dark'
6
+ import { onKeyboardShortcut } from '../../util/keyboard'
7
+ import { makeTooltip } from '../../util/tooltip'
8
+
9
+ defineEmits({
10
+ search: () => true,
11
+ })
12
+
13
+ const themeIcon = computed(() => {
14
+ return isDark.value ? 'carbon:moon' : 'carbon:sun'
15
+ })
16
+
17
+ onKeyboardShortcut(['ctrl+shift+d', 'meta+shift+d'], (event) => {
18
+ toggleDark()
19
+ event.preventDefault()
20
+ })
21
+ </script>
22
+
23
+ <template>
24
+ <div
25
+ class="htw-px-4 htw-h-16 htw-flex htw-items-center htw-gap-2"
26
+ >
27
+ <div class="htw-py-4 htw-flex-1 htw-h-full htw-flex htw-items-center htw-pr-2">
28
+ <AppLogo
29
+ class="htw-max-w-full htw-max-h-full"
30
+ />
31
+ </div>
32
+ <div class="htw-ml-auto htw-flex-none htw-flex">
33
+ <a
34
+ v-tooltip="makeTooltip('Search', ({ isMac }) => isMac ? 'meta+k' : 'ctrl+k')"
35
+ class="htw-p-1 hover:htw-text-primary-500 dark:hover:htw-text-primary-400 htw-cursor-pointer"
36
+ @click="$emit('search')"
37
+ >
38
+ <Icon
39
+ icon="carbon:search"
40
+ class="htw-w-5 htw-h-5"
41
+ />
42
+ </a>
43
+
44
+ <a
45
+ v-tooltip="makeTooltip('Toggle dark mode', ({ isMac }) => isMac ? 'meta+shift+d' : 'ctrl+shift+d')"
46
+ class="htw-p-1 hover:htw-text-primary-500 dark:hover:htw-text-primary-400 htw-cursor-pointer"
47
+ @click="toggleDark()"
48
+ >
49
+ <Icon
50
+ :icon="themeIcon"
51
+ class="htw-w-5 htw-h-5"
52
+ />
53
+ </a>
54
+ </div>
55
+ </div>
56
+ </template>
@@ -0,0 +1,24 @@
1
+ <script lang="ts" setup>
2
+ import { isDark } from '../../util/dark'
3
+ import { computed } from 'vue'
4
+ import { histoireConfig, customLogos } from '../../util/config.js'
5
+
6
+ import HistoireLogoDark from '../../assets/histoire-text-dark.svg'
7
+ import HistoireLogoLight from '../../assets/histoire-text.svg'
8
+
9
+ const logoUrl = computed(() => {
10
+ if (isDark.value) {
11
+ return histoireConfig.theme.logo?.dark ? customLogos.dark : HistoireLogoDark
12
+ }
13
+ return histoireConfig.theme.logo?.light ? customLogos.light : HistoireLogoLight
14
+ })
15
+
16
+ const altText = computed(() => histoireConfig.theme.title + ' logo')
17
+ </script>
18
+
19
+ <template>
20
+ <img
21
+ :src="logoUrl"
22
+ :alt="altText"
23
+ >
24
+ </template>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="htw-flex htw-flex-col htw-items-center htw-justify-center htw-space-y-4 htw-py-12 htw-h-full htw-text-center htw-text-gray-400 dark:htw-text-gray-600 htw-text-lg">
2
+ <div class="htw-flex htw-flex-col htw-items-center htw-justify-center htw-space-y-4 htw-py-12 htw-h-full htw-text-center htw-text-gray-400 htw-text-lg">
3
3
  <slot />
4
4
  </div>
5
5
  </template>
@@ -0,0 +1,55 @@
1
+ <script lang="ts">
2
+ import { defineComponent } from 'vue'
3
+
4
+ export default defineComponent({
5
+ inheritAttrs: false,
6
+
7
+ props: {
8
+ isActive: {
9
+ type: Boolean,
10
+ default: undefined,
11
+ },
12
+ },
13
+
14
+ emits: {
15
+ navigate: () => true,
16
+ },
17
+
18
+ setup (props, { emit }) {
19
+ function handleNavigate (event, navigate: (event) => unknown) {
20
+ emit('navigate')
21
+ navigate(event)
22
+ }
23
+
24
+ return {
25
+ handleNavigate,
26
+ }
27
+ },
28
+ })
29
+ </script>
30
+
31
+ <template>
32
+ <RouterLink
33
+ v-slot="{ isActive: linkIsActive, href, navigate }"
34
+ v-bind="$attrs"
35
+ custom
36
+ >
37
+ <a
38
+ :href="href"
39
+ class="htw-flex htw-items-center htw-gap-2"
40
+ :class="[
41
+ $attrs.class,
42
+ (isActive != null ? isActive : linkIsActive)
43
+ ? 'active htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
44
+ : 'hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900'
45
+ ]"
46
+ @click="handleNavigate($event, navigate)"
47
+ @keyup.enter="handleNavigate($event, navigate)"
48
+ @keyup.space="handleNavigate($event, navigate)"
49
+ >
50
+ <slot
51
+ :active="isActive != null ? isActive : linkIsActive"
52
+ />
53
+ </a>
54
+ </RouterLink>
55
+ </template>
@@ -15,6 +15,11 @@ const props = defineProps({
15
15
  default: 50,
16
16
  },
17
17
 
18
+ split: {
19
+ type: Number,
20
+ default: undefined,
21
+ },
22
+
18
23
  min: {
19
24
  type: Number,
20
25
  default: 20,
@@ -35,9 +40,26 @@ const props = defineProps({
35
40
  type: String,
36
41
  default: null,
37
42
  },
43
+
44
+ fixed: {
45
+ type: Boolean,
46
+ default: false,
47
+ },
48
+ })
49
+
50
+ const emit = defineEmits({
51
+ 'update:split': (value: number) => true,
38
52
  })
39
53
 
40
- const split = ref(props.defaultSplit)
54
+ const currentSplit = ref(props.defaultSplit)
55
+
56
+ watch(() => props.split, (value) => {
57
+ if (value !== undefined) {
58
+ currentSplit.value = value
59
+ }
60
+ }, {
61
+ immediate: true,
62
+ })
41
63
 
42
64
  if (props.saveId) {
43
65
  const storageKey = `${SAVE_PREFIX}-split-pane-${props.saveId}`
@@ -52,31 +74,39 @@ if (props.saveId) {
52
74
  }
53
75
 
54
76
  if (typeof parsedValue === 'number') {
55
- split.value = parsedValue
77
+ currentSplit.value = parsedValue
56
78
  }
57
79
  }
58
80
 
59
- watch(split, value => {
81
+ watch(currentSplit, value => {
60
82
  localStorage.setItem(storageKey, JSON.stringify(value))
61
83
  })
84
+
85
+ watch(currentSplit, value => {
86
+ if (value !== props.split) {
87
+ emit('update:split', value)
88
+ }
89
+ }, {
90
+ immediate: true,
91
+ })
62
92
  }
63
93
 
64
94
  const boundSplit = computed(() => {
65
- if (split.value < props.min) {
95
+ if (currentSplit.value < props.min) {
66
96
  return props.min
67
- } else if (split.value > props.max) {
97
+ } else if (currentSplit.value > props.max) {
68
98
  return props.max
69
99
  } else {
70
- return split.value
100
+ return currentSplit.value
71
101
  }
72
102
  })
73
103
 
74
104
  const leftStyle = computed(() => ({
75
- [props.orientation === 'landscape' ? 'width' : 'height']: `${boundSplit.value}%`,
105
+ [props.orientation === 'landscape' ? 'width' : 'height']: props.fixed ? `${boundSplit.value}px` : `${boundSplit.value}%`,
76
106
  }))
77
107
 
78
108
  const rightStyle = computed(() => ({
79
- [props.orientation === 'landscape' ? 'width' : 'height']: `${100 - boundSplit.value}%`,
109
+ [props.orientation === 'landscape' ? 'width' : 'height']: props.fixed ? null : `${100 - boundSplit.value}%`,
80
110
  }))
81
111
 
82
112
  const dragging = ref(false)
@@ -104,7 +134,11 @@ function dragMove (e) {
104
134
  totalSize = el.value.offsetHeight
105
135
  }
106
136
  const dPosition = position - startPosition
107
- split.value = startSplit + ~~(dPosition / totalSize * 200) / 2
137
+ if (props.fixed) {
138
+ currentSplit.value = startSplit + dPosition
139
+ } else {
140
+ currentSplit.value = startSplit + ~~(dPosition / totalSize * 200) / 2
141
+ }
108
142
  }
109
143
  }
110
144
 
@@ -126,7 +160,7 @@ onUnmounted(() => {
126
160
  <template>
127
161
  <div
128
162
  ref="el"
129
- class="htw-flex htw-h-full htw-isolate"
163
+ class="htw-flex htw-h-full htw-isolate htw-overflow-auto"
130
164
  :class="{
131
165
  'htw-flex-col': orientation === 'portrait',
132
166
  'htw-cursor-ew-resize': dragging && orientation === 'landscape',
@@ -138,14 +172,15 @@ onUnmounted(() => {
138
172
  class="htw-relative htw-top-0 htw-left-0 htw-z-20"
139
173
  :class="{
140
174
  'htw-pointer-events-none': dragging,
141
- 'htw-border-r htw-border-gray-200 dark:htw-border-gray-800': orientation === 'landscape'
175
+ 'htw-border-r htw-border-gray-200 dark:htw-border-gray-850': orientation === 'landscape',
176
+ 'htw-flex-none': fixed,
142
177
  }"
143
178
  :style="leftStyle"
144
179
  >
145
180
  <slot name="first" />
146
181
 
147
182
  <div
148
- class="dragger htw-absolute htw-z-100 hover:htw-bg-primary-500/25 htw-transition-colors htw-duration-150 htw-delay-150"
183
+ class="dragger htw-absolute htw-z-100 hover:htw-bg-primary-500/50 htw-transition-colors htw-duration-150 htw-delay-150"
149
184
  :class="{
150
185
  'htw-top-0 htw-bottom-0 htw-cursor-ew-resize': orientation === 'landscape',
151
186
  'htw-left-0 htw-right-0 htw-cursor-ns-resize': orientation === 'portrait',
@@ -159,7 +194,8 @@ onUnmounted(() => {
159
194
  class="htw-relative htw-bottom-0 htw-right-0"
160
195
  :class="{
161
196
  'htw-pointer-events-none': dragging,
162
- 'htw-border-t htw-border-gray-200 dark:htw-border-gray-800': orientation === 'portrait'
197
+ 'htw-border-t htw-border-gray-200 dark:htw-border-gray-850': orientation === 'portrait',
198
+ 'htw-flex-1': fixed,
163
199
  }"
164
200
  :style="rightStyle"
165
201
  >
@@ -169,35 +205,35 @@ onUnmounted(() => {
169
205
  </template>
170
206
 
171
207
  <style lang="postcss" scoped>
172
- .landscape .dragger {
208
+ .landscape > div > .dragger {
173
209
  width: 10px;
174
210
  }
175
211
 
176
- .portrait .dragger {
212
+ .portrait > div > .dragger {
177
213
  height: 10px;
178
214
  }
179
215
 
180
- .landscape .dragger.dragger-offset-before {
216
+ .landscape > div > .dragger.dragger-offset-before {
181
217
  right: 0;
182
218
  }
183
219
 
184
- .portrait .dragger.dragger-offset-before {
220
+ .portrait > div > .dragger.dragger-offset-before {
185
221
  bottom: 0;
186
222
  }
187
223
 
188
- .landscape .dragger.dragger-offset-center {
224
+ .landscape > div > .dragger.dragger-offset-center {
189
225
  right: -5px;
190
226
  }
191
227
 
192
- .portrait .dragger.dragger-offset-center {
228
+ .portrait > div > .dragger.dragger-offset-center {
193
229
  bottom: -5px;
194
230
  }
195
231
 
196
- .landscape .dragger.dragger-offset-after {
232
+ .landscape > div > .dragger.dragger-offset-after {
197
233
  right: -10px;
198
234
  }
199
235
 
200
- .portrait .dragger.dragger-offset-after {
236
+ .portrait > div > .dragger.dragger-offset-after {
201
237
  bottom: -10px;
202
238
  }
203
239
  </style>
@@ -1,77 +1,42 @@
1
1
  <script lang="ts">
2
- import { defineComponent, onBeforeMount, onBeforeUnmount, PropType, provide, ref, useAttrs } from 'vue'
3
- import { useStoryStore } from '../../stores/story.js'
4
- import { Story, Variant } from '../../types.js'
2
+ import { computed, defineComponent, provide, useAttrs, VNode } from 'vue'
3
+ import { Story } from '../../types.js'
5
4
 
6
5
  export default defineComponent({
7
- inheritAttrs: false,
8
-
9
- props: {
10
- title: {
11
- type: String,
12
- required: true,
13
- },
6
+ // eslint-disable-next-line vue/multi-word-component-names
7
+ name: 'Story',
8
+ __histoireType: 'story',
14
9
 
15
- layout: {
16
- type: Object as PropType<Story['layout']>,
17
- default: () => ({ type: 'single' }),
18
- },
19
- },
10
+ inheritAttrs: false,
20
11
 
21
- setup (props) {
12
+ setup () {
22
13
  const attrs = useAttrs() as {
23
- data: {
24
- id: string
25
- reloadHandlers: (() => unknown)[]
26
- }
14
+ story: Story
27
15
  }
28
16
 
29
- // Story
30
-
31
- const storyStore = useStoryStore()
32
-
33
- const story = ref<Story>(null)
34
-
35
- onBeforeMount(() => {
36
- story.value = storyStore.addStory({
37
- id: attrs.data.id,
38
- title: props.title,
39
- layout: props.layout,
40
- variants: [],
41
- mountTime: Date.now(),
42
- })
43
- })
44
-
45
- onBeforeUnmount(() => {
46
- storyStore.removeStory(story.value)
47
- })
48
-
49
- // Variants
50
-
17
+ const story = computed(() => attrs.story)
51
18
  provide('story', story)
52
19
 
53
- provide('addVariant', (variant: Variant) => {
54
- story.value.variants.push(variant)
55
- })
56
-
57
- provide('removeVariant', (variant: Variant) => {
58
- const index = story.value.variants.indexOf(variant)
59
- if (index !== -1) {
60
- story.value.variants.splice(index, 1)
61
- }
62
- })
63
-
64
20
  return {
65
21
  story,
66
22
  }
67
23
  },
68
24
 
69
25
  render () {
70
- Object.assign(this.story, {
71
- title: this.title,
72
- layout: this.layout,
73
- })
74
- return this.$slots.default()
26
+ // Apply variant as attribute to each child vnode (should be `<Variant>` components)
27
+ const vnodes: VNode[] = this.$slots.default()
28
+ // @ts-expect-error custom option
29
+ .filter(vnode => vnode.type?.__histoireType === 'variant')
30
+ // Same number of vnodes as variants
31
+ .slice(0, this.story.variants.length)
32
+ for (const index in vnodes) {
33
+ const vnode = vnodes[index]
34
+ if (!vnode.props) {
35
+ vnode.props = {}
36
+ }
37
+ vnode.props.variant = this.story.variants[index]
38
+ }
39
+ return vnodes
75
40
  },
76
41
  })
77
42
  </script>