histoire 0.2.5 → 0.3.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 (219) hide show
  1. package/dist/client/app/App.vue +8 -3
  2. package/dist/client/app/codegen/const.d.ts +1 -0
  3. package/dist/client/app/codegen/const.js +3 -0
  4. package/dist/client/app/codegen/vue3.js +83 -21
  5. package/dist/client/app/codegen/vue3.js.map +1 -0
  6. package/dist/client/app/components/base/BaseEmpty.vue +17 -1
  7. package/dist/client/app/components/base/BaseOverflowMenu.vue +118 -0
  8. package/dist/client/app/components/base/BaseOverflowTab.vue +46 -0
  9. package/dist/client/app/components/exposed/Story.vue +33 -1
  10. package/dist/client/app/components/exposed/Variant.vue +19 -1
  11. package/dist/client/app/components/panel/PaneTabs.vue +64 -0
  12. package/dist/client/app/components/{story → panel}/StoryControls.vue +6 -1
  13. package/dist/client/app/components/{story → panel}/StoryDocs.vue +18 -11
  14. package/dist/client/app/components/panel/StoryEvent.vue +53 -0
  15. package/dist/client/app/components/panel/StoryEvents.vue +45 -0
  16. package/{src/client/app/components/story → dist/client/app/components/panel}/StorySidePanel.vue +17 -20
  17. package/{src/client/app/components/story → dist/client/app/components/panel}/StorySourceCode.vue +24 -14
  18. package/dist/client/app/components/sandbox/SandboxVue3.vue +16 -4
  19. package/dist/client/app/components/sandbox/lib.js +2 -1
  20. package/dist/client/app/components/search/SearchLoading.vue +16 -0
  21. package/dist/client/app/components/search/SearchModal.vue +12 -149
  22. package/dist/client/app/components/search/SearchPane.vue +210 -0
  23. package/dist/client/app/components/search/search-data.d.ts +2 -0
  24. package/dist/client/app/components/search/search-data.js +8 -0
  25. package/dist/client/app/components/search/search-data.js.map +1 -0
  26. package/dist/client/app/components/story/StoryResponsivePreview.vue +9 -98
  27. package/dist/client/app/components/story/StoryVariantSingle.vue +109 -0
  28. package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +39 -0
  29. package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
  30. package/dist/client/app/components/story/StoryVariantSingleView.vue +13 -6
  31. package/dist/client/app/components/story/StoryView.vue +17 -3
  32. package/dist/client/app/components/story/StoryViewer.vue +2 -92
  33. package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantBackground.vue +3 -3
  34. package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantNewTab.vue +2 -2
  35. package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantResponsiveSize.vue +3 -3
  36. package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
  37. package/dist/client/app/components/tree/StoryGroup.vue +4 -4
  38. package/dist/client/app/components/tree/StoryListFolder.vue +4 -4
  39. package/dist/client/app/components/tree/StoryListItem.vue +4 -1
  40. package/dist/client/app/global-components.js +1 -0
  41. package/dist/client/app/global-components.js.map +1 -0
  42. package/dist/client/app/index.js +1 -0
  43. package/dist/client/app/index.js.map +1 -0
  44. package/dist/client/app/router.d.ts +1 -0
  45. package/dist/client/app/router.js +3 -1
  46. package/dist/client/app/sandbox.js +12 -1
  47. package/dist/client/app/sandbox.js.map +1 -0
  48. package/dist/client/app/stores/events.d.ts +29 -0
  49. package/dist/client/app/stores/events.js +26 -0
  50. package/dist/client/app/stores/events.js.map +1 -0
  51. package/dist/client/app/stores/folder.d.ts +10 -0
  52. package/dist/client/app/stores/folder.js +48 -0
  53. package/dist/client/app/stores/folder.js.map +1 -0
  54. package/dist/client/app/stores/story.d.ts +41 -8
  55. package/dist/client/app/stores/story.js +21 -33
  56. package/dist/client/app/stores/story.js.map +1 -0
  57. package/dist/client/app/style/main.pcss +5 -0
  58. package/dist/client/app/style/sandbox.css +2 -0
  59. package/dist/client/app/style/transitions.pcss +13 -0
  60. package/dist/client/app/types.d.ts +4 -0
  61. package/dist/client/app/types.js +1 -0
  62. package/dist/client/app/types.js.map +1 -0
  63. package/dist/client/app/util/const.d.ts +1 -0
  64. package/dist/client/app/util/const.js +1 -0
  65. package/dist/client/app/util/events.d.ts +1 -0
  66. package/dist/client/app/util/events.js +32 -0
  67. package/dist/client/app/util/events.js.map +1 -0
  68. package/dist/client/app/util/keyboard.js +1 -0
  69. package/dist/client/app/util/keyboard.js.map +1 -0
  70. package/dist/client/app/util/mapping.js +5 -2
  71. package/dist/client/app/util/mapping.js.map +1 -0
  72. package/dist/client/app/util/preview-settings.js +1 -0
  73. package/dist/client/app/util/preview-settings.js.map +1 -0
  74. package/dist/client/app/util/reactivity.js +1 -0
  75. package/dist/client/app/util/reactivity.js.map +1 -0
  76. package/dist/client/app/util/scroll.js +1 -0
  77. package/dist/client/app/util/scroll.js.map +1 -0
  78. package/dist/client/app/util/variant.js +1 -0
  79. package/dist/client/app/util/variant.js.map +1 -0
  80. package/dist/client/index.d.ts +4 -3
  81. package/dist/client/index.js +3 -1
  82. package/dist/client/index.js.map +1 -0
  83. package/dist/client/server/index.d.ts +7 -2
  84. package/dist/client/server/index.js +8 -26
  85. package/{src/client/server/Story.server.vue → dist/client/server/vue3/Story.vue} +14 -3
  86. package/dist/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
  87. package/dist/client/server/vue3/run.d.ts +2 -0
  88. package/dist/client/server/vue3/run.js +33 -0
  89. package/dist/client/server/vue3/run.js.map +1 -0
  90. package/dist/controls.js +1 -0
  91. package/dist/controls.js.map +1 -0
  92. package/dist/node/alias.d.ts +2 -1
  93. package/dist/node/alias.js +3 -2
  94. package/dist/node/build.js +74 -21
  95. package/dist/node/builtin-plugins/tailwind-tokens.d.ts +5 -0
  96. package/dist/node/builtin-plugins/tailwind-tokens.js +510 -0
  97. package/dist/node/collect/index.js +3 -1
  98. package/dist/node/collect/worker.js +6 -2
  99. package/dist/node/commands/preview.js +4 -25
  100. package/dist/node/config.d.ts +103 -3
  101. package/dist/node/config.js +40 -23
  102. package/dist/node/context.d.ts +3 -3
  103. package/dist/node/context.js +1 -1
  104. package/dist/node/index.d.ts +1 -0
  105. package/dist/node/index.js +1 -0
  106. package/dist/node/load.d.ts +12 -0
  107. package/dist/node/load.js +42 -0
  108. package/dist/node/plugin.d.ts +67 -11
  109. package/dist/node/plugin.js +42 -245
  110. package/dist/node/preview.d.ts +8 -0
  111. package/dist/node/preview.js +41 -0
  112. package/dist/node/search.d.ts +2 -0
  113. package/dist/node/search.js +68 -0
  114. package/dist/node/server.js +43 -21
  115. package/dist/node/stories.d.ts +2 -0
  116. package/dist/node/stories.js +4 -4
  117. package/dist/node/types.d.ts +1 -0
  118. package/dist/node/util/find-up.d.ts +1 -0
  119. package/dist/node/util/find-up.js +20 -0
  120. package/dist/node/vite.d.ts +13 -0
  121. package/dist/node/vite.js +278 -0
  122. package/dist/style.css +174 -86
  123. package/package.json +7 -6
  124. package/scripts/copy.mjs +2 -1
  125. package/src/client/app/App.vue +8 -3
  126. package/src/client/app/codegen/const.ts +3 -0
  127. package/src/client/app/codegen/vue3.ts +80 -22
  128. package/src/client/app/components/base/BaseEmpty.vue +17 -1
  129. package/src/client/app/components/base/BaseOverflowMenu.vue +118 -0
  130. package/src/client/app/components/base/BaseOverflowTab.vue +46 -0
  131. package/src/client/app/components/exposed/Story.vue +33 -1
  132. package/src/client/app/components/exposed/Variant.vue +19 -1
  133. package/src/client/app/components/panel/PaneTabs.vue +64 -0
  134. package/src/client/app/components/{story → panel}/StoryControls.vue +6 -1
  135. package/src/client/app/components/{story → panel}/StoryDocs.vue +18 -11
  136. package/src/client/app/components/panel/StoryEvent.vue +53 -0
  137. package/src/client/app/components/panel/StoryEvents.vue +45 -0
  138. package/{dist/client/app/components/story → src/client/app/components/panel}/StorySidePanel.vue +17 -20
  139. package/{dist/client/app/components/story → src/client/app/components/panel}/StorySourceCode.vue +24 -14
  140. package/src/client/app/components/sandbox/SandboxVue3.vue +16 -4
  141. package/src/client/app/components/sandbox/lib.ts +3 -1
  142. package/src/client/app/components/search/SearchLoading.vue +16 -0
  143. package/src/client/app/components/search/SearchModal.vue +12 -149
  144. package/src/client/app/components/search/SearchPane.vue +210 -0
  145. package/src/client/app/components/search/search-data.ts +9 -0
  146. package/src/client/app/components/story/StoryResponsivePreview.vue +9 -98
  147. package/src/client/app/components/story/StoryVariantSingle.vue +109 -0
  148. package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +39 -0
  149. package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
  150. package/src/client/app/components/story/StoryVariantSingleView.vue +13 -6
  151. package/src/client/app/components/story/StoryView.vue +17 -3
  152. package/src/client/app/components/story/StoryViewer.vue +2 -92
  153. package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantBackground.vue +3 -3
  154. package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantNewTab.vue +2 -2
  155. package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantResponsiveSize.vue +3 -3
  156. package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
  157. package/src/client/app/components/tree/StoryGroup.vue +4 -4
  158. package/src/client/app/components/tree/StoryListFolder.vue +4 -4
  159. package/src/client/app/components/tree/StoryListItem.vue +4 -1
  160. package/src/client/app/router.ts +4 -1
  161. package/src/client/app/sandbox.ts +11 -1
  162. package/src/client/app/stores/events.ts +36 -0
  163. package/{dist/client/app/stores/story.ts → src/client/app/stores/folder.ts} +16 -23
  164. package/src/client/app/stores/story.ts +21 -40
  165. package/src/client/app/style/main.pcss +5 -0
  166. package/src/client/app/style/sandbox.css +2 -0
  167. package/src/client/app/style/transitions.pcss +13 -0
  168. package/src/client/app/types.ts +5 -0
  169. package/src/client/app/util/const.ts +1 -0
  170. package/src/client/app/util/events.ts +30 -0
  171. package/src/client/app/util/mapping.ts +4 -2
  172. package/src/client/index.ts +4 -3
  173. package/src/client/server/index.ts +14 -27
  174. package/{dist/client/server/Story.server.vue → src/client/server/vue3/Story.vue} +14 -3
  175. package/src/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
  176. package/{dist/client/server/index.ts → src/client/server/vue3/run.ts} +10 -4
  177. package/src/node/alias.ts +4 -2
  178. package/src/node/build.ts +86 -21
  179. package/src/node/builtin-plugins/tailwind-tokens.ts +521 -0
  180. package/src/node/collect/index.ts +3 -1
  181. package/src/node/collect/worker.ts +7 -2
  182. package/src/node/commands/preview.ts +4 -33
  183. package/src/node/config.ts +53 -27
  184. package/src/node/context.ts +3 -3
  185. package/src/node/index.ts +1 -0
  186. package/src/node/load.ts +63 -0
  187. package/src/node/plugin.ts +75 -252
  188. package/src/node/preview.ts +56 -0
  189. package/src/node/search.ts +75 -0
  190. package/src/node/server.ts +49 -23
  191. package/src/node/stories.ts +4 -4
  192. package/src/node/types.ts +1 -0
  193. package/src/node/util/find-up.ts +24 -0
  194. package/src/node/vite.ts +296 -0
  195. package/tailwind.config.cjs +1 -0
  196. package/dist/client/app/codegen/serialize-js.ts +0 -119
  197. package/dist/client/app/codegen/util.ts +0 -79
  198. package/dist/client/app/codegen/vue3.ts +0 -276
  199. package/dist/client/app/components/sandbox/lib.ts +0 -8
  200. package/dist/client/app/global-components.ts +0 -13
  201. package/dist/client/app/index.ts +0 -28
  202. package/dist/client/app/router.ts +0 -17
  203. package/dist/client/app/sandbox.ts +0 -94
  204. package/dist/client/app/stores/preview-settings.ts +0 -17
  205. package/dist/client/app/types.ts +0 -78
  206. package/dist/client/app/util/config.ts +0 -6
  207. package/dist/client/app/util/const.ts +0 -3
  208. package/dist/client/app/util/dark.ts +0 -4
  209. package/dist/client/app/util/env.ts +0 -1
  210. package/dist/client/app/util/keyboard.ts +0 -99
  211. package/dist/client/app/util/mapping.ts +0 -48
  212. package/dist/client/app/util/preview-settings.ts +0 -8
  213. package/dist/client/app/util/reactivity.ts +0 -22
  214. package/dist/client/app/util/responsive.ts +0 -3
  215. package/dist/client/app/util/scroll.ts +0 -31
  216. package/dist/client/app/util/tooltip.ts +0 -13
  217. package/dist/client/app/util/variant.ts +0 -20
  218. package/dist/client/index.ts +0 -12
  219. package/dist/client/shim.d.ts +0 -5
@@ -4,7 +4,7 @@ import StoryListItem from './StoryListItem.vue'
4
4
  import StoryListFolder from './StoryListFolder.vue'
5
5
  import { Icon } from '@iconify/vue'
6
6
  import { computed, withDefaults } from 'vue'
7
- import { useStoryStore } from '../../stores/story'
7
+ import { useFolderStore } from '../../stores/folder'
8
8
 
9
9
  const props = withDefaults(defineProps<{
10
10
  path?: Array<string>
@@ -14,13 +14,13 @@ const props = withDefaults(defineProps<{
14
14
  path: () => [],
15
15
  })
16
16
 
17
- const storyStore = useStoryStore()
17
+ const folderStore = useFolderStore()
18
18
 
19
19
  const folderPath = computed(() => [...props.path, props.group.title])
20
- const isFolderOpen = computed(() => storyStore.isFolderOpened(folderPath.value, true))
20
+ const isFolderOpen = computed(() => folderStore.isFolderOpened(folderPath.value, true))
21
21
 
22
22
  function toggleOpen () {
23
- storyStore.toggleFolder(folderPath.value, false)
23
+ folderStore.toggleFolder(folderPath.value, false)
24
24
  }
25
25
  </script>
26
26
 
@@ -3,7 +3,7 @@ import type { Story, TreeFolder, TreeLeaf } from '../../types'
3
3
  import StoryListItem from './StoryListItem.vue'
4
4
  import { Icon } from '@iconify/vue'
5
5
  import { computed, withDefaults } from 'vue'
6
- import { useStoryStore } from '../../stores/story'
6
+ import { useFolderStore } from '../../stores/folder'
7
7
 
8
8
  const props = withDefaults(defineProps<{
9
9
  path?: Array<string>
@@ -15,13 +15,13 @@ const props = withDefaults(defineProps<{
15
15
  path: () => [],
16
16
  })
17
17
 
18
- const storyStore = useStoryStore()
18
+ const folderStore = useFolderStore()
19
19
 
20
20
  const folderPath = computed(() => [...props.path, props.folder.title])
21
- const isFolderOpen = computed(() => storyStore.isFolderOpened(folderPath.value))
21
+ const isFolderOpen = computed(() => folderStore.isFolderOpened(folderPath.value))
22
22
 
23
23
  function toggleOpen () {
24
- storyStore.toggleFolder(folderPath.value)
24
+ folderStore.toggleFolder(folderPath.value)
25
25
  }
26
26
 
27
27
  const folderPadding = computed(() => {
@@ -50,7 +50,10 @@ useScrollOnActive(active, el)
50
50
  <span class="htw-truncate">{{ story.title }}</span>
51
51
  </span>
52
52
 
53
- <span class="htw-opacity-40 htw-text-sm">
53
+ <span
54
+ v-if="!story.docsOnly"
55
+ class="htw-opacity-40 htw-text-sm"
56
+ >
54
57
  {{ story.variants.length }}
55
58
  </span>
56
59
  </BaseListItemLink>
@@ -1,7 +1,10 @@
1
1
  import { createRouter, createWebHistory } from 'vue-router'
2
2
 
3
+ // @ts-expect-error env not defined
4
+ export const base = import.meta.env.BASE_URL
5
+
3
6
  export const router = createRouter({
4
- history: createWebHistory(),
7
+ history: createWebHistory(base),
5
8
  routes: [
6
9
  {
7
10
  path: '/',
@@ -18,6 +18,8 @@ const query = parseQuery(window.location.search)
18
18
  const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
19
19
 
20
20
  const app = createApp({
21
+ name: 'SandboxApp',
22
+
21
23
  setup () {
22
24
  const story = computed(() => file.value.story)
23
25
  const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId))
@@ -29,7 +31,15 @@ const app = createApp({
29
31
  if (event.data?.type === STATE_SYNC) {
30
32
  if (!mounted) return
31
33
  synced = true
32
- Object.assign(variant.value.state, event.data.state)
34
+ if (variant.value.state) {
35
+ for (const key in event.data.state) {
36
+ if (typeof variant.value.state[key] === 'object') {
37
+ Object.assign(variant.value.state[key], event.data.state[key])
38
+ } else {
39
+ variant.value.state[key] = event.data.state[key]
40
+ }
41
+ }
42
+ }
33
43
  } else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
34
44
  applyPreviewSettings(event.data.settings)
35
45
  }
@@ -0,0 +1,36 @@
1
+ import { defineStore } from 'pinia'
2
+ import { ref, reactive, watch } from 'vue'
3
+ import { useStoryStore } from './story.js'
4
+
5
+ export type HstEvent = {
6
+ name: string
7
+ argument: unknown
8
+ }
9
+
10
+ export const useEventsStore = defineStore('events', () => {
11
+ const storyStore = useStoryStore()
12
+
13
+ const events = reactive<Array<HstEvent>>([])
14
+ const unseen = ref(0)
15
+
16
+ function addEvent (event: HstEvent) {
17
+ events.push(event)
18
+ unseen.value++
19
+ }
20
+
21
+ function reset () {
22
+ events.length = 0
23
+ unseen.value = 0
24
+ }
25
+
26
+ watch(() => storyStore.currentVariant, () => {
27
+ reset()
28
+ })
29
+
30
+ return {
31
+ addEvent,
32
+ reset,
33
+ events,
34
+ unseen,
35
+ }
36
+ })
@@ -1,19 +1,9 @@
1
1
  import { defineStore } from 'pinia'
2
- import { computed, ref, watch } from 'vue'
3
- import { router } from '../router'
4
- import { Story } from '../types'
2
+ import { watch } from 'vue'
5
3
  import { useStorage } from '@vueuse/core'
4
+ import { useStoryStore } from './story'
6
5
 
7
- export const useStoryStore = defineStore('story', () => {
8
- const stories = ref<Story[]>([])
9
- function setStories (value: Story[]) {
10
- stories.value = value
11
- }
12
-
13
- const currentStory = computed(() => stories.value.find(s => s.id === router.currentRoute.value.params.storyId))
14
-
15
- const currentVariant = computed(() => currentStory.value?.variants.find(v => v.id === router.currentRoute.value.query.variantId))
16
-
6
+ export const useFolderStore = defineStore('folder', () => {
17
7
  const openedFolders = useStorage<Map<string, boolean>>(
18
8
  '_histoire-tree-state',
19
9
  new Map(),
@@ -29,14 +19,19 @@ export const useStoryStore = defineStore('story', () => {
29
19
  const currentValue = openedFolders.value.get(stringPath)
30
20
 
31
21
  if (currentValue == null) {
32
- openedFolders.value.set(stringPath, defaultToggleValue)
22
+ setFolderOpen(stringPath, defaultToggleValue)
33
23
  } else if (currentValue) {
34
- openedFolders.value.set(stringPath, false)
24
+ setFolderOpen(stringPath, false)
35
25
  } else {
36
- openedFolders.value.set(stringPath, true)
26
+ setFolderOpen(stringPath, true)
37
27
  }
38
28
  }
39
29
 
30
+ function setFolderOpen (path: Array<string> | string, value: boolean) {
31
+ const stringPath = typeof path === 'string' ? path : getStringPath(path)
32
+ openedFolders.value.set(stringPath, value)
33
+ }
34
+
40
35
  function isFolderOpened (path: Array<string>, defaultValue = false) {
41
36
  const value = openedFolders.value.get(getStringPath(path))
42
37
  if (value == null) {
@@ -47,19 +42,17 @@ export const useStoryStore = defineStore('story', () => {
47
42
 
48
43
  function openFileFolders (path: Array<string>) {
49
44
  for (let pathLength = 1; pathLength < path.length; pathLength++) {
50
- toggleFolder(path.slice(0, pathLength), true)
45
+ setFolderOpen(path.slice(0, pathLength), true)
51
46
  }
52
47
  }
53
48
 
54
- watch(currentStory, () => {
55
- openFileFolders(currentStory.value.file.path)
49
+ const storyStore = useStoryStore()
50
+
51
+ watch(() => storyStore.currentStory, (story) => {
52
+ openFileFolders(story.file.path)
56
53
  })
57
54
 
58
55
  return {
59
- stories,
60
- setStories,
61
- currentStory,
62
- currentVariant,
63
56
  isFolderOpened,
64
57
  toggleFolder,
65
58
  }
@@ -1,8 +1,7 @@
1
1
  import { defineStore } from 'pinia'
2
- import { computed, ref, watch } from 'vue'
2
+ import { computed, ref } from 'vue'
3
3
  import { router } from '../router'
4
- import { Story } from '../types'
5
- import { useStorage } from '@vueuse/core'
4
+ import { Story, Variant } from '../types'
6
5
 
7
6
  export const useStoryStore = defineStore('story', () => {
8
7
  const stories = ref<Story[]>([])
@@ -14,53 +13,35 @@ export const useStoryStore = defineStore('story', () => {
14
13
 
15
14
  const currentVariant = computed(() => currentStory.value?.variants.find(v => v.id === router.currentRoute.value.query.variantId))
16
15
 
17
- const openedFolders = useStorage<Map<string, boolean>>(
18
- '_histoire-tree-state',
19
- new Map(),
20
- )
21
-
22
- function getStringPath (path: Array<string>) {
23
- return path.join('␜')
24
- }
25
-
26
- function toggleFolder (path: Array<string>, defaultToggleValue = true) {
27
- const stringPath = getStringPath(path)
28
-
29
- const currentValue = openedFolders.value.get(stringPath)
30
-
31
- if (currentValue == null) {
32
- openedFolders.value.set(stringPath, defaultToggleValue)
33
- } else if (currentValue) {
34
- openedFolders.value.set(stringPath, false)
35
- } else {
36
- openedFolders.value.set(stringPath, true)
16
+ const maps = computed(() => {
17
+ const storyMap = new Map<string, Story>()
18
+ const variantMap = new Map<string, Variant>()
19
+ for (const story of stories.value) {
20
+ storyMap.set(story.id, story)
21
+ for (const variant of story.variants) {
22
+ variantMap.set(`${story.id}:${variant.id}`, variant)
23
+ }
37
24
  }
38
- }
39
-
40
- function isFolderOpened (path: Array<string>, defaultValue = false) {
41
- const value = openedFolders.value.get(getStringPath(path))
42
- if (value == null) {
43
- return defaultValue
25
+ return {
26
+ stories: storyMap,
27
+ variants: variantMap,
44
28
  }
45
- return value
46
- }
29
+ })
47
30
 
48
- function openFileFolders (path: Array<string>) {
49
- for (let pathLength = 1; pathLength < path.length; pathLength++) {
50
- toggleFolder(path.slice(0, pathLength), true)
51
- }
31
+ function getStoryById (id: string) {
32
+ return maps.value.stories.get(id)
52
33
  }
53
34
 
54
- watch(currentStory, () => {
55
- openFileFolders(currentStory.value.file.path)
56
- })
35
+ function getVariantById (idWithStoryId: string) {
36
+ return maps.value.variants.get(idWithStoryId)
37
+ }
57
38
 
58
39
  return {
59
40
  stories,
60
41
  setStories,
61
42
  currentStory,
62
43
  currentVariant,
63
- isFolderOpened,
64
- toggleFolder,
44
+ getStoryById,
45
+ getVariantById,
65
46
  }
66
47
  })
@@ -1,5 +1,6 @@
1
1
  @import url('https://fonts.googleapis.com/css2?family=Lato&display=swap');
2
2
  @import 'floating-vue/dist/style.css';
3
+ @import '@histoire/controls/dist/style.css';
3
4
 
4
5
  @import 'floating-vue.pcss';
5
6
  @import 'transitions.pcss';
@@ -78,4 +79,8 @@ body {
78
79
  }
79
80
  }
80
81
  }
82
+
83
+ hr {
84
+ margin: 1rem 0;
85
+ }
81
86
  }
@@ -1,3 +1,5 @@
1
+ @import '@histoire/controls/dist/style.css';
2
+
1
3
  html,
2
4
  body {
3
5
  background: transparent !important;
@@ -11,6 +11,19 @@
11
11
  }
12
12
  }
13
13
 
14
+ .__histoire-scale-y {
15
+ &-enter-active,
16
+ &-leave-active {
17
+ transition: transform .15s, opacity .15s;
18
+ }
19
+
20
+ &-enter-from,
21
+ &-leave-to {
22
+ transform: scaleY(0);
23
+ opacity: 0;
24
+ }
25
+ }
26
+
14
27
  .__histoire-fade {
15
28
  &-enter-active,
16
29
  &-leave-active {
@@ -1,3 +1,4 @@
1
+ import { App } from 'vue'
1
2
  import type { RouteLocationRaw } from 'vue-router'
2
3
 
3
4
  export interface StoryFile {
@@ -15,14 +16,17 @@ export interface Story {
15
16
  variants: Variant[]
16
17
  layout?: {
17
18
  type: 'single'
19
+ iframe?: boolean
18
20
  } | {
19
21
  type: 'grid'
20
22
  width?: number | string
21
23
  }
22
24
  icon?: string
23
25
  iconColor?: string
26
+ docsOnly?: boolean
24
27
  file?: StoryFile
25
28
  lastSelectedVariant?: Variant
29
+ slots?: () => Readonly<any>
26
30
  }
27
31
 
28
32
  export interface Variant {
@@ -31,6 +35,7 @@ export interface Variant {
31
35
  icon?: string
32
36
  iconColor?: string
33
37
  initState?: () => any
38
+ setupApp?: (payload: any) => unknown
34
39
  slots?: () => Readonly<any>
35
40
  state?: any
36
41
  source?: string
@@ -1,3 +1,4 @@
1
1
  export const STATE_SYNC = '__histoire:state-sync'
2
2
  export const SANDBOX_READY = '__histoire:sandbox-ready'
3
+ export const EVENT_SEND = '__histoire:event'
3
4
  export const PREVIEW_SETTINGS_SYNC = '__histoire:preview-settings-sync'
@@ -0,0 +1,30 @@
1
+ import { useEventsStore } from '../stores/events.js'
2
+ import { EVENT_SEND } from './const'
3
+
4
+ export function hstEvent (name: string, argument) {
5
+ console.log('[histoire] Event fired', { name, argument })
6
+ const event = {
7
+ name,
8
+ argument: JSON.parse(stringifyEvent(argument)), // Needed for HTMLEvent that can't be cloned
9
+ }
10
+ if (location.href.includes('__sandbox')) {
11
+ window.parent?.postMessage({
12
+ type: EVENT_SEND,
13
+ event,
14
+ })
15
+ } else {
16
+ useEventsStore().addEvent(event)
17
+ }
18
+ }
19
+
20
+ function stringifyEvent (e) {
21
+ const obj = {}
22
+ for (const k in e) {
23
+ obj[k] = e[k]
24
+ }
25
+ return JSON.stringify(obj, (k, v) => {
26
+ if (v instanceof Node) return 'Node'
27
+ if (v instanceof Window) return 'Window'
28
+ return v
29
+ }, ' ')
30
+ }
@@ -10,6 +10,7 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
10
10
  title: file.story.title,
11
11
  file: markRaw(file),
12
12
  variants: file.story.variants.map(v => mapVariant(v)),
13
+ slots: () => ({}),
13
14
  },
14
15
  }
15
16
 
@@ -21,7 +22,7 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
21
22
  for (const key in existingVariant) {
22
23
  if (typeof existingVariant[key] !== 'undefined') {
23
24
  if (key === 'state') {
24
- Object.assign(variant.state, existingVariant.state)
25
+ variant.state = existingVariant.state
25
26
  continue
26
27
  }
27
28
  variant[key] = existingVariant[key]
@@ -40,8 +41,9 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
40
41
  export function mapVariant (variant: Variant): Variant {
41
42
  return {
42
43
  ...variant,
43
- state: {},
44
+ state: null,
44
45
  initState: null,
46
+ setupApp: null,
45
47
  slots: () => ({}),
46
48
  previewReady: false,
47
49
  }
@@ -1,12 +1,13 @@
1
1
  import type { App } from 'vue'
2
2
  import type { Story, Variant } from './app/types.js'
3
+ export { hstEvent } from './app/util/events'
3
4
 
4
5
  export type Vue3StorySetupHandler = (payload: {
5
6
  app: App
6
- story: Story
7
- variant: Variant
7
+ story?: Story
8
+ variant?: Variant
8
9
  }) => Promise<void> | void
9
10
 
10
- export function defineVue3StorySetup (handler: Vue3StorySetupHandler): Vue3StorySetupHandler {
11
+ export function defineSetupVue3 (handler: Vue3StorySetupHandler): Vue3StorySetupHandler {
11
12
  return handler
12
13
  }
@@ -1,32 +1,19 @@
1
- import { createApp, h } from 'vue'
2
- import { registerVueComponents } from '@histoire/controls'
3
- import type { StoryFile } from '../../node/types'
4
- import Story from './Story.server.vue'
5
- import Variant from './Variant.server.vue'
1
+ import type { StoryFile, Story } from '../../node/types'
6
2
 
7
- export async function run (file: StoryFile, storyData, el) {
8
- const { default: Comp } = await import(file.moduleId)
9
- const app = createApp({
10
- provide: {
11
- addStory (data) {
12
- storyData.push(data)
13
- },
14
- },
15
- render () {
16
- return h(Comp, {
17
- ref: 'comp',
18
- data: file,
19
- })
20
- },
21
- })
3
+ export interface ServerRunPayload {
4
+ file: StoryFile
5
+ storyData: Story[]
6
+ el: HTMLElement
7
+ }
22
8
 
23
- // eslint-disable-next-line vue/multi-word-component-names
24
- app.component('Story', Story)
25
- // eslint-disable-next-line vue/multi-word-component-names
26
- app.component('Variant', Variant)
9
+ export async function run (payload: ServerRunPayload) {
10
+ let result: any
27
11
 
28
- registerVueComponents(app)
12
+ // @TODO if (vue3)
13
+ {
14
+ const { run } = await import('./vue3/run.js')
15
+ result = await run(payload)
16
+ }
29
17
 
30
- app.mount(el)
31
- app.unmount()
18
+ return result
32
19
  }
@@ -11,6 +11,11 @@ export default defineComponent({
11
11
  default: null,
12
12
  },
13
13
 
14
+ id: {
15
+ type: String,
16
+ default: null,
17
+ },
18
+
14
19
  group: {
15
20
  type: String,
16
21
  default: null,
@@ -18,7 +23,7 @@ export default defineComponent({
18
23
 
19
24
  layout: {
20
25
  type: Object as PropType<Story['layout']>,
21
- default: () => ({ type: 'single' }),
26
+ default: () => ({ type: 'single', iframe: true }),
22
27
  },
23
28
 
24
29
  icon: {
@@ -30,6 +35,11 @@ export default defineComponent({
30
35
  type: String,
31
36
  default: null,
32
37
  },
38
+
39
+ docsOnly: {
40
+ type: Boolean,
41
+ default: false,
42
+ },
33
43
  },
34
44
 
35
45
  setup (props) {
@@ -40,12 +50,13 @@ export default defineComponent({
40
50
  // Story
41
51
 
42
52
  const story: Story = {
43
- id: attrs.data.id,
53
+ id: props.id ?? attrs.data.id,
44
54
  title: props.title ?? attrs.data.fileName,
45
55
  group: props.group,
46
56
  layout: props.layout,
47
57
  icon: props.icon,
48
58
  iconColor: props.iconColor,
59
+ docsOnly: props.docsOnly,
49
60
  variants: [],
50
61
  }
51
62
  const addStory = inject('addStory', null)
@@ -76,7 +87,7 @@ export default defineComponent({
76
87
  render () {
77
88
  let suppressError = false
78
89
  try {
79
- return this.$slots.default({
90
+ return this.$slots.default?.({
80
91
  get state () {
81
92
  // No variant tags
82
93
  suppressError = true
@@ -1,10 +1,12 @@
1
1
  import { createApp, h } from 'vue'
2
2
  import { registerVueComponents } from '@histoire/controls'
3
- import type { StoryFile } from '../../node/types'
4
- import Story from './Story.server.vue'
5
- import Variant from './Variant.server.vue'
3
+ import type { ServerRunPayload } from '../index.js'
4
+ import Story from './Story.vue'
5
+ import Variant from './Variant.vue'
6
+ // @ts-expect-error virtual module id
7
+ import * as setup from '$histoire-setup'
6
8
 
7
- export async function run (file: StoryFile, storyData, el) {
9
+ export async function run ({ file, storyData, el }: ServerRunPayload) {
8
10
  const { default: Comp } = await import(file.moduleId)
9
11
  const app = createApp({
10
12
  provide: {
@@ -20,6 +22,10 @@ export async function run (file: StoryFile, storyData, el) {
20
22
  },
21
23
  })
22
24
 
25
+ if (typeof setup?.setupVue3 === 'function') {
26
+ await setup.setupVue3({ app })
27
+ }
28
+
23
29
  // eslint-disable-next-line vue/multi-word-component-names
24
30
  app.component('Story', Story)
25
31
  // eslint-disable-next-line vue/multi-word-component-names
package/src/node/alias.ts CHANGED
@@ -3,5 +3,7 @@ import { fileURLToPath } from 'url'
3
3
 
4
4
  const __dirname = dirname(fileURLToPath(import.meta.url))
5
5
 
6
- export const DIST_CLIENT_PATH = join(__dirname, '../client')
7
- export const APP_PATH = join(DIST_CLIENT_PATH, 'app')
6
+ export const DIST_PATH = join(__dirname, '../')
7
+ export const APP_PATH = join(DIST_PATH, 'client', 'app')
8
+
9
+ export const TEMP_PATH = join(process.cwd(), 'node_modules', '.histoire')