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,276 +0,0 @@
1
- // @ts-nocheck
2
- // @TODO remove no-check and fix vnode type errors
3
-
4
- import { VNode, vModelText, vModelCheckbox, vModelSelect, vModelRadio, vModelDynamic } from 'vue'
5
- import { Text } from '@vue/runtime-core'
6
- import { pascal } from 'case'
7
- import { createAutoBuildingObject, indent } from './util'
8
- import { serializeJs } from './serialize-js'
9
- import type { Variant } from '../types'
10
-
11
- export async function generateSourceCode (variant: Variant) {
12
- const vnode = variant.slots().default?.({ state: variant.state }) ?? []
13
- const list = Array.isArray(vnode) ? vnode : [vnode]
14
- const lines: string[] = []
15
- for (const vnode of list) {
16
- lines.push(...await printVNode(vnode))
17
- }
18
- return lines.join('\n')
19
- }
20
-
21
- async function printVNode (vnode: VNode): Promise<string[]> {
22
- if (vnode.type === Text) {
23
- return [vnode.children.trim()]
24
- }
25
-
26
- const lines: string[] = []
27
-
28
- if (typeof vnode.type === 'object' || typeof vnode.type === 'string') {
29
- // Wait for async component
30
- if (vnode.type?.__asyncLoader && !vnode.type.__asyncResolved) {
31
- await vnode.type.__asyncLoader()
32
- }
33
-
34
- const attrs: string[][] = []
35
- let multilineAttrs = false
36
- const skipProps: string[] = [
37
- 'key',
38
- ]
39
-
40
- // Directives
41
- function genDirective (dirName: string, dir, valueCode: string = null) {
42
- let modifiers = ''
43
- for (const key in dir.modifiers) {
44
- if (dir.modifiers[key]) {
45
- modifiers += `.${key}`
46
- }
47
- }
48
- let arg = ''
49
- if (dir.arg) {
50
- arg = `:${dir.arg}`
51
- }
52
- const valueLines = valueCode ? [valueCode] : serializeAndCleanJs(dir.value)
53
- const attr: string[] = []
54
- const dirAttr = `v-${dirName}${arg}${modifiers}="`
55
- if (valueLines.length > 1) {
56
- attr.push(`${dirAttr}${valueLines[0]}`)
57
- attr.push(...valueLines.slice(1, valueLines.length - 1))
58
- attr.push(`${valueLines[valueLines.length - 1]}"`)
59
- multilineAttrs = true
60
- } else {
61
- attr.push(`${dirAttr}${valueLines[0] ?? ''}"`)
62
- }
63
- attrs.push(attr)
64
- }
65
- if (vnode.dirs) {
66
- for (const dir of vnode.dirs) {
67
- // Vmodel
68
- if (dir.dir === vModelText || dir.dir === vModelSelect || dir.dir === vModelRadio || dir.dir === vModelCheckbox || dir.dir === vModelDynamic) {
69
- const listenerKey = `onUpdate:${dir.arg ?? 'modelValue'}`
70
- const listener = vnode.props[listenerKey]
71
- let valueCode: string = null
72
- if (listener) {
73
- skipProps.push(listenerKey)
74
- const listenerSource = listener.toString()
75
- const result = /\(\$event\) => (.*?) = \$event/.exec(listenerSource)
76
- if (result) {
77
- valueCode = result[1]
78
- }
79
- }
80
- genDirective('model', dir, valueCode)
81
- } else {
82
- let dirName: string
83
- for (const directives of [dir.instance._.directives, dir.instance._.appContext.directives]) {
84
- for (const key in directives) {
85
- if (dir.instance._.directives[key] === dir.dir) {
86
- dirName = key
87
- break
88
- }
89
- }
90
- if (dirName) break
91
- }
92
- if (dirName) {
93
- genDirective(dirName, dir)
94
- }
95
- }
96
- }
97
- }
98
-
99
- // Attributes
100
- for (const prop in vnode.props) {
101
- if (skipProps.includes(prop)) {
102
- continue
103
- }
104
- const value = vnode.props[prop]
105
- if (typeof value !== 'string' || vnode.dynamicProps?.includes(prop)) {
106
- let directive = ':'
107
- if (prop.startsWith('on')) {
108
- directive = '@'
109
- }
110
- const arg = directive === '@' ? `${prop[2].toLowerCase()}${prop.slice(3)}` : prop
111
-
112
- // v-model on component
113
- const vmodelListener = `onUpdate:${prop}`
114
- if (directive === ':' && vnode.dynamicProps?.includes(vmodelListener)) {
115
- // Listener
116
- skipProps.push(vmodelListener)
117
- const listener = vnode.props[vmodelListener]
118
- const listenerSource = listener.toString()
119
- let valueCode: string
120
- const result = /\(\$event\) => (.*?) = \$event/.exec(listenerSource)
121
- if (result) {
122
- valueCode = result[1]
123
- }
124
-
125
- // Modifiers
126
- const modifiersKey = `${prop === 'modelValue' ? 'model' : prop}Modifiers`
127
- const modifiers = vnode.props[modifiersKey] ?? {}
128
- skipProps.push(modifiersKey)
129
-
130
- // Directive
131
- genDirective('model', {
132
- arg: prop === 'modelValue' ? null : prop,
133
- modifiers,
134
- value,
135
- }, valueCode)
136
- continue
137
- }
138
-
139
- let serialized: string[]
140
- if (typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}')) {
141
- // It was formatted from auto building object (slot props)
142
- serialized = [value.substring(2, value.length - 2).trim()]
143
- } else if (typeof value === 'function') {
144
- serialized = [value.toString()]
145
- } else {
146
- serialized = serializeAndCleanJs(value)
147
- }
148
- if (serialized.length > 1) {
149
- multilineAttrs = true
150
- const indented: string[] = [`${directive}${arg}="${serialized[0]}`]
151
- indented.push(...serialized.slice(1, serialized.length - 1))
152
- indented.push(`${serialized[serialized.length - 1]}"`)
153
- attrs.push(indented)
154
- } else {
155
- attrs.push([`${directive}${arg}="${serialized[0]}"`])
156
- }
157
- } else {
158
- attrs.push([`${prop}="${value}"`])
159
- }
160
- }
161
- if (attrs.length > 1) {
162
- multilineAttrs = true
163
- }
164
-
165
- // Tags
166
- const tagName = getTagName(vnode)
167
-
168
- // Children
169
- const childLines: string[] = []
170
- if (typeof vnode.children === 'string') {
171
- childLines.push(vnode.children)
172
- } else if (Array.isArray(vnode.children)) {
173
- for (const child of vnode.children) {
174
- childLines.push(...await printVNode(child))
175
- }
176
- }
177
-
178
- // Slots
179
- if (vnode.children && typeof vnode.children === 'object' && !Array.isArray(vnode.children)) {
180
- for (const key in vnode.children) {
181
- if (typeof vnode.children[key] === 'function') {
182
- const autoObject = createAutoBuildingObject(key => `{{ ${key} }}`, (target, p) => {
183
- // Vue 3
184
- if (p === '__v_isRef') {
185
- return () => false
186
- }
187
- })
188
- const children = vnode.children[key](autoObject.proxy)
189
- const slotLines: string[] = []
190
- for (const child of children) {
191
- slotLines.push(...await printVNode(child))
192
- }
193
- const slotProps = Object.keys(autoObject.cache)
194
- if (slotProps.length) {
195
- childLines.push(`<template #${key}="{ ${slotProps.join(', ')} }">`)
196
- childLines.push(...indent(slotLines))
197
- childLines.push('</template>')
198
- } else if (key === 'default') {
199
- childLines.push(...slotLines)
200
- } else {
201
- childLines.push(`<template #${key}>`)
202
- childLines.push(...indent(slotLines))
203
- childLines.push(`</template>`)
204
- }
205
- }
206
- }
207
- }
208
-
209
- // Template
210
- const tag = [`<${tagName}`]
211
- if (multilineAttrs) {
212
- for (const attrLines of attrs) {
213
- tag.push(...indent(attrLines))
214
- }
215
- if (childLines.length > 0) {
216
- tag.push('>')
217
- }
218
- } else {
219
- if (attrs.length === 1) {
220
- tag[0] += ` ${attrs[0]}`
221
- }
222
- if (childLines.length > 0) {
223
- tag[0] += '>'
224
- }
225
- }
226
-
227
- if (childLines.length > 0) {
228
- lines.push(...tag)
229
- lines.push(...indent(childLines))
230
- lines.push(`</${tagName}>`)
231
- } else if (tag.length > 1) {
232
- lines.push(...tag)
233
- lines.push('/>')
234
- } else {
235
- lines.push(`${tag[0]} />`)
236
- }
237
- } else if (vnode?.shapeFlag & 1 << 4) {
238
- for (const child of vnode.children) {
239
- lines.push(...await printVNode(child))
240
- }
241
- }
242
-
243
- return lines
244
- }
245
-
246
- function getTagName (vnode: VNode) {
247
- if (typeof vnode.type === 'string') {
248
- return vnode.type
249
- } else if (vnode.type?.__asyncResolved) {
250
- const asyncComp = vnode.type?.__asyncResolved
251
- return asyncComp.name ?? getNameFromFile(asyncComp.__file)
252
- } else if (vnode.type?.name) {
253
- return vnode.type.name
254
- } else if (vnode.type?.__file) {
255
- return getNameFromFile(vnode.type.__file)
256
- }
257
- return 'Anonymous'
258
- }
259
-
260
- function getNameFromFile (file: string) {
261
- const parts = /\/([^/]+)\.vue$/.exec(file)
262
- if (parts) {
263
- return pascal(parts[1])
264
- }
265
- return 'Anonymous'
266
- }
267
-
268
- function serializeAndCleanJs (value: any) {
269
- const isAutoBuildingObject = !!value?.__autoBuildingObject
270
- const result = serializeJs(value)
271
- if (isAutoBuildingObject) {
272
- return [result.__autoBuildingObjectGetKey]
273
- } else {
274
- return result.replace(/\$setup\./g, '').split('\n')
275
- }
276
- }
@@ -1,8 +0,0 @@
1
- import { Story, Variant } from '../../types'
2
-
3
- export function getSandboxUrl (story: Story, variant: Variant) {
4
- const url = new URLSearchParams()
5
- url.append('storyId', story.id)
6
- url.append('variantId', variant.id)
7
- return '/__sandbox?' + url.toString()
8
- }
@@ -1,13 +0,0 @@
1
- import { App } from 'vue'
2
- import { registerVueComponents } from '@histoire/controls'
3
- import Story from './components/exposed/Story.vue'
4
- import Variant from './components/exposed/Variant.vue'
5
-
6
- export function registerGlobalComponents (app: App) {
7
- // eslint-disable-next-line vue/multi-word-component-names
8
- app.component('Story', Story)
9
- // eslint-disable-next-line vue/multi-word-component-names
10
- app.component('Variant', Variant)
11
-
12
- registerVueComponents(app)
13
- }
@@ -1,28 +0,0 @@
1
- import '$histoire-theme'
2
- import '../../style.css'
3
-
4
- import { createApp } from 'vue'
5
- import { createPinia } from 'pinia'
6
- import FloatingVue from 'floating-vue'
7
- import App from './App.vue'
8
- import { registerGlobalComponents } from './global-components.js'
9
- import { router } from './router'
10
-
11
- const app = createApp(App)
12
- app.use(createPinia())
13
- app.use(FloatingVue, {
14
- overflowPadding: 4,
15
- arrowPadding: 8,
16
- themes: {
17
- tooltip: {
18
- distance: 8,
19
- },
20
- dropdown: {
21
- computeTransformOrigin: true,
22
- distance: 8,
23
- },
24
- },
25
- })
26
- app.use(router)
27
- registerGlobalComponents(app)
28
- app.mount('#app')
@@ -1,17 +0,0 @@
1
- import { createRouter, createWebHistory } from 'vue-router'
2
-
3
- export const router = createRouter({
4
- history: createWebHistory(),
5
- routes: [
6
- {
7
- path: '/',
8
- name: 'home',
9
- component: () => import('./components/HomeView.vue'),
10
- },
11
- {
12
- path: '/story/:storyId',
13
- name: 'story',
14
- component: () => import('./components/story/StoryView.vue'),
15
- },
16
- ],
17
- })
@@ -1,94 +0,0 @@
1
- import './style/sandbox.css'
2
- import { parseQuery } from 'vue-router'
3
- import { computed, createApp, h, onMounted, ref, watch } from 'vue'
4
- import { createPinia } from 'pinia'
5
- import { registerGlobalComponents } from './global-components'
6
- import SandboxVue3 from './components/sandbox/SandboxVue3.vue'
7
- import type { StoryFile } from './types'
8
- import { mapFile } from './util/mapping'
9
- // @ts-expect-error virtual module
10
- import { files } from '$histoire-stories'
11
- import { PREVIEW_SETTINGS_SYNC, STATE_SYNC, SANDBOX_READY } from './util/const.js'
12
- import { applyPreviewSettings } from './util/preview-settings.js'
13
- import { isDark } from './util/dark.js'
14
- import { histoireConfig } from './util/config.js'
15
- import { toRawDeep } from './util/reactivity'
16
-
17
- const query = parseQuery(window.location.search)
18
- const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
19
-
20
- const app = createApp({
21
- setup () {
22
- const story = computed(() => file.value.story)
23
- const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId))
24
-
25
- let synced = false
26
- let mounted = false
27
-
28
- window.addEventListener('message', event => {
29
- if (event.data?.type === STATE_SYNC) {
30
- if (!mounted) return
31
- synced = true
32
- Object.assign(variant.value.state, event.data.state)
33
- } else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
34
- applyPreviewSettings(event.data.settings)
35
- }
36
- })
37
-
38
- watch(() => variant.value.state, value => {
39
- if (synced && mounted) {
40
- synced = false
41
- return
42
- }
43
- window.parent?.postMessage({
44
- type: STATE_SYNC,
45
- state: toRawDeep(value),
46
- })
47
- }, {
48
- deep: true,
49
- })
50
-
51
- onMounted(() => {
52
- mounted = true
53
- })
54
-
55
- return {
56
- story,
57
- variant,
58
- }
59
- },
60
-
61
- render () {
62
- return [
63
- h('div', { class: 'htw-sandbox-hidden' }, [
64
- h(file.value.component, {
65
- story: file.value.story,
66
- }),
67
- ]),
68
- this.story && this.variant
69
- ? h(SandboxVue3, {
70
- story: this.story,
71
- variant: this.variant,
72
- onReady: () => {
73
- window.parent?.postMessage({
74
- type: SANDBOX_READY,
75
- })
76
- },
77
- })
78
- : null,
79
- ]
80
- },
81
- })
82
- app.use(createPinia())
83
- registerGlobalComponents(app)
84
- app.mount('#app')
85
-
86
- watch(isDark, value => {
87
- if (value) {
88
- document.documentElement.classList.add(histoireConfig.sandboxDarkClass)
89
- } else {
90
- document.documentElement.classList.remove(histoireConfig.sandboxDarkClass)
91
- }
92
- }, {
93
- immediate: true,
94
- })
@@ -1,17 +0,0 @@
1
- import { defineStore } from 'pinia'
2
- import { useStorage } from '@vueuse/core'
3
- import type { PreviewSettings } from '../types'
4
-
5
- export const usePreviewSettingsStore = defineStore('preview-settings', () => {
6
- const currentSettings = useStorage<PreviewSettings>('_histoire-sandbox-settings-v2', {
7
- responsiveWidth: 720,
8
- responsiveHeight: null,
9
- rotate: false,
10
- backgroundColor: 'transparent',
11
- checkerboard: false,
12
- })
13
-
14
- return {
15
- currentSettings,
16
- }
17
- })
@@ -1,62 +0,0 @@
1
- import { defineStore } from 'pinia'
2
- import { computed, ref, watch } from 'vue'
3
- import { router } from '../router'
4
- import { Story } from '../types'
5
- import { useStorage } from '@vueuse/core'
6
-
7
- export const useStoryStore = defineStore('story', () => {
8
- const stories = ref<Story[]>([])
9
- function setStories (value: Story[]) {
10
- stories.value = value
11
- }
12
-
13
- const currentStory = computed(() => stories.value.find(s => s.id === router.currentRoute.value.params.storyId))
14
-
15
- const currentVariant = computed(() => currentStory.value?.variants.find(v => v.id === router.currentRoute.value.query.variantId))
16
-
17
- const openedFolders = useStorage<Map<string, boolean>>(
18
- '_histoire-tree-state',
19
- new Map(),
20
- )
21
-
22
- function getStringPath (path: Array<string>) {
23
- return path.join('␜')
24
- }
25
-
26
- function toggleFolder (path: Array<string>, force?: boolean) {
27
- const stringPath = getStringPath(path)
28
-
29
- if (force === undefined) {
30
- force = !openedFolders.value.get(stringPath)
31
- }
32
-
33
- if (force) {
34
- openedFolders.value.set(stringPath, true)
35
- } else {
36
- openedFolders.value.delete(stringPath)
37
- }
38
- }
39
-
40
- function isFolderOpened (path: Array<string>) {
41
- return openedFolders.value.get(getStringPath(path))
42
- }
43
-
44
- function openFileFolders (path: Array<string>) {
45
- for (let pathLength = 1; pathLength < path.length; pathLength++) {
46
- toggleFolder(path.slice(0, pathLength), true)
47
- }
48
- }
49
-
50
- watch(currentStory, () => {
51
- openFileFolders(currentStory.value.file.path)
52
- })
53
-
54
- return {
55
- stories,
56
- setStories,
57
- currentStory,
58
- currentVariant,
59
- isFolderOpened,
60
- toggleFolder,
61
- }
62
- })
@@ -1,70 +0,0 @@
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 | string
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
- responsiveDisabled?: boolean
37
- configReady?: boolean
38
- previewReady?: boolean
39
- }
40
-
41
- export type TreeLeaf = {
42
- title: string
43
- index: number
44
- }
45
-
46
- export type TreeFolder = {
47
- title: string
48
- children: (TreeFolder | TreeLeaf)[]
49
- }
50
-
51
- export type Tree = (TreeFolder | TreeLeaf)[]
52
-
53
- export interface SearchResult {
54
- kind: 'story' | 'variant'
55
- rank: number
56
- id: string
57
- title: string
58
- route: RouteLocationRaw
59
- path?: string[]
60
- icon?: string
61
- iconColor?: string
62
- }
63
-
64
- export interface PreviewSettings {
65
- responsiveWidth: number
66
- responsiveHeight: number
67
- rotate: boolean
68
- backgroundColor: string
69
- checkerboard: boolean
70
- }
@@ -1,6 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- export const STATE_SYNC = '__histoire:state-sync'
2
- export const SANDBOX_READY = '__histoire:sandbox-ready'
3
- export const PREVIEW_SETTINGS_SYNC = '__histoire:preview-settings-sync'
@@ -1,4 +0,0 @@
1
- import { useDark, useToggle } from '@vueuse/core'
2
-
3
- export const isDark = useDark({ valueDark: 'htw-dark' })
4
- export const toggleDark = useToggle(isDark)
@@ -1 +0,0 @@
1
- export const isMac = navigator.platform.toLowerCase().includes('mac')