@histoire/app 0.9.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 (210) hide show
  1. package/LICENSE +21 -0
  2. package/dist/app/assets/histoire-text-dark.svg +89 -0
  3. package/dist/app/assets/histoire-text.svg +89 -0
  4. package/dist/app/assets/histoire.svg +51 -0
  5. package/dist/app/style/floating-vue.pcss +34 -0
  6. package/dist/app/style/main.pcss +86 -0
  7. package/dist/app/style/sandbox.css +19 -0
  8. package/dist/app/style/transitions.pcss +51 -0
  9. package/dist/bundle-index.js +1 -0
  10. package/dist/bundle-main.js +5 -0
  11. package/dist/bundle-sandbox.js +2 -0
  12. package/dist/bundled/App.js +148 -0
  13. package/dist/bundled/_virtual/plugin-vue_export-helper.js +8 -0
  14. package/dist/bundled/api.js +1 -0
  15. package/dist/bundled/assets/histoire-text-dark.js +2 -0
  16. package/dist/bundled/assets/histoire-text.js +2 -0
  17. package/dist/bundled/assets/histoire.js +2 -0
  18. package/dist/bundled/components/HomeView.js +24 -0
  19. package/dist/bundled/components/app/AppHeader.js +67 -0
  20. package/dist/bundled/components/app/AppLogo.js +26 -0
  21. package/dist/bundled/components/app/Breadcrumb.js +95 -0
  22. package/dist/bundled/components/app/Breadcrumb.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  23. package/dist/bundled/components/app/InitialLoading.js +48 -0
  24. package/dist/bundled/components/app/MobileOverlay.js +41 -0
  25. package/dist/bundled/components/base/BaseCheckbox.js +75 -0
  26. package/dist/bundled/components/base/BaseEmpty.js +13 -0
  27. package/dist/bundled/components/base/BaseEmpty.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  28. package/dist/bundled/components/base/BaseListItemLink.js +50 -0
  29. package/dist/bundled/components/base/BaseOverflowMenu.js +97 -0
  30. package/dist/bundled/components/base/BaseOverflowTab.js +45 -0
  31. package/dist/bundled/components/base/BaseSelect.js +69 -0
  32. package/dist/bundled/components/base/BaseSplitPane.js +184 -0
  33. package/dist/bundled/components/base/BaseSplitPane.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  34. package/dist/bundled/components/base/BaseTab.js +45 -0
  35. package/dist/bundled/components/misc/CheckerboardPattern.js +41 -0
  36. package/dist/bundled/components/misc/HatchedPattern.js +11 -0
  37. package/dist/bundled/components/misc/HatchedPattern.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  38. package/dist/bundled/components/panel/ControlsComponentPropItem.js +98 -0
  39. package/dist/bundled/components/panel/ControlsComponentProps.js +42 -0
  40. package/dist/bundled/components/panel/PaneTabs.js +112 -0
  41. package/dist/bundled/components/panel/StatePresets.js +190 -0
  42. package/dist/bundled/components/panel/StoryControls.js +66 -0
  43. package/dist/bundled/components/panel/StoryDocs.js +57 -0
  44. package/dist/bundled/components/panel/StoryEvent.js +56 -0
  45. package/dist/bundled/components/panel/StoryEvents.js +49 -0
  46. package/dist/bundled/components/panel/StorySidePanel.js +72 -0
  47. package/dist/bundled/components/panel/StorySourceCode.js +119 -0
  48. package/dist/bundled/components/panel/StorySourceCode.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  49. package/dist/bundled/components/search/SearchItem.js +113 -0
  50. package/dist/bundled/components/search/SearchItem.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  51. package/dist/bundled/components/search/SearchLoading.js +19 -0
  52. package/dist/bundled/components/search/SearchModal.js +46 -0
  53. package/dist/bundled/components/search/SearchPane.js +263 -0
  54. package/dist/bundled/components/search/search-docs-data.js +7 -0
  55. package/dist/bundled/components/search/search-title-data.js +7 -0
  56. package/dist/bundled/components/story/GenericMountStory.js +27 -0
  57. package/dist/bundled/components/story/GenericRenderStory.js +27 -0
  58. package/dist/bundled/components/story/StoryResponsivePreview.js +180 -0
  59. package/dist/bundled/components/story/StoryResponsivePreview.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  60. package/dist/bundled/components/story/StoryVariantGrid.js +94 -0
  61. package/dist/bundled/components/story/StoryVariantGridItem.js +106 -0
  62. package/dist/bundled/components/story/StoryVariantGridItem.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  63. package/dist/bundled/components/story/StoryVariantListItem.js +58 -0
  64. package/dist/bundled/components/story/StoryVariantListItem.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  65. package/dist/bundled/components/story/StoryVariantSingle.js +115 -0
  66. package/dist/bundled/components/story/StoryVariantSingle.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  67. package/dist/bundled/components/story/StoryVariantSinglePreviewNative.js +43 -0
  68. package/dist/bundled/components/story/StoryVariantSinglePreviewRemote.js +119 -0
  69. package/dist/bundled/components/story/StoryVariantSingleView.js +49 -0
  70. package/dist/bundled/components/story/StoryView.js +90 -0
  71. package/dist/bundled/components/story/StoryViewer.js +57 -0
  72. package/dist/bundled/components/story/StoryViewer.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  73. package/dist/bundled/components/toolbar/StoryVariantBackground.js +85 -0
  74. package/dist/bundled/components/toolbar/StoryVariantBackground.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  75. package/dist/bundled/components/toolbar/StoryVariantNewTab.js +33 -0
  76. package/dist/bundled/components/toolbar/StoryVariantResponsiveSize.js +129 -0
  77. package/dist/bundled/components/toolbar/StoryVariantTitle.js +24 -0
  78. package/dist/bundled/components/tree/StoryGroup.js +74 -0
  79. package/dist/bundled/components/tree/StoryList.js +37 -0
  80. package/dist/bundled/components/tree/StoryListFolder.js +89 -0
  81. package/dist/bundled/components/tree/StoryListFolder.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  82. package/dist/bundled/components/tree/StoryListItem.js +72 -0
  83. package/dist/bundled/components/tree/StoryListItem.vue_vue_type_style_index_0_scoped_true_lang.js +2 -0
  84. package/dist/bundled/index.js +29 -0
  85. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/common.js +40 -0
  86. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/lang/en.js +5 -0
  87. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/lang/latin/advanced.js +11 -0
  88. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/lang/latin/balance.js +26 -0
  89. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/lang/latin/simple.js +10 -0
  90. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/lang.js +50 -0
  91. package/dist/bundled/node_modules/.pnpm/flexsearch@0.7.21/node_modules/flexsearch/dist/module/type.js +8 -0
  92. package/dist/bundled/router.js +28 -0
  93. package/dist/bundled/sandbox.js +88 -0
  94. package/dist/bundled/stores/events.js +29 -0
  95. package/dist/bundled/stores/folder.js +49 -0
  96. package/dist/bundled/stores/preview-settings.js +15 -0
  97. package/dist/bundled/stores/story.js +43 -0
  98. package/dist/bundled/style.css +102 -0
  99. package/dist/bundled/util/config.js +4 -0
  100. package/dist/bundled/util/const.js +5 -0
  101. package/dist/bundled/util/dark.js +4 -0
  102. package/dist/bundled/util/env.js +2 -0
  103. package/dist/bundled/util/events.js +32 -0
  104. package/dist/bundled/util/keyboard.js +84 -0
  105. package/dist/bundled/util/mapping.js +65 -0
  106. package/dist/bundled/util/preview-settings.js +6 -0
  107. package/dist/bundled/util/responsive.js +3 -0
  108. package/dist/bundled/util/sandbox.js +8 -0
  109. package/dist/bundled/util/scroll.js +28 -0
  110. package/dist/bundled/util/state.js +31 -0
  111. package/dist/bundled/util/tooltip.js +12 -0
  112. package/dist/bundled/util/variant.js +18 -0
  113. package/dist/style.css +2697 -0
  114. package/package.json +57 -0
  115. package/postcss.config.cjs +8 -0
  116. package/scripts/copy.mjs +12 -0
  117. package/scripts/watchAndCopy.mjs +15 -0
  118. package/src/app/App.vue +162 -0
  119. package/src/app/api.ts +1 -0
  120. package/src/app/assets/histoire-text-dark.svg +89 -0
  121. package/src/app/assets/histoire-text.svg +89 -0
  122. package/src/app/assets/histoire.svg +51 -0
  123. package/src/app/components/HomeView.vue +17 -0
  124. package/src/app/components/app/AppHeader.vue +64 -0
  125. package/src/app/components/app/AppLogo.vue +24 -0
  126. package/src/app/components/app/Breadcrumb.vue +98 -0
  127. package/src/app/components/app/InitialLoading.vue +44 -0
  128. package/src/app/components/app/MobileOverlay.vue +33 -0
  129. package/src/app/components/base/BaseCheckbox.vue +77 -0
  130. package/src/app/components/base/BaseCopyIcon.vue +34 -0
  131. package/src/app/components/base/BaseEmpty.vue +21 -0
  132. package/src/app/components/base/BaseListItemLink.vue +55 -0
  133. package/src/app/components/base/BaseOverflowMenu.vue +119 -0
  134. package/src/app/components/base/BaseOverflowTab.vue +46 -0
  135. package/src/app/components/base/BaseSelect.vue +72 -0
  136. package/src/app/components/base/BaseSplitPane.vue +240 -0
  137. package/src/app/components/base/BaseTab.vue +46 -0
  138. package/src/app/components/misc/CheckerboardPattern.vue +32 -0
  139. package/src/app/components/misc/HatchedPattern.vue +13 -0
  140. package/src/app/components/panel/ControlsComponentPropItem.vue +103 -0
  141. package/src/app/components/panel/ControlsComponentProps.vue +34 -0
  142. package/src/app/components/panel/PaneTabs.vue +89 -0
  143. package/src/app/components/panel/StatePresets.vue +196 -0
  144. package/src/app/components/panel/StoryControls.vue +68 -0
  145. package/src/app/components/panel/StoryDocs.vue +60 -0
  146. package/src/app/components/panel/StoryEvent.vue +54 -0
  147. package/src/app/components/panel/StoryEvents.vue +45 -0
  148. package/src/app/components/panel/StorySidePanel.vue +70 -0
  149. package/src/app/components/panel/StorySourceCode.vue +126 -0
  150. package/src/app/components/search/SearchItem.vue +110 -0
  151. package/src/app/components/search/SearchLoading.vue +16 -0
  152. package/src/app/components/search/SearchModal.vue +43 -0
  153. package/src/app/components/search/SearchPane.vue +293 -0
  154. package/src/app/components/search/search-docs-data.ts +10 -0
  155. package/src/app/components/search/search-title-data.ts +10 -0
  156. package/src/app/components/search/types.ts +4 -0
  157. package/src/app/components/story/GenericMountStory.vue +28 -0
  158. package/src/app/components/story/GenericRenderStory.vue +29 -0
  159. package/src/app/components/story/StoryResponsivePreview.vue +204 -0
  160. package/src/app/components/story/StoryVariantGrid.vue +112 -0
  161. package/src/app/components/story/StoryVariantGridItem.vue +110 -0
  162. package/src/app/components/story/StoryVariantListItem.vue +50 -0
  163. package/src/app/components/story/StoryVariantSingle.vue +105 -0
  164. package/src/app/components/story/StoryVariantSinglePreviewNative.vue +42 -0
  165. package/src/app/components/story/StoryVariantSinglePreviewRemote.vue +139 -0
  166. package/src/app/components/story/StoryVariantSingleView.vue +52 -0
  167. package/src/app/components/story/StoryView.vue +96 -0
  168. package/src/app/components/story/StoryViewer.vue +53 -0
  169. package/src/app/components/toolbar/StoryVariantBackground.vue +67 -0
  170. package/src/app/components/toolbar/StoryVariantNewTab.vue +29 -0
  171. package/src/app/components/toolbar/StoryVariantResponsiveSize.vue +82 -0
  172. package/src/app/components/toolbar/StoryVariantTitle.vue +21 -0
  173. package/src/app/components/tree/StoryGroup.vue +75 -0
  174. package/src/app/components/tree/StoryList.vue +35 -0
  175. package/src/app/components/tree/StoryListFolder.vue +89 -0
  176. package/src/app/components/tree/StoryListItem.vue +71 -0
  177. package/src/app/index.ts +30 -0
  178. package/src/app/router.ts +29 -0
  179. package/src/app/sandbox.ts +96 -0
  180. package/src/app/stores/events.ts +36 -0
  181. package/src/app/stores/folder.ts +59 -0
  182. package/src/app/stores/preview-settings.ts +17 -0
  183. package/src/app/stores/story.ts +47 -0
  184. package/src/app/style/floating-vue.pcss +34 -0
  185. package/src/app/style/main.pcss +86 -0
  186. package/src/app/style/sandbox.css +19 -0
  187. package/src/app/style/transitions.pcss +51 -0
  188. package/src/app/types.ts +46 -0
  189. package/src/app/util/config.ts +6 -0
  190. package/src/app/util/const.ts +4 -0
  191. package/src/app/util/dark.ts +4 -0
  192. package/src/app/util/env.ts +1 -0
  193. package/src/app/util/events.ts +30 -0
  194. package/src/app/util/keyboard.ts +99 -0
  195. package/src/app/util/mapping.ts +76 -0
  196. package/src/app/util/preview-settings.ts +8 -0
  197. package/src/app/util/responsive.ts +3 -0
  198. package/src/app/util/sandbox.ts +10 -0
  199. package/src/app/util/scroll.ts +31 -0
  200. package/src/app/util/state.ts +37 -0
  201. package/src/app/util/tooltip.ts +13 -0
  202. package/src/app/util/variant.ts +20 -0
  203. package/src/bundle-index.js +1 -0
  204. package/src/bundle-main.js +5 -0
  205. package/src/bundle-sandbox.js +2 -0
  206. package/src/index.ts +1 -0
  207. package/src/shim.d.ts +7 -0
  208. package/tailwind.config.cjs +126 -0
  209. package/tsconfig.json +54 -0
  210. package/vite.config.ts +87 -0
@@ -0,0 +1,89 @@
1
+ <script lang="ts" setup>
2
+ import type { Story, TreeFolder, TreeLeaf } from '../../types'
3
+ import StoryListItem from './StoryListItem.vue'
4
+ import { Icon } from '@iconify/vue'
5
+ import { computed, withDefaults } from 'vue'
6
+ import { useFolderStore } from '../../stores/folder'
7
+
8
+ const props = withDefaults(defineProps<{
9
+ path?: Array<string>
10
+ folder: TreeFolder
11
+ stories: Story[]
12
+ depth?: number
13
+ }>(), {
14
+ depth: 0,
15
+ path: () => [],
16
+ })
17
+
18
+ const folderStore = useFolderStore()
19
+
20
+ const folderPath = computed(() => [...props.path, props.folder.title])
21
+ const isFolderOpen = computed(() => folderStore.isFolderOpened(folderPath.value))
22
+
23
+ function toggleOpen () {
24
+ folderStore.toggleFolder(folderPath.value)
25
+ }
26
+
27
+ const folderPadding = computed(() => {
28
+ return (props.depth * 12) + 'px'
29
+ })
30
+ </script>
31
+
32
+ <template>
33
+ <div data-test-id="story-list-folder">
34
+ <div
35
+ role="button"
36
+ tabindex="0"
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
+ @click="toggleOpen"
39
+ @keyup.enter="toggleOpen"
40
+ @keyup.space="toggleOpen"
41
+ >
42
+ <span class="bind-tree-padding htw-flex htw-items-center htw-gap-2 htw-min-w-0">
43
+ <span class="htw-flex htw-flex-none htw-items-center">
44
+ <Icon
45
+ icon="carbon:caret-right"
46
+ class="htw-w-4 htw-h-4 htw-transition-transform htw-duration-150 htw-opacity-30"
47
+ :class="{
48
+ 'htw-rotate-90': isFolderOpen,
49
+ }"
50
+ />
51
+ <Icon
52
+ icon="carbon:folder"
53
+ class="htw-w-5 htw-h-5 sm:htw-w-4 sm:htw-h-4"
54
+ />
55
+ </span>
56
+ <span class="htw-truncate">{{ folder.title }}</span>
57
+ </span>
58
+ </div>
59
+
60
+ <!-- Children -->
61
+ <div
62
+ v-if="isFolderOpen"
63
+ >
64
+ <template
65
+ v-for="element of folder.children"
66
+ :key="element.title"
67
+ >
68
+ <StoryListFolder
69
+ v-if="(element as TreeFolder).children"
70
+ :path="folderPath"
71
+ :folder="(element as TreeFolder)"
72
+ :stories="stories"
73
+ :depth="depth + 1"
74
+ />
75
+ <StoryListItem
76
+ v-else
77
+ :story="stories[(element as TreeLeaf).index]"
78
+ :depth="depth + 1"
79
+ />
80
+ </template>
81
+ </div>
82
+ </div>
83
+ </template>
84
+
85
+ <style scoped>
86
+ .bind-tree-padding {
87
+ padding-left: v-bind(folderPadding);
88
+ }
89
+ </style>
@@ -0,0 +1,71 @@
1
+ <script lang="ts" setup>
2
+ import type { Story } from '../../types'
3
+ import BaseListItemLink from '../base/BaseListItemLink.vue'
4
+ import { Icon } from '@iconify/vue'
5
+ import { computed, ref, withDefaults } from 'vue'
6
+ import { useRoute } from 'vue-router'
7
+ import { useScrollOnActive } from '../../util/scroll'
8
+
9
+ const props = withDefaults(defineProps<{
10
+ story: Story
11
+ depth?: number
12
+ }>(), {
13
+ depth: 0,
14
+ })
15
+
16
+ const filePadding = computed(() => {
17
+ return (props.depth * 12) + 'px'
18
+ })
19
+
20
+ const route = useRoute()
21
+ const isActive = computed(() => route.params.storyId === props.story.id)
22
+ const el = ref<HTMLDivElement>()
23
+ useScrollOnActive(isActive, el)
24
+ </script>
25
+
26
+ <template>
27
+ <div
28
+ ref="el"
29
+ data-test-id="story-list-item"
30
+ >
31
+ <BaseListItemLink
32
+ v-slot="{ active }"
33
+ :to="{
34
+ name: 'story',
35
+ params: {
36
+ storyId: story.id,
37
+ },
38
+ }"
39
+ class="htw-pl-0.5 htw-pr-2 htw-py-2 md:htw-py-1.5 htw-mx-1 htw-rounded-sm"
40
+ >
41
+ <span class="bind-tree-margin htw-flex htw-items-center htw-gap-2 htw-pl-4 htw-min-w-0">
42
+ <Icon
43
+ :icon="story.icon ?? 'carbon:cube'"
44
+ class="base-list-item-link-icon htw-w-5 htw-h-5 sm:htw-w-4 sm:htw-h-4 htw-flex-none"
45
+ :class="{
46
+ 'htw-text-primary-500': !active && !story.iconColor,
47
+ 'bind-icon-color': !active && story.iconColor,
48
+ }"
49
+ />
50
+ <span class="htw-truncate">{{ story.title }}</span>
51
+ </span>
52
+
53
+ <span
54
+ v-if="!story.docsOnly"
55
+ class="htw-opacity-40 htw-text-sm"
56
+ >
57
+ {{ story.variants.length }}
58
+ </span>
59
+ </BaseListItemLink>
60
+ </div>
61
+ </template>
62
+
63
+ <style scoped>
64
+ .bind-tree-margin {
65
+ margin-left: v-bind(filePadding);
66
+ }
67
+
68
+ .bind-icon-color {
69
+ color: v-bind('story.iconColor');
70
+ }
71
+ </style>
@@ -0,0 +1,30 @@
1
+ import '$histoire-theme'
2
+ import { createApp } from 'vue'
3
+ import { createPinia } from 'pinia'
4
+ import FloatingVue from 'floating-vue'
5
+ import App from './App.vue'
6
+ import { router } from './router'
7
+
8
+ export function mountMainApp () {
9
+ const app = createApp(App)
10
+ app.use(createPinia())
11
+ app.use(FloatingVue, {
12
+ overflowPadding: 4,
13
+ arrowPadding: 8,
14
+ themes: {
15
+ tooltip: {
16
+ distance: 8,
17
+ },
18
+ dropdown: {
19
+ computeTransformOrigin: true,
20
+ distance: 8,
21
+ },
22
+ },
23
+ })
24
+ app.use(router)
25
+ app.mount('#app')
26
+
27
+ if (import.meta.hot) {
28
+ import.meta.hot.send('histoire:mount', {})
29
+ }
30
+ }
@@ -0,0 +1,29 @@
1
+ import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
2
+ import { histoireConfig } from './util/config'
3
+
4
+ export const base = import.meta.env.BASE_URL as string
5
+
6
+ function createRouterHistory () {
7
+ switch (histoireConfig.routerMode) {
8
+ case 'hash': return createWebHashHistory(base)
9
+ case 'history':
10
+ default:
11
+ return createWebHistory(base)
12
+ }
13
+ }
14
+
15
+ export const router = createRouter({
16
+ history: createRouterHistory(),
17
+ routes: [
18
+ {
19
+ path: '/',
20
+ name: 'home',
21
+ component: () => import('./components/HomeView.vue'),
22
+ },
23
+ {
24
+ path: '/story/:storyId',
25
+ name: 'story',
26
+ component: () => import('./components/story/StoryView.vue'),
27
+ },
28
+ ],
29
+ })
@@ -0,0 +1,96 @@
1
+ import { parseQuery } from 'vue-router'
2
+ import { computed, createApp, h, onMounted, ref, watch } from 'vue'
3
+ import { createPinia } from 'pinia'
4
+ import { applyState } from '@histoire/shared'
5
+ import GenericMountStory from './components/story/GenericMountStory.vue'
6
+ import GenericRenderStory from './components/story/GenericRenderStory.vue'
7
+ import type { StoryFile } from './types'
8
+ import { mapFile } from './util/mapping'
9
+ // @ts-expect-error virtual module
10
+ import { files } from '$histoire-stories'
11
+ import { PREVIEW_SETTINGS_SYNC, STATE_SYNC, SANDBOX_READY } from './util/const.js'
12
+ import { applyPreviewSettings } from './util/preview-settings.js'
13
+ import { isDark } from './util/dark.js'
14
+ import { histoireConfig } from './util/config.js'
15
+ import { toRawDeep } from './util/state.js'
16
+
17
+ const query = parseQuery(window.location.search)
18
+ const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
19
+
20
+ const app = createApp({
21
+ name: 'SandboxApp',
22
+
23
+ setup () {
24
+ const story = computed(() => file.value.story)
25
+ const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId))
26
+
27
+ let synced = false
28
+ let mounted = false
29
+
30
+ window.addEventListener('message', event => {
31
+ // console.log('[sandbox] received message', event.data)
32
+ if (event.data?.type === STATE_SYNC) {
33
+ if (!mounted) return
34
+ synced = true
35
+ applyState(variant.value.state, event.data.state)
36
+ } else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
37
+ applyPreviewSettings(event.data.settings)
38
+ }
39
+ })
40
+
41
+ watch(() => variant.value.state, value => {
42
+ if (synced && mounted) {
43
+ synced = false
44
+ return
45
+ }
46
+ window.parent?.postMessage({
47
+ type: STATE_SYNC,
48
+ state: toRawDeep(value),
49
+ })
50
+ }, {
51
+ deep: true,
52
+ })
53
+
54
+ onMounted(() => {
55
+ mounted = true
56
+ })
57
+
58
+ return {
59
+ story,
60
+ variant,
61
+ }
62
+ },
63
+
64
+ render () {
65
+ return [
66
+ h('div', { class: 'htw-sandbox-hidden' }, [
67
+ h(GenericMountStory, {
68
+ story: file.value.story,
69
+ }),
70
+ ]),
71
+ this.story && this.variant
72
+ ? h(GenericRenderStory, {
73
+ story: this.story,
74
+ variant: this.variant,
75
+ onReady: () => {
76
+ window.parent?.postMessage({
77
+ type: SANDBOX_READY,
78
+ })
79
+ },
80
+ })
81
+ : null,
82
+ ]
83
+ },
84
+ })
85
+ app.use(createPinia())
86
+ app.mount('#app')
87
+
88
+ watch(isDark, value => {
89
+ if (value) {
90
+ document.documentElement.classList.add(histoireConfig.sandboxDarkClass)
91
+ } else {
92
+ document.documentElement.classList.remove(histoireConfig.sandboxDarkClass)
93
+ }
94
+ }, {
95
+ immediate: true,
96
+ })
@@ -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?.id, () => {
27
+ reset()
28
+ })
29
+
30
+ return {
31
+ addEvent,
32
+ reset,
33
+ events,
34
+ unseen,
35
+ }
36
+ })
@@ -0,0 +1,59 @@
1
+ import { defineStore } from 'pinia'
2
+ import { watch } from 'vue'
3
+ import { useStorage } from '@vueuse/core'
4
+ import { useStoryStore } from './story'
5
+
6
+ export const useFolderStore = defineStore('folder', () => {
7
+ const openedFolders = useStorage<Map<string, boolean>>(
8
+ '_histoire-tree-state',
9
+ new Map(),
10
+ )
11
+
12
+ function getStringPath (path: Array<string>) {
13
+ return path.join('␜')
14
+ }
15
+
16
+ function toggleFolder (path: Array<string>, defaultToggleValue = true) {
17
+ const stringPath = getStringPath(path)
18
+
19
+ const currentValue = openedFolders.value.get(stringPath)
20
+
21
+ if (currentValue == null) {
22
+ setFolderOpen(stringPath, defaultToggleValue)
23
+ } else if (currentValue) {
24
+ setFolderOpen(stringPath, false)
25
+ } else {
26
+ setFolderOpen(stringPath, true)
27
+ }
28
+ }
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
+
35
+ function isFolderOpened (path: Array<string>, defaultValue = false) {
36
+ const value = openedFolders.value.get(getStringPath(path))
37
+ if (value == null) {
38
+ return defaultValue
39
+ }
40
+ return value
41
+ }
42
+
43
+ function openFileFolders (path: Array<string>) {
44
+ for (let pathLength = 1; pathLength < path.length; pathLength++) {
45
+ setFolderOpen(path.slice(0, pathLength), true)
46
+ }
47
+ }
48
+
49
+ const storyStore = useStoryStore()
50
+
51
+ watch(() => storyStore.currentStory, (story) => {
52
+ openFileFolders(story.file.path)
53
+ })
54
+
55
+ return {
56
+ isFolderOpened,
57
+ toggleFolder,
58
+ }
59
+ })
@@ -0,0 +1,17 @@
1
+ import { defineStore } from 'pinia'
2
+ import { useStorage } from '@vueuse/core'
3
+ import type { PreviewSettings } from '../types'
4
+
5
+ export const usePreviewSettingsStore = defineStore('preview-settings', () => {
6
+ const currentSettings = useStorage<PreviewSettings>('_histoire-sandbox-settings-v2', {
7
+ responsiveWidth: 720,
8
+ responsiveHeight: null,
9
+ rotate: false,
10
+ backgroundColor: 'transparent',
11
+ checkerboard: false,
12
+ })
13
+
14
+ return {
15
+ currentSettings,
16
+ }
17
+ })
@@ -0,0 +1,47 @@
1
+ import { defineStore } from 'pinia'
2
+ import { computed, ref } from 'vue'
3
+ import { router } from '../router'
4
+ import { Story, Variant } from '../types'
5
+
6
+ export const useStoryStore = defineStore('story', () => {
7
+ const stories = ref<Story[]>([])
8
+ function setStories (value: Story[]) {
9
+ stories.value = value
10
+ }
11
+
12
+ const currentStory = computed(() => stories.value.find(s => s.id === router.currentRoute.value.params.storyId))
13
+
14
+ const currentVariant = computed(() => currentStory.value?.variants.find(v => v.id === router.currentRoute.value.query.variantId))
15
+
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
+ }
24
+ }
25
+ return {
26
+ stories: storyMap,
27
+ variants: variantMap,
28
+ }
29
+ })
30
+
31
+ function getStoryById (id: string) {
32
+ return maps.value.stories.get(id)
33
+ }
34
+
35
+ function getVariantById (idWithStoryId: string) {
36
+ return maps.value.variants.get(idWithStoryId)
37
+ }
38
+
39
+ return {
40
+ stories,
41
+ setStories,
42
+ currentStory,
43
+ currentVariant,
44
+ getStoryById,
45
+ getVariantById,
46
+ }
47
+ })
@@ -0,0 +1,34 @@
1
+ /* @TODO custom themes */
2
+
3
+ .v-popper {
4
+ line-height: 0;
5
+ }
6
+
7
+ .v-popper--theme-dropdown {
8
+ .htw-dark & {
9
+ .v-popper__inner {
10
+ @apply htw-bg-gray-700 htw-border-gray-850 htw-text-gray-100;
11
+ }
12
+
13
+ .v-popper__arrow-inner {
14
+ @apply htw-border-gray-700;
15
+ }
16
+
17
+ .v-popper__arrow-outer {
18
+ @apply htw-border-gray-850;
19
+ }
20
+ }
21
+
22
+ &.v-popper__popper--show-from .v-popper__wrapper {
23
+ transform: scale(.75);
24
+ }
25
+
26
+ &.v-popper__popper--show-to .v-popper__wrapper {
27
+ transform: none;
28
+ transition: transform .15s cubic-bezier(0, 1, .5, 1);
29
+ }
30
+ }
31
+
32
+ .v-popper__popper:focus-visible {
33
+ outline: none;
34
+ }
@@ -0,0 +1,86 @@
1
+ @import url('https://fonts.googleapis.com/css2?family=Lato&display=swap');
2
+ @import 'floating-vue/dist/style.css';
3
+ @import '@histoire/controls/dist/style.css';
4
+
5
+ @import 'floating-vue.pcss';
6
+ @import 'transitions.pcss';
7
+
8
+ *,
9
+ ::before,
10
+ ::after {
11
+ box-sizing: border-box;
12
+ border-width: 0;
13
+ border-style: solid;
14
+ border-color: #e5e7eb;
15
+ }
16
+
17
+ a,
18
+ input,
19
+ button {
20
+ color: inherit;
21
+ }
22
+
23
+ a {
24
+ text-decoration: inherit;
25
+ }
26
+
27
+ input {
28
+ font-family: inherit;
29
+ }
30
+
31
+ a,
32
+ button {
33
+ user-select: none;
34
+ }
35
+
36
+ @tailwind base;
37
+ @tailwind components;
38
+ @tailwind utilities;
39
+
40
+ body,
41
+ pre {
42
+ margin: 0;
43
+ }
44
+
45
+ html,
46
+ body,
47
+ #app {
48
+ height: 100%;
49
+ }
50
+
51
+ html {
52
+ font-family: 'Lato', sans-serif;
53
+ font-size: 1rem;
54
+ }
55
+
56
+ body {
57
+ font-size: 1.125rem;
58
+ }
59
+
60
+ @media (min-width: 640px) {
61
+ body {
62
+ font-size: .875rem;
63
+ }
64
+ }
65
+
66
+ .__histoire-sandbox {
67
+ contain: content;
68
+ }
69
+
70
+ .__histoire-code .shiki {
71
+ background: transparent !important;
72
+ }
73
+
74
+ .htw-prose {
75
+ h1, h2, h3, h4 {
76
+ &:not(:hover) {
77
+ .header-anchor[aria-hidden="true"] {
78
+ visibility: hidden;
79
+ }
80
+ }
81
+ }
82
+
83
+ hr {
84
+ margin: 1rem 0;
85
+ }
86
+ }
@@ -0,0 +1,19 @@
1
+ @import '@histoire/controls/dist/style.css';
2
+
3
+ html,
4
+ body {
5
+ background: transparent !important;
6
+ }
7
+
8
+ body {
9
+ margin: 0;
10
+ }
11
+
12
+ html {
13
+ font-size: .875rem;
14
+ font-family: 'Lato', sans-serif;
15
+ }
16
+
17
+ .htw-sandbox-hidden {
18
+ display: none;
19
+ }
@@ -0,0 +1,51 @@
1
+ .__histoire-scale-x {
2
+ &-enter-active,
3
+ &-leave-active {
4
+ transition: transform .15s, opacity .15s;
5
+ }
6
+
7
+ &-enter-from,
8
+ &-leave-to {
9
+ transform: scaleX(0);
10
+ opacity: 0;
11
+ }
12
+ }
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
+
27
+ .__histoire-fade {
28
+ &-enter-active,
29
+ &-leave-active {
30
+ transition: opacity .15s;
31
+ }
32
+
33
+ &-enter-from,
34
+ &-leave-to {
35
+ opacity: 0;
36
+ }
37
+ }
38
+
39
+ .__histoire-fade-bottom {
40
+ &-enter-active,
41
+ &-leave-active {
42
+ transition: transform .15s, opacity .15s;
43
+ transform: translateY(0px);
44
+ }
45
+
46
+ &-enter-from,
47
+ &-leave-to {
48
+ transform: translateY(32px);
49
+ opacity: 0;
50
+ }
51
+ }