histoire 0.0.0 → 0.0.3

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 (204) hide show
  1. package/LICENSE +21 -0
  2. package/client.d.ts +2 -0
  3. package/dist/client/app/App.vue +84 -21
  4. package/dist/client/app/assets/histoire-text-dark.svg +89 -0
  5. package/dist/client/app/assets/histoire-text.svg +89 -0
  6. package/dist/client/app/assets/histoire.svg +51 -0
  7. package/dist/client/app/codegen/serialize-js.d.ts +1 -0
  8. package/dist/client/app/codegen/serialize-js.js +113 -0
  9. package/dist/client/app/codegen/serialize-js.ts +119 -0
  10. package/dist/client/app/codegen/util.d.ts +10 -0
  11. package/dist/client/app/codegen/util.js +70 -0
  12. package/dist/client/app/codegen/util.ts +79 -0
  13. package/dist/client/app/codegen/vue3.d.ts +2 -0
  14. package/dist/client/app/codegen/vue3.js +238 -0
  15. package/dist/client/app/codegen/vue3.ts +240 -0
  16. package/dist/client/app/components/HomeView.vue +15 -1
  17. package/dist/client/app/components/StoryControls.vue +7 -2
  18. package/dist/client/app/components/StoryList.vue +20 -13
  19. package/dist/client/app/components/StoryListFolder.vue +87 -0
  20. package/dist/client/app/components/StoryListItem.vue +38 -12
  21. package/dist/client/app/components/StorySourceCode.vue +121 -0
  22. package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
  23. package/dist/client/app/components/StoryVariantListItem.vue +46 -0
  24. package/dist/client/app/components/StoryVariantSingleView.vue +145 -15
  25. package/dist/client/app/components/StoryView.vue +88 -54
  26. package/dist/client/app/components/app/AppHeader.vue +56 -0
  27. package/dist/client/app/components/app/AppLogo.vue +24 -0
  28. package/dist/client/app/components/base/BaseEmpty.vue +1 -1
  29. package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
  30. package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
  31. package/dist/client/app/components/exposed/Story.vue +23 -58
  32. package/dist/client/app/components/exposed/Variant.vue +24 -47
  33. package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
  34. package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  35. package/dist/client/app/components/search/SearchItem.vue +110 -0
  36. package/dist/client/app/components/search/SearchModal.vue +179 -0
  37. package/dist/client/app/composable/variant.js +0 -1
  38. package/dist/client/app/composable/variant.ts +20 -0
  39. package/dist/client/app/global-components.js +0 -1
  40. package/dist/client/app/global-components.ts +10 -0
  41. package/dist/client/app/index.d.ts +1 -0
  42. package/dist/client/app/index.js +10 -2
  43. package/dist/client/app/index.ts +24 -0
  44. package/dist/client/app/router.js +0 -1
  45. package/dist/client/app/router.ts +17 -0
  46. package/dist/client/app/sandbox.d.ts +1 -0
  47. package/dist/client/app/sandbox.js +53 -0
  48. package/dist/client/app/sandbox.ts +60 -0
  49. package/dist/client/app/stores/story.d.ts +167 -50
  50. package/dist/client/app/stores/story.js +33 -16
  51. package/dist/client/app/stores/story.ts +58 -0
  52. package/dist/client/app/style/floating-vue.css +31 -0
  53. package/dist/client/app/style/main.css +17 -2
  54. package/dist/client/app/style/sandbox.css +14 -0
  55. package/dist/client/app/types.d.ts +36 -4
  56. package/dist/client/app/types.js +0 -1
  57. package/dist/client/app/types.ts +59 -0
  58. package/dist/client/app/util/config.d.ts +3 -0
  59. package/dist/client/app/util/config.js +4 -0
  60. package/dist/client/app/util/config.ts +6 -0
  61. package/dist/client/app/util/const.d.ts +1 -0
  62. package/dist/client/app/util/const.js +1 -0
  63. package/dist/client/app/util/const.ts +1 -0
  64. package/dist/client/app/util/dark.d.ts +2 -0
  65. package/dist/client/app/util/dark.js +3 -0
  66. package/dist/client/app/util/dark.ts +4 -0
  67. package/dist/client/app/util/env.d.ts +1 -0
  68. package/dist/client/app/util/env.js +1 -0
  69. package/dist/client/app/util/env.ts +1 -0
  70. package/dist/client/app/util/keyboard.d.ts +8 -0
  71. package/dist/client/app/util/keyboard.js +82 -0
  72. package/dist/client/app/util/keyboard.ts +99 -0
  73. package/dist/client/app/util/mapping.d.ts +3 -0
  74. package/dist/client/app/util/mapping.js +39 -0
  75. package/dist/client/app/util/mapping.ts +41 -0
  76. package/dist/client/app/util/tooltip.d.ts +6 -0
  77. package/dist/client/app/util/tooltip.js +11 -0
  78. package/dist/client/app/util/tooltip.ts +13 -0
  79. package/dist/client/index.d.ts +8 -0
  80. package/dist/client/index.js +3 -0
  81. package/dist/client/index.ts +12 -0
  82. package/dist/client/server/Story.server.vue +65 -0
  83. package/dist/client/server/Variant.server.vue +50 -0
  84. package/dist/client/server/index.d.ts +2 -0
  85. package/dist/client/server/index.js +25 -0
  86. package/dist/client/server/index.ts +29 -0
  87. package/dist/client/shim.d.ts +5 -0
  88. package/dist/node/alias.js +0 -1
  89. package/dist/node/bin.js +8 -3
  90. package/dist/node/build.d.ts +2 -0
  91. package/dist/node/build.js +71 -0
  92. package/dist/node/collect.d.ts +12 -0
  93. package/dist/node/collect.js +65 -0
  94. package/dist/node/colors.d.ts +286 -0
  95. package/dist/node/colors.js +324 -0
  96. package/dist/node/commands/build.d.ts +1 -0
  97. package/dist/node/commands/build.js +10 -0
  98. package/dist/node/commands/dev.d.ts +1 -1
  99. package/dist/node/commands/dev.js +45 -13
  100. package/dist/node/config.d.ts +112 -1
  101. package/dist/node/config.js +124 -2
  102. package/dist/node/context.d.ts +13 -0
  103. package/dist/node/context.js +12 -2
  104. package/dist/node/dom/dom-keys.d.ts +4 -0
  105. package/dist/node/dom/dom-keys.js +223 -0
  106. package/dist/node/dom/env.d.ts +5 -0
  107. package/dist/node/dom/env.js +22 -0
  108. package/dist/node/index.d.ts +2 -0
  109. package/dist/node/index.js +2 -2
  110. package/dist/node/plugin.d.ts +8 -2
  111. package/dist/node/plugin.js +150 -22
  112. package/dist/node/server.d.ts +4 -1
  113. package/dist/node/server.js +80 -21
  114. package/dist/node/stories.d.ts +8 -9
  115. package/dist/node/stories.js +42 -23
  116. package/dist/node/tree.d.ts +19 -0
  117. package/dist/node/tree.js +54 -0
  118. package/dist/node/types.d.ts +38 -0
  119. package/dist/node/types.js +1 -0
  120. package/dist/style.css +610 -53
  121. package/package.json +45 -25
  122. package/scripts/copy.mjs +11 -0
  123. package/src/client/app/App.vue +84 -21
  124. package/src/client/app/assets/histoire-text-dark.svg +89 -0
  125. package/src/client/app/assets/histoire-text.svg +89 -0
  126. package/src/client/app/assets/histoire.svg +51 -0
  127. package/src/client/app/codegen/serialize-js.ts +119 -0
  128. package/src/client/app/codegen/util.ts +79 -0
  129. package/src/client/app/codegen/vue3.ts +240 -0
  130. package/src/client/app/components/HomeView.vue +15 -1
  131. package/src/client/app/components/StoryControls.vue +7 -2
  132. package/src/client/app/components/StoryList.vue +20 -13
  133. package/src/client/app/components/StoryListFolder.vue +87 -0
  134. package/src/client/app/components/StoryListItem.vue +38 -12
  135. package/src/client/app/components/StorySourceCode.vue +121 -0
  136. package/src/client/app/components/StoryVariantGridItem.vue +32 -17
  137. package/src/client/app/components/StoryVariantListItem.vue +46 -0
  138. package/src/client/app/components/StoryVariantSingleView.vue +145 -15
  139. package/src/client/app/components/StoryView.vue +88 -54
  140. package/src/client/app/components/app/AppHeader.vue +56 -0
  141. package/src/client/app/components/app/AppLogo.vue +24 -0
  142. package/src/client/app/components/base/BaseEmpty.vue +1 -1
  143. package/src/client/app/components/base/BaseListItemLink.vue +55 -0
  144. package/src/client/app/components/base/BaseSplitPane.vue +57 -21
  145. package/src/client/app/components/exposed/Story.vue +23 -58
  146. package/src/client/app/components/exposed/Variant.vue +24 -47
  147. package/src/client/app/components/misc/HatchedPattern.vue +25 -0
  148. package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  149. package/src/client/app/components/search/SearchItem.vue +110 -0
  150. package/src/client/app/components/search/SearchModal.vue +179 -0
  151. package/src/client/app/index.ts +10 -1
  152. package/src/client/app/sandbox.ts +60 -0
  153. package/src/client/app/stores/story.ts +39 -15
  154. package/src/client/app/style/floating-vue.css +31 -0
  155. package/src/client/app/style/main.css +17 -2
  156. package/src/client/app/style/sandbox.css +14 -0
  157. package/src/client/app/types.ts +42 -4
  158. package/src/client/app/util/config.ts +6 -0
  159. package/src/client/app/util/const.ts +1 -0
  160. package/src/client/app/util/dark.ts +4 -0
  161. package/src/client/app/util/env.ts +1 -0
  162. package/src/client/app/util/keyboard.ts +99 -0
  163. package/src/client/app/util/mapping.ts +41 -0
  164. package/src/client/app/util/tooltip.ts +13 -0
  165. package/src/client/index.ts +12 -0
  166. package/src/client/server/Story.server.vue +65 -0
  167. package/src/client/server/Variant.server.vue +50 -0
  168. package/src/client/server/index.ts +29 -0
  169. package/src/node/bin.ts +9 -2
  170. package/src/node/build.ts +80 -0
  171. package/src/node/collect.ts +78 -0
  172. package/src/node/colors.ts +340 -0
  173. package/src/node/commands/build.ts +12 -0
  174. package/src/node/commands/dev.ts +49 -12
  175. package/src/node/config.ts +240 -1
  176. package/src/node/context.ts +21 -1
  177. package/src/node/dom/dom-keys.ts +227 -0
  178. package/src/node/dom/env.ts +26 -0
  179. package/src/node/index.ts +2 -0
  180. package/src/node/plugin.ts +155 -22
  181. package/src/node/server.ts +95 -20
  182. package/src/node/stories.ts +53 -31
  183. package/src/node/tree.spec.ts +28 -0
  184. package/src/node/tree.ts +88 -0
  185. package/src/node/types.ts +40 -0
  186. package/tailwind.config.cjs +41 -1
  187. package/tsconfig.json +2 -1
  188. package/dist/client/app/components/StoryVariantItem.vue +0 -29
  189. package/dist/client/app/composable/variant.js.map +0 -1
  190. package/dist/client/app/global-components.js.map +0 -1
  191. package/dist/client/app/index.js.map +0 -1
  192. package/dist/client/app/router.js.map +0 -1
  193. package/dist/client/app/stores/story.js.map +0 -1
  194. package/dist/client/app/types.js.map +0 -1
  195. package/dist/node/alias.js.map +0 -1
  196. package/dist/node/bin.js.map +0 -1
  197. package/dist/node/commands/dev.js.map +0 -1
  198. package/dist/node/config.js.map +0 -1
  199. package/dist/node/context.js.map +0 -1
  200. package/dist/node/index.js.map +0 -1
  201. package/dist/node/plugin.js.map +0 -1
  202. package/dist/node/server.js.map +0 -1
  203. package/dist/node/stories.js.map +0 -1
  204. package/src/client/app/components/StoryVariantItem.vue +0 -29
@@ -0,0 +1,59 @@
1
+ import type { RouteLocationRaw } from 'vue-router'
2
+
3
+ export interface StoryFile {
4
+ id: string
5
+ framework: string
6
+ component: any
7
+ story: Story
8
+ path: string[]
9
+ }
10
+
11
+ export interface Story {
12
+ id: string
13
+ title: string
14
+ variants: Variant[]
15
+ layout?: {
16
+ type: 'single'
17
+ } | {
18
+ type: 'grid'
19
+ width: number
20
+ }
21
+ icon?: string
22
+ iconColor?: string
23
+ file?: StoryFile
24
+ lastSelectedVariant?: Variant
25
+ }
26
+
27
+ export interface Variant {
28
+ id: string
29
+ title: string
30
+ icon?: string
31
+ iconColor?: string
32
+ initState?: () => any
33
+ slots?: () => Readonly<any>
34
+ state?: any
35
+ source?: string
36
+ }
37
+
38
+ export type TreeLeaf = {
39
+ title: string
40
+ index: number
41
+ }
42
+
43
+ export type TreeFolder = {
44
+ title: string
45
+ children: (TreeFolder | TreeLeaf)[]
46
+ }
47
+
48
+ export type Tree = (TreeFolder | TreeLeaf)[]
49
+
50
+ export interface SearchResult {
51
+ kind: 'story' | 'variant'
52
+ rank: number
53
+ id: string
54
+ title: string
55
+ route: RouteLocationRaw
56
+ path?: string[]
57
+ icon?: string
58
+ iconColor?: string
59
+ }
@@ -0,0 +1,3 @@
1
+ import type { HistoireConfig } from '../../../node/config';
2
+ export declare const histoireConfig: HistoireConfig;
3
+ export declare const customLogos: HistoireConfig['theme']['logo'];
@@ -0,0 +1,4 @@
1
+ // @ts-expect-error virtual module
2
+ import { config as configRaw, logos as logosRaw } from '$histoire-config';
3
+ export const histoireConfig = configRaw;
4
+ export const customLogos = logosRaw;
@@ -0,0 +1,6 @@
1
+ import type { HistoireConfig } from '../../../node/config'
2
+ // @ts-expect-error virtual module
3
+ import { config as configRaw, logos as logosRaw } from '$histoire-config'
4
+
5
+ export const histoireConfig: HistoireConfig = configRaw
6
+ export const customLogos: HistoireConfig['theme']['logo'] = logosRaw
@@ -0,0 +1 @@
1
+ export declare const STATE_SYNC = "__histoire:state-sync";
@@ -0,0 +1 @@
1
+ export const STATE_SYNC = '__histoire:state-sync';
@@ -0,0 +1 @@
1
+ export const STATE_SYNC = '__histoire:state-sync'
@@ -0,0 +1,2 @@
1
+ export declare const isDark: import("vue").WritableComputedRef<boolean>;
2
+ export declare const toggleDark: (value?: boolean) => boolean;
@@ -0,0 +1,3 @@
1
+ import { useDark, useToggle } from '@vueuse/core';
2
+ export const isDark = useDark({ valueDark: 'htw-dark' });
3
+ export const toggleDark = useToggle(isDark);
@@ -0,0 +1,4 @@
1
+ import { useDark, useToggle } from '@vueuse/core'
2
+
3
+ export const isDark = useDark({ valueDark: 'htw-dark' })
4
+ export const toggleDark = useToggle(isDark)
@@ -0,0 +1 @@
1
+ export declare const isMac: boolean;
@@ -0,0 +1 @@
1
+ export const isMac = navigator.platform.toLowerCase().includes('mac');
@@ -0,0 +1 @@
1
+ export const isMac = navigator.platform.toLowerCase().includes('mac')
@@ -0,0 +1,8 @@
1
+ import { Ref } from 'vue';
2
+ export declare type KeyboardShortcut = string[];
3
+ export declare type KeyboardHandler = (event: KeyboardEvent) => unknown;
4
+ export interface KeyboardShortcutOptions {
5
+ event?: 'keyup' | 'keydown' | 'keypress';
6
+ }
7
+ export declare function onKeyboardShortcut(shortcut: KeyboardShortcut | Ref<KeyboardShortcut>, handler: KeyboardHandler, options?: KeyboardShortcutOptions): void;
8
+ export declare function formatKey(key: string): string;
@@ -0,0 +1,82 @@
1
+ import { useEventListener } from '@vueuse/core';
2
+ import { isRef } from 'vue';
3
+ import { isMac } from './env.js';
4
+ export function onKeyboardShortcut(shortcut, handler, options = {}) {
5
+ useEventListener(options.event ?? 'keydown', event => {
6
+ if (isMatchingShortcut(isRef(shortcut) ? shortcut.value : shortcut)) {
7
+ handler(event);
8
+ }
9
+ });
10
+ }
11
+ const modifiers = {
12
+ ctrl: { key: 'Control', pressed: false },
13
+ alt: { key: 'Alt', pressed: false },
14
+ shift: { key: 'Shift', pressed: false },
15
+ meta: { key: 'Meta', pressed: false },
16
+ };
17
+ const pressedKeys = new Set();
18
+ window.addEventListener('keydown', event => {
19
+ for (const i in modifiers) {
20
+ const mod = modifiers[i];
21
+ if (mod.key === event.key) {
22
+ mod.pressed = true;
23
+ return;
24
+ }
25
+ }
26
+ pressedKeys.add(event.key.toLocaleLowerCase());
27
+ });
28
+ window.addEventListener('keyup', event => {
29
+ requestAnimationFrame(() => {
30
+ pressedKeys.clear();
31
+ for (const i in modifiers) {
32
+ const mod = modifiers[i];
33
+ if (mod.key === event.key) {
34
+ mod.pressed = false;
35
+ break;
36
+ }
37
+ }
38
+ });
39
+ });
40
+ window.addEventListener('blur', () => {
41
+ pressedKeys.clear();
42
+ for (const i in modifiers) {
43
+ const mod = modifiers[i];
44
+ mod.pressed = false;
45
+ }
46
+ });
47
+ function isMatchingShortcut(shortcut) {
48
+ for (const combination of shortcut) {
49
+ if (isMatchingCombination(combination.toLowerCase())) {
50
+ return true;
51
+ }
52
+ }
53
+ return false;
54
+ }
55
+ function isMatchingCombination(combination) {
56
+ const splitted = combination.split('+').map(key => key.trim());
57
+ const targetKey = splitted.pop();
58
+ for (const mod in modifiers) {
59
+ const containsMod = splitted.includes(mod);
60
+ const isPressed = modifiers[mod].pressed;
61
+ if (containsMod !== isPressed) {
62
+ return false;
63
+ }
64
+ }
65
+ return pressedKeys.has(targetKey);
66
+ }
67
+ export function formatKey(key) {
68
+ key = key.toLowerCase();
69
+ if (key === 'ctrl') {
70
+ return isMac ? '^' : 'Ctrl';
71
+ }
72
+ if (key === 'alt') {
73
+ return isMac ? '⎇' : 'Alt';
74
+ }
75
+ if (key === 'shift') {
76
+ return '⇧';
77
+ }
78
+ if (key === 'meta') {
79
+ return '⌘';
80
+ }
81
+ return key.charAt(0).toUpperCase() + key.substring(1).toLowerCase();
82
+ }
@@ -0,0 +1,99 @@
1
+ import { useEventListener } from '@vueuse/core'
2
+ import { isRef, Ref } from 'vue'
3
+ import { isMac } from './env.js'
4
+
5
+ export type KeyboardShortcut = string[]
6
+
7
+ export type KeyboardHandler = (event: KeyboardEvent) => unknown
8
+
9
+ export interface KeyboardShortcutOptions {
10
+ event?: 'keyup' | 'keydown' | 'keypress'
11
+ }
12
+
13
+ export function onKeyboardShortcut (shortcut: KeyboardShortcut | Ref<KeyboardShortcut>, handler: KeyboardHandler, options: KeyboardShortcutOptions = {}) {
14
+ useEventListener(options.event ?? 'keydown', event => {
15
+ if (isMatchingShortcut(isRef(shortcut) ? shortcut.value : shortcut)) {
16
+ handler(event)
17
+ }
18
+ })
19
+ }
20
+
21
+ const modifiers: { [i: string]: { key: string, pressed: boolean } } = {
22
+ ctrl: { key: 'Control', pressed: false },
23
+ alt: { key: 'Alt', pressed: false },
24
+ shift: { key: 'Shift', pressed: false },
25
+ meta: { key: 'Meta', pressed: false },
26
+ }
27
+
28
+ const pressedKeys = new Set<string>()
29
+
30
+ window.addEventListener('keydown', event => {
31
+ for (const i in modifiers) {
32
+ const mod = modifiers[i]
33
+ if (mod.key === event.key) {
34
+ mod.pressed = true
35
+ return
36
+ }
37
+ }
38
+ pressedKeys.add(event.key.toLocaleLowerCase())
39
+ })
40
+
41
+ window.addEventListener('keyup', event => {
42
+ requestAnimationFrame(() => {
43
+ pressedKeys.clear()
44
+ for (const i in modifiers) {
45
+ const mod = modifiers[i]
46
+ if (mod.key === event.key) {
47
+ mod.pressed = false
48
+ break
49
+ }
50
+ }
51
+ })
52
+ })
53
+
54
+ window.addEventListener('blur', () => {
55
+ pressedKeys.clear()
56
+ for (const i in modifiers) {
57
+ const mod = modifiers[i]
58
+ mod.pressed = false
59
+ }
60
+ })
61
+
62
+ function isMatchingShortcut (shortcut: KeyboardShortcut): boolean {
63
+ for (const combination of shortcut) {
64
+ if (isMatchingCombination(combination.toLowerCase())) {
65
+ return true
66
+ }
67
+ }
68
+ return false
69
+ }
70
+
71
+ function isMatchingCombination (combination: string): boolean {
72
+ const splitted = combination.split('+').map(key => key.trim())
73
+ const targetKey = splitted.pop()
74
+ for (const mod in modifiers) {
75
+ const containsMod = splitted.includes(mod)
76
+ const isPressed = modifiers[mod].pressed
77
+ if (containsMod !== isPressed) {
78
+ return false
79
+ }
80
+ }
81
+ return pressedKeys.has(targetKey)
82
+ }
83
+
84
+ export function formatKey (key: string) {
85
+ key = key.toLowerCase()
86
+ if (key === 'ctrl') {
87
+ return isMac ? '^' : 'Ctrl'
88
+ }
89
+ if (key === 'alt') {
90
+ return isMac ? '⎇' : 'Alt'
91
+ }
92
+ if (key === 'shift') {
93
+ return '⇧'
94
+ }
95
+ if (key === 'meta') {
96
+ return '⌘'
97
+ }
98
+ return key.charAt(0).toUpperCase() + key.substring(1).toLowerCase()
99
+ }
@@ -0,0 +1,3 @@
1
+ import type { StoryFile, Variant } from '../types';
2
+ export declare function mapFile(file: StoryFile, existingFile?: StoryFile): StoryFile;
3
+ export declare function mapVariant(variant: Variant): Variant;
@@ -0,0 +1,39 @@
1
+ import { markRaw } from 'vue';
2
+ export function mapFile(file, existingFile) {
3
+ const result = {
4
+ ...file,
5
+ component: markRaw(file.component),
6
+ story: {
7
+ ...file.story,
8
+ title: file.story.title,
9
+ file: markRaw(file),
10
+ variants: file.story.variants.map(v => mapVariant(v)),
11
+ },
12
+ };
13
+ if (existingFile) {
14
+ for (const index in result.story.variants) {
15
+ const variant = result.story.variants[index];
16
+ const existingVariant = existingFile.story.variants[index];
17
+ if (existingVariant) {
18
+ if (existingVariant.state)
19
+ Object.assign(variant.state, existingVariant.state);
20
+ if (existingVariant.initState)
21
+ variant.initState = existingVariant.initState;
22
+ if (existingVariant.slots)
23
+ variant.slots = existingVariant.slots;
24
+ }
25
+ }
26
+ if (existingFile.story.lastSelectedVariant) {
27
+ result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id);
28
+ }
29
+ }
30
+ return result;
31
+ }
32
+ export function mapVariant(variant) {
33
+ return {
34
+ ...variant,
35
+ state: {},
36
+ initState: null,
37
+ slots: () => ({}),
38
+ };
39
+ }
@@ -0,0 +1,41 @@
1
+ import { markRaw } from 'vue'
2
+ import type { StoryFile, Variant } from '../types'
3
+
4
+ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
5
+ const result: StoryFile = {
6
+ ...file,
7
+ component: markRaw(file.component),
8
+ story: {
9
+ ...file.story,
10
+ title: file.story.title,
11
+ file: markRaw(file),
12
+ variants: file.story.variants.map(v => mapVariant(v)),
13
+ },
14
+ }
15
+
16
+ if (existingFile) {
17
+ for (const index in result.story.variants) {
18
+ const variant = result.story.variants[index]
19
+ const existingVariant = existingFile.story.variants[index]
20
+ if (existingVariant) {
21
+ if (existingVariant.state) Object.assign(variant.state, existingVariant.state)
22
+ if (existingVariant.initState) variant.initState = existingVariant.initState
23
+ if (existingVariant.slots) variant.slots = existingVariant.slots
24
+ }
25
+ }
26
+ if (existingFile.story.lastSelectedVariant) {
27
+ result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id)
28
+ }
29
+ }
30
+
31
+ return result
32
+ }
33
+
34
+ export function mapVariant (variant: Variant): Variant {
35
+ return {
36
+ ...variant,
37
+ state: {},
38
+ initState: null,
39
+ slots: () => ({}),
40
+ }
41
+ }
@@ -0,0 +1,6 @@
1
+ export declare function makeTooltip(descriptionHtml: string, keyboardShortcut: ({ isMac: boolean }: {
2
+ isMac: any;
3
+ }) => string): {
4
+ content: string;
5
+ html: boolean;
6
+ };
@@ -0,0 +1,11 @@
1
+ import { isMac } from './env.js';
2
+ import { formatKey } from './keyboard.js';
3
+ export function makeTooltip(descriptionHtml, keyboardShortcut) {
4
+ return {
5
+ content: `<div>${descriptionHtml}</div><div class="htw-flex htw-items-center htw-gap-1 htw-mt-2 htw-text-sm">${genKeyboardShortcutHtml(keyboardShortcut({ isMac }))}</div>`,
6
+ html: true,
7
+ };
8
+ }
9
+ function genKeyboardShortcutHtml(shortcut) {
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
+ }
@@ -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
+ }
@@ -0,0 +1,8 @@
1
+ import type { App } from 'vue';
2
+ import type { Story, Variant } from './app/types.js';
3
+ export declare type Vue3StorySetupHandler = (payload: {
4
+ app: App;
5
+ story: Story;
6
+ variant: Variant;
7
+ }) => Promise<void> | void;
8
+ export declare function defineVue3StorySetup(handler: Vue3StorySetupHandler): Vue3StorySetupHandler;
@@ -0,0 +1,3 @@
1
+ export function defineVue3StorySetup(handler) {
2
+ return handler;
3
+ }
@@ -0,0 +1,12 @@
1
+ import type { App } from 'vue'
2
+ import type { Story, Variant } from './app/types.js'
3
+
4
+ export type Vue3StorySetupHandler = (payload: {
5
+ app: App
6
+ story: Story
7
+ variant: Variant
8
+ }) => Promise<void> | void
9
+
10
+ export function defineVue3StorySetup (handler: Vue3StorySetupHandler): Vue3StorySetupHandler {
11
+ return handler
12
+ }
@@ -0,0 +1,65 @@
1
+ <script lang="ts">
2
+ import { defineComponent, inject, PropType, provide, useAttrs } from 'vue'
3
+ import type { StoryFile, Story, Variant } from '../../node/types'
4
+
5
+ export default defineComponent({
6
+ inheritAttrs: false,
7
+
8
+ props: {
9
+ title: {
10
+ type: String,
11
+ required: true,
12
+ },
13
+
14
+ layout: {
15
+ type: Object as PropType<Story['layout']>,
16
+ default: () => ({ type: 'single' }),
17
+ },
18
+
19
+ icon: {
20
+ type: String,
21
+ default: null,
22
+ },
23
+
24
+ iconColor: {
25
+ type: String,
26
+ default: null,
27
+ },
28
+ },
29
+
30
+ setup (props) {
31
+ const attrs = useAttrs() as {
32
+ data: StoryFile
33
+ }
34
+
35
+ // Story
36
+
37
+ const story: Story = {
38
+ id: attrs.data.id,
39
+ title: props.title,
40
+ layout: props.layout,
41
+ icon: props.icon,
42
+ iconColor: props.iconColor,
43
+ variants: [],
44
+ }
45
+ const addStory = inject('addStory', null)
46
+ addStory?.(story)
47
+
48
+ // Variants
49
+
50
+ provide('story', story)
51
+
52
+ provide('addVariant', (variant: Variant) => {
53
+ story.variants.push(variant)
54
+ })
55
+
56
+ return {
57
+ story,
58
+ }
59
+ },
60
+
61
+ render () {
62
+ return this.$slots.default()
63
+ },
64
+ })
65
+ </script>
@@ -0,0 +1,50 @@
1
+ <script lang="ts">
2
+ import { defineComponent, inject } from 'vue'
3
+ import type { Story, Variant } from '../../node/types'
4
+
5
+ export default defineComponent({
6
+ props: {
7
+ title: {
8
+ type: String,
9
+ default: 'untitled',
10
+ },
11
+
12
+ id: {
13
+ type: String,
14
+ default: null,
15
+ },
16
+
17
+ icon: {
18
+ type: String,
19
+ default: null,
20
+ },
21
+
22
+ iconColor: {
23
+ type: String,
24
+ default: null,
25
+ },
26
+ },
27
+
28
+ setup (props) {
29
+ const story = inject<Story>('story')
30
+
31
+ function generateId () {
32
+ return `${story.id}-${story.variants.length}`
33
+ }
34
+
35
+ const variant: Variant = {
36
+ id: props.id ?? generateId(),
37
+ title: props.title,
38
+ icon: props.icon,
39
+ iconColor: props.iconColor,
40
+ }
41
+
42
+ const addVariant = inject('addVariant') as (variant: Variant) => void
43
+ addVariant(variant)
44
+ },
45
+
46
+ render () {
47
+ return null
48
+ },
49
+ })
50
+ </script>
@@ -0,0 +1,2 @@
1
+ import type { StoryFile } from '../../node/types';
2
+ export declare function run(file: StoryFile, storyData: any, el: any): Promise<void>;
@@ -0,0 +1,25 @@
1
+ import { createApp, h } from 'vue';
2
+ import Story from './Story.server.vue';
3
+ import Variant from './Variant.server.vue';
4
+ export async function run(file, storyData, el) {
5
+ const { default: Comp } = await import(file.moduleId);
6
+ const app = createApp({
7
+ provide: {
8
+ addStory(data) {
9
+ storyData.push(data);
10
+ },
11
+ },
12
+ render() {
13
+ return h(Comp, {
14
+ ref: 'comp',
15
+ data: file,
16
+ });
17
+ },
18
+ });
19
+ // eslint-disable-next-line vue/multi-word-component-names
20
+ app.component('Story', Story);
21
+ // eslint-disable-next-line vue/multi-word-component-names
22
+ app.component('Variant', Variant);
23
+ app.mount(el);
24
+ app.unmount();
25
+ }
@@ -0,0 +1,29 @@
1
+ import { createApp, h } from 'vue'
2
+ import type { StoryFile } from '../../node/types'
3
+ import Story from './Story.server.vue'
4
+ import Variant from './Variant.server.vue'
5
+
6
+ export async function run (file: StoryFile, storyData, el) {
7
+ const { default: Comp } = await import(file.moduleId)
8
+ const app = createApp({
9
+ provide: {
10
+ addStory (data) {
11
+ storyData.push(data)
12
+ },
13
+ },
14
+ render () {
15
+ return h(Comp, {
16
+ ref: 'comp',
17
+ data: file,
18
+ })
19
+ },
20
+ })
21
+
22
+ // eslint-disable-next-line vue/multi-word-component-names
23
+ app.component('Story', Story)
24
+ // eslint-disable-next-line vue/multi-word-component-names
25
+ app.component('Variant', Variant)
26
+
27
+ app.mount(el)
28
+ app.unmount()
29
+ }
@@ -0,0 +1,5 @@
1
+ declare module '*.vue' {
2
+ import { ComponentOptions } from 'vue'
3
+ const comp: ComponentOptions
4
+ export default comp
5
+ }
@@ -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
@@ -10,8 +10,13 @@ program.command('dev')
10
10
  .describe('open the stories in your browser for development')
11
11
  .option('-p, --port <port>', 'Listening port of the server')
12
12
  .action(async (options) => {
13
- const { dev } = await import('./commands/dev.js');
14
- return dev(options);
13
+ const { devCommand } = await import('./commands/dev.js');
14
+ return devCommand(options);
15
+ });
16
+ program.command('build')
17
+ .describe('build the histoire final app you can deploy')
18
+ .action(async () => {
19
+ const { buildCommand } = await import('./commands/build.js');
20
+ return buildCommand();
15
21
  });
16
22
  program.parse(process.argv);
17
- //# sourceMappingURL=bin.js.map
@@ -0,0 +1,2 @@
1
+ import { Context } from './context.js';
2
+ export declare function build(ctx: Context): Promise<void>;