histoire 0.2.4 → 0.2.5

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 (44) hide show
  1. package/dist/client/app/App.vue +1 -1
  2. package/dist/client/app/codegen/vue3.js +1 -1
  3. package/dist/client/app/codegen/vue3.ts +1 -1
  4. package/dist/client/app/components/app/Breadcrumb.vue +1 -1
  5. package/dist/client/app/components/search/SearchItem.vue +1 -0
  6. package/dist/client/app/components/tree/StoryGroup.vue +75 -0
  7. package/dist/client/app/components/{story → tree}/StoryList.vue +8 -2
  8. package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListFolder.vue +6 -4
  9. package/dist/client/app/components/{story → tree}/StoryListItem.vue +3 -3
  10. package/dist/client/app/stores/story.d.ts +12 -6
  11. package/dist/client/app/stores/story.js +13 -8
  12. package/dist/client/app/stores/story.ts +13 -9
  13. package/dist/client/app/style/floating-vue.pcss +3 -1
  14. package/dist/client/app/types.d.ts +8 -1
  15. package/dist/client/app/types.ts +9 -1
  16. package/dist/client/server/Story.server.vue +8 -2
  17. package/dist/node/collect/index.js +2 -2
  18. package/dist/node/config.d.ts +8 -2
  19. package/dist/node/plugin.js +1 -1
  20. package/dist/node/stories.js +6 -1
  21. package/dist/node/tree.d.ts +16 -12
  22. package/dist/node/tree.js +45 -5
  23. package/dist/node/types.d.ts +10 -0
  24. package/dist/style.css +103 -29
  25. package/package.json +2 -2
  26. package/src/client/app/App.vue +1 -1
  27. package/src/client/app/codegen/vue3.ts +1 -1
  28. package/src/client/app/components/app/Breadcrumb.vue +1 -1
  29. package/src/client/app/components/search/SearchItem.vue +1 -0
  30. package/src/client/app/components/tree/StoryGroup.vue +75 -0
  31. package/src/client/app/components/{story → tree}/StoryList.vue +8 -2
  32. package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListFolder.vue +6 -4
  33. package/src/client/app/components/{story → tree}/StoryListItem.vue +3 -3
  34. package/src/client/app/stores/story.ts +13 -9
  35. package/src/client/app/style/floating-vue.pcss +3 -1
  36. package/src/client/app/types.ts +9 -1
  37. package/src/client/server/Story.server.vue +8 -2
  38. package/src/node/collect/index.ts +3 -3
  39. package/src/node/config.ts +9 -2
  40. package/src/node/plugin.ts +1 -1
  41. package/src/node/stories.ts +6 -1
  42. package/src/node/tree.spec.ts +35 -17
  43. package/src/node/tree.ts +64 -10
  44. package/src/node/types.ts +11 -0
package/dist/style.css CHANGED
@@ -238,6 +238,10 @@
238
238
  transition: transform .15s cubic-bezier(0, 1, .5, 1);
239
239
  }
240
240
 
241
+ .v-popper__popper:focus-visible {
242
+ outline: none;
243
+ }
244
+
241
245
  .__histoire-scale-x-enter-active,
242
246
  .__histoire-scale-x-leave-active {
243
247
  transition: transform .15s, opacity .15s;
@@ -868,10 +872,6 @@ button {
868
872
  z-index:20
869
873
  }
870
874
 
871
- .htw-m-1{
872
- margin:0.25rem
873
- }
874
-
875
875
  .htw-m-0{
876
876
  margin:0px
877
877
  }
@@ -880,11 +880,40 @@ button {
880
880
  margin:1rem
881
881
  }
882
882
 
883
+ .htw-m-1{
884
+ margin:0.25rem
885
+ }
886
+
887
+ .htw-my-2{
888
+ margin-top:0.5rem;
889
+ margin-bottom:0.5rem
890
+ }
891
+
892
+ .htw-mx-1{
893
+ margin-left:0.25rem;
894
+ margin-right:0.25rem
895
+ }
896
+
897
+ .htw-mx-2{
898
+ margin-left:0.5rem;
899
+ margin-right:0.5rem
900
+ }
901
+
883
902
  .htw-my-0{
884
903
  margin-top:0px;
885
904
  margin-bottom:0px
886
905
  }
887
906
 
907
+ .htw-my-8{
908
+ margin-top:2rem;
909
+ margin-bottom:2rem
910
+ }
911
+
912
+ .htw-mx-4{
913
+ margin-left:1rem;
914
+ margin-right:1rem
915
+ }
916
+
888
917
  .-htw-my-1{
889
918
  margin-top:-0.25rem;
890
919
  margin-bottom:-0.25rem
@@ -914,6 +943,10 @@ button {
914
943
  margin-right:auto
915
944
  }
916
945
 
946
+ .htw-mb-2{
947
+ margin-bottom:0.5rem
948
+ }
949
+
917
950
  .htw-box-border{
918
951
  box-sizing:border-box
919
952
  }
@@ -1000,10 +1033,22 @@ button {
1000
1033
  height:2.5rem
1001
1034
  }
1002
1035
 
1036
+ .htw-h-\[1px\]{
1037
+ height:1px
1038
+ }
1039
+
1003
1040
  .htw-h-\[100px\]{
1004
1041
  height:100px
1005
1042
  }
1006
1043
 
1044
+ .htw-h-32{
1045
+ height:8rem
1046
+ }
1047
+
1048
+ .htw-h-20{
1049
+ height:5rem
1050
+ }
1051
+
1007
1052
  .htw-max-h-full{
1008
1053
  max-height:100%
1009
1054
  }
@@ -1080,14 +1125,18 @@ button {
1080
1125
  width:4rem
1081
1126
  }
1082
1127
 
1083
- .htw-min-w-0{
1084
- min-width:0px
1128
+ .htw-w-32{
1129
+ width:8rem
1085
1130
  }
1086
1131
 
1087
1132
  .htw-min-w-16{
1088
1133
  min-width:4rem
1089
1134
  }
1090
1135
 
1136
+ .htw-min-w-0{
1137
+ min-width:0px
1138
+ }
1139
+
1091
1140
  .htw-max-w-full{
1092
1141
  max-width:100%
1093
1142
  }
@@ -1112,6 +1161,10 @@ button {
1112
1161
  flex-shrink:0
1113
1162
  }
1114
1163
 
1164
+ .htw-shrink{
1165
+ flex-shrink:1
1166
+ }
1167
+
1115
1168
  .htw-grow{
1116
1169
  flex-grow:1
1117
1170
  }
@@ -1160,8 +1213,8 @@ button {
1160
1213
  resize:vertical
1161
1214
  }
1162
1215
 
1163
- .htw-grid-cols-\[repeat\(auto-fill\,minmax\(100px\,1fr\)\)\]{
1164
- grid-template-columns:repeat(auto-fill,minmax(100px,1fr))
1216
+ .htw-grid-cols-\[repeat\(auto-fill\,minmax\(200px\,1fr\)\)\]{
1217
+ grid-template-columns:repeat(auto-fill,minmax(200px,1fr))
1165
1218
  }
1166
1219
 
1167
1220
  .htw-flex-col{
@@ -1422,6 +1475,14 @@ button {
1422
1475
  background-color:rgb(var(--_histoire-color-gray-50) / var(--tw-bg-opacity))
1423
1476
  }
1424
1477
 
1478
+ .htw-bg-gray-500\/10{
1479
+ background-color:rgb(var(--_histoire-color-gray-500) / 0.1)
1480
+ }
1481
+
1482
+ .htw-bg-gray-500\/50{
1483
+ background-color:rgb(var(--_histoire-color-gray-500) / 0.5)
1484
+ }
1485
+
1425
1486
  .htw-stroke-white{
1426
1487
  stroke:#fff
1427
1488
  }
@@ -1476,21 +1537,6 @@ button {
1476
1537
  padding-bottom:1rem
1477
1538
  }
1478
1539
 
1479
- .htw-px-0\.5{
1480
- padding-left:0.125rem;
1481
- padding-right:0.125rem
1482
- }
1483
-
1484
- .htw-py-2{
1485
- padding-top:0.5rem;
1486
- padding-bottom:0.5rem
1487
- }
1488
-
1489
- .htw-px-0{
1490
- padding-left:0px;
1491
- padding-right:0px
1492
- }
1493
-
1494
1540
  .htw-px-2{
1495
1541
  padding-left:0.5rem;
1496
1542
  padding-right:0.5rem
@@ -1506,6 +1552,21 @@ button {
1506
1552
  padding-bottom:0px
1507
1553
  }
1508
1554
 
1555
+ .htw-py-2{
1556
+ padding-top:0.5rem;
1557
+ padding-bottom:0.5rem
1558
+ }
1559
+
1560
+ .htw-px-0\.5{
1561
+ padding-left:0.125rem;
1562
+ padding-right:0.125rem
1563
+ }
1564
+
1565
+ .htw-px-0{
1566
+ padding-left:0px;
1567
+ padding-right:0px
1568
+ }
1569
+
1509
1570
  .htw-py-1{
1510
1571
  padding-top:0.25rem;
1511
1572
  padding-bottom:0.25rem
@@ -1531,8 +1592,8 @@ button {
1531
1592
  padding-left:0.125rem
1532
1593
  }
1533
1594
 
1534
- .htw-pl-5{
1535
- padding-left:1.25rem
1595
+ .htw-pl-4{
1596
+ padding-left:1rem
1536
1597
  }
1537
1598
 
1538
1599
  .htw-pl-2{
@@ -1638,14 +1699,14 @@ button {
1638
1699
  opacity:0.5
1639
1700
  }
1640
1701
 
1641
- .htw-opacity-30{
1642
- opacity:0.3
1643
- }
1644
-
1645
1702
  .htw-opacity-20{
1646
1703
  opacity:0.2
1647
1704
  }
1648
1705
 
1706
+ .htw-opacity-30{
1707
+ opacity:0.3
1708
+ }
1709
+
1649
1710
  .htw-opacity-70{
1650
1711
  opacity:0.7
1651
1712
  }
@@ -1749,6 +1810,14 @@ body {
1749
1810
  visibility: hidden;
1750
1811
  }
1751
1812
 
1813
+ .first\:htw-mt-0:first-child{
1814
+ margin-top:0px
1815
+ }
1816
+
1817
+ .last\:htw-mb-0:last-child{
1818
+ margin-bottom:0px
1819
+ }
1820
+
1752
1821
  .hover\:htw-bg-primary-100:hover{
1753
1822
  --tw-bg-opacity:1;
1754
1823
  background-color:rgb(var(--_histoire-color-primary-100) / var(--tw-bg-opacity))
@@ -1916,6 +1985,11 @@ body {
1916
1985
  background-color:rgb(var(--_histoire-color-gray-750) / var(--tw-bg-opacity))
1917
1986
  }
1918
1987
 
1988
+ .htw-dark .dark\:htw-bg-black{
1989
+ --tw-bg-opacity:1;
1990
+ background-color:rgb(0 0 0 / var(--tw-bg-opacity))
1991
+ }
1992
+
1919
1993
  .htw-dark .dark\:htw-text-gray-100{
1920
1994
  --tw-text-opacity:1;
1921
1995
  color:rgb(var(--_histoire-color-gray-100) / var(--tw-text-opacity))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,7 +33,7 @@
33
33
  "histoire": "./bin.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@histoire/controls": "^0.2.4",
36
+ "@histoire/controls": "^0.2.5",
37
37
  "@iconify/vue": "^3.2.1",
38
38
  "@vitejs/plugin-vue": "^2.3.1",
39
39
  "@vueuse/core": "^8.2.5",
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  // @ts-expect-error virtual module
3
3
  import { files as rawFiles, tree as rawTree, onUpdate } from '$histoire-stories'
4
- import StoryList from './components/story/StoryList.vue'
4
+ import StoryList from './components/tree/StoryList.vue'
5
5
  import BaseSplitPane from './components/base/BaseSplitPane.vue'
6
6
  import { computed, ref, watch, defineAsyncComponent } from 'vue'
7
7
  import AppHeader from './components/app/AppHeader.vue'
@@ -141,7 +141,7 @@ async function printVNode (vnode: VNode): Promise<string[]> {
141
141
  // It was formatted from auto building object (slot props)
142
142
  serialized = [value.substring(2, value.length - 2).trim()]
143
143
  } else if (typeof value === 'function') {
144
- serialized = [value.toString()]
144
+ serialized = [value.toString().replace(/'/g, '\\\'').replace(/"/g, '\'')]
145
145
  } else {
146
146
  serialized = serializeAndCleanJs(value)
147
147
  }
@@ -4,7 +4,7 @@ import { Icon } from '@iconify/vue'
4
4
  import { useStoryStore } from '../../stores/story'
5
5
  import { Story, Tree } from '../../types'
6
6
  import MobileOverlay from './MobileOverlay.vue'
7
- import StoryList from '../story/StoryList.vue'
7
+ import StoryList from '../tree/StoryList.vue'
8
8
 
9
9
  const props = defineProps<{
10
10
  tree: Tree
@@ -51,6 +51,7 @@ const kindLabels = {
51
51
  <div
52
52
  ref="el"
53
53
  data-test-id="search-item"
54
+ :data-selected="selected ? '' : undefined"
54
55
  >
55
56
  <BaseListItemLink
56
57
  :to="result.route"
@@ -0,0 +1,75 @@
1
+ <script lang="ts" setup>
2
+ import type { Story, TreeGroup, TreeFolder, TreeLeaf } from '../../types'
3
+ import StoryListItem from './StoryListItem.vue'
4
+ import StoryListFolder from './StoryListFolder.vue'
5
+ import { Icon } from '@iconify/vue'
6
+ import { computed, withDefaults } from 'vue'
7
+ import { useStoryStore } from '../../stores/story'
8
+
9
+ const props = withDefaults(defineProps<{
10
+ path?: Array<string>
11
+ group: TreeGroup
12
+ stories: Story[]
13
+ }>(), {
14
+ path: () => [],
15
+ })
16
+
17
+ const storyStore = useStoryStore()
18
+
19
+ const folderPath = computed(() => [...props.path, props.group.title])
20
+ const isFolderOpen = computed(() => storyStore.isFolderOpened(folderPath.value, true))
21
+
22
+ function toggleOpen () {
23
+ storyStore.toggleFolder(folderPath.value, false)
24
+ }
25
+ </script>
26
+
27
+ <template>
28
+ <div
29
+ data-test-id="story-group"
30
+ class="htw-my-2 first:htw-mt-0 last:htw-mb-0"
31
+ >
32
+ <div
33
+ v-if="group.title"
34
+ role="button"
35
+ tabindex="0"
36
+ class="htw-px-0.5 htw-py-2 md:htw-py-1.5 htw-mx-1 htw-rounded-sm hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900 htw-cursor-pointer htw-select-none htw-flex htw-items-center htw-gap-1 htw-min-w-0"
37
+ @click="toggleOpen"
38
+ @keyup.enter="toggleOpen"
39
+ @keyup.space="toggleOpen"
40
+ >
41
+ <Icon
42
+ icon="carbon:caret-right"
43
+ class="htw-w-4 htw-h-4 htw-transition-transform htw-duration-150 htw-opacity-30 htw-flex-none"
44
+ :class="{
45
+ 'htw-rotate-90': isFolderOpen,
46
+ }"
47
+ />
48
+ <span class="htw-truncate htw-opacity-50">{{ group.title }}</span>
49
+ <span class="htw-h-[1px] htw-flex-1 htw-bg-gray-500/10 htw-mx-2" />
50
+ </div>
51
+
52
+ <!-- Children -->
53
+ <div
54
+ v-if="isFolderOpen"
55
+ >
56
+ <template
57
+ v-for="element of group.children"
58
+ :key="element.title"
59
+ >
60
+ <StoryListFolder
61
+ v-if="(element as TreeFolder).children"
62
+ :path="folderPath"
63
+ :folder="(element as TreeFolder)"
64
+ :stories="stories"
65
+ :depth="0"
66
+ />
67
+ <StoryListItem
68
+ v-else
69
+ :story="stories[(element as TreeLeaf).index]"
70
+ :depth="0"
71
+ />
72
+ </template>
73
+ </div>
74
+ </div>
75
+ </template>
@@ -1,7 +1,8 @@
1
1
  <script lang="ts" setup>
2
- import type { Story, Tree, TreeFolder, TreeLeaf } from '../../types'
2
+ import type { Story, Tree, TreeGroup, TreeFolder, TreeLeaf } from '../../types'
3
3
  import StoryListItem from './StoryListItem.vue'
4
4
  import StoryListFolder from './StoryListFolder.vue'
5
+ import StoryGroup from './StoryGroup.vue'
5
6
 
6
7
  const props = defineProps<{
7
8
  tree: Tree
@@ -15,8 +16,13 @@ const props = defineProps<{
15
16
  v-for="element of tree"
16
17
  :key="element.title"
17
18
  >
19
+ <StoryGroup
20
+ v-if="(element as TreeGroup).group"
21
+ :group="(element as TreeGroup)"
22
+ :stories="stories"
23
+ />
18
24
  <StoryListFolder
19
- v-if="(element as TreeFolder).children"
25
+ v-else-if="(element as TreeFolder).children"
20
26
  :folder="(element as TreeFolder)"
21
27
  :stories="stories"
22
28
  />
@@ -25,7 +25,7 @@ function toggleOpen () {
25
25
  }
26
26
 
27
27
  const folderPadding = computed(() => {
28
- return (props.depth * 16) + 'px'
28
+ return (props.depth * 12) + 'px'
29
29
  })
30
30
  </script>
31
31
 
@@ -34,13 +34,13 @@ const folderPadding = computed(() => {
34
34
  <div
35
35
  role="button"
36
36
  tabindex="0"
37
- class="htw-px-0.5 htw-py-2 md:htw-py-1.5 htw-m-1 htw-rounded-sm hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900 htw-cursor-pointer htw-select-none htw-flex"
37
+ class="htw-px-0.5 htw-py-2 md:htw-py-1.5 htw-mx-1 htw-rounded-sm hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900 htw-cursor-pointer htw-select-none htw-flex"
38
38
  @click="toggleOpen"
39
39
  @keyup.enter="toggleOpen"
40
40
  @keyup.space="toggleOpen"
41
41
  >
42
42
  <span class="bind-tree-padding htw-flex htw-items-center htw-gap-2 htw-min-w-0">
43
- <span class="htw-flex htw-gap-1 htw-flex-none htw-items-center">
43
+ <span class="htw-flex htw-flex-none htw-items-center">
44
44
  <Icon
45
45
  icon="carbon:caret-right"
46
46
  class="htw-w-4 htw-h-4 htw-transition-transform htw-duration-150 htw-opacity-30"
@@ -56,6 +56,8 @@ const folderPadding = computed(() => {
56
56
  <span class="htw-truncate">{{ folder.title }}</span>
57
57
  </span>
58
58
  </div>
59
+
60
+ <!-- Children -->
59
61
  <div
60
62
  v-if="isFolderOpen"
61
63
  >
@@ -66,7 +68,7 @@ const folderPadding = computed(() => {
66
68
  <StoryListFolder
67
69
  v-if="(element as TreeFolder).children"
68
70
  :path="folderPath"
69
- :folder="element"
71
+ :folder="(element as TreeFolder)"
70
72
  :stories="stories"
71
73
  :depth="depth + 1"
72
74
  />
@@ -14,7 +14,7 @@ const props = withDefaults(defineProps<{
14
14
  })
15
15
 
16
16
  const filePadding = computed(() => {
17
- return (props.depth * 16) + 'px'
17
+ return (props.depth * 12) + 'px'
18
18
  })
19
19
 
20
20
  const route = useRoute()
@@ -36,9 +36,9 @@ useScrollOnActive(active, el)
36
36
  storyId: story.id,
37
37
  },
38
38
  }"
39
- class="htw-pl-0.5 htw-pr-2 htw-py-2 md:htw-py-1.5 htw-m-1 htw-rounded-sm"
39
+ class="htw-pl-0.5 htw-pr-2 htw-py-2 md:htw-py-1.5 htw-mx-1 htw-rounded-sm"
40
40
  >
41
- <span class="bind-tree-margin htw-flex htw-items-center htw-gap-2 htw-pl-5 htw-min-w-0">
41
+ <span class="bind-tree-margin htw-flex htw-items-center htw-gap-2 htw-pl-4 htw-min-w-0">
42
42
  <Icon
43
43
  :icon="story.icon ?? 'carbon:cube'"
44
44
  class="base-list-item-link-icon htw-w-5 htw-h-5 sm:htw-w-4 sm:htw-h-4 htw-flex-none"
@@ -23,22 +23,26 @@ export const useStoryStore = defineStore('story', () => {
23
23
  return path.join('␜')
24
24
  }
25
25
 
26
- function toggleFolder (path: Array<string>, force?: boolean) {
26
+ function toggleFolder (path: Array<string>, defaultToggleValue = true) {
27
27
  const stringPath = getStringPath(path)
28
28
 
29
- if (force === undefined) {
30
- force = !openedFolders.value.get(stringPath)
31
- }
29
+ const currentValue = openedFolders.value.get(stringPath)
32
30
 
33
- if (force) {
34
- openedFolders.value.set(stringPath, true)
31
+ if (currentValue == null) {
32
+ openedFolders.value.set(stringPath, defaultToggleValue)
33
+ } else if (currentValue) {
34
+ openedFolders.value.set(stringPath, false)
35
35
  } else {
36
- openedFolders.value.delete(stringPath)
36
+ openedFolders.value.set(stringPath, true)
37
37
  }
38
38
  }
39
39
 
40
- function isFolderOpened (path: Array<string>) {
41
- return openedFolders.value.get(getStringPath(path))
40
+ function isFolderOpened (path: Array<string>, defaultValue = false) {
41
+ const value = openedFolders.value.get(getStringPath(path))
42
+ if (value == null) {
43
+ return defaultValue
44
+ }
45
+ return value
42
46
  }
43
47
 
44
48
  function openFileFolders (path: Array<string>) {
@@ -29,4 +29,6 @@
29
29
  }
30
30
  }
31
31
 
32
-
32
+ .v-popper__popper:focus-visible {
33
+ outline: none;
34
+ }
@@ -11,6 +11,7 @@ export interface StoryFile {
11
11
  export interface Story {
12
12
  id: string
13
13
  title: string
14
+ group?: string
14
15
  variants: Variant[]
15
16
  layout?: {
16
17
  type: 'single'
@@ -48,7 +49,14 @@ export type TreeFolder = {
48
49
  children: (TreeFolder | TreeLeaf)[]
49
50
  }
50
51
 
51
- export type Tree = (TreeFolder | TreeLeaf)[]
52
+ export interface TreeGroup {
53
+ group: true
54
+ id: string
55
+ title: string
56
+ children: (TreeFolder | TreeLeaf)[]
57
+ }
58
+
59
+ export type Tree = (TreeGroup | TreeFolder | TreeLeaf)[]
52
60
 
53
61
  export interface SearchResult {
54
62
  kind: 'story' | 'variant'
@@ -8,7 +8,12 @@ export default defineComponent({
8
8
  props: {
9
9
  title: {
10
10
  type: String,
11
- required: true,
11
+ default: null,
12
+ },
13
+
14
+ group: {
15
+ type: String,
16
+ default: null,
12
17
  },
13
18
 
14
19
  layout: {
@@ -36,7 +41,8 @@ export default defineComponent({
36
41
 
37
42
  const story: Story = {
38
43
  id: attrs.data.id,
39
- title: props.title,
44
+ title: props.title ?? attrs.data.fileName,
45
+ group: props.group,
40
46
  layout: props.layout,
41
47
  icon: props.icon,
42
48
  iconColor: props.iconColor,
@@ -7,7 +7,7 @@ import pc from 'picocolors'
7
7
  import Tinypool from 'tinypool'
8
8
  import { createBirpc } from 'birpc'
9
9
  import type { StoryFile } from '../types.js'
10
- import { createPath, TreeFile } from '../tree.js'
10
+ import { createPath } from '../tree.js'
11
11
  import type { Context } from '../context.js'
12
12
  import type { Payload, ReturnData } from './worker.js'
13
13
 
@@ -79,11 +79,11 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
79
79
  console.warn(pc.yellow(`⚠️ Multiple stories not supported: ${storyFile.path}`))
80
80
  }
81
81
  storyFile.story = storyData[0]
82
- const file: TreeFile = {
82
+ storyFile.treeFile = {
83
83
  title: storyData[0].title,
84
84
  path: relative(server.config.root, storyFile.path),
85
85
  }
86
- storyFile.treePath = createPath(ctx.config, file)
86
+ storyFile.treePath = createPath(ctx.config, storyFile.treeFile)
87
87
  storyFile.story.title = storyFile.treePath[storyFile.treePath.length - 1]
88
88
  } catch (e) {
89
89
  console.error(pc.red(`Error while collecting story ${storyFile.path}:\n${e.frame ? `${pc.bold(e.message)}\n${e.frame}` : e.stack}`))
@@ -13,17 +13,23 @@ type CustomizableColors = 'primary' | 'gray'
13
13
  type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'
14
14
  type GrayColorKeys = ColorKeys | '750' | '850' | '950'
15
15
 
16
- interface ResponsivePreset {
16
+ export interface ResponsivePreset {
17
17
  label: string
18
18
  width: number
19
19
  height: number
20
20
  }
21
21
 
22
- interface BackgroundPreset {
22
+ export interface BackgroundPreset {
23
23
  label: string
24
24
  color: string
25
25
  }
26
26
 
27
+ export interface TreeGroupConfig {
28
+ title: string
29
+ id?: string
30
+ include?: (file: TreeFile) => boolean
31
+ }
32
+
27
33
  export interface HistoireConfig {
28
34
  /**
29
35
  * Output directory.
@@ -48,6 +54,7 @@ export interface HistoireConfig {
48
54
  */
49
55
  file?: 'title' | 'path' | ((file: TreeFile) => string[])
50
56
  order?: 'asc' | ((a: string, b: string) => number)
57
+ groups?: TreeGroupConfig[]
51
58
  }
52
59
  /**
53
60
  * Customize the look of the histoire book.
@@ -99,7 +99,7 @@ export async function createVitePlugins (ctx: Context): Promise<VitePlugin[]> {
99
99
  return `import { defineAsyncComponent } from 'vue'
100
100
  ${resolvedStories.map((file, index) => `const Comp${index} = defineAsyncComponent(() => import('${file.path}'))`).join('\n')}
101
101
  export let files = [${files.map((file) => `{${JSON.stringify(file).slice(1, -1)}, component: Comp${file.index}}`).join(',\n')}]
102
- export let tree = ${JSON.stringify(makeTree(ctx.config, files))}
102
+ export let tree = ${JSON.stringify(makeTree(ctx.config, resolvedStories))}
103
103
  const handlers = []
104
104
  export function onUpdate (cb) {
105
105
  handlers.push(cb)
@@ -1,7 +1,7 @@
1
1
  import chokidar from 'chokidar'
2
2
  import { globby } from 'globby'
3
3
  import Case from 'case'
4
- import { join } from 'pathe'
4
+ import { join, basename } from 'pathe'
5
5
  import { Context } from './context.js'
6
6
  import type { StoryFile } from './types.js'
7
7
 
@@ -47,10 +47,15 @@ function getAbsoluteFilePath (relativeFilePath: string) {
47
47
  function addStory (relativeFilePath: string) {
48
48
  const absoluteFilePath = getAbsoluteFilePath(relativeFilePath)
49
49
  const fileId = Case.kebab(relativeFilePath)
50
+ let fileName = basename(relativeFilePath)
51
+ if (fileName.includes('.')) {
52
+ fileName = fileName.substring(0, fileName.indexOf('.'))
53
+ }
50
54
 
51
55
  const file: StoryFile = {
52
56
  id: fileId,
53
57
  path: absoluteFilePath,
58
+ fileName,
54
59
  moduleId: `/${relativeFilePath}`,
55
60
  }
56
61
  context.storyFiles.push(file)