histoire 0.2.3 → 0.3.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 (178) hide show
  1. package/dist/client/app/App.vue +9 -4
  2. package/dist/client/app/codegen/const.d.ts +1 -0
  3. package/dist/client/app/codegen/const.js +3 -0
  4. package/dist/client/app/codegen/vue3.js +82 -21
  5. package/dist/client/app/components/app/AppHeader.vue +2 -2
  6. package/dist/client/app/components/app/Breadcrumb.vue +1 -1
  7. package/dist/client/app/components/base/BaseEmpty.vue +17 -1
  8. package/dist/client/app/components/base/BaseListItemLink.vue +1 -1
  9. package/dist/client/app/components/base/BaseTab.vue +1 -1
  10. package/dist/client/app/components/exposed/Story.vue +22 -1
  11. package/dist/client/app/components/exposed/Variant.vue +13 -1
  12. package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -4
  13. package/dist/client/app/components/sandbox/lib.js +2 -1
  14. package/dist/client/app/components/search/SearchItem.vue +1 -0
  15. package/dist/client/app/components/search/SearchLoading.vue +16 -0
  16. package/dist/client/app/components/search/SearchModal.vue +12 -148
  17. package/dist/client/app/components/search/SearchPane.vue +210 -0
  18. package/dist/client/app/components/search/search-data.d.ts +2 -0
  19. package/dist/client/app/components/search/search-data.js +7 -0
  20. package/dist/client/app/components/story/StoryControls.vue +5 -0
  21. package/dist/client/app/components/story/StoryDocs.vue +18 -11
  22. package/dist/client/app/components/story/StoryEvent.vue +53 -0
  23. package/dist/client/app/components/story/StoryEvents.vue +45 -0
  24. package/dist/client/app/components/story/StoryResponsivePreview.vue +41 -8
  25. package/dist/client/app/components/story/StorySidePanel.vue +28 -3
  26. package/dist/client/app/components/story/StorySourceCode.vue +24 -14
  27. package/dist/client/app/components/story/StoryView.vue +16 -2
  28. package/dist/client/app/components/story/toolbar/StoryVariantNewTab.vue +1 -1
  29. package/dist/client/app/components/tree/StoryGroup.vue +75 -0
  30. package/dist/client/app/components/{story → tree}/StoryList.vue +8 -2
  31. package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListFolder.vue +10 -8
  32. package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListItem.vue +7 -4
  33. package/dist/client/app/router.d.ts +1 -0
  34. package/dist/client/app/router.js +3 -1
  35. package/dist/client/app/sandbox.js +11 -1
  36. package/dist/client/app/stores/events.d.ts +29 -0
  37. package/dist/client/app/stores/events.js +25 -0
  38. package/dist/client/app/stores/folder.d.ts +10 -0
  39. package/dist/client/app/stores/folder.js +47 -0
  40. package/dist/client/app/stores/story.d.ts +20 -8
  41. package/dist/client/app/stores/story.js +20 -28
  42. package/dist/client/app/style/floating-vue.pcss +3 -1
  43. package/dist/client/app/style/main.pcss +5 -0
  44. package/dist/client/app/style/sandbox.css +2 -0
  45. package/dist/client/app/types.d.ts +9 -1
  46. package/dist/client/app/util/const.d.ts +1 -0
  47. package/dist/client/app/util/const.js +1 -0
  48. package/dist/client/app/util/events.d.ts +1 -0
  49. package/dist/client/app/util/events.js +31 -0
  50. package/dist/client/app/util/mapping.js +2 -2
  51. package/dist/client/index.d.ts +2 -1
  52. package/dist/client/index.js +2 -1
  53. package/dist/client/server/Story.server.vue +21 -4
  54. package/dist/node/alias.d.ts +2 -1
  55. package/dist/node/alias.js +3 -2
  56. package/dist/node/build.js +74 -21
  57. package/dist/node/builtin-plugins/tailwind-tokens.d.ts +5 -0
  58. package/dist/node/builtin-plugins/tailwind-tokens.js +510 -0
  59. package/dist/node/collect/index.js +5 -3
  60. package/dist/node/commands/preview.js +4 -25
  61. package/dist/node/config.d.ts +111 -5
  62. package/dist/node/config.js +40 -23
  63. package/dist/node/context.d.ts +3 -3
  64. package/dist/node/context.js +1 -1
  65. package/dist/node/index.d.ts +1 -0
  66. package/dist/node/index.js +1 -0
  67. package/dist/node/load.d.ts +12 -0
  68. package/dist/node/load.js +42 -0
  69. package/dist/node/plugin.d.ts +67 -11
  70. package/dist/node/plugin.js +42 -245
  71. package/dist/node/preview.d.ts +8 -0
  72. package/dist/node/preview.js +41 -0
  73. package/dist/node/search.d.ts +2 -0
  74. package/dist/node/search.js +68 -0
  75. package/dist/node/server.js +43 -21
  76. package/dist/node/stories.d.ts +2 -0
  77. package/dist/node/stories.js +9 -4
  78. package/dist/node/tree.d.ts +16 -12
  79. package/dist/node/tree.js +45 -5
  80. package/dist/node/types.d.ts +11 -0
  81. package/dist/node/util/find-up.d.ts +1 -0
  82. package/dist/node/util/find-up.js +20 -0
  83. package/dist/node/vite.d.ts +13 -0
  84. package/dist/node/vite.js +278 -0
  85. package/dist/style.css +179 -36
  86. package/package.json +5 -3
  87. package/scripts/copy.mjs +2 -1
  88. package/src/client/app/App.vue +9 -4
  89. package/src/client/app/codegen/const.ts +3 -0
  90. package/src/client/app/codegen/vue3.ts +80 -22
  91. package/src/client/app/components/app/AppHeader.vue +2 -2
  92. package/src/client/app/components/app/Breadcrumb.vue +1 -1
  93. package/src/client/app/components/base/BaseEmpty.vue +17 -1
  94. package/src/client/app/components/base/BaseListItemLink.vue +1 -1
  95. package/src/client/app/components/base/BaseTab.vue +1 -1
  96. package/src/client/app/components/exposed/Story.vue +22 -1
  97. package/src/client/app/components/exposed/Variant.vue +13 -1
  98. package/src/client/app/components/sandbox/SandboxVue3.vue +6 -4
  99. package/src/client/app/components/sandbox/lib.ts +3 -1
  100. package/src/client/app/components/search/SearchItem.vue +1 -0
  101. package/src/client/app/components/search/SearchLoading.vue +16 -0
  102. package/src/client/app/components/search/SearchModal.vue +12 -148
  103. package/src/client/app/components/search/SearchPane.vue +210 -0
  104. package/src/client/app/components/search/search-data.ts +9 -0
  105. package/src/client/app/components/story/StoryControls.vue +5 -0
  106. package/src/client/app/components/story/StoryDocs.vue +18 -11
  107. package/src/client/app/components/story/StoryEvent.vue +53 -0
  108. package/src/client/app/components/story/StoryEvents.vue +45 -0
  109. package/src/client/app/components/story/StoryResponsivePreview.vue +41 -8
  110. package/src/client/app/components/story/StorySidePanel.vue +28 -3
  111. package/src/client/app/components/story/StorySourceCode.vue +24 -14
  112. package/src/client/app/components/story/StoryView.vue +16 -2
  113. package/src/client/app/components/story/toolbar/StoryVariantNewTab.vue +1 -1
  114. package/src/client/app/components/tree/StoryGroup.vue +75 -0
  115. package/src/client/app/components/{story → tree}/StoryList.vue +8 -2
  116. package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListFolder.vue +10 -8
  117. package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListItem.vue +7 -4
  118. package/src/client/app/router.ts +4 -1
  119. package/src/client/app/sandbox.ts +12 -2
  120. package/src/client/app/stores/events.ts +36 -0
  121. package/src/client/app/stores/folder.ts +59 -0
  122. package/src/client/app/stores/story.ts +20 -35
  123. package/src/client/app/style/floating-vue.pcss +3 -1
  124. package/src/client/app/style/main.pcss +5 -0
  125. package/src/client/app/style/sandbox.css +2 -0
  126. package/src/client/app/types.ts +10 -1
  127. package/src/client/app/util/const.ts +1 -0
  128. package/src/client/app/util/events.ts +30 -0
  129. package/src/client/app/util/mapping.ts +2 -2
  130. package/src/client/index.ts +2 -1
  131. package/src/client/server/Story.server.vue +21 -4
  132. package/src/node/alias.ts +4 -2
  133. package/src/node/build.ts +86 -21
  134. package/src/node/builtin-plugins/tailwind-tokens.ts +521 -0
  135. package/src/node/collect/index.ts +6 -4
  136. package/src/node/commands/preview.ts +4 -33
  137. package/src/node/config.ts +62 -29
  138. package/src/node/context.ts +3 -3
  139. package/src/node/index.ts +1 -0
  140. package/src/node/load.ts +63 -0
  141. package/src/node/plugin.ts +75 -252
  142. package/src/node/preview.ts +56 -0
  143. package/src/node/search.ts +75 -0
  144. package/src/node/server.ts +49 -23
  145. package/src/node/stories.ts +9 -4
  146. package/src/node/tree.spec.ts +35 -17
  147. package/src/node/tree.ts +64 -10
  148. package/src/node/types.ts +12 -0
  149. package/src/node/util/find-up.ts +24 -0
  150. package/src/node/vite.ts +296 -0
  151. package/tailwind.config.cjs +1 -0
  152. package/tsconfig.json +2 -0
  153. package/dist/client/app/codegen/serialize-js.ts +0 -119
  154. package/dist/client/app/codegen/util.ts +0 -79
  155. package/dist/client/app/codegen/vue3.ts +0 -276
  156. package/dist/client/app/components/sandbox/lib.ts +0 -8
  157. package/dist/client/app/global-components.ts +0 -13
  158. package/dist/client/app/index.ts +0 -28
  159. package/dist/client/app/router.ts +0 -17
  160. package/dist/client/app/sandbox.ts +0 -94
  161. package/dist/client/app/stores/preview-settings.ts +0 -17
  162. package/dist/client/app/stores/story.ts +0 -62
  163. package/dist/client/app/types.ts +0 -70
  164. package/dist/client/app/util/config.ts +0 -6
  165. package/dist/client/app/util/const.ts +0 -3
  166. package/dist/client/app/util/dark.ts +0 -4
  167. package/dist/client/app/util/env.ts +0 -1
  168. package/dist/client/app/util/keyboard.ts +0 -99
  169. package/dist/client/app/util/mapping.ts +0 -48
  170. package/dist/client/app/util/preview-settings.ts +0 -8
  171. package/dist/client/app/util/reactivity.ts +0 -22
  172. package/dist/client/app/util/responsive.ts +0 -3
  173. package/dist/client/app/util/scroll.ts +0 -31
  174. package/dist/client/app/util/tooltip.ts +0 -13
  175. package/dist/client/app/util/variant.ts +0 -20
  176. package/dist/client/index.ts +0 -12
  177. package/dist/client/server/index.ts +0 -32
  178. package/dist/client/shim.d.ts +0 -5
@@ -1,99 +0,0 @@
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
- }
@@ -1,48 +0,0 @@
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
- for (const key in existingVariant) {
22
- if (typeof existingVariant[key] !== 'undefined') {
23
- if (key === 'state') {
24
- Object.assign(variant.state, existingVariant.state)
25
- continue
26
- }
27
- variant[key] = existingVariant[key]
28
- }
29
- }
30
- }
31
- }
32
- if (existingFile.story.lastSelectedVariant) {
33
- result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id)
34
- }
35
- }
36
-
37
- return result
38
- }
39
-
40
- export function mapVariant (variant: Variant): Variant {
41
- return {
42
- ...variant,
43
- state: {},
44
- initState: null,
45
- slots: () => ({}),
46
- previewReady: false,
47
- }
48
- }
@@ -1,8 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- }, {})
@@ -1,3 +0,0 @@
1
- import { useMediaQuery } from '@vueuse/core'
2
-
3
- export const isMobile = useMediaQuery('(max-width: 640px)')
@@ -1,31 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
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
- }
@@ -1,20 +0,0 @@
1
- import { computed, Ref } from 'vue'
2
- import { useRoute } from 'vue-router'
3
- import { 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
- }
@@ -1,12 +0,0 @@
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
- }
@@ -1,32 +0,0 @@
1
- import { createApp, h } from 'vue'
2
- import { registerVueComponents } from '@histoire/controls'
3
- import type { StoryFile } from '../../node/types'
4
- import Story from './Story.server.vue'
5
- import Variant from './Variant.server.vue'
6
-
7
- export async function run (file: StoryFile, storyData, el) {
8
- const { default: Comp } = await import(file.moduleId)
9
- const app = createApp({
10
- provide: {
11
- addStory (data) {
12
- storyData.push(data)
13
- },
14
- },
15
- render () {
16
- return h(Comp, {
17
- ref: 'comp',
18
- data: file,
19
- })
20
- },
21
- })
22
-
23
- // eslint-disable-next-line vue/multi-word-component-names
24
- app.component('Story', Story)
25
- // eslint-disable-next-line vue/multi-word-component-names
26
- app.component('Variant', Variant)
27
-
28
- registerVueComponents(app)
29
-
30
- app.mount(el)
31
- app.unmount()
32
- }
@@ -1,5 +0,0 @@
1
- declare module '*.vue' {
2
- import { ComponentOptions } from 'vue'
3
- const comp: ComponentOptions
4
- export default comp
5
- }