histoire 0.2.5 → 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 (156) hide show
  1. package/dist/client/app/App.vue +8 -3
  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/base/BaseEmpty.vue +17 -1
  6. package/dist/client/app/components/exposed/Story.vue +22 -1
  7. package/dist/client/app/components/exposed/Variant.vue +13 -1
  8. package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -4
  9. package/dist/client/app/components/sandbox/lib.js +2 -1
  10. package/dist/client/app/components/search/SearchLoading.vue +16 -0
  11. package/dist/client/app/components/search/SearchModal.vue +12 -149
  12. package/dist/client/app/components/search/SearchPane.vue +210 -0
  13. package/dist/client/app/components/search/search-data.d.ts +2 -0
  14. package/dist/client/app/components/search/search-data.js +7 -0
  15. package/dist/client/app/components/story/StoryControls.vue +5 -0
  16. package/dist/client/app/components/story/StoryDocs.vue +18 -11
  17. package/dist/client/app/components/story/StoryEvent.vue +53 -0
  18. package/dist/client/app/components/story/StoryEvents.vue +45 -0
  19. package/dist/client/app/components/story/StoryResponsivePreview.vue +41 -8
  20. package/dist/client/app/components/story/StorySidePanel.vue +28 -3
  21. package/dist/client/app/components/story/StorySourceCode.vue +24 -14
  22. package/dist/client/app/components/story/StoryView.vue +16 -2
  23. package/dist/client/app/components/tree/StoryGroup.vue +4 -4
  24. package/dist/client/app/components/tree/StoryListFolder.vue +4 -4
  25. package/dist/client/app/components/tree/StoryListItem.vue +4 -1
  26. package/dist/client/app/router.d.ts +1 -0
  27. package/dist/client/app/router.js +3 -1
  28. package/dist/client/app/sandbox.js +11 -1
  29. package/dist/client/app/stores/events.d.ts +29 -0
  30. package/dist/client/app/stores/events.js +25 -0
  31. package/dist/client/app/stores/folder.d.ts +10 -0
  32. package/dist/client/app/stores/folder.js +47 -0
  33. package/dist/client/app/stores/story.d.ts +14 -8
  34. package/dist/client/app/stores/story.js +20 -33
  35. package/dist/client/app/style/main.pcss +5 -0
  36. package/dist/client/app/style/sandbox.css +2 -0
  37. package/dist/client/app/types.d.ts +1 -0
  38. package/dist/client/app/util/const.d.ts +1 -0
  39. package/dist/client/app/util/const.js +1 -0
  40. package/dist/client/app/util/events.d.ts +1 -0
  41. package/dist/client/app/util/events.js +31 -0
  42. package/dist/client/app/util/mapping.js +2 -2
  43. package/dist/client/index.d.ts +2 -1
  44. package/dist/client/index.js +2 -1
  45. package/dist/client/server/Story.server.vue +13 -2
  46. package/dist/node/alias.d.ts +2 -1
  47. package/dist/node/alias.js +3 -2
  48. package/dist/node/build.js +74 -21
  49. package/dist/node/builtin-plugins/tailwind-tokens.d.ts +5 -0
  50. package/dist/node/builtin-plugins/tailwind-tokens.js +510 -0
  51. package/dist/node/collect/index.js +3 -1
  52. package/dist/node/commands/preview.js +4 -25
  53. package/dist/node/config.d.ts +103 -3
  54. package/dist/node/config.js +40 -23
  55. package/dist/node/context.d.ts +3 -3
  56. package/dist/node/context.js +1 -1
  57. package/dist/node/index.d.ts +1 -0
  58. package/dist/node/index.js +1 -0
  59. package/dist/node/load.d.ts +12 -0
  60. package/dist/node/load.js +42 -0
  61. package/dist/node/plugin.d.ts +67 -11
  62. package/dist/node/plugin.js +42 -245
  63. package/dist/node/preview.d.ts +8 -0
  64. package/dist/node/preview.js +41 -0
  65. package/dist/node/search.d.ts +2 -0
  66. package/dist/node/search.js +68 -0
  67. package/dist/node/server.js +43 -21
  68. package/dist/node/stories.d.ts +2 -0
  69. package/dist/node/stories.js +4 -4
  70. package/dist/node/types.d.ts +1 -0
  71. package/dist/node/util/find-up.d.ts +1 -0
  72. package/dist/node/util/find-up.js +20 -0
  73. package/dist/node/vite.d.ts +13 -0
  74. package/dist/node/vite.js +278 -0
  75. package/dist/style.css +111 -47
  76. package/package.json +5 -3
  77. package/scripts/copy.mjs +2 -1
  78. package/src/client/app/App.vue +8 -3
  79. package/src/client/app/codegen/const.ts +3 -0
  80. package/src/client/app/codegen/vue3.ts +80 -22
  81. package/src/client/app/components/base/BaseEmpty.vue +17 -1
  82. package/src/client/app/components/exposed/Story.vue +22 -1
  83. package/src/client/app/components/exposed/Variant.vue +13 -1
  84. package/src/client/app/components/sandbox/SandboxVue3.vue +6 -4
  85. package/src/client/app/components/sandbox/lib.ts +3 -1
  86. package/src/client/app/components/search/SearchLoading.vue +16 -0
  87. package/src/client/app/components/search/SearchModal.vue +12 -149
  88. package/src/client/app/components/search/SearchPane.vue +210 -0
  89. package/src/client/app/components/search/search-data.ts +9 -0
  90. package/src/client/app/components/story/StoryControls.vue +5 -0
  91. package/src/client/app/components/story/StoryDocs.vue +18 -11
  92. package/src/client/app/components/story/StoryEvent.vue +53 -0
  93. package/src/client/app/components/story/StoryEvents.vue +45 -0
  94. package/src/client/app/components/story/StoryResponsivePreview.vue +41 -8
  95. package/src/client/app/components/story/StorySidePanel.vue +28 -3
  96. package/src/client/app/components/story/StorySourceCode.vue +24 -14
  97. package/src/client/app/components/story/StoryView.vue +16 -2
  98. package/src/client/app/components/tree/StoryGroup.vue +4 -4
  99. package/src/client/app/components/tree/StoryListFolder.vue +4 -4
  100. package/src/client/app/components/tree/StoryListItem.vue +4 -1
  101. package/src/client/app/router.ts +4 -1
  102. package/src/client/app/sandbox.ts +12 -2
  103. package/src/client/app/stores/events.ts +36 -0
  104. package/{dist/client/app/stores/story.ts → src/client/app/stores/folder.ts} +16 -23
  105. package/src/client/app/stores/story.ts +21 -40
  106. package/src/client/app/style/main.pcss +5 -0
  107. package/src/client/app/style/sandbox.css +2 -0
  108. package/src/client/app/types.ts +1 -0
  109. package/src/client/app/util/const.ts +1 -0
  110. package/src/client/app/util/events.ts +30 -0
  111. package/src/client/app/util/mapping.ts +2 -2
  112. package/src/client/index.ts +2 -1
  113. package/src/client/server/Story.server.vue +13 -2
  114. package/src/node/alias.ts +4 -2
  115. package/src/node/build.ts +86 -21
  116. package/src/node/builtin-plugins/tailwind-tokens.ts +521 -0
  117. package/src/node/collect/index.ts +3 -1
  118. package/src/node/commands/preview.ts +4 -33
  119. package/src/node/config.ts +53 -27
  120. package/src/node/context.ts +3 -3
  121. package/src/node/index.ts +1 -0
  122. package/src/node/load.ts +63 -0
  123. package/src/node/plugin.ts +75 -252
  124. package/src/node/preview.ts +56 -0
  125. package/src/node/search.ts +75 -0
  126. package/src/node/server.ts +49 -23
  127. package/src/node/stories.ts +4 -4
  128. package/src/node/types.ts +1 -0
  129. package/src/node/util/find-up.ts +24 -0
  130. package/src/node/vite.ts +296 -0
  131. package/tailwind.config.cjs +1 -0
  132. package/dist/client/app/codegen/serialize-js.ts +0 -119
  133. package/dist/client/app/codegen/util.ts +0 -79
  134. package/dist/client/app/codegen/vue3.ts +0 -276
  135. package/dist/client/app/components/sandbox/lib.ts +0 -8
  136. package/dist/client/app/global-components.ts +0 -13
  137. package/dist/client/app/index.ts +0 -28
  138. package/dist/client/app/router.ts +0 -17
  139. package/dist/client/app/sandbox.ts +0 -94
  140. package/dist/client/app/stores/preview-settings.ts +0 -17
  141. package/dist/client/app/types.ts +0 -78
  142. package/dist/client/app/util/config.ts +0 -6
  143. package/dist/client/app/util/const.ts +0 -3
  144. package/dist/client/app/util/dark.ts +0 -4
  145. package/dist/client/app/util/env.ts +0 -1
  146. package/dist/client/app/util/keyboard.ts +0 -99
  147. package/dist/client/app/util/mapping.ts +0 -48
  148. package/dist/client/app/util/preview-settings.ts +0 -8
  149. package/dist/client/app/util/reactivity.ts +0 -22
  150. package/dist/client/app/util/responsive.ts +0 -3
  151. package/dist/client/app/util/scroll.ts +0 -31
  152. package/dist/client/app/util/tooltip.ts +0 -13
  153. package/dist/client/app/util/variant.ts +0 -20
  154. package/dist/client/index.ts +0 -12
  155. package/dist/client/server/index.ts +0 -32
  156. 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
- }