histoire 0.7.7 → 0.8.0

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 (164) hide show
  1. package/dist/bundled/App.js +166 -0
  2. package/dist/bundled/_virtual/plugin-vue_export-helper.js +8 -0
  3. package/dist/bundled/api.js +1 -32
  4. package/dist/bundled/assets/histoire-text-dark.js +2 -0
  5. package/dist/bundled/assets/histoire-text.js +2 -0
  6. package/dist/bundled/{HomeView.js → assets/histoire.js} +1 -23
  7. package/dist/bundled/components/HomeView.js +24 -0
  8. package/dist/bundled/components/app/AppHeader.js +67 -0
  9. package/dist/bundled/components/app/AppLogo.js +26 -0
  10. package/dist/bundled/components/app/Breadcrumb.js +95 -0
  11. package/dist/bundled/components/app/Breadcrumb.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  12. package/dist/bundled/components/app/InitialLoading.js +48 -0
  13. package/dist/bundled/components/app/MobileOverlay.js +41 -0
  14. package/dist/bundled/components/base/BaseCheckbox.js +75 -0
  15. package/dist/bundled/{BaseEmpty.js → components/base/BaseEmpty.js} +4 -4
  16. package/dist/bundled/components/base/BaseEmpty.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  17. package/dist/bundled/components/base/BaseListItemLink.js +50 -0
  18. package/dist/bundled/components/base/BaseOverflowMenu.js +97 -0
  19. package/dist/bundled/components/base/BaseOverflowTab.js +45 -0
  20. package/dist/bundled/components/base/BaseSelect.js +88 -0
  21. package/dist/bundled/{MobileOverlay.js → components/base/BaseSplitPane.js} +9 -130
  22. package/dist/bundled/components/base/BaseSplitPane.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  23. package/dist/bundled/components/base/BaseTab.js +45 -0
  24. package/dist/bundled/components/misc/CheckerboardPattern.js +41 -0
  25. package/dist/bundled/components/misc/HatchedPattern.js +11 -0
  26. package/dist/bundled/components/misc/HatchedPattern.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  27. package/dist/bundled/components/panel/ControlsComponentPropItem.js +98 -0
  28. package/dist/bundled/components/panel/ControlsComponentProps.js +42 -0
  29. package/dist/bundled/components/panel/PaneTabs.js +110 -0
  30. package/dist/bundled/components/panel/StatePresets.js +184 -0
  31. package/dist/bundled/components/panel/StoryControls.js +66 -0
  32. package/dist/bundled/components/panel/StoryDocs.js +48 -0
  33. package/dist/bundled/components/panel/StoryEvent.js +56 -0
  34. package/dist/bundled/components/panel/StoryEvents.js +49 -0
  35. package/dist/bundled/components/panel/StorySidePanel.js +68 -0
  36. package/dist/bundled/components/panel/StorySourceCode.js +110 -0
  37. package/dist/bundled/components/panel/StorySourceCode.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  38. package/dist/bundled/components/search/SearchItem.js +113 -0
  39. package/dist/bundled/components/search/SearchItem.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  40. package/dist/bundled/components/search/SearchLoading.js +19 -0
  41. package/dist/bundled/components/search/SearchModal.js +46 -0
  42. package/dist/bundled/components/search/SearchPane.js +263 -0
  43. package/dist/bundled/{search-docs-data.js → components/search/search-docs-data.js} +1 -1
  44. package/dist/bundled/components/search/search-title-data.js +7 -0
  45. package/dist/bundled/components/story/StoryResponsivePreview.js +180 -0
  46. package/dist/bundled/components/story/StoryResponsivePreview.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  47. package/dist/bundled/components/story/StoryVariantGrid.js +94 -0
  48. package/dist/bundled/components/story/StoryVariantGridItem.js +106 -0
  49. package/dist/bundled/components/story/StoryVariantGridItem.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  50. package/dist/bundled/components/story/StoryVariantListItem.js +58 -0
  51. package/dist/bundled/components/story/StoryVariantListItem.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  52. package/dist/bundled/components/story/StoryVariantSingle.js +115 -0
  53. package/dist/bundled/components/story/StoryVariantSingle.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  54. package/dist/bundled/components/story/StoryVariantSinglePreviewNative.js +43 -0
  55. package/dist/bundled/components/story/StoryVariantSinglePreviewRemote.js +119 -0
  56. package/dist/bundled/components/story/StoryVariantSingleView.js +49 -0
  57. package/dist/bundled/components/story/StoryView.js +107 -0
  58. package/dist/bundled/components/story/StoryViewer.js +57 -0
  59. package/dist/bundled/components/story/StoryViewer.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  60. package/dist/bundled/components/toolbar/StoryVariantBackground.js +85 -0
  61. package/dist/bundled/components/toolbar/StoryVariantBackground.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  62. package/dist/bundled/components/toolbar/StoryVariantNewTab.js +33 -0
  63. package/dist/bundled/components/toolbar/StoryVariantResponsiveSize.js +129 -0
  64. package/dist/bundled/components/toolbar/StoryVariantTitle.js +24 -0
  65. package/dist/bundled/components/tree/StoryGroup.js +74 -0
  66. package/dist/bundled/components/tree/StoryList.js +37 -0
  67. package/dist/bundled/components/tree/StoryListFolder.js +89 -0
  68. package/dist/bundled/components/tree/StoryListFolder.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  69. package/dist/bundled/components/tree/StoryListItem.js +72 -0
  70. package/dist/bundled/components/tree/StoryListItem.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  71. package/dist/bundled/index.js +28 -5
  72. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/common.js +40 -0
  73. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/lang/en.js +5 -0
  74. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/lang/latin/advanced.js +11 -0
  75. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/lang/latin/balance.js +26 -0
  76. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/lang/latin/simple.js +10 -0
  77. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/lang.js +50 -0
  78. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/type.js +8 -0
  79. package/dist/bundled/router.js +28 -0
  80. package/dist/bundled/sandbox.js +11 -14
  81. package/dist/bundled/{events.js → stores/events.js} +3 -3
  82. package/dist/bundled/stores/folder.js +46 -0
  83. package/dist/bundled/stores/preview-settings.js +15 -0
  84. package/dist/bundled/{story.js → stores/story.js} +4 -30
  85. package/dist/bundled/style.css +56 -56
  86. package/dist/bundled/{config.js → util/config.js} +1 -1
  87. package/dist/bundled/{const.js → util/const.js} +1 -1
  88. package/dist/bundled/util/dark.js +4 -0
  89. package/dist/bundled/util/env.js +2 -0
  90. package/dist/bundled/util/events.js +32 -0
  91. package/dist/bundled/util/keyboard.js +84 -0
  92. package/dist/bundled/{mapping.js → util/mapping.js} +5 -5
  93. package/dist/bundled/util/preview-settings.js +6 -0
  94. package/dist/bundled/util/responsive.js +3 -0
  95. package/dist/bundled/util/sandbox.js +8 -0
  96. package/dist/bundled/util/scroll.js +28 -0
  97. package/dist/bundled/{state.js → util/state.js} +4 -3
  98. package/dist/bundled/util/tooltip.js +12 -0
  99. package/dist/bundled/util/variant.js +35 -0
  100. package/dist/client/app/App.vue +0 -1
  101. package/dist/client/app/components/app/Breadcrumb.vue +1 -1
  102. package/dist/client/app/components/app/MobileOverlay.vue +1 -1
  103. package/dist/client/app/components/base/BaseCheckbox.vue +2 -1
  104. package/dist/client/app/components/base/BaseCopyIcon.vue +34 -0
  105. package/dist/client/app/components/base/BaseOverflowMenu.vue +1 -0
  106. package/dist/client/app/components/base/BaseSplitPane.vue +1 -0
  107. package/dist/client/app/components/panel/StatePresets.vue +3 -3
  108. package/dist/client/app/components/panel/StorySidePanel.vue +1 -1
  109. package/dist/client/app/components/story/StoryVariantGridItem.vue +1 -0
  110. package/dist/client/app/components/story/StoryVariantSingle.vue +5 -7
  111. package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -6
  112. package/dist/client/app/components/story/StoryViewer.vue +2 -2
  113. package/dist/client/app/components/tree/StoryList.vue +1 -1
  114. package/dist/client/app/components/tree/StoryListItem.vue +2 -2
  115. package/dist/client/app/index.js +1 -3
  116. package/dist/client/app/sandbox.js +3 -2
  117. package/dist/client/app/stores/story.d.ts +30 -30
  118. package/dist/client/app/util/dark.d.ts +1 -1
  119. package/dist/client/app/util/mapping.js +3 -3
  120. package/dist/client/app/util/responsive.d.ts +1 -1
  121. package/dist/client/app/util/scroll.js +1 -1
  122. package/dist/client/app/util/state.js +2 -1
  123. package/dist/node/build.js +8 -1
  124. package/dist/node/commands/dev.js +1 -1
  125. package/dist/node/server.js +5 -4
  126. package/dist/node/util/log.d.ts +1 -0
  127. package/dist/node/util/log.js +9 -0
  128. package/dist/node/vite.d.ts +1 -1
  129. package/dist/node/vite.js +5 -3
  130. package/dist/style.css +21 -0
  131. package/index.d.ts +0 -2
  132. package/package.json +8 -15
  133. package/src/client/app/App.vue +0 -1
  134. package/src/client/app/components/app/Breadcrumb.vue +1 -1
  135. package/src/client/app/components/app/MobileOverlay.vue +1 -1
  136. package/src/client/app/components/base/BaseCheckbox.vue +2 -1
  137. package/src/client/app/components/base/BaseCopyIcon.vue +34 -0
  138. package/src/client/app/components/base/BaseOverflowMenu.vue +1 -0
  139. package/src/client/app/components/base/BaseSplitPane.vue +1 -0
  140. package/src/client/app/components/panel/StatePresets.vue +3 -3
  141. package/src/client/app/components/panel/StorySidePanel.vue +1 -1
  142. package/src/client/app/components/story/StoryVariantGridItem.vue +1 -0
  143. package/src/client/app/components/story/StoryVariantSingle.vue +5 -7
  144. package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -6
  145. package/src/client/app/components/story/StoryViewer.vue +2 -2
  146. package/src/client/app/components/tree/StoryList.vue +1 -1
  147. package/src/client/app/components/tree/StoryListItem.vue +2 -2
  148. package/src/client/app/index.ts +1 -5
  149. package/src/client/app/sandbox.ts +3 -2
  150. package/src/client/app/util/mapping.ts +3 -3
  151. package/src/client/app/util/scroll.ts +1 -1
  152. package/src/client/app/util/state.ts +2 -1
  153. package/src/node/build.ts +13 -3
  154. package/src/node/commands/dev.ts +1 -1
  155. package/src/node/server.ts +5 -4
  156. package/src/node/util/log.ts +9 -0
  157. package/src/node/vite.ts +5 -3
  158. package/tsconfig.json +12 -0
  159. package/vite.config.ts +21 -10
  160. package/vue.d.ts +1 -0
  161. package/dist/bundled/SearchPane.js +0 -506
  162. package/dist/bundled/StoryView.js +0 -2264
  163. package/dist/bundled/dark.js +0 -4
  164. package/dist/bundled/index2.js +0 -843
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import { Icon } from '@iconify/vue'
3
3
 
4
- const props = defineProps<{
4
+ defineProps<{
5
5
  title: string
6
6
  opened: boolean
7
7
  }>()
@@ -9,6 +9,7 @@ const props = defineProps({
9
9
  })
10
10
 
11
11
  const emit = defineEmits({
12
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
13
  'update:modelValue': (newValue: boolean) => true,
13
14
  })
14
15
 
@@ -25,7 +26,7 @@ const progress = computed(() => props.modelValue ? 1 : 0)
25
26
  const dashoffset = computed(() => (1 - progress.value) * dasharray.value)
26
27
  const animationEnabled = ref(false)
27
28
 
28
- watch(path, value => {
29
+ watch(path, () => {
29
30
  dasharray.value = path.value.getTotalLength?.() ?? 21.21
30
31
  })
31
32
  </script>
@@ -0,0 +1,34 @@
1
+ <script lang="ts">
2
+ export default {
3
+ name: 'HstCopyIcon',
4
+ }
5
+ </script>
6
+
7
+ <script lang="ts" setup>
8
+ import { Icon } from '@iconify/vue'
9
+ import { useClipboard } from '@vueuse/core'
10
+ import { VTooltip as vTooltip } from 'floating-vue'
11
+
12
+ const props = defineProps<{
13
+ content: string
14
+ }>()
15
+
16
+ const { copy, copied } = useClipboard()
17
+
18
+ const action = () => copy(props.content)
19
+ </script>
20
+
21
+ <template>
22
+ <Icon
23
+ v-tooltip="{
24
+ content: 'Copied!',
25
+ triggers: [],
26
+ shown: copied,
27
+ distance: 12,
28
+ delay: 0,
29
+ }"
30
+ icon="carbon:copy-file"
31
+ class="htw-w-4 htw-h-4 htw-opacity-50 hover:htw-opacity-100 hover:htw-text-primary-500 htw-cursor-pointer"
32
+ @click="action()"
33
+ />
34
+ </template>
@@ -41,6 +41,7 @@ const visibleChildrenCount = computed(() => {
41
41
  * Watches for the size of each child and automatically hide them
42
42
  */
43
43
  const ChildWrapper = {
44
+ name: 'ChildWrapper',
44
45
  props: ['index'],
45
46
  setup (props, { slots }) {
46
47
  const el = ref<HTMLDivElement>()
@@ -48,6 +48,7 @@ const props = defineProps({
48
48
  })
49
49
 
50
50
  const emit = defineEmits({
51
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
51
52
  'update:split': (value: number) => true,
52
53
  })
53
54
 
@@ -2,7 +2,7 @@
2
2
  import { ref, computed, nextTick, onMounted } from 'vue'
3
3
  import { Icon } from '@iconify/vue'
4
4
  import { useStorage, onClickOutside, useTimeoutFn } from '@vueuse/core'
5
- import { applyStateToVariant, clone, omit } from '@histoire/shared'
5
+ import { applyState, clone, omit } from '@histoire/shared'
6
6
  import BaseSelect from '../base/BaseSelect.vue'
7
7
  import { toRawDeep } from '../../util/state'
8
8
  import type { Story, Variant } from '../../types'
@@ -40,14 +40,14 @@ const presetsOptions = computed(() => {
40
40
 
41
41
  function resetState () {
42
42
  selectedOption.value = DEFAULT_ID
43
- applyStateToVariant(props.variant, clone(defaultState))
43
+ applyState(props.variant.state, clone(defaultState))
44
44
  }
45
45
 
46
46
  function applyPreset (id) {
47
47
  if (id === DEFAULT_ID) {
48
48
  resetState()
49
49
  } else if (presetStates.value.has(id)) {
50
- applyStateToVariant(props.variant, clone(presetStates.value.get(id).state))
50
+ applyState(props.variant.state, clone(presetStates.value.get(id).state))
51
51
  }
52
52
  }
53
53
 
@@ -32,7 +32,7 @@ const panelContentComponent = computed(() => {
32
32
  <span>Select a variant</span>
33
33
  </BaseEmpty>
34
34
 
35
- <BaseEmpty v-else-if="!storyStore.currentVariant.previewReady">
35
+ <BaseEmpty v-else-if="!storyStore.currentVariant.configReady || !storyStore.currentVariant.previewReady">
36
36
  <span>Loading...</span>
37
37
  </BaseEmpty>
38
38
 
@@ -21,6 +21,7 @@ const props = defineProps({
21
21
  })
22
22
 
23
23
  const emit = defineEmits({
24
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
24
25
  resize: (width: number, height: number) => true,
25
26
  })
26
27
 
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" setup>
2
- import { computed, ref } from 'vue'
2
+ import { computed } from 'vue'
3
3
  import { useStoryStore } from '../../stores/story'
4
4
  import { Icon } from '@iconify/vue'
5
5
  import { isMobile } from '../../util/responsive'
@@ -20,12 +20,11 @@ const variant = computed(() => storyStore.currentVariant)
20
20
 
21
21
  <template>
22
22
  <div
23
- v-if="hasSingleVariant && storyStore.currentVariant"
23
+ v-if="hasSingleVariant && variant"
24
24
  class="htw-p-2 htw-h-full"
25
25
  >
26
26
  <StoryVariantSingleView
27
- v-if="storyStore.currentVariant.configReady"
28
- :variant="storyStore.currentVariant"
27
+ :variant="variant"
29
28
  :story="storyStore.currentStory"
30
29
  />
31
30
  </div>
@@ -63,7 +62,6 @@ const variant = computed(() => storyStore.currentVariant)
63
62
  class="htw-p-2 htw-h-full"
64
63
  >
65
64
  <StoryVariantSingleView
66
- v-if="storyStore.currentVariant.configReady"
67
65
  :variant="storyStore.currentVariant"
68
66
  :story="storyStore.currentStory"
69
67
  />
@@ -79,9 +77,9 @@ const variant = computed(() => storyStore.currentVariant)
79
77
  <template #first>
80
78
  <div class="htw-h-full htw-overflow-y-auto">
81
79
  <StoryVariantListItem
82
- v-for="(variant, index) of storyStore.currentStory.variants"
80
+ v-for="(v, index) of storyStore.currentStory.variants"
83
81
  :key="index"
84
- :variant="variant"
82
+ :variant="v"
85
83
  />
86
84
  </div>
87
85
  </template>
@@ -1,12 +1,9 @@
1
1
  <script lang="ts" setup>
2
- import { computed, onUnmounted, Ref, ref, toRaw, watch } from 'vue'
2
+ import { computed, ref, toRaw, watch } from 'vue'
3
3
  import { useEventListener } from '@vueuse/core'
4
- import { Icon } from '@iconify/vue'
5
- import { applyStateToVariant } from '@histoire/shared'
4
+ import { applyState } from '@histoire/shared'
6
5
  import { STATE_SYNC, PREVIEW_SETTINGS_SYNC, SANDBOX_READY, EVENT_SEND } from '../../util/const'
7
6
  import type { Story, Variant } from '../../types'
8
- import HatchedPattern from '../misc/HatchedPattern.vue'
9
- import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
10
7
  import { getSandboxUrl } from '../../util/sandbox'
11
8
  import { usePreviewSettingsStore } from '../../stores/preview-settings'
12
9
  import { HstEvent, useEventsStore } from '../../stores/events'
@@ -66,7 +63,7 @@ useEventListener(window, 'message', (event) => {
66
63
 
67
64
  function updateVariantState (state: any) {
68
65
  synced = true
69
- applyStateToVariant(props.variant, state)
66
+ applyState(props.variant.state, state)
70
67
  }
71
68
 
72
69
  function logEvent (event: HstEvent) {
@@ -39,9 +39,9 @@ watch(variant, () => {
39
39
  @close="closeMenu"
40
40
  >
41
41
  <StoryVariantListItem
42
- v-for="(variant, index) of storyStore.currentStory.variants"
42
+ v-for="(v, index) of storyStore.currentStory.variants"
43
43
  :key="index"
44
- :variant="variant"
44
+ :variant="v"
45
45
  />
46
46
  </MobileOverlay>
47
47
  </template>
@@ -4,7 +4,7 @@ import StoryListItem from './StoryListItem.vue'
4
4
  import StoryListFolder from './StoryListFolder.vue'
5
5
  import StoryGroup from './StoryGroup.vue'
6
6
 
7
- const props = defineProps<{
7
+ defineProps<{
8
8
  tree: Tree
9
9
  stories: Story[]
10
10
  }>()
@@ -18,9 +18,9 @@ const filePadding = computed(() => {
18
18
  })
19
19
 
20
20
  const route = useRoute()
21
- const active = computed(() => route.params.storyId === props.story.id)
21
+ const isActive = computed(() => route.params.storyId === props.story.id)
22
22
  const el = ref<HTMLDivElement>()
23
- useScrollOnActive(active, el)
23
+ useScrollOnActive(isActive, el)
24
24
  </script>
25
25
 
26
26
  <template>
@@ -1,11 +1,7 @@
1
- /* eslint-disable import/first */
2
-
3
- // export * from 'vue'
4
-
5
1
  import '$histoire-theme'
6
2
  import { createApp } from 'vue'
7
3
  import { createPinia } from 'pinia'
8
- import FloatingVue from 'floating-vue'
4
+ import { FloatingVue } from 'floating-vue'
9
5
  import App from './App.vue'
10
6
  import { router } from './router'
11
7
 
@@ -1,7 +1,7 @@
1
1
  import { parseQuery } from 'vue-router'
2
2
  import { computed, createApp, h, onMounted, ref, watch } from 'vue'
3
3
  import { createPinia } from 'pinia'
4
- import { applyStateToVariant } from '@histoire/shared'
4
+ import { applyState } from '@histoire/shared'
5
5
  import { SandboxVue3, MountStoryVue3 } from '@histoire/plugin-vue/client'
6
6
  import type { StoryFile } from './types'
7
7
  import { mapFile } from './util/mapping'
@@ -27,10 +27,11 @@ const app = createApp({
27
27
  let mounted = false
28
28
 
29
29
  window.addEventListener('message', event => {
30
+ // console.log('[sandbox] received message', event.data)
30
31
  if (event.data?.type === STATE_SYNC) {
31
32
  if (!mounted) return
32
33
  synced = true
33
- applyStateToVariant(variant.value, event.data.state)
34
+ applyState(variant.value.state, event.data.state)
34
35
  } else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
35
36
  applyPreviewSettings(event.data.settings)
36
37
  }
@@ -1,12 +1,13 @@
1
1
  import { markRaw } from 'vue'
2
+ import { reactive as _reactive } from '@histoire/vendors/dist/client/vue'
2
3
  import type { StoryFile, Variant } from '../types'
3
4
 
4
5
  const copiedFromExistingVariant = [
5
6
  'state',
6
7
  'slots',
7
- 'initState',
8
8
  'source',
9
9
  'responsiveDisabled',
10
+ 'autoPropsDisabled',
10
11
  'setupApp',
11
12
  'configReady',
12
13
  'previewReady',
@@ -62,8 +63,7 @@ export function mapVariant (variant: Variant, existingVariant?: Variant): Varian
62
63
  // Create
63
64
  result = {
64
65
  ...variant,
65
- state: null,
66
- initState: null,
66
+ state: _reactive({}),
67
67
  setupApp: null,
68
68
  slots: () => ({}),
69
69
  previewReady: false,
@@ -1,5 +1,5 @@
1
1
  import { watch, onMounted, Ref } from 'vue'
2
- import scrollIntoView from 'scroll-into-view-if-needed'
2
+ import { scrollIntoView } from 'scroll-into-view-if-needed'
3
3
 
4
4
  export function useScrollOnActive (active: Ref<boolean>, el: Ref<HTMLElement>) {
5
5
  watch(active, value => {
@@ -4,8 +4,9 @@ const isObject = (val) => val !== null && typeof val === 'object'
4
4
 
5
5
  export function toRawDeep (val, seen = new Set()) {
6
6
  const unwrappedValue = isRef(val) ? unref(val) : val
7
+ const valueType = typeof unwrappedValue
7
8
 
8
- if (typeof unwrappedValue === 'symbol') {
9
+ if (valueType === 'symbol' || valueType === 'function') {
9
10
  return unwrappedValue.toString()
10
11
  }
11
12
 
package/src/node/build.ts CHANGED
@@ -2,8 +2,10 @@ import { join } from 'pathe'
2
2
  import {
3
3
  build as viteBuild,
4
4
  createServer as createViteServer,
5
+ InlineConfig as ViteInlineConfig,
5
6
  ResolvedConfig as ViteConfig,
6
7
  mergeConfig as mergeViteConfig,
8
+ Plugin as VitePlugin,
7
9
  } from 'vite'
8
10
  import fs from 'fs-extra'
9
11
  import { lookup as lookupMime } from 'mrmime'
@@ -65,7 +67,7 @@ export async function build (ctx: Context) {
65
67
  const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0)
66
68
  const emptyStoryCount = ctx.storyFiles.length - storyCount
67
69
 
68
- const buildViteConfig = mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
70
+ const buildViteConfig: ViteInlineConfig = mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
69
71
  mode: 'development',
70
72
  build: {
71
73
  rollupOptions: {
@@ -95,7 +97,7 @@ export async function build (ctx: Context) {
95
97
  buildViteConfig.plugins.push({
96
98
  name: 'histoire-vue-plugin-override',
97
99
  config (config) {
98
- const vuePlugin = config.plugins.find((p: any) => p.name === 'vite:vue')
100
+ const vuePlugin = config.plugins.find((p: any) => p.name === 'vite:vue') as VitePlugin
99
101
  if (vuePlugin) {
100
102
  const original = vuePlugin.configureServer.bind(vuePlugin)
101
103
  vuePlugin.configureServer = () => {
@@ -110,11 +112,19 @@ export async function build (ctx: Context) {
110
112
  },
111
113
  })
112
114
  }
113
- vuePlugin.configureServer()
115
+ vuePlugin.configureServer(server)
114
116
  }
115
117
  },
116
118
  })
117
119
 
120
+ buildViteConfig.plugins.push({
121
+ name: 'histoire-build-config-override',
122
+ config (config) {
123
+ // Don't externalize
124
+ config.build.rollupOptions.external = []
125
+ },
126
+ })
127
+
118
128
  const results = await viteBuild(buildViteConfig)
119
129
  const result = Array.isArray(results) ? results[0] : results as RollupOutput
120
130
 
@@ -38,7 +38,7 @@ export async function devCommand (options: DevOptions) {
38
38
  async function restart (source: string) {
39
39
  if (stop) {
40
40
  console.log(pc.blue(`${source} config changed, restarting...`))
41
- stop()
41
+ await stop()
42
42
  stop = null // Don't call stop again until new start() is done
43
43
  stop = await start()
44
44
  }
@@ -6,6 +6,7 @@ import { onStoryChange, watchStories } from './stories.js'
6
6
  import { useCollectStories } from './collect/index.js'
7
7
  import { DevPluginApi } from './plugin.js'
8
8
  import { useModuleLoader } from './load.js'
9
+ import { wrapLogError } from './util/log.js'
9
10
 
10
11
  export async function createServer (ctx: Context, port: number) {
11
12
  const server = await createViteServer(await getViteConfigWithPlugins(false, ctx))
@@ -143,11 +144,11 @@ export async function createServer (ctx: Context, port: number) {
143
144
 
144
145
  async function close () {
145
146
  for (const cb of pluginOnCleanups) {
146
- await cb()
147
+ await wrapLogError('plugin.onDev.onCleanup', () => cb())
147
148
  }
148
- await server.close()
149
- await nodeServer.close()
150
- await destroyCollectStories()
149
+ await wrapLogError('server.close', () => server.close())
150
+ await wrapLogError('nodeServer', () => nodeServer.close())
151
+ await wrapLogError('destroyCollectStories', () => destroyCollectStories())
151
152
  }
152
153
 
153
154
  return {
@@ -0,0 +1,9 @@
1
+ import pc from 'picocolors'
2
+
3
+ export async function wrapLogError (id: string, cb: () => unknown) {
4
+ try {
5
+ await cb()
6
+ } catch (e) {
7
+ console.error(pc.red(`[Error] ${id}: ${e}`))
8
+ }
9
+ }
package/src/node/vite.ts CHANGED
@@ -59,7 +59,7 @@ async function mergeHistoireViteConfig (viteConfig: InlineConfig, ctx: Context)
59
59
  return viteConfig
60
60
  }
61
61
 
62
- export async function getViteConfigWithPlugins (server: boolean, ctx: Context): Promise<InlineConfig> {
62
+ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context): Promise<InlineConfig> {
63
63
  const resolvedViteConfig = await resolveViteConfig(ctx)
64
64
 
65
65
  const inlineConfig = await mergeHistoireViteConfig({}, ctx)
@@ -76,7 +76,7 @@ export async function getViteConfigWithPlugins (server: boolean, ctx: Context):
76
76
  ],
77
77
  },
78
78
  optimizeDeps: {
79
- disabled: server,
79
+ disabled: isServer,
80
80
  entries: [
81
81
  `${APP_PATH}/bundle-main.js`,
82
82
  `${APP_PATH}/bundle-sandbox.js`,
@@ -100,12 +100,14 @@ export async function getViteConfigWithPlugins (server: boolean, ctx: Context):
100
100
  allow: [DIST_PATH, TEMP_PATH, resolvedViteConfig.root, process.cwd()],
101
101
  },
102
102
  watch: {
103
- ignored: [`!**/node_modules/.histoire/**`],
103
+ ignored: [`!**/node_modules/.histoire/**`, '**/vite.config.*'],
104
104
  },
105
105
  },
106
106
  define: {
107
107
  // We need to force this to be able to use `devtoolsRawSetupState`
108
108
  __VUE_PROD_DEVTOOLS__: 'true',
109
+ // Disable warnings
110
+ 'process.env.NODE_ENV': JSON.stringify(isServer ? 'production' : process.env.NODE_ENV ?? 'development'),
109
111
  },
110
112
  }
111
113
  },
package/tsconfig.json CHANGED
@@ -21,6 +21,7 @@
21
21
  "sourceMap": false,
22
22
  "preserveWatchOutput": true,
23
23
  "preserveSymlinks": true,
24
+ "declaration": true,
24
25
  // Strict
25
26
  "noImplicitAny": false,
26
27
  "noImplicitThis": true,
@@ -29,6 +30,17 @@
29
30
  "strictFunctionTypes": true,
30
31
  // Volar
31
32
  "jsx": "preserve",
33
+ // Alias
34
+ "paths": {
35
+ "floating-vue": ["./node_modules/@histoire/vendors/dist/client/floating-vue"],
36
+ "@iconify/vue": ["./node_modules/@histoire/vendors/dist/client/iconify"],
37
+ "pinia": ["./node_modules/@histoire/vendors/dist/client/pinia"],
38
+ "scroll-into-view-if-needed": ["./node_modules/@histoire/vendors/dist/client/scroll"],
39
+ "shiki": ["./node_modules/@histoire/vendors/dist/client/shiki"],
40
+ "vue-router": ["./node_modules/@histoire/vendors/dist/client/vue-router"],
41
+ "@vueuse/core": ["./node_modules/@histoire/vendors/dist/client/vue-use"],
42
+ "vue": ["./node_modules/@histoire/vendors/dist/client/vue"]
43
+ }
32
44
  },
33
45
  "include": [
34
46
  "src"
package/vite.config.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { defineConfig } from 'vite'
2
2
  import vue from '@vitejs/plugin-vue'
3
3
  import fs from 'fs-extra'
4
- import path from 'pathe'
4
+ import { globbySync } from 'globby'
5
5
 
6
6
  export default defineConfig({
7
7
  plugins: [
@@ -18,14 +18,11 @@ export default defineConfig({
18
18
  },
19
19
  closeBundle () {
20
20
  try {
21
- const files = fs.readdirSync('./dist/bundled')
21
+ const files = globbySync('./dist/bundled/**/*.js')
22
22
  for (const file of files) {
23
- if (file.endsWith('.js')) {
24
- const filePath = path.join('./dist/bundled', file)
25
- const content = fs.readFileSync(filePath, 'utf-8')
26
- if (content.includes('import__meta')) {
27
- fs.writeFileSync(filePath, content.replace(/import__meta/g, 'import.meta'), 'utf-8')
28
- }
23
+ const content = fs.readFileSync(file, 'utf-8')
24
+ if (content.includes('import__meta')) {
25
+ fs.writeFileSync(file, content.replace(/import__meta/g, 'import.meta'), 'utf-8')
29
26
  }
30
27
  }
31
28
  } catch (e) {
@@ -35,6 +32,19 @@ export default defineConfig({
35
32
  },
36
33
  ],
37
34
 
35
+ resolve: {
36
+ alias: {
37
+ 'floating-vue': '@histoire/vendors/dist/client/floating-vue.js',
38
+ '@iconify/vue': '@histoire/vendors/dist/client/iconify.js',
39
+ pinia: '@histoire/vendors/dist/client/pinia.js',
40
+ 'scroll-into-view-if-needed': '@histoire/vendors/dist/client/scroll.js',
41
+ shiki: '@histoire/vendors/dist/client/shiki.js',
42
+ 'vue-router': '@histoire/vendors/dist/client/vue-router.js',
43
+ '@vueuse/core': '@histoire/vendors/dist/client/vue-use.js',
44
+ vue: '@histoire/vendors/dist/client/vue.js',
45
+ },
46
+ },
47
+
38
48
  build: {
39
49
  emptyOutDir: false,
40
50
  outDir: 'dist/bundled',
@@ -46,7 +56,6 @@ export default defineConfig({
46
56
  external: [
47
57
  /\$histoire/,
48
58
  /@histoire/,
49
- /@vue\/*/,
50
59
  // eslint-disable-next-line @typescript-eslint/no-var-requires
51
60
  ...Object.keys(require('./package.json').dependencies),
52
61
  ],
@@ -66,7 +75,9 @@ export default defineConfig({
66
75
  entryFileNames: '[name].js',
67
76
  chunkFileNames: '[name].js',
68
77
  assetFileNames: '[name][extname]',
69
- hoistTransitiveImports: false,
78
+ // hoistTransitiveImports: false,
79
+ preserveModules: true,
80
+ preserveModulesRoot: 'src/client/app',
70
81
  },
71
82
  treeshake: false,
72
83
  preserveEntrySignatures: 'strict',
package/vue.d.ts ADDED
@@ -0,0 +1 @@
1
+ import '@histoire/plugin-vue/components'