histoire 0.1.5 → 0.2.2

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 (107) hide show
  1. package/dist/client/app/codegen/vue3.js +1 -0
  2. package/dist/client/app/codegen/vue3.js.map +1 -0
  3. package/dist/client/app/components/app/AppHeader.vue +2 -1
  4. package/dist/client/app/components/base/BaseCheckbox.vue +76 -0
  5. package/dist/client/app/components/exposed/Story.vue +20 -14
  6. package/dist/client/app/components/sandbox/lib.d.ts +2 -0
  7. package/dist/client/app/components/sandbox/lib.js +6 -0
  8. package/dist/client/app/components/sandbox/lib.ts +8 -0
  9. package/dist/client/app/components/search/SearchItem.vue +4 -1
  10. package/dist/client/app/components/search/SearchModal.vue +4 -4
  11. package/dist/client/app/components/story/StoryControls.vue +1 -1
  12. package/dist/client/app/components/story/StoryDocs.vue +1 -0
  13. package/dist/client/app/components/story/StoryListFolder.vue +1 -1
  14. package/dist/client/app/components/story/StoryListItem.vue +4 -1
  15. package/dist/client/app/components/story/StoryResponsivePreview.vue +3 -4
  16. package/dist/client/app/components/story/StorySidePanel.vue +1 -0
  17. package/dist/client/app/components/story/StorySourceCode.vue +4 -1
  18. package/dist/client/app/components/story/StoryVariantGrid.vue +112 -0
  19. package/dist/client/app/components/story/StoryVariantGridItem.vue +34 -4
  20. package/dist/client/app/components/story/StoryVariantListItem.vue +4 -1
  21. package/dist/client/app/components/story/StoryVariantSingleView.vue +20 -160
  22. package/dist/client/app/components/story/StoryViewer.vue +6 -25
  23. package/dist/client/app/components/story/variant/StoryVariantBackground.vue +67 -0
  24. package/dist/client/app/components/story/variant/StoryVariantNewTab.vue +29 -0
  25. package/dist/client/app/components/story/variant/StoryVariantResponsiveSize.vue +82 -0
  26. package/dist/client/app/components/story/variant/StoryVariantTitle.vue +21 -0
  27. package/dist/client/app/global-components.js +1 -0
  28. package/dist/client/app/global-components.js.map +1 -0
  29. package/dist/client/app/index.js +1 -0
  30. package/dist/client/app/index.js.map +1 -0
  31. package/dist/client/app/sandbox.js +1 -0
  32. package/dist/client/app/sandbox.js.map +1 -0
  33. package/dist/client/app/stores/story.d.ts +6 -6
  34. package/dist/client/app/stores/story.js +1 -0
  35. package/dist/client/app/stores/story.js.map +1 -0
  36. package/dist/client/app/style/main.pcss +9 -5
  37. package/dist/client/app/types.d.ts +1 -1
  38. package/dist/client/app/types.ts +1 -1
  39. package/dist/client/app/util/keyboard.js +1 -0
  40. package/dist/client/app/util/keyboard.js.map +1 -0
  41. package/dist/client/app/util/mapping.js +1 -0
  42. package/dist/client/app/util/mapping.js.map +1 -0
  43. package/dist/client/app/util/preview-settings.js +1 -0
  44. package/dist/client/app/util/preview-settings.js.map +1 -0
  45. package/dist/client/app/util/reactivity.js +1 -0
  46. package/dist/client/app/util/reactivity.js.map +1 -0
  47. package/dist/client/app/util/scroll.d.ts +3 -1
  48. package/dist/client/app/util/scroll.js +4 -0
  49. package/dist/client/app/util/scroll.js.map +1 -0
  50. package/dist/client/app/util/scroll.ts +4 -0
  51. package/dist/client/app/util/variant.js +1 -0
  52. package/dist/client/app/util/variant.js.map +1 -0
  53. package/dist/client/index.js +1 -0
  54. package/dist/client/index.js.map +1 -0
  55. package/dist/client/server/index.js +1 -0
  56. package/dist/client/server/index.js.map +1 -0
  57. package/dist/controls.js +1 -0
  58. package/dist/controls.js.map +1 -0
  59. package/dist/node/bin.js +7 -0
  60. package/dist/node/build.js +1 -1
  61. package/dist/node/{collect.d.ts → collect/index.d.ts} +2 -2
  62. package/dist/node/{collect.js → collect/index.js} +37 -27
  63. package/dist/node/collect/worker.d.ts +14 -0
  64. package/dist/node/collect/worker.js +36 -0
  65. package/dist/node/commands/preview.d.ts +4 -0
  66. package/dist/node/commands/preview.js +36 -0
  67. package/dist/node/config.d.ts +2 -2
  68. package/dist/node/server.js +1 -1
  69. package/dist/node/tree.js +24 -4
  70. package/dist/node/types.d.ts +1 -1
  71. package/dist/style.css +98 -50
  72. package/package.json +10 -6
  73. package/src/client/app/components/app/AppHeader.vue +2 -1
  74. package/src/client/app/components/base/BaseCheckbox.vue +76 -0
  75. package/src/client/app/components/exposed/Story.vue +20 -14
  76. package/src/client/app/components/sandbox/lib.ts +8 -0
  77. package/src/client/app/components/search/SearchItem.vue +4 -1
  78. package/src/client/app/components/search/SearchModal.vue +4 -4
  79. package/src/client/app/components/story/StoryControls.vue +1 -1
  80. package/src/client/app/components/story/StoryDocs.vue +1 -0
  81. package/src/client/app/components/story/StoryListFolder.vue +1 -1
  82. package/src/client/app/components/story/StoryListItem.vue +4 -1
  83. package/src/client/app/components/story/StoryResponsivePreview.vue +3 -4
  84. package/src/client/app/components/story/StorySidePanel.vue +1 -0
  85. package/src/client/app/components/story/StorySourceCode.vue +4 -1
  86. package/src/client/app/components/story/StoryVariantGrid.vue +112 -0
  87. package/src/client/app/components/story/StoryVariantGridItem.vue +34 -4
  88. package/src/client/app/components/story/StoryVariantListItem.vue +4 -1
  89. package/src/client/app/components/story/StoryVariantSingleView.vue +20 -160
  90. package/src/client/app/components/story/StoryViewer.vue +6 -25
  91. package/src/client/app/components/story/variant/StoryVariantBackground.vue +67 -0
  92. package/src/client/app/components/story/variant/StoryVariantNewTab.vue +29 -0
  93. package/src/client/app/components/story/variant/StoryVariantResponsiveSize.vue +82 -0
  94. package/src/client/app/components/story/variant/StoryVariantTitle.vue +21 -0
  95. package/src/client/app/style/main.pcss +9 -5
  96. package/src/client/app/types.ts +1 -1
  97. package/src/client/app/util/scroll.ts +4 -0
  98. package/src/node/bin.ts +8 -0
  99. package/src/node/build.ts +1 -1
  100. package/src/node/{collect.ts → collect/index.ts} +48 -30
  101. package/src/node/collect/worker.ts +61 -0
  102. package/src/node/commands/preview.ts +50 -0
  103. package/src/node/config.ts +2 -2
  104. package/src/node/server.ts +1 -1
  105. package/src/node/tree.spec.ts +61 -0
  106. package/src/node/tree.ts +29 -5
  107. package/src/node/types.ts +1 -1
@@ -1,173 +1,39 @@
1
1
  <script lang="ts" setup>
2
- import { PropType, ref } from 'vue'
3
- import { Icon } from '@iconify/vue'
2
+ import { PropType } from 'vue'
4
3
  import type { Story, Variant } from '../../types'
5
- import { histoireConfig } from '../../util/config'
6
4
  import { usePreviewSettings } from '../../util/preview-settings'
7
5
  import StoryResponsivePreview from './StoryResponsivePreview.vue'
8
6
  import { isMobile } from '../../util/responsive'
7
+ import StoryVariantTitle from './variant/StoryVariantTitle.vue'
8
+ import StoryVariantResponsiveSize from './variant/StoryVariantResponsiveSize.vue'
9
+ import StoryVariantBackground from './variant/StoryVariantBackground.vue'
10
+ import StoryVariantNewTab from './variant/StoryVariantNewTab.vue'
9
11
 
10
- defineProps({
11
- variant: {
12
- type: Object as PropType<Variant>,
13
- required: true,
14
- },
15
-
16
- story: {
17
- type: Object as PropType<Story>,
18
- required: true,
19
- },
20
- })
12
+ defineProps<{
13
+ variant: Variant
14
+ story: Story
15
+ }>()
21
16
 
22
17
  const settings = usePreviewSettings()
23
18
  </script>
24
19
 
25
20
  <template>
26
- <div class="htw-h-full htw-flex htw-flex-col">
21
+ <div
22
+ class="htw-h-full htw-flex htw-flex-col"
23
+ data-test-id="story-variant-single-view"
24
+ >
27
25
  <!-- Toolbar -->
28
26
  <div
29
27
  v-if="!isMobile"
30
28
  class="htw-flex-none htw-flex htw-items-center htw-h-8 -htw-mt-1"
31
29
  >
32
- <!-- Variant title -->
33
- <div class="htw-flex htw-items-center htw-gap-1 htw-text-gray-500 htw-flex-1 htw-truncate htw-min-w-0">
34
- <Icon
35
- :icon="variant.icon ?? 'carbon:cube'"
36
- class="base-list-item-link-icon htw-w-4 htw-h-4 htw-opacity-50"
37
- :class="[
38
- variant.iconColor ? 'bind-icon-color' : 'htw-text-gray-500',
39
- ]"
40
- />
41
- <span>{{ variant.title }}</span>
42
- </div>
43
-
44
- <!-- Responsive size -->
45
- <VDropdown
46
- placement="bottom-end"
47
- :skidding="6"
48
- :disabled="!histoireConfig.responsivePresets?.length"
49
- class="htw-h-full htw-flex-none"
50
- >
51
- <div
52
- v-tooltip="'Responsive sizes'"
53
- class="htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2"
54
- :class="{
55
- 'htw-cursor-pointer hover:htw-text-primary-500': histoireConfig.responsivePresets?.length,
56
- }"
57
- >
58
- <Icon
59
- icon="ic:baseline-phone-android"
60
- class="htw-w-4 htw-h-4 htw-opacity-50"
61
- />
62
- <Icon
63
- icon="carbon:caret-down"
64
- class="htw-w-4 htw-h-4 htw-opacity-50"
65
- />
66
- </div>
67
-
68
- <template #popper="{ hide }">
69
- <div class="htw-flex htw-flex-col htw-items-stretch">
70
- <HstCheckbox
71
- v-model="settings.rotate"
72
- >
73
- Rotate
74
- </HstCheckbox>
75
-
76
- <div class="htw-flex htw-gap-2 htw-px-4 htw-py-3">
77
- <input
78
- v-model.number="settings.responsiveWidth"
79
- v-tooltip="'Responsive width (px)'"
80
- type="number"
81
- class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-20 htw-opacity-50 focus:htw-opacity-100 htw-flex-1 htw-min-w-0"
82
- step="16"
83
- placeholder="Auto"
84
- >
85
- <span class="htw-opacity-50">x</span>
86
- <input
87
- v-model.number="settings.responsiveHeight"
88
- v-tooltip="'Responsive height (px)'"
89
- type="number"
90
- class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-20 htw-opacity-50 focus:htw-opacity-100 htw-flex-1 htw-min-w-0"
91
- step="16"
92
- placeholder="Auto"
93
- >
94
- </div>
95
-
96
- <button
97
- v-for="(preset, index) in histoireConfig.responsivePresets"
98
- :key="index"
99
- class="htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-4"
100
- :class="[
101
- settings.responsiveWidth === preset.width && settings.responsiveHeight === preset.height
102
- ? 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
103
- : 'htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700',
104
- ]"
105
- @click="settings.responsiveWidth = preset.width;settings.responsiveHeight = preset.height;hide()"
106
- >
107
- {{ preset.label }}
108
- <span class="htw-ml-auto htw-opacity-70 htw-flex htw-gap-1">
109
- <span v-if="preset.width">{{ preset.width }}<span v-if="!preset.height">px</span></span>
110
- <span v-if="preset.width && preset.height">x</span>
111
- <span v-if="preset.height">{{ preset.height }}<span v-if="!preset.width">px</span></span>
112
- </span>
113
- </button>
114
- </div>
115
- </template>
116
- </VDropdown>
117
-
118
- <!-- Background -->
119
- <VDropdown
120
- v-if="histoireConfig.backgroundPresets.length"
121
- placement="bottom-end"
122
- :skidding="6"
123
- class="htw-h-full htw-flex-none"
124
- >
125
- <div
126
- v-tooltip="'Background color'"
127
- class="htw-cursor-pointer hover:htw-text-primary-500 htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2"
128
- >
129
- <div
130
- class="bind-preview-bg htw-w-4 htw-h-4 htw-rounded-full htw-border htw-border-black/20 dark:htw-border-white/20"
131
- />
132
- <Icon
133
- icon="carbon:caret-down"
134
- class="htw-w-4 htw-h-4 htw-opacity-50"
135
- />
136
- </div>
137
-
138
- <template #popper="{ hide }">
139
- <div class="htw-flex htw-flex-col htw-items-stretch">
140
- <HstCheckbox
141
- v-model="settings.checkerboard"
142
- >
143
- Checkerboard
144
- </HstCheckbox>
145
-
146
- <button
147
- v-for="(option, index) in histoireConfig.backgroundPresets"
148
- :key="index"
149
- class="htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-4"
150
- :class="[
151
- settings.backgroundColor === option.color
152
- ? 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
153
- : 'htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700',
154
- ]"
155
- @click="settings.backgroundColor = option.color;hide()"
156
- >
157
- <span class="htw-mr-auto">{{ option.label }}</span>
158
- <template v-if="option.color !== '$checkerboard'">
159
- <span class="htw-ml-auto htw-opacity-70">{{ option.color }}</span>
160
- <div
161
- class="htw-w-4 htw-h-4 htw-rounded-full htw-border htw-border-black/20 dark:htw-border-white/20"
162
- :style="{
163
- backgroundColor: option.color,
164
- }"
165
- />
166
- </template>
167
- </button>
168
- </div>
169
- </template>
170
- </VDropdown>
30
+ <StoryVariantTitle :variant="variant" />
31
+ <StoryVariantResponsiveSize />
32
+ <StoryVariantBackground />
33
+ <StoryVariantNewTab
34
+ :variant="variant"
35
+ :story="story"
36
+ />
171
37
  </div>
172
38
 
173
39
  <!-- Preview -->
@@ -178,9 +44,3 @@ const settings = usePreviewSettings()
178
44
  />
179
45
  </div>
180
46
  </template>
181
-
182
- <style scoped>
183
- .bind-preview-bg {
184
- background-color: v-bind('settings.backgroundColor');
185
- }
186
- </style>
@@ -1,21 +1,16 @@
1
1
  <script lang="ts" setup>
2
2
  import { computed, ref, watch } from 'vue'
3
- import { useRoute, useRouter } from 'vue-router'
4
3
  import { useStoryStore } from '../../stores/story'
5
-
4
+ import { Icon } from '@iconify/vue'
5
+ import { isMobile } from '../../util/responsive'
6
6
  import BaseSplitPane from '../base/BaseSplitPane.vue'
7
7
  import StoryVariantListItem from './StoryVariantListItem.vue'
8
- import StoryVariantGridItem from './StoryVariantGridItem.vue'
9
8
  import StoryVariantSingleView from './StoryVariantSingleView.vue'
10
- import { isMobile } from '../../util/responsive'
11
- import { Icon } from '@iconify/vue'
12
9
  import MobileOverlay from '../app/MobileOverlay.vue'
10
+ import StoryVariantGrid from './StoryVariantGrid.vue'
13
11
 
14
12
  const storyStore = useStoryStore()
15
13
 
16
- const router = useRouter()
17
- const route = useRoute()
18
-
19
14
  const hasSingleVariant = computed(() => (storyStore.currentStory?.variants.length === 1))
20
15
 
21
16
  const variant = computed(() => storyStore.currentVariant)
@@ -33,28 +28,14 @@ function closeMenu () {
33
28
  watch(variant, () => {
34
29
  isMenuOpened.value = false
35
30
  })
31
+
36
32
  </script>
37
33
 
38
34
  <template>
39
35
  <div class="htw-bg-gray-50 htw-h-full dark:htw-bg-gray-750">
40
- <div
36
+ <StoryVariantGrid
41
37
  v-if="storyStore.currentStory.layout.type === 'grid'"
42
- class="htw-h-full htw-overflow-y-auto"
43
- >
44
- <div
45
- class="htw-grid htw-gap-4 htw-m-4"
46
- :style="{
47
- gridTemplateColumns: `repeat(auto-fill, ${storyStore.currentStory.layout.width ?? 200}px)`,
48
- }"
49
- >
50
- <StoryVariantGridItem
51
- v-for="(variant, index) of storyStore.currentStory.variants"
52
- :key="index"
53
- :variant="variant"
54
- :story="storyStore.currentStory"
55
- />
56
- </div>
57
- </div>
38
+ />
58
39
 
59
40
  <template v-else-if="storyStore.currentStory.layout.type === 'single'">
60
41
  <div
@@ -0,0 +1,67 @@
1
+ <script lang="ts" setup>
2
+ import { Icon } from '@iconify/vue'
3
+ import { histoireConfig } from '../../../util/config'
4
+ import { usePreviewSettings } from '../../../util/preview-settings'
5
+ import BaseCheckbox from '../../base/BaseCheckbox.vue'
6
+
7
+ const settings = usePreviewSettings()
8
+ </script>
9
+
10
+ <template>
11
+ <VDropdown
12
+ v-if="histoireConfig.backgroundPresets.length"
13
+ placement="bottom-end"
14
+ :skidding="6"
15
+ class="htw-h-full htw-flex-none"
16
+ >
17
+ <div
18
+ v-tooltip="'Background color'"
19
+ class="htw-cursor-pointer hover:htw-text-primary-500 htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2"
20
+ >
21
+ <div
22
+ class="bind-preview-bg htw-w-4 htw-h-4 htw-rounded-full htw-border htw-border-black/50 dark:htw-border-white/50"
23
+ />
24
+ <Icon
25
+ icon="carbon:caret-down"
26
+ class="htw-w-4 htw-h-4 htw-opacity-50"
27
+ />
28
+ </div>
29
+
30
+ <template #popper="{ hide }">
31
+ <div class="htw-flex htw-flex-col htw-items-stretch">
32
+ <BaseCheckbox v-model="settings.checkerboard">
33
+ Checkerboard
34
+ </BaseCheckbox>
35
+
36
+ <button
37
+ v-for="(option, index) in histoireConfig.backgroundPresets"
38
+ :key="index"
39
+ class="htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-4"
40
+ :class="[
41
+ settings.backgroundColor === option.color
42
+ ? 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
43
+ : 'htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700',
44
+ ]"
45
+ @click="settings.backgroundColor = option.color;hide()"
46
+ >
47
+ <span class="htw-mr-auto">{{ option.label }}</span>
48
+ <template v-if="option.color !== '$checkerboard'">
49
+ <span class="htw-ml-auto htw-opacity-70">{{ option.color }}</span>
50
+ <div
51
+ class="htw-w-4 htw-h-4 htw-rounded-full htw-border htw-border-black/20 dark:htw-border-white/20"
52
+ :style="{
53
+ backgroundColor: option.color,
54
+ }"
55
+ />
56
+ </template>
57
+ </button>
58
+ </div>
59
+ </template>
60
+ </VDropdown>
61
+ </template>
62
+
63
+ <style scoped>
64
+ .bind-preview-bg {
65
+ background-color: v-bind('settings.backgroundColor');
66
+ }
67
+ </style>
@@ -0,0 +1,29 @@
1
+ <script lang="ts" setup>
2
+ import { Icon } from '@iconify/vue'
3
+ import type { Story, Variant } from '../../../types'
4
+ import { computed } from 'vue'
5
+ import { getSandboxUrl } from '../../sandbox/lib'
6
+
7
+ const props = defineProps<{
8
+ variant: Variant
9
+ story: Story
10
+ }>()
11
+
12
+ const sandboxUrl = computed(() => {
13
+ return getSandboxUrl(props.story, props.variant)
14
+ })
15
+ </script>
16
+
17
+ <template>
18
+ <a
19
+ v-tooltip="'Open variant in new tab'"
20
+ :href="sandboxUrl"
21
+ target="_blank"
22
+ class="htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2 hover:htw-text-primary-500"
23
+ >
24
+ <Icon
25
+ icon="carbon:launch"
26
+ class="base-list-item-link-icon htw-w-4 htw-h-4 htw-opacity-50"
27
+ />
28
+ </a>
29
+ </template>
@@ -0,0 +1,82 @@
1
+ <script lang="ts" setup>
2
+ import { Icon } from '@iconify/vue'
3
+ import { histoireConfig } from '../../../util/config'
4
+ import { usePreviewSettings } from '../../../util/preview-settings'
5
+ import BaseCheckbox from '../../base/BaseCheckbox.vue'
6
+
7
+ const settings = usePreviewSettings()
8
+ </script>
9
+
10
+ <template>
11
+ <!-- Responsive size -->
12
+ <VDropdown
13
+ placement="bottom-end"
14
+ :skidding="6"
15
+ :disabled="!histoireConfig.responsivePresets?.length"
16
+ class="htw-h-full htw-flex-none"
17
+ >
18
+ <div
19
+ v-tooltip="'Responsive sizes'"
20
+ class="htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2"
21
+ :class="{
22
+ 'htw-cursor-pointer hover:htw-text-primary-500': histoireConfig.responsivePresets?.length,
23
+ }"
24
+ >
25
+ <Icon
26
+ icon="carbon:devices"
27
+ class="htw-w-4 htw-h-4 htw-opacity-50"
28
+ />
29
+ <Icon
30
+ icon="carbon:caret-down"
31
+ class="htw-w-4 htw-h-4 htw-opacity-50"
32
+ />
33
+ </div>
34
+
35
+ <template #popper="{ hide }">
36
+ <div class="htw-flex htw-flex-col htw-items-stretch">
37
+ <BaseCheckbox v-model="settings.rotate">
38
+ Rotate
39
+ </BaseCheckbox>
40
+
41
+ <div class="htw-flex htw-gap-2 htw-px-4 htw-py-3">
42
+ <input
43
+ v-model.number="settings.responsiveWidth"
44
+ v-tooltip="'Responsive width (px)'"
45
+ type="number"
46
+ class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-20 htw-opacity-50 focus:htw-opacity-100 htw-flex-1 htw-min-w-0"
47
+ step="16"
48
+ placeholder="Auto"
49
+ >
50
+ <span class="htw-opacity-50">x</span>
51
+ <input
52
+ v-model.number="settings.responsiveHeight"
53
+ v-tooltip="'Responsive height (px)'"
54
+ type="number"
55
+ class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-20 htw-opacity-50 focus:htw-opacity-100 htw-flex-1 htw-min-w-0"
56
+ step="16"
57
+ placeholder="Auto"
58
+ >
59
+ </div>
60
+
61
+ <button
62
+ v-for="(preset, index) in histoireConfig.responsivePresets"
63
+ :key="index"
64
+ class="htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-4"
65
+ :class="[
66
+ settings.responsiveWidth === preset.width && settings.responsiveHeight === preset.height
67
+ ? 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
68
+ : 'htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700',
69
+ ]"
70
+ @click="settings.responsiveWidth = preset.width;settings.responsiveHeight = preset.height;hide()"
71
+ >
72
+ {{ preset.label }}
73
+ <span class="htw-ml-auto htw-opacity-70 htw-flex htw-gap-1">
74
+ <span v-if="preset.width">{{ preset.width }}<span v-if="!preset.height">px</span></span>
75
+ <span v-if="preset.width && preset.height">x</span>
76
+ <span v-if="preset.height">{{ preset.height }}<span v-if="!preset.width">px</span></span>
77
+ </span>
78
+ </button>
79
+ </div>
80
+ </template>
81
+ </VDropdown>
82
+ </template>
@@ -0,0 +1,21 @@
1
+ <script lang="ts" setup>
2
+ import { Icon } from '@iconify/vue'
3
+ import type { Variant } from '../../../types'
4
+
5
+ defineProps<{
6
+ variant: Variant
7
+ }>()
8
+ </script>
9
+
10
+ <template>
11
+ <div class="htw-flex htw-items-center htw-gap-1 htw-text-gray-500 htw-flex-1 htw-truncate htw-min-w-0">
12
+ <Icon
13
+ :icon="variant.icon ?? 'carbon:cube'"
14
+ class="base-list-item-link-icon htw-w-4 htw-h-4 htw-opacity-50"
15
+ :class="[
16
+ variant.iconColor ? 'bind-icon-color' : 'htw-text-gray-500',
17
+ ]"
18
+ />
19
+ <span>{{ variant.title }}</span>
20
+ </div>
21
+ </template>
@@ -48,14 +48,18 @@ body,
48
48
  font-family: 'Lato', sans-serif;
49
49
  }
50
50
 
51
- #app {
52
- font-size: 18px;
51
+ html {
52
+ font-size: 16px;
53
+ }
54
+
55
+ body {
56
+ font-size: 18px;
53
57
  }
54
58
 
55
59
  @media (min-width: 640px) {
56
- #app {
57
- font-size: 14px;
58
- }
60
+ body {
61
+ font-size: 14px;
62
+ }
59
63
  }
60
64
 
61
65
  .__histoire-sandbox {
@@ -16,7 +16,7 @@ export interface Story {
16
16
  type: 'single'
17
17
  } | {
18
18
  type: 'grid'
19
- width: number
19
+ width?: number | string
20
20
  }
21
21
  icon?: string
22
22
  iconColor?: string
@@ -24,4 +24,8 @@ export function useScrollOnActive (active: Ref<boolean>, el: Ref<HTMLElement>) {
24
24
  autoScroll()
25
25
  }
26
26
  })
27
+
28
+ return {
29
+ autoScroll,
30
+ }
27
31
  }
package/src/node/bin.ts CHANGED
@@ -25,4 +25,12 @@ program.command('build')
25
25
  return buildCommand()
26
26
  })
27
27
 
28
+ program.command('preview')
29
+ .describe('preview the built directory')
30
+ .option('-p, --port <port>', 'Listening port of the server')
31
+ .action(async (options) => {
32
+ const { previewCommand } = await import('./commands/preview.js')
33
+ return previewCommand(options)
34
+ })
35
+
28
36
  program.parse(process.argv)
package/src/node/build.ts CHANGED
@@ -9,7 +9,7 @@ import { Context } from './context.js'
9
9
  import { createVitePlugins } from './plugin.js'
10
10
  import { findAllStories } from './stories.js'
11
11
  import type { RollupOutput } from 'rollup'
12
- import { useCollectStories } from './collect.js'
12
+ import { useCollectStories } from './collect/index.js'
13
13
 
14
14
  const PRELOAD_MODULES = [
15
15
  'vendor',
@@ -1,15 +1,15 @@
1
- import { fileURLToPath } from 'url'
1
+ import { MessageChannel } from 'worker_threads'
2
2
  import type { ViteDevServer } from 'vite'
3
3
  import { ViteNodeServer } from 'vite-node/server'
4
- import { ViteNodeRunner } from 'vite-node/client'
5
- import { dirname, resolve, relative } from 'pathe'
4
+ import type { FetchFunction, ResolveIdFunction } from 'vite-node'
5
+ import { relative } from 'pathe'
6
6
  import pc from 'picocolors'
7
- import type { StoryFile, Story } from './types.js'
8
- import { createDomEnv } from './dom/env.js'
9
- import { createPath, TreeFile } from './tree.js'
10
- import type { Context } from './context.js'
11
-
12
- const __dirname = dirname(fileURLToPath(import.meta.url))
7
+ import Tinypool from 'tinypool'
8
+ import { createBirpc } from 'birpc'
9
+ import type { StoryFile } from '../types.js'
10
+ import { createPath, TreeFile } from '../tree.js'
11
+ import type { Context } from '../context.js'
12
+ import type { Payload, ReturnData } from './worker.js'
13
13
 
14
14
  export interface UseCollectStoriesOptions {
15
15
  server: ViteDevServer
@@ -18,7 +18,6 @@ export interface UseCollectStoriesOptions {
18
18
 
19
19
  export function useCollectStories (options: UseCollectStoriesOptions, ctx: Context) {
20
20
  const { server } = options
21
- const { destroy: destroyDomEnv } = createDomEnv()
22
21
 
23
22
  const node = new ViteNodeServer(server, {
24
23
  deps: {
@@ -27,33 +26,52 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
27
26
  ],
28
27
  },
29
28
  })
30
- const runner = new ViteNodeRunner({
31
- root: server.config.root,
32
- base: server.config.base,
33
- fetchModule (id) {
34
- // Alias
35
- if (id.endsWith('vue.runtime.esm-bundler.js')) {
36
- id = 'vue'
37
- }
38
- return node.fetchModule(id)
39
- },
40
- resolveId (id, importer) {
41
- return node.resolveId(id, importer)
42
- },
29
+
30
+ const threadPool = new Tinypool({
31
+ filename: new URL('./worker.js', import.meta.url).href,
32
+ // WebContainer compatibility (Stackblitz)
33
+ useAtomics: false,
43
34
  })
44
35
 
45
36
  function clearCache () {
46
37
  node.fetchCache.clear()
47
- runner.moduleCache.clear()
38
+ }
39
+
40
+ function createChannel () {
41
+ const channel = new MessageChannel()
42
+ const port = channel.port2
43
+ const workerPort = channel.port1
44
+
45
+ createBirpc<Record<string, never>, {
46
+ fetchModule: FetchFunction
47
+ resolveId: ResolveIdFunction
48
+ }>({
49
+ fetchModule: (id) => node.fetchModule(id),
50
+ resolveId: (id, importer) => node.resolveId(id, importer),
51
+ }, {
52
+ post: data => port.postMessage(data),
53
+ on: data => port.on('message', data),
54
+ })
55
+
56
+ return {
57
+ port,
58
+ workerPort,
59
+ }
48
60
  }
49
61
 
50
62
  async function executeStoryFile (storyFile: StoryFile) {
51
63
  try {
52
- // Mount app to collect stories/variants
53
- const el = window.document.createElement('div')
54
- const { run } = await runner.executeFile(resolve(__dirname, '../client/server/index.js'))
55
- const storyData: Story[] = []
56
- await run(storyFile, storyData, el)
64
+ const { workerPort } = createChannel()
65
+ const { storyData } = await threadPool.run({
66
+ root: server.config.root,
67
+ base: server.config.base,
68
+ storyFile,
69
+ port: workerPort,
70
+ } as Payload, {
71
+ transferList: [
72
+ workerPort,
73
+ ],
74
+ }) as ReturnData
57
75
  if (storyData.length === 0) {
58
76
  console.warn(pc.yellow(`⚠️ No story found for ${storyFile.path}`))
59
77
  return
@@ -76,7 +94,7 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
76
94
  }
77
95
 
78
96
  async function destroy () {
79
- destroyDomEnv()
97
+ await threadPool.destroy()
80
98
  }
81
99
 
82
100
  return {