histoire 0.2.4 → 0.3.1

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