@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,46 @@
1
+ import type { RouteLocationRaw } from 'vue-router'
2
+
3
+ export type {
4
+ StoryFile,
5
+ StoryLayout,
6
+ Story,
7
+ Variant,
8
+ } from '@histoire/shared'
9
+
10
+ export type TreeLeaf = {
11
+ title: string
12
+ index: number
13
+ }
14
+
15
+ export type TreeFolder = {
16
+ title: string
17
+ children: (TreeFolder | TreeLeaf)[]
18
+ }
19
+
20
+ export interface TreeGroup {
21
+ group: true
22
+ id: string
23
+ title: string
24
+ children: (TreeFolder | TreeLeaf)[]
25
+ }
26
+
27
+ export type Tree = (TreeGroup | TreeFolder | TreeLeaf)[]
28
+
29
+ export interface SearchResult {
30
+ kind: 'story' | 'variant'
31
+ rank: number
32
+ id: string
33
+ title: string
34
+ route: RouteLocationRaw
35
+ path?: string[]
36
+ icon?: string
37
+ iconColor?: string
38
+ }
39
+
40
+ export interface PreviewSettings {
41
+ responsiveWidth: number
42
+ responsiveHeight: number
43
+ rotate: boolean
44
+ backgroundColor: string
45
+ checkerboard: boolean
46
+ }
@@ -0,0 +1,6 @@
1
+ import type { HistoireConfig } from '../../../../histoire/src/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,4 @@
1
+ export const STATE_SYNC = '__histoire:state-sync'
2
+ export const SANDBOX_READY = '__histoire:sandbox-ready'
3
+ export const EVENT_SEND = '__histoire:event'
4
+ export const PREVIEW_SETTINGS_SYNC = '__histoire:preview-settings-sync'
@@ -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 const isMac = navigator.platform.toLowerCase().includes('mac')
@@ -0,0 +1,30 @@
1
+ import { EVENT_SEND } from './const'
2
+
3
+ export async function hstEvent (name: string, argument) {
4
+ console.log('[histoire] Event fired', { name, argument })
5
+ const event = {
6
+ name,
7
+ argument: JSON.parse(stringifyEvent(argument)), // Needed for HTMLEvent that can't be cloned
8
+ }
9
+ if (location.href.includes('__sandbox')) {
10
+ window.parent?.postMessage({
11
+ type: EVENT_SEND,
12
+ event,
13
+ })
14
+ } else {
15
+ const { useEventsStore } = await import('../stores/events.js')
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
+ }
@@ -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,76 @@
1
+ import { markRaw, reactive } from 'vue'
2
+ import type { StoryFile, Variant } from '../types'
3
+
4
+ const copiedFromExistingVariant = [
5
+ 'state',
6
+ 'slots',
7
+ 'source',
8
+ 'responsiveDisabled',
9
+ 'autoPropsDisabled',
10
+ 'setupApp',
11
+ 'configReady',
12
+ 'previewReady',
13
+ ]
14
+
15
+ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
16
+ let result: StoryFile
17
+
18
+ if (existingFile) {
19
+ // Update
20
+ result = existingFile
21
+ for (const key in file) {
22
+ if (key === 'story') {
23
+ Object.assign(result.story, {
24
+ ...file.story,
25
+ file: markRaw(result),
26
+ variants: file.story.variants.map(v => mapVariant(v, existingFile.story.variants.find(item => item.id === v.id))),
27
+ })
28
+ } else if (key !== 'component') {
29
+ result[key] = file[key]
30
+ }
31
+ }
32
+ } else {
33
+ // Create
34
+ result = {
35
+ ...file,
36
+ component: markRaw(file.component),
37
+ story: {
38
+ ...file.story,
39
+ title: file.story.title,
40
+ file: markRaw(file),
41
+ variants: file.story.variants.map(v => mapVariant(v)),
42
+ slots: () => ({}),
43
+ },
44
+ }
45
+ }
46
+
47
+ return result
48
+ }
49
+
50
+ export function mapVariant (variant: Variant, existingVariant?: Variant): Variant {
51
+ let result: Variant
52
+
53
+ if (existingVariant) {
54
+ // Update
55
+ result = existingVariant
56
+ for (const key in variant) {
57
+ if (!copiedFromExistingVariant.includes(key)) {
58
+ result[key] = variant[key]
59
+ }
60
+ }
61
+ } else {
62
+ // Create
63
+ result = {
64
+ ...variant,
65
+ state: reactive({
66
+ _hPropState: {},
67
+ _hPropDefs: {},
68
+ }),
69
+ setupApp: null,
70
+ slots: () => ({}),
71
+ previewReady: false,
72
+ }
73
+ }
74
+
75
+ return result
76
+ }
@@ -0,0 +1,8 @@
1
+ import { reactive } from 'vue'
2
+ import type { PreviewSettings } from '../types'
3
+
4
+ export const receivedSettings = reactive<PreviewSettings>({} as PreviewSettings)
5
+
6
+ export function applyPreviewSettings (settings: PreviewSettings) {
7
+ Object.assign(receivedSettings, settings)
8
+ }
@@ -0,0 +1,3 @@
1
+ import { useMediaQuery } from '@vueuse/core'
2
+
3
+ export const isMobile = useMediaQuery('(max-width: 640px)')
@@ -0,0 +1,10 @@
1
+
2
+ import { base } from '../router'
3
+ import { Story, Variant } from '../types'
4
+
5
+ export function getSandboxUrl (story: Story, variant: Variant) {
6
+ const url = new URLSearchParams()
7
+ url.append('storyId', story.id)
8
+ url.append('variantId', variant.id)
9
+ return `${base}__sandbox.html?${url.toString()}`
10
+ }
@@ -0,0 +1,31 @@
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
+
28
+ return {
29
+ autoScroll,
30
+ }
31
+ }
@@ -0,0 +1,37 @@
1
+ import { unref, isRef } from 'vue'
2
+
3
+ const isObject = (val) => val !== null && typeof val === 'object'
4
+
5
+ export function toRawDeep (val, seen = new WeakMap()) {
6
+ const unwrappedValue = isRef(val) ? unref(val) : val
7
+
8
+ if (typeof unwrappedValue === 'symbol') {
9
+ return unwrappedValue.toString()
10
+ }
11
+
12
+ if (!isObject(unwrappedValue)) {
13
+ return unwrappedValue
14
+ }
15
+
16
+ if (seen.has(unwrappedValue)) {
17
+ return seen.get(unwrappedValue)
18
+ }
19
+
20
+ if (Array.isArray(unwrappedValue)) {
21
+ const result = []
22
+ seen.set(unwrappedValue, result)
23
+ result.push(...unwrappedValue.map(value => toRawDeep(value, seen)))
24
+ return result
25
+ } else {
26
+ const result = {}
27
+ seen.set(unwrappedValue, result)
28
+ toRawObject(unwrappedValue, result, seen)
29
+ return result
30
+ }
31
+ }
32
+
33
+ const toRawObject = (obj: Record<any, any>, target: Record<any, any>, seen = new WeakMap()) => {
34
+ Object.keys(obj).forEach((key) => {
35
+ target[key] = toRawDeep(obj[key], seen)
36
+ })
37
+ }
@@ -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,20 @@
1
+ import { computed, Ref } from 'vue'
2
+ import { useRoute } from 'vue-router'
3
+ import type { Variant } from '../types'
4
+
5
+ export function useCurrentVariantRoute (variant: Ref<Variant>) {
6
+ const route = useRoute()
7
+ const isActive = computed(() => route.query.variantId === variant.value.id)
8
+ const targetRoute = computed(() => ({
9
+ ...route,
10
+ query: {
11
+ ...route.query,
12
+ variantId: variant.value.id,
13
+ },
14
+ }))
15
+
16
+ return {
17
+ isActive,
18
+ targetRoute,
19
+ }
20
+ }
@@ -0,0 +1 @@
1
+ export * from './bundled/api.js'
@@ -0,0 +1,5 @@
1
+ import './style.css'
2
+ import './bundled/style.css'
3
+ import { mountMainApp } from './bundled/index.js'
4
+
5
+ mountMainApp()
@@ -0,0 +1,2 @@
1
+ import './app/style/sandbox.css'
2
+ import './bundled/sandbox.js'
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './app/api.js'
package/src/shim.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ declare module '*.vue' {
4
+ import { ComponentOptions } from 'vue'
5
+ const comp: ComponentOptions
6
+ export default comp
7
+ }
@@ -0,0 +1,126 @@
1
+
2
+ const inheritedConfig = require('../../tailwind.config.cjs')
3
+ const defaultColors = require('tailwindcss/colors')
4
+ const path = require('pathe')
5
+
6
+ // Colors
7
+
8
+ function withOpacityValue (variable) {
9
+ return ({ opacityValue }) => {
10
+ if (opacityValue === undefined) {
11
+ return `rgb(var(${variable}))`
12
+ }
13
+ return `rgb(var(${variable}) / ${opacityValue})`
14
+ }
15
+ }
16
+
17
+ const colorKeys = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900]
18
+ const grayKeys = [...colorKeys, 750, 850, 950]
19
+ const themedColors = ['primary', 'gray'].reduce((acc, color) => {
20
+ const keys = (color === 'gray' ? grayKeys : colorKeys)
21
+ for (const key of keys) {
22
+ acc[`${color}-${key}`] = withOpacityValue(`--_histoire-color-${color}-${key}`)
23
+ }
24
+ return acc
25
+ }, {})
26
+
27
+ const excludedDefaultColors = [
28
+ // Grays
29
+ 'slate',
30
+ 'gray',
31
+ 'zinc',
32
+ 'neutral',
33
+ 'stone',
34
+ // Deprecated colors
35
+ 'lightBlue',
36
+ 'warmGray',
37
+ 'trueGray',
38
+ 'coolGray',
39
+ 'blueGray',
40
+ ]
41
+
42
+ const includedDefaultColors = {}
43
+ for (const key in defaultColors) {
44
+ if (!excludedDefaultColors.includes(key)) {
45
+ includedDefaultColors[key] = defaultColors[key]
46
+ }
47
+ }
48
+
49
+ const colors = {
50
+ ...includedDefaultColors,
51
+ white: '#fff',
52
+ black: '#000',
53
+ transparent: 'transparent',
54
+ ...themedColors,
55
+ }
56
+
57
+ module.exports = {
58
+ ...inheritedConfig,
59
+ prefix: 'htw-',
60
+ content: [
61
+ './src/**/*.{vue,js,ts,jsx,tsx,md}',
62
+ // Include controls CSS directly
63
+ path.resolve(__dirname, '../histoire-controls/src/**/*.{vue,js,ts,jsx,tsx,md}'),
64
+ ],
65
+ corePlugins: {
66
+ preflight: false,
67
+ },
68
+ }
69
+
70
+ delete module.exports.theme.extend.colors.primary
71
+ delete module.exports.theme.extend.colors.gray
72
+ module.exports.theme.colors = colors
73
+
74
+ module.exports.plugins.push(require('@tailwindcss/typography'))
75
+ // prose-a:htw-text-primary-500 prose-headings:htw-mb-2 prose-headings:htw-mt-4 first:prose-headings:htw-mt-0 prose-blockquote:htw-ml-0
76
+ module.exports.theme.extend.typography = (theme) => ({
77
+ DEFAULT: {
78
+ css: {
79
+ a: {
80
+ color: theme('colors.primary-500'),
81
+ textDecoration: 'none',
82
+
83
+ '&:hover': {
84
+ textDecoration: 'underline',
85
+ },
86
+ },
87
+
88
+ 'h1, h2, h3, h4, th': {
89
+ marginBottom: '0.75rem',
90
+
91
+ '&:not(:first-child)': {
92
+ marginTop: '1.25rem',
93
+ },
94
+ },
95
+
96
+ '--tw-prose-invert-quote-borders': theme('colors.gray-800'),
97
+ '--tw-prose-invert-hr': theme('colors.gray-800'),
98
+
99
+ blockquote: {
100
+ marginLeft: 0,
101
+ marginRight: 0,
102
+ backgroundColor: theme('colors.gray-100'),
103
+ padding: '.25rem .375rem',
104
+
105
+ '& p:first-child': {
106
+ marginTop: 0,
107
+ },
108
+
109
+ '& p:last-child': {
110
+ marginBottom: 0,
111
+ },
112
+
113
+ '.dark &': {
114
+ backgroundColor: theme('colors.gray-750'),
115
+ },
116
+ },
117
+
118
+ '--tw-prose-invert-bullets': theme('colors.gray-500'),
119
+
120
+ li: {
121
+ marginTop: '0.1rem',
122
+ marginBottom: '0.1rem',
123
+ },
124
+ },
125
+ },
126
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "node",
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "baseUrl": ".",
9
+ "allowSyntheticDefaultImports": true,
10
+ "esModuleInterop": true,
11
+ "removeComments": false,
12
+ "resolveJsonModule": true,
13
+ "skipLibCheck": true,
14
+ "types": [
15
+ "node",
16
+ "@peeky/test"
17
+ ],
18
+ "lib": [
19
+ "ESNext",
20
+ "DOM"
21
+ ],
22
+ "sourceMap": false,
23
+ "preserveWatchOutput": true,
24
+ "preserveSymlinks": true,
25
+ "declaration": false,
26
+ // Strict
27
+ "noImplicitAny": false,
28
+ "noImplicitThis": true,
29
+ "alwaysStrict": true,
30
+ "strictBindCallApply": true,
31
+ "strictFunctionTypes": true,
32
+ // Volar
33
+ "jsx": "preserve",
34
+ // Alias
35
+ "paths": {
36
+ "floating-vue": ["node_modules/@histoire/vendors/floating-vue"],
37
+ "@iconify/vue": ["node_modules/@histoire/vendors/iconify"],
38
+ "pinia": ["node_modules/@histoire/vendors/pinia"],
39
+ "scroll-into-view-if-needed": ["node_modules/@histoire/vendors/scroll"],
40
+ "vue-router": ["node_modules/@histoire/vendors/vue-router"],
41
+ "@vueuse/core": ["node_modules/@histoire/vendors/vue-use"],
42
+ "vue": ["node_modules/@histoire/vendors/vue"]
43
+ }
44
+ },
45
+ "include": [
46
+ "src"
47
+ ],
48
+ "exclude": [
49
+ "node_modules",
50
+ "generated/**/*",
51
+ "dist/**/*",
52
+ "src/**/*.spec.ts"
53
+ ]
54
+ }