histoire 0.0.1 → 0.0.4

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 (186) hide show
  1. package/README.md +11 -0
  2. package/dist/client/app/App.vue +8 -8
  3. package/dist/client/app/codegen/serialize-js.js +0 -1
  4. package/dist/client/app/codegen/util.js +0 -1
  5. package/dist/client/app/codegen/vue3.js +28 -5
  6. package/dist/client/app/codegen/vue3.ts +32 -4
  7. package/dist/client/app/components/app/AppHeader.vue +10 -3
  8. package/dist/client/app/components/base/BaseTab.vue +46 -0
  9. package/dist/client/app/components/exposed/Story.vue +21 -1
  10. package/dist/client/app/components/exposed/Variant.vue +1 -0
  11. package/dist/client/app/components/misc/CheckerboardPattern.vue +32 -0
  12. package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -0
  13. package/dist/client/app/components/search/SearchItem.vue +5 -9
  14. package/{src/client/app/components → dist/client/app/components/story}/StoryControls.vue +3 -3
  15. package/dist/client/app/components/story/StoryDocs.vue +37 -0
  16. package/dist/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
  17. package/dist/client/app/components/{StoryListFolder.vue → story/StoryListFolder.vue} +13 -6
  18. package/dist/client/app/components/{StoryListItem.vue → story/StoryListItem.vue} +11 -6
  19. package/dist/client/app/components/story/StoryResponsivePreview.vue +214 -0
  20. package/{src/client/app/components → dist/client/app/components/story}/StorySourceCode.vue +4 -8
  21. package/{src/client/app/components → dist/client/app/components/story}/StoryVariantGridItem.vue +14 -6
  22. package/dist/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
  23. package/dist/client/app/components/story/StoryVariantSingleView.vue +182 -0
  24. package/dist/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
  25. package/dist/client/app/global-components.js +2 -1
  26. package/dist/client/app/global-components.ts +3 -0
  27. package/dist/client/app/index.js +10 -1
  28. package/dist/client/app/index.ts +10 -0
  29. package/dist/client/app/router.js +1 -2
  30. package/dist/client/app/router.ts +1 -1
  31. package/dist/client/app/sandbox.js +37 -4
  32. package/dist/client/app/sandbox.ts +37 -3
  33. package/dist/client/app/stores/story.d.ts +22 -1
  34. package/dist/client/app/stores/story.js +30 -2
  35. package/dist/client/app/stores/story.ts +37 -1
  36. package/dist/client/app/style/floating-vue.css +31 -0
  37. package/dist/client/app/style/main.css +17 -1
  38. package/dist/client/app/style/sandbox.css +5 -0
  39. package/dist/client/app/style/transitions.css +12 -0
  40. package/dist/client/app/types.d.ts +1 -0
  41. package/dist/client/app/types.js +0 -1
  42. package/dist/client/app/types.ts +15 -0
  43. package/dist/client/app/util/config.js +0 -1
  44. package/dist/client/app/util/const.d.ts +2 -0
  45. package/dist/client/app/util/const.js +2 -1
  46. package/dist/client/app/util/const.ts +2 -0
  47. package/dist/client/app/util/dark.js +0 -1
  48. package/dist/client/app/util/env.js +0 -1
  49. package/dist/client/app/util/env.ts +1 -0
  50. package/dist/client/app/util/keyboard.js +0 -1
  51. package/dist/client/app/util/keyboard.ts +99 -0
  52. package/dist/client/app/util/mapping.js +6 -1
  53. package/dist/client/app/util/mapping.ts +5 -0
  54. package/dist/client/app/util/preview-settings.d.ts +16 -0
  55. package/dist/client/app/util/preview-settings.js +15 -0
  56. package/dist/client/app/util/preview-settings.ts +26 -0
  57. package/dist/client/app/util/reactivity.d.ts +1 -0
  58. package/dist/client/app/util/reactivity.js +16 -0
  59. package/dist/client/app/util/reactivity.ts +22 -0
  60. package/dist/client/app/util/scroll.d.ts +2 -0
  61. package/dist/client/app/util/scroll.js +24 -0
  62. package/dist/client/app/util/scroll.ts +27 -0
  63. package/dist/client/app/util/tooltip.js +0 -1
  64. package/dist/client/app/util/tooltip.ts +13 -0
  65. package/dist/client/app/{composable → util}/variant.d.ts +0 -0
  66. package/dist/client/app/{composable → util}/variant.js +0 -1
  67. package/dist/client/app/{composable → util}/variant.ts +0 -0
  68. package/dist/client/index.js +0 -1
  69. package/dist/client/server/Story.server.vue +25 -2
  70. package/dist/client/server/index.js +2 -1
  71. package/dist/client/server/index.ts +3 -0
  72. package/dist/controls.d.ts +1 -0
  73. package/dist/controls.js +1 -0
  74. package/dist/node/alias.js +0 -1
  75. package/dist/node/bin.js +0 -1
  76. package/dist/node/build.js +13 -9
  77. package/dist/node/collect.js +12 -4
  78. package/dist/node/colors.d.ts +12 -0
  79. package/dist/node/colors.js +12 -1
  80. package/dist/node/commands/build.js +0 -1
  81. package/dist/node/commands/dev.js +43 -6
  82. package/dist/node/config.d.ts +35 -0
  83. package/dist/node/config.js +75 -2
  84. package/dist/node/context.js +0 -1
  85. package/dist/node/dom/dom-keys.js +0 -1
  86. package/dist/node/dom/env.js +0 -1
  87. package/dist/node/index.js +0 -1
  88. package/dist/node/markdown.d.ts +2 -0
  89. package/dist/node/markdown.js +48 -0
  90. package/dist/node/plugin.js +35 -1
  91. package/dist/node/server.js +0 -1
  92. package/dist/node/stories.js +0 -1
  93. package/dist/node/tree.js +0 -1
  94. package/dist/node/types.js +0 -1
  95. package/dist/node/util/slugify.d.ts +1 -0
  96. package/dist/node/util/slugify.js +22 -0
  97. package/dist/style.css +863 -157
  98. package/package.json +17 -4
  99. package/src/client/app/App.vue +8 -8
  100. package/src/client/app/codegen/vue3.ts +32 -4
  101. package/src/client/app/components/app/AppHeader.vue +10 -3
  102. package/src/client/app/components/base/BaseTab.vue +46 -0
  103. package/src/client/app/components/exposed/Story.vue +21 -1
  104. package/src/client/app/components/exposed/Variant.vue +1 -0
  105. package/src/client/app/components/misc/CheckerboardPattern.vue +32 -0
  106. package/src/client/app/components/sandbox/SandboxVue3.vue +6 -0
  107. package/src/client/app/components/search/SearchItem.vue +5 -9
  108. package/{dist/client/app/components → src/client/app/components/story}/StoryControls.vue +3 -3
  109. package/src/client/app/components/story/StoryDocs.vue +37 -0
  110. package/src/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
  111. package/src/client/app/components/{StoryListFolder.vue → story/StoryListFolder.vue} +13 -6
  112. package/src/client/app/components/{StoryListItem.vue → story/StoryListItem.vue} +11 -6
  113. package/src/client/app/components/story/StoryResponsivePreview.vue +214 -0
  114. package/{dist/client/app/components → src/client/app/components/story}/StorySourceCode.vue +4 -8
  115. package/{dist/client/app/components → src/client/app/components/story}/StoryVariantGridItem.vue +14 -6
  116. package/src/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
  117. package/src/client/app/components/story/StoryVariantSingleView.vue +182 -0
  118. package/src/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
  119. package/src/client/app/global-components.ts +3 -0
  120. package/src/client/app/index.ts +10 -0
  121. package/src/client/app/router.ts +1 -1
  122. package/src/client/app/sandbox.ts +37 -3
  123. package/src/client/app/stores/story.ts +37 -1
  124. package/src/client/app/style/floating-vue.css +31 -0
  125. package/src/client/app/style/main.css +17 -1
  126. package/src/client/app/style/sandbox.css +5 -0
  127. package/src/client/app/style/transitions.css +12 -0
  128. package/src/client/app/types.ts +1 -0
  129. package/src/client/app/util/const.ts +2 -0
  130. package/src/client/app/util/mapping.ts +5 -0
  131. package/src/client/app/util/preview-settings.ts +26 -0
  132. package/src/client/app/util/reactivity.ts +22 -0
  133. package/src/client/app/util/scroll.ts +27 -0
  134. package/src/client/app/{composable → util}/variant.ts +0 -0
  135. package/src/client/server/Story.server.vue +25 -2
  136. package/src/client/server/index.ts +3 -0
  137. package/src/controls.ts +1 -0
  138. package/src/node/build.ts +15 -8
  139. package/src/node/collect.ts +12 -3
  140. package/src/node/colors.ts +12 -0
  141. package/src/node/commands/dev.ts +49 -5
  142. package/src/node/config.ts +112 -2
  143. package/src/node/markdown.ts +56 -0
  144. package/src/node/plugin.ts +38 -0
  145. package/src/node/tree.spec.ts +28 -0
  146. package/src/node/util/slugify.ts +26 -0
  147. package/tailwind.config.cjs +79 -4
  148. package/tsconfig.json +2 -1
  149. package/dist/client/app/codegen/serialize-js.js.map +0 -1
  150. package/dist/client/app/codegen/util.js.map +0 -1
  151. package/dist/client/app/codegen/vue3.js.map +0 -1
  152. package/dist/client/app/components/StoryVariantSingleView.vue +0 -145
  153. package/dist/client/app/composable/variant.js.map +0 -1
  154. package/dist/client/app/global-components.js.map +0 -1
  155. package/dist/client/app/index.js.map +0 -1
  156. package/dist/client/app/router.js.map +0 -1
  157. package/dist/client/app/sandbox.js.map +0 -1
  158. package/dist/client/app/stores/story.js.map +0 -1
  159. package/dist/client/app/types.js.map +0 -1
  160. package/dist/client/app/util/config.js.map +0 -1
  161. package/dist/client/app/util/const.js.map +0 -1
  162. package/dist/client/app/util/dark.js.map +0 -1
  163. package/dist/client/app/util/env.js.map +0 -1
  164. package/dist/client/app/util/keyboard.js.map +0 -1
  165. package/dist/client/app/util/mapping.js.map +0 -1
  166. package/dist/client/app/util/tooltip.js.map +0 -1
  167. package/dist/client/index.js.map +0 -1
  168. package/dist/client/server/index.js.map +0 -1
  169. package/dist/node/alias.js.map +0 -1
  170. package/dist/node/bin.js.map +0 -1
  171. package/dist/node/build.js.map +0 -1
  172. package/dist/node/collect.js.map +0 -1
  173. package/dist/node/colors.js.map +0 -1
  174. package/dist/node/commands/build.js.map +0 -1
  175. package/dist/node/commands/dev.js.map +0 -1
  176. package/dist/node/config.js.map +0 -1
  177. package/dist/node/context.js.map +0 -1
  178. package/dist/node/dom/dom-keys.js.map +0 -1
  179. package/dist/node/dom/env.js.map +0 -1
  180. package/dist/node/index.js.map +0 -1
  181. package/dist/node/plugin.js.map +0 -1
  182. package/dist/node/server.js.map +0 -1
  183. package/dist/node/stories.js.map +0 -1
  184. package/dist/node/tree.js.map +0 -1
  185. package/dist/node/types.js.map +0 -1
  186. package/src/client/app/components/StoryVariantSingleView.vue +0 -145
@@ -21,8 +21,13 @@ export function mapFile(file, existingFile) {
21
21
  variant.initState = existingVariant.initState;
22
22
  if (existingVariant.slots)
23
23
  variant.slots = existingVariant.slots;
24
+ if (existingVariant.ready)
25
+ variant.ready = existingVariant.ready;
24
26
  }
25
27
  }
28
+ if (existingFile.story.lastSelectedVariant) {
29
+ result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id);
30
+ }
26
31
  }
27
32
  return result;
28
33
  }
@@ -32,6 +37,6 @@ export function mapVariant(variant) {
32
37
  state: {},
33
38
  initState: null,
34
39
  slots: () => ({}),
40
+ ready: false,
35
41
  };
36
42
  }
37
- //# sourceMappingURL=mapping.js.map
@@ -21,8 +21,12 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
21
21
  if (existingVariant.state) Object.assign(variant.state, existingVariant.state)
22
22
  if (existingVariant.initState) variant.initState = existingVariant.initState
23
23
  if (existingVariant.slots) variant.slots = existingVariant.slots
24
+ if (existingVariant.ready) variant.ready = existingVariant.ready
24
25
  }
25
26
  }
27
+ if (existingFile.story.lastSelectedVariant) {
28
+ result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id)
29
+ }
26
30
  }
27
31
 
28
32
  return result
@@ -34,5 +38,6 @@ export function mapVariant (variant: Variant): Variant {
34
38
  state: {},
35
39
  initState: null,
36
40
  slots: () => ({}),
41
+ ready: false,
37
42
  }
38
43
  }
@@ -0,0 +1,16 @@
1
+ export interface PreviewSettings {
2
+ responsiveWidth: number;
3
+ responsiveHeight: number;
4
+ rotate: boolean;
5
+ backgroundColor: string;
6
+ checkerboard: boolean;
7
+ }
8
+ export declare function usePreviewSettings(): import("@vueuse/shared").RemovableRef<PreviewSettings>;
9
+ export declare const receivedSettings: {
10
+ responsiveWidth: number;
11
+ responsiveHeight: number;
12
+ rotate: boolean;
13
+ backgroundColor: string;
14
+ checkerboard: boolean;
15
+ };
16
+ export declare function applyPreviewSettings(settings: PreviewSettings): void;
@@ -0,0 +1,15 @@
1
+ import { useStorage } from '@vueuse/core';
2
+ import { reactive } from 'vue';
3
+ export function usePreviewSettings() {
4
+ return useStorage('_histoire-sandbox-settings-v1', {
5
+ responsiveWidth: 720,
6
+ responsiveHeight: null,
7
+ rotate: false,
8
+ backgroundColor: 'transparent',
9
+ checkerboard: false,
10
+ });
11
+ }
12
+ export const receivedSettings = reactive({});
13
+ export function applyPreviewSettings(settings) {
14
+ Object.assign(receivedSettings, settings);
15
+ }
@@ -0,0 +1,26 @@
1
+ import { useStorage } from '@vueuse/core'
2
+ import { reactive } from 'vue'
3
+
4
+ export interface PreviewSettings {
5
+ responsiveWidth: number
6
+ responsiveHeight: number
7
+ rotate: boolean
8
+ backgroundColor: string
9
+ checkerboard: boolean
10
+ }
11
+
12
+ export function usePreviewSettings () {
13
+ return useStorage<PreviewSettings>('_histoire-sandbox-settings-v1', {
14
+ responsiveWidth: 720,
15
+ responsiveHeight: null,
16
+ rotate: false,
17
+ backgroundColor: 'transparent',
18
+ checkerboard: false,
19
+ })
20
+ }
21
+
22
+ export const receivedSettings = reactive<PreviewSettings>({} as PreviewSettings)
23
+
24
+ export function applyPreviewSettings (settings: PreviewSettings) {
25
+ Object.assign(receivedSettings, settings)
26
+ }
@@ -0,0 +1 @@
1
+ export declare function toRawDeep(val: any): any;
@@ -0,0 +1,16 @@
1
+ import { unref, isRef } from 'vue';
2
+ const isObject = (val) => val !== null && typeof val === 'object';
3
+ export function toRawDeep(val) {
4
+ const unwrappedValue = isRef(val) ? unref(val) : val;
5
+ if (!isObject(unwrappedValue)) {
6
+ return unwrappedValue;
7
+ }
8
+ if (Array.isArray(unwrappedValue)) {
9
+ return unwrappedValue.map(toRawDeep);
10
+ }
11
+ return toRawObject(unwrappedValue);
12
+ }
13
+ const toRawObject = (obj) => Object.keys(obj).reduce((raw, key) => {
14
+ raw[key] = toRawDeep(obj[key]);
15
+ return raw;
16
+ }, {});
@@ -0,0 +1,22 @@
1
+ import { unref, isRef } from 'vue'
2
+
3
+ const isObject = (val) => val !== null && typeof val === 'object'
4
+
5
+ export function toRawDeep (val) {
6
+ const unwrappedValue = isRef(val) ? unref(val) : val
7
+
8
+ if (!isObject(unwrappedValue)) {
9
+ return unwrappedValue
10
+ }
11
+
12
+ if (Array.isArray(unwrappedValue)) {
13
+ return unwrappedValue.map(toRawDeep)
14
+ }
15
+
16
+ return toRawObject(unwrappedValue)
17
+ }
18
+
19
+ const toRawObject = (obj: Record<any, any>) => Object.keys(obj).reduce((raw, key) => {
20
+ raw[key] = toRawDeep(obj[key])
21
+ return raw
22
+ }, {})
@@ -0,0 +1,2 @@
1
+ import { Ref } from 'vue';
2
+ export declare function useScrollOnActive(active: Ref<boolean>, el: Ref<HTMLElement>): void;
@@ -0,0 +1,24 @@
1
+ import { watch, onMounted } from 'vue';
2
+ import scrollIntoView from 'scroll-into-view-if-needed';
3
+ export function useScrollOnActive(active, el) {
4
+ watch(active, value => {
5
+ if (value) {
6
+ autoScroll();
7
+ }
8
+ });
9
+ function autoScroll() {
10
+ if (el.value) {
11
+ scrollIntoView(el.value, {
12
+ scrollMode: 'if-needed',
13
+ block: 'center',
14
+ inline: 'nearest',
15
+ behavior: 'smooth',
16
+ });
17
+ }
18
+ }
19
+ onMounted(() => {
20
+ if (active.value) {
21
+ autoScroll();
22
+ }
23
+ });
24
+ }
@@ -0,0 +1,27 @@
1
+ import { watch, onMounted, Ref } from 'vue'
2
+ import scrollIntoView from 'scroll-into-view-if-needed'
3
+
4
+ export function useScrollOnActive (active: Ref<boolean>, el: Ref<HTMLElement>) {
5
+ watch(active, value => {
6
+ if (value) {
7
+ autoScroll()
8
+ }
9
+ })
10
+
11
+ function autoScroll () {
12
+ if (el.value) {
13
+ scrollIntoView(el.value, {
14
+ scrollMode: 'if-needed',
15
+ block: 'center',
16
+ inline: 'nearest',
17
+ behavior: 'smooth',
18
+ })
19
+ }
20
+ }
21
+
22
+ onMounted(() => {
23
+ if (active.value) {
24
+ autoScroll()
25
+ }
26
+ })
27
+ }
@@ -9,4 +9,3 @@ export function makeTooltip(descriptionHtml, keyboardShortcut) {
9
9
  function genKeyboardShortcutHtml(shortcut) {
10
10
  return shortcut.split('+').map(k => k.trim()).map(key => `<span class="htw-bg-gray-500 htw-border-b-2 htw-border-gray-600 htw-px-1 htw-rounded-sm">${formatKey(key)}</span>`).join('');
11
11
  }
12
- //# sourceMappingURL=tooltip.js.map
@@ -0,0 +1,13 @@
1
+ import { isMac } from './env.js'
2
+ import { formatKey } from './keyboard.js'
3
+
4
+ export function makeTooltip (descriptionHtml: string, keyboardShortcut: ({ isMac: boolean }) => string) {
5
+ return {
6
+ content: `<div>${descriptionHtml}</div><div class="htw-flex htw-items-center htw-gap-1 htw-mt-2 htw-text-sm">${genKeyboardShortcutHtml(keyboardShortcut({ isMac }))}</div>`,
7
+ html: true,
8
+ }
9
+ }
10
+
11
+ function genKeyboardShortcutHtml (shortcut: string) {
12
+ return shortcut.split('+').map(k => k.trim()).map(key => `<span class="htw-bg-gray-500 htw-border-b-2 htw-border-gray-600 htw-px-1 htw-rounded-sm">${formatKey(key)}</span>`).join('')
13
+ }
@@ -15,4 +15,3 @@ export function useCurrentVariantRoute(variant) {
15
15
  targetRoute,
16
16
  };
17
17
  }
18
- //# sourceMappingURL=variant.js.map
File without changes
@@ -1,4 +1,3 @@
1
1
  export function defineVue3StorySetup(handler) {
2
2
  return handler;
3
3
  }
4
- //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { defineComponent, inject, PropType, provide, useAttrs } from 'vue'
2
+ import { defineComponent, inject, onMounted, PropType, provide, useAttrs } from 'vue'
3
3
  import type { StoryFile, Story, Variant } from '../../node/types'
4
4
 
5
5
  export default defineComponent({
@@ -53,13 +53,36 @@ export default defineComponent({
53
53
  story.variants.push(variant)
54
54
  })
55
55
 
56
+ onMounted(() => {
57
+ if (!story.variants.length) {
58
+ story.variants.push({
59
+ id: '_default',
60
+ title: 'default',
61
+ })
62
+ }
63
+ })
64
+
56
65
  return {
57
66
  story,
58
67
  }
59
68
  },
60
69
 
61
70
  render () {
62
- return this.$slots.default()
71
+ let suppressError = false
72
+ try {
73
+ return this.$slots.default({
74
+ get state () {
75
+ // No variant tags
76
+ suppressError = true
77
+ return {}
78
+ },
79
+ })
80
+ } catch (e) {
81
+ if (!suppressError) {
82
+ console.error(e)
83
+ }
84
+ return null
85
+ }
63
86
  },
64
87
  })
65
88
  </script>
@@ -1,4 +1,5 @@
1
1
  import { createApp, h } from 'vue';
2
+ import { registerVueComponents } from '@histoire/controls';
2
3
  import Story from './Story.server.vue';
3
4
  import Variant from './Variant.server.vue';
4
5
  export async function run(file, storyData, el) {
@@ -20,7 +21,7 @@ export async function run(file, storyData, el) {
20
21
  app.component('Story', Story);
21
22
  // eslint-disable-next-line vue/multi-word-component-names
22
23
  app.component('Variant', Variant);
24
+ registerVueComponents(app);
23
25
  app.mount(el);
24
26
  app.unmount();
25
27
  }
26
- //# sourceMappingURL=index.js.map
@@ -1,4 +1,5 @@
1
1
  import { createApp, h } from 'vue'
2
+ import { registerVueComponents } from '@histoire/controls'
2
3
  import type { StoryFile } from '../../node/types'
3
4
  import Story from './Story.server.vue'
4
5
  import Variant from './Variant.server.vue'
@@ -24,6 +25,8 @@ export async function run (file: StoryFile, storyData, el) {
24
25
  // eslint-disable-next-line vue/multi-word-component-names
25
26
  app.component('Variant', Variant)
26
27
 
28
+ registerVueComponents(app)
29
+
27
30
  app.mount(el)
28
31
  app.unmount()
29
32
  }
@@ -0,0 +1 @@
1
+ export * from '@histoire/controls';
@@ -0,0 +1 @@
1
+ export * from '@histoire/controls';
@@ -3,4 +3,3 @@ import { fileURLToPath } from 'url';
3
3
  const __dirname = dirname(fileURLToPath(import.meta.url));
4
4
  export const DIST_CLIENT_PATH = join(__dirname, '../client');
5
5
  export const APP_PATH = join(DIST_CLIENT_PATH, 'app');
6
- //# sourceMappingURL=alias.js.map
package/dist/node/bin.js CHANGED
@@ -20,4 +20,3 @@ program.command('build')
20
20
  return buildCommand();
21
21
  });
22
22
  program.parse(process.argv);
23
- //# sourceMappingURL=bin.js.map
@@ -1,22 +1,19 @@
1
1
  import { join } from 'pathe';
2
- import { build as viteBuild, createServer as createViteServer, resolveConfig as resolveViteConfig } from 'vite';
2
+ import { build as viteBuild, createServer as createViteServer } from 'vite';
3
3
  import fs from 'fs-extra';
4
4
  import { lookup as lookupMime } from 'mrmime';
5
+ import pc from 'picocolors';
6
+ import { performance } from 'perf_hooks';
5
7
  import { APP_PATH } from './alias.js';
6
8
  import { createVitePlugins } from './plugin.js';
7
9
  import { findAllStories } from './stories.js';
8
10
  import { useCollectStories } from './collect.js';
9
11
  export async function build(ctx) {
12
+ const startTime = performance.now();
10
13
  await findAllStories(ctx);
11
14
  // Collect story data
12
- const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
13
- const plugins = [];
14
- const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue');
15
- if (!hasVuePlugin) {
16
- plugins.push((await import('@vitejs/plugin-vue')).default());
17
- }
18
15
  const server = await createViteServer({
19
- plugins,
16
+ plugins: await createVitePlugins(ctx),
20
17
  });
21
18
  await server.pluginContainer.buildStart({});
22
19
  const { executeStoryFile, destroy: destroyCollectStories } = useCollectStories({
@@ -28,6 +25,9 @@ export async function build(ctx) {
28
25
  }
29
26
  await server.close();
30
27
  await destroyCollectStories();
28
+ const storyCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ? 1 : 0), 0);
29
+ const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0);
30
+ const emptyStoryCount = ctx.storyFiles.length - storyCount;
31
31
  const results = await viteBuild({
32
32
  plugins: await createVitePlugins(ctx),
33
33
  build: {
@@ -50,6 +50,11 @@ export async function build(ctx) {
50
50
  // Sandbox
51
51
  const sandboxOutput = result.output.find(o => o.name === 'sandbox' && o.type === 'chunk');
52
52
  await writeHtml(sandboxOutput.fileName, styleOutput.fileName, '__sandbox.html', ctx);
53
+ const duration = performance.now() - startTime;
54
+ if (emptyStoryCount) {
55
+ console.warn(pc.yellow(`⚠️ ${emptyStoryCount} empty story file`));
56
+ }
57
+ console.log(pc.green(`✅ Built ${storyCount} stories (${variantCount} variants) in ${Math.round(duration / 1000 * 100) / 100}s`));
53
58
  }
54
59
  async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, ctx) {
55
60
  const code = `<!DOCTYPE html>
@@ -69,4 +74,3 @@ async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, ctx) {
69
74
  </html>`;
70
75
  await fs.writeFile(join(ctx.config.outDir, htmlFileName), code, 'utf8');
71
76
  }
72
- //# sourceMappingURL=build.js.map
@@ -9,7 +9,13 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
9
9
  export function useCollectStories(options, ctx) {
10
10
  const { server } = options;
11
11
  const { destroy: destroyDomEnv } = createDomEnv();
12
- const node = new ViteNodeServer(server);
12
+ const node = new ViteNodeServer(server, {
13
+ deps: {
14
+ inline: [
15
+ /histoire\/dist/,
16
+ ],
17
+ },
18
+ });
13
19
  const runner = new ViteNodeRunner({
14
20
  root: server.config.root,
15
21
  base: server.config.base,
@@ -20,6 +26,9 @@ export function useCollectStories(options, ctx) {
20
26
  }
21
27
  return node.fetchModule(id);
22
28
  },
29
+ resolveId(id, importer) {
30
+ return node.resolveId(id, importer);
31
+ },
23
32
  });
24
33
  function clearCache() {
25
34
  node.fetchCache.clear();
@@ -33,11 +42,11 @@ export function useCollectStories(options, ctx) {
33
42
  const storyData = [];
34
43
  await run(storyFile, storyData, el);
35
44
  if (storyData.length === 0) {
36
- console.warn(pc.yellow(`No story found for ${storyFile.path}`));
45
+ console.warn(pc.yellow(`⚠️ No story found for ${storyFile.path}`));
37
46
  return;
38
47
  }
39
48
  else if (storyData.length > 1) {
40
- console.warn(pc.yellow(`Multiple stories not supported: ${storyFile.path}`));
49
+ console.warn(pc.yellow(`⚠️ Multiple stories not supported: ${storyFile.path}`));
41
50
  }
42
51
  storyFile.story = storyData[0];
43
52
  const file = {
@@ -63,4 +72,3 @@ export function useCollectStories(options, ctx) {
63
72
  destroy,
64
73
  };
65
74
  }
66
- //# sourceMappingURL=collect.js.map
@@ -8,8 +8,11 @@ export declare const defaultColors: {
8
8
  500: string;
9
9
  600: string;
10
10
  700: string;
11
+ 750: string;
11
12
  800: string;
13
+ 850: string;
12
14
  900: string;
15
+ 950: string;
13
16
  };
14
17
  gray: {
15
18
  50: string;
@@ -20,8 +23,11 @@ export declare const defaultColors: {
20
23
  500: string;
21
24
  600: string;
22
25
  700: string;
26
+ 750: string;
23
27
  800: string;
28
+ 850: string;
24
29
  900: string;
30
+ 950: string;
25
31
  };
26
32
  zinc: {
27
33
  50: string;
@@ -47,8 +53,11 @@ export declare const defaultColors: {
47
53
  500: string;
48
54
  600: string;
49
55
  700: string;
56
+ 750: string;
50
57
  800: string;
58
+ 850: string;
51
59
  900: string;
60
+ 950: string;
52
61
  };
53
62
  stone: {
54
63
  50: string;
@@ -59,8 +68,11 @@ export declare const defaultColors: {
59
68
  500: string;
60
69
  600: string;
61
70
  700: string;
71
+ 750: string;
62
72
  800: string;
73
+ 850: string;
63
74
  900: string;
75
+ 950: string;
64
76
  };
65
77
  red: {
66
78
  50: string;
@@ -8,8 +8,11 @@ export const defaultColors = {
8
8
  500: '#64748b',
9
9
  600: '#475569',
10
10
  700: '#334155',
11
+ 750: '#283548',
11
12
  800: '#1e293b',
13
+ 850: '#151f32',
12
14
  900: '#0f172a',
15
+ 950: '#09101f',
13
16
  },
14
17
  gray: {
15
18
  50: '#f9fafb',
@@ -20,8 +23,11 @@ export const defaultColors = {
20
23
  500: '#6b7280',
21
24
  600: '#4b5563',
22
25
  700: '#374151',
26
+ 750: '#2b3546',
23
27
  800: '#1f2937',
28
+ 850: '#18212f',
24
29
  900: '#111827',
30
+ 950: '#0c101d',
25
31
  },
26
32
  zinc: {
27
33
  50: '#fafafa',
@@ -47,8 +53,11 @@ export const defaultColors = {
47
53
  500: '#737373',
48
54
  600: '#525252',
49
55
  700: '#404040',
56
+ 750: '#333333',
50
57
  800: '#262626',
58
+ 850: '#1f1f1f',
51
59
  900: '#171717',
60
+ 950: '#0f0f0f',
52
61
  },
53
62
  stone: {
54
63
  50: '#fafaf9',
@@ -59,8 +68,11 @@ export const defaultColors = {
59
68
  500: '#78716c',
60
69
  600: '#57534e',
61
70
  700: '#44403c',
71
+ 750: '#363230',
62
72
  800: '#292524',
73
+ 850: '#211e1c',
63
74
  900: '#1c1917',
75
+ 950: '#171412',
64
76
  },
65
77
  red: {
66
78
  50: '#fef2f2',
@@ -310,4 +322,3 @@ export function parseColor(value) {
310
322
  }
311
323
  return null;
312
324
  }
313
- //# sourceMappingURL=colors.js.map
@@ -8,4 +8,3 @@ export async function buildCommand() {
8
8
  // @TODO remove when https://github.com/vitejs/vite/issues/6815 is fixed
9
9
  process.exit(0);
10
10
  }
11
- //# sourceMappingURL=build.js.map
@@ -1,10 +1,47 @@
1
+ import { resolveConfigFile } from '../config.js';
1
2
  import { createContext } from '../context.js';
2
3
  import { createServer } from '../server.js';
4
+ import chokidar from 'chokidar';
5
+ import pc from 'picocolors';
3
6
  export async function devCommand(options) {
4
- const ctx = await createContext({
5
- mode: 'dev',
6
- });
7
- const { server } = await createServer(ctx, options.port);
8
- server.printUrls();
7
+ let stop;
8
+ async function start() {
9
+ const ctx = await createContext({
10
+ mode: 'dev',
11
+ });
12
+ const { server, close } = await createServer(ctx, options.port);
13
+ server.printUrls();
14
+ // Histoire config watcher
15
+ let watcher;
16
+ if (server.config.configFile) {
17
+ watcher = chokidar.watch(server.config.configFile, {
18
+ ignoreInitial: true,
19
+ });
20
+ watcher.on('change', () => {
21
+ restart('Vite');
22
+ });
23
+ }
24
+ return async () => {
25
+ await watcher?.close();
26
+ await close();
27
+ };
28
+ }
29
+ async function restart(source) {
30
+ if (stop) {
31
+ console.log(pc.blue(`${source} config changed, restarting...`));
32
+ stop();
33
+ stop = null; // Don't call stop again until new start() is done
34
+ stop = await start();
35
+ }
36
+ }
37
+ stop = await start();
38
+ const configFile = await resolveConfigFile();
39
+ if (configFile) {
40
+ const watcher = chokidar.watch(configFile, {
41
+ ignoreInitial: true,
42
+ });
43
+ watcher.on('change', () => {
44
+ restart('Histoire');
45
+ });
46
+ }
9
47
  }
10
- //# sourceMappingURL=dev.js.map
@@ -1,7 +1,18 @@
1
+ import { UserConfig as ViteConfig, ConfigEnv as ViteConfigEnv } from 'vite';
1
2
  import { TreeFile } from './tree.js';
3
+ import type MarkdownIt from 'markdown-it';
2
4
  declare type CustomizableColors = 'primary' | 'gray';
3
5
  declare type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
4
6
  declare type GrayColorKeys = ColorKeys | '750' | '850' | '950';
7
+ interface ResponsivePreset {
8
+ label: string;
9
+ width: number;
10
+ height: number;
11
+ }
12
+ interface BackgroundPreset {
13
+ label: string;
14
+ color: string;
15
+ }
5
16
  export interface HistoireConfig {
6
17
  /**
7
18
  * Output directory.
@@ -74,6 +85,10 @@ export interface HistoireConfig {
74
85
  [key in ColorKeys]?: string;
75
86
  };
76
87
  };
88
+ /**
89
+ * Add a link to the main logo
90
+ */
91
+ logoHref?: string;
77
92
  };
78
93
  /**
79
94
  * Setup file exposting a default function executed when setting up each story preview.
@@ -83,6 +98,26 @@ export interface HistoireConfig {
83
98
  * Example: `'/src/histoire-setup.ts'`
84
99
  */
85
100
  setupFile?: string;
101
+ /**
102
+ * Predefined responsive sizes for story playgrounds.
103
+ */
104
+ responsivePresets?: ResponsivePreset[];
105
+ /**
106
+ * Background color of the story preview.
107
+ */
108
+ backgroundPresets?: BackgroundPreset[];
109
+ /**
110
+ * Class added to the html root of the story preview when dark mode is enabled.
111
+ */
112
+ sandboxDarkClass?: string;
113
+ /**
114
+ * Customize the markdown-it renderer
115
+ */
116
+ markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>;
117
+ /**
118
+ * Vite config override
119
+ */
120
+ vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>);
86
121
  }
87
122
  export declare function getDefaultConfig(): HistoireConfig;
88
123
  export declare const configFileNames: string[];