histoire 0.2.5 → 0.3.2
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.
- package/dist/client/app/App.vue +8 -3
- package/dist/client/app/codegen/const.d.ts +1 -0
- package/dist/client/app/codegen/const.js +3 -0
- package/dist/client/app/codegen/vue3.js +83 -21
- package/dist/client/app/codegen/vue3.js.map +1 -0
- package/dist/client/app/components/base/BaseEmpty.vue +17 -1
- package/dist/client/app/components/base/BaseOverflowMenu.vue +118 -0
- package/dist/client/app/components/base/BaseOverflowTab.vue +46 -0
- package/dist/client/app/components/exposed/Story.vue +33 -1
- package/dist/client/app/components/exposed/Variant.vue +19 -1
- package/dist/client/app/components/panel/PaneTabs.vue +64 -0
- package/dist/client/app/components/{story → panel}/StoryControls.vue +6 -1
- package/dist/client/app/components/{story → panel}/StoryDocs.vue +18 -11
- package/dist/client/app/components/panel/StoryEvent.vue +53 -0
- package/dist/client/app/components/panel/StoryEvents.vue +45 -0
- package/{src/client/app/components/story → dist/client/app/components/panel}/StorySidePanel.vue +17 -20
- package/{src/client/app/components/story → dist/client/app/components/panel}/StorySourceCode.vue +24 -14
- package/dist/client/app/components/sandbox/SandboxVue3.vue +16 -4
- package/dist/client/app/components/sandbox/lib.js +2 -1
- package/dist/client/app/components/search/SearchLoading.vue +16 -0
- package/dist/client/app/components/search/SearchModal.vue +12 -149
- package/dist/client/app/components/search/SearchPane.vue +210 -0
- package/dist/client/app/components/search/search-data.d.ts +2 -0
- package/dist/client/app/components/search/search-data.js +8 -0
- package/dist/client/app/components/search/search-data.js.map +1 -0
- package/dist/client/app/components/story/StoryResponsivePreview.vue +9 -98
- package/dist/client/app/components/story/StoryVariantSingle.vue +109 -0
- package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +39 -0
- package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
- package/dist/client/app/components/story/StoryVariantSingleView.vue +13 -6
- package/dist/client/app/components/story/StoryView.vue +17 -3
- package/dist/client/app/components/story/StoryViewer.vue +2 -92
- package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantBackground.vue +3 -3
- package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantNewTab.vue +2 -2
- package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantResponsiveSize.vue +3 -3
- package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
- package/dist/client/app/components/tree/StoryGroup.vue +4 -4
- package/dist/client/app/components/tree/StoryListFolder.vue +4 -4
- package/dist/client/app/components/tree/StoryListItem.vue +4 -1
- package/dist/client/app/global-components.js +1 -0
- package/dist/client/app/global-components.js.map +1 -0
- package/dist/client/app/index.js +1 -0
- package/dist/client/app/index.js.map +1 -0
- package/dist/client/app/router.d.ts +1 -0
- package/dist/client/app/router.js +3 -1
- package/dist/client/app/sandbox.js +12 -1
- package/dist/client/app/sandbox.js.map +1 -0
- package/dist/client/app/stores/events.d.ts +29 -0
- package/dist/client/app/stores/events.js +26 -0
- package/dist/client/app/stores/events.js.map +1 -0
- package/dist/client/app/stores/folder.d.ts +10 -0
- package/dist/client/app/stores/folder.js +48 -0
- package/dist/client/app/stores/folder.js.map +1 -0
- package/dist/client/app/stores/story.d.ts +41 -8
- package/dist/client/app/stores/story.js +21 -33
- package/dist/client/app/stores/story.js.map +1 -0
- package/dist/client/app/style/main.pcss +5 -0
- package/dist/client/app/style/sandbox.css +2 -0
- package/dist/client/app/style/transitions.pcss +13 -0
- package/dist/client/app/types.d.ts +4 -0
- package/dist/client/app/types.js +1 -0
- package/dist/client/app/types.js.map +1 -0
- package/dist/client/app/util/const.d.ts +1 -0
- package/dist/client/app/util/const.js +1 -0
- package/dist/client/app/util/events.d.ts +1 -0
- package/dist/client/app/util/events.js +32 -0
- package/dist/client/app/util/events.js.map +1 -0
- package/dist/client/app/util/keyboard.js +1 -0
- package/dist/client/app/util/keyboard.js.map +1 -0
- package/dist/client/app/util/mapping.js +5 -2
- package/dist/client/app/util/mapping.js.map +1 -0
- package/dist/client/app/util/preview-settings.js +1 -0
- package/dist/client/app/util/preview-settings.js.map +1 -0
- package/dist/client/app/util/reactivity.js +1 -0
- package/dist/client/app/util/reactivity.js.map +1 -0
- package/dist/client/app/util/scroll.js +1 -0
- package/dist/client/app/util/scroll.js.map +1 -0
- package/dist/client/app/util/variant.js +1 -0
- package/dist/client/app/util/variant.js.map +1 -0
- package/dist/client/index.d.ts +4 -3
- package/dist/client/index.js +3 -1
- package/dist/client/index.js.map +1 -0
- package/dist/client/server/index.d.ts +7 -2
- package/dist/client/server/index.js +8 -26
- package/{src/client/server/Story.server.vue → dist/client/server/vue3/Story.vue} +14 -3
- package/dist/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
- package/dist/client/server/vue3/run.d.ts +2 -0
- package/dist/client/server/vue3/run.js +33 -0
- package/dist/client/server/vue3/run.js.map +1 -0
- package/dist/controls.js +1 -0
- package/dist/controls.js.map +1 -0
- package/dist/node/alias.d.ts +2 -1
- package/dist/node/alias.js +3 -2
- package/dist/node/build.js +74 -21
- package/dist/node/builtin-plugins/tailwind-tokens.d.ts +5 -0
- package/dist/node/builtin-plugins/tailwind-tokens.js +510 -0
- package/dist/node/collect/index.js +3 -1
- package/dist/node/collect/worker.js +6 -2
- package/dist/node/commands/preview.js +4 -25
- package/dist/node/config.d.ts +103 -3
- package/dist/node/config.js +40 -23
- package/dist/node/context.d.ts +3 -3
- package/dist/node/context.js +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/load.d.ts +12 -0
- package/dist/node/load.js +42 -0
- package/dist/node/plugin.d.ts +67 -11
- package/dist/node/plugin.js +42 -245
- package/dist/node/preview.d.ts +8 -0
- package/dist/node/preview.js +41 -0
- package/dist/node/search.d.ts +2 -0
- package/dist/node/search.js +68 -0
- package/dist/node/server.js +43 -21
- package/dist/node/stories.d.ts +2 -0
- package/dist/node/stories.js +4 -4
- package/dist/node/types.d.ts +1 -0
- package/dist/node/util/find-up.d.ts +1 -0
- package/dist/node/util/find-up.js +20 -0
- package/dist/node/vite.d.ts +13 -0
- package/dist/node/vite.js +278 -0
- package/dist/style.css +174 -86
- package/package.json +7 -6
- package/scripts/copy.mjs +2 -1
- package/src/client/app/App.vue +8 -3
- package/src/client/app/codegen/const.ts +3 -0
- package/src/client/app/codegen/vue3.ts +80 -22
- package/src/client/app/components/base/BaseEmpty.vue +17 -1
- package/src/client/app/components/base/BaseOverflowMenu.vue +118 -0
- package/src/client/app/components/base/BaseOverflowTab.vue +46 -0
- package/src/client/app/components/exposed/Story.vue +33 -1
- package/src/client/app/components/exposed/Variant.vue +19 -1
- package/src/client/app/components/panel/PaneTabs.vue +64 -0
- package/src/client/app/components/{story → panel}/StoryControls.vue +6 -1
- package/src/client/app/components/{story → panel}/StoryDocs.vue +18 -11
- package/src/client/app/components/panel/StoryEvent.vue +53 -0
- package/src/client/app/components/panel/StoryEvents.vue +45 -0
- package/{dist/client/app/components/story → src/client/app/components/panel}/StorySidePanel.vue +17 -20
- package/{dist/client/app/components/story → src/client/app/components/panel}/StorySourceCode.vue +24 -14
- package/src/client/app/components/sandbox/SandboxVue3.vue +16 -4
- package/src/client/app/components/sandbox/lib.ts +3 -1
- package/src/client/app/components/search/SearchLoading.vue +16 -0
- package/src/client/app/components/search/SearchModal.vue +12 -149
- package/src/client/app/components/search/SearchPane.vue +210 -0
- package/src/client/app/components/search/search-data.ts +9 -0
- package/src/client/app/components/story/StoryResponsivePreview.vue +9 -98
- package/src/client/app/components/story/StoryVariantSingle.vue +109 -0
- package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +39 -0
- package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
- package/src/client/app/components/story/StoryVariantSingleView.vue +13 -6
- package/src/client/app/components/story/StoryView.vue +17 -3
- package/src/client/app/components/story/StoryViewer.vue +2 -92
- package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantBackground.vue +3 -3
- package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantNewTab.vue +2 -2
- package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantResponsiveSize.vue +3 -3
- package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
- package/src/client/app/components/tree/StoryGroup.vue +4 -4
- package/src/client/app/components/tree/StoryListFolder.vue +4 -4
- package/src/client/app/components/tree/StoryListItem.vue +4 -1
- package/src/client/app/router.ts +4 -1
- package/src/client/app/sandbox.ts +11 -1
- package/src/client/app/stores/events.ts +36 -0
- package/{dist/client/app/stores/story.ts → src/client/app/stores/folder.ts} +16 -23
- package/src/client/app/stores/story.ts +21 -40
- package/src/client/app/style/main.pcss +5 -0
- package/src/client/app/style/sandbox.css +2 -0
- package/src/client/app/style/transitions.pcss +13 -0
- package/src/client/app/types.ts +5 -0
- package/src/client/app/util/const.ts +1 -0
- package/src/client/app/util/events.ts +30 -0
- package/src/client/app/util/mapping.ts +4 -2
- package/src/client/index.ts +4 -3
- package/src/client/server/index.ts +14 -27
- package/{dist/client/server/Story.server.vue → src/client/server/vue3/Story.vue} +14 -3
- package/src/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
- package/{dist/client/server/index.ts → src/client/server/vue3/run.ts} +10 -4
- package/src/node/alias.ts +4 -2
- package/src/node/build.ts +86 -21
- package/src/node/builtin-plugins/tailwind-tokens.ts +521 -0
- package/src/node/collect/index.ts +3 -1
- package/src/node/collect/worker.ts +7 -2
- package/src/node/commands/preview.ts +4 -33
- package/src/node/config.ts +53 -27
- package/src/node/context.ts +3 -3
- package/src/node/index.ts +1 -0
- package/src/node/load.ts +63 -0
- package/src/node/plugin.ts +75 -252
- package/src/node/preview.ts +56 -0
- package/src/node/search.ts +75 -0
- package/src/node/server.ts +49 -23
- package/src/node/stories.ts +4 -4
- package/src/node/types.ts +1 -0
- package/src/node/util/find-up.ts +24 -0
- package/src/node/vite.ts +296 -0
- package/tailwind.config.cjs +1 -0
- package/dist/client/app/codegen/serialize-js.ts +0 -119
- package/dist/client/app/codegen/util.ts +0 -79
- package/dist/client/app/codegen/vue3.ts +0 -276
- package/dist/client/app/components/sandbox/lib.ts +0 -8
- package/dist/client/app/global-components.ts +0 -13
- package/dist/client/app/index.ts +0 -28
- package/dist/client/app/router.ts +0 -17
- package/dist/client/app/sandbox.ts +0 -94
- package/dist/client/app/stores/preview-settings.ts +0 -17
- package/dist/client/app/types.ts +0 -78
- package/dist/client/app/util/config.ts +0 -6
- package/dist/client/app/util/const.ts +0 -3
- package/dist/client/app/util/dark.ts +0 -4
- package/dist/client/app/util/env.ts +0 -1
- package/dist/client/app/util/keyboard.ts +0 -99
- package/dist/client/app/util/mapping.ts +0 -48
- package/dist/client/app/util/preview-settings.ts +0 -8
- package/dist/client/app/util/reactivity.ts +0 -22
- package/dist/client/app/util/responsive.ts +0 -3
- package/dist/client/app/util/scroll.ts +0 -31
- package/dist/client/app/util/tooltip.ts +0 -13
- package/dist/client/app/util/variant.ts +0 -20
- package/dist/client/index.ts +0 -12
- package/dist/client/shim.d.ts +0 -5
|
@@ -7,20 +7,24 @@ import { pascal } from 'case'
|
|
|
7
7
|
import { createAutoBuildingObject, indent } from './util'
|
|
8
8
|
import { serializeJs } from './serialize-js'
|
|
9
9
|
import type { Variant } from '../types'
|
|
10
|
+
import { voidElements } from './const'
|
|
10
11
|
|
|
11
12
|
export async function generateSourceCode (variant: Variant) {
|
|
12
|
-
const vnode = variant.slots().default?.({ state: variant.state }) ?? []
|
|
13
|
+
const vnode = variant.slots().default?.({ state: variant.state ?? {} }) ?? []
|
|
13
14
|
const list = Array.isArray(vnode) ? vnode : [vnode]
|
|
14
15
|
const lines: string[] = []
|
|
15
16
|
for (const vnode of list) {
|
|
16
|
-
lines.push(...await printVNode(vnode))
|
|
17
|
+
lines.push(...(await printVNode(vnode)).lines)
|
|
17
18
|
}
|
|
18
19
|
return lines.join('\n')
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
async function printVNode (vnode: VNode): Promise<string[]> {
|
|
22
|
+
async function printVNode (vnode: VNode): Promise<{ lines: string[], isText?: boolean }> {
|
|
22
23
|
if (vnode.type === Text) {
|
|
23
|
-
return
|
|
24
|
+
return {
|
|
25
|
+
lines: [vnode.children],
|
|
26
|
+
isText: true,
|
|
27
|
+
}
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
const lines: string[] = []
|
|
@@ -49,6 +53,10 @@ async function printVNode (vnode: VNode): Promise<string[]> {
|
|
|
49
53
|
if (dir.arg) {
|
|
50
54
|
arg = `:${dir.arg}`
|
|
51
55
|
}
|
|
56
|
+
if (valueCode) {
|
|
57
|
+
// Cleanup render code
|
|
58
|
+
valueCode = valueCode.replace(/^\$(setup|props|data)\./g, '')
|
|
59
|
+
}
|
|
52
60
|
const valueLines = valueCode ? [valueCode] : serializeAndCleanJs(dir.value)
|
|
53
61
|
const attr: string[] = []
|
|
54
62
|
const dirAttr = `v-${dirName}${arg}${modifiers}="`
|
|
@@ -78,11 +86,12 @@ async function printVNode (vnode: VNode): Promise<string[]> {
|
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
88
|
genDirective('model', dir, valueCode)
|
|
81
|
-
} else {
|
|
89
|
+
} else if (dir.instance._ || dir.instance.$) {
|
|
90
|
+
const target = dir.instance.$ ?? dir.instance._
|
|
82
91
|
let dirName: string
|
|
83
|
-
for (const directives of [
|
|
92
|
+
for (const directives of [target.directives, target.appContext.directives]) {
|
|
84
93
|
for (const key in directives) {
|
|
85
|
-
if (
|
|
94
|
+
if (target.directives[key] === dir.dir) {
|
|
86
95
|
dirName = key
|
|
87
96
|
break
|
|
88
97
|
}
|
|
@@ -139,9 +148,20 @@ async function printVNode (vnode: VNode): Promise<string[]> {
|
|
|
139
148
|
let serialized: string[]
|
|
140
149
|
if (typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}')) {
|
|
141
150
|
// It was formatted from auto building object (slot props)
|
|
142
|
-
serialized =
|
|
151
|
+
serialized = cleanupExpression(value.substring(2, value.length - 2).trim()).split('\n')
|
|
143
152
|
} else if (typeof value === 'function') {
|
|
144
|
-
|
|
153
|
+
let code = cleanupExpression(value.toString().replace(/'/g, '\\\'').replace(/"/g, '\''))
|
|
154
|
+
const testResult = /function ([^\s]+)\(/.exec(code)
|
|
155
|
+
if (testResult) {
|
|
156
|
+
// Function name only
|
|
157
|
+
serialized = [testResult[1]]
|
|
158
|
+
} else {
|
|
159
|
+
if (code.startsWith('($event) => ')) {
|
|
160
|
+
// Remove unnecessary `($event) => `
|
|
161
|
+
code = code.substring('($event) => '.length)
|
|
162
|
+
}
|
|
163
|
+
serialized = code.split('\n')
|
|
164
|
+
}
|
|
145
165
|
} else {
|
|
146
166
|
serialized = serializeAndCleanJs(value)
|
|
147
167
|
}
|
|
@@ -166,12 +186,38 @@ async function printVNode (vnode: VNode): Promise<string[]> {
|
|
|
166
186
|
const tagName = getTagName(vnode)
|
|
167
187
|
|
|
168
188
|
// Children
|
|
189
|
+
let isChildText = false
|
|
169
190
|
const childLines: string[] = []
|
|
170
191
|
if (typeof vnode.children === 'string') {
|
|
171
|
-
|
|
192
|
+
if (tagName === 'pre') {
|
|
193
|
+
childLines.push(vnode.children)
|
|
194
|
+
} else {
|
|
195
|
+
childLines.push(...vnode.children.split('\n'))
|
|
196
|
+
}
|
|
197
|
+
isChildText = true
|
|
172
198
|
} else if (Array.isArray(vnode.children)) {
|
|
199
|
+
let isAllChildText
|
|
173
200
|
for (const child of vnode.children) {
|
|
174
|
-
|
|
201
|
+
const result = await printVNode(child)
|
|
202
|
+
if (result.isText) {
|
|
203
|
+
if (isAllChildText === undefined) {
|
|
204
|
+
isAllChildText = true
|
|
205
|
+
}
|
|
206
|
+
const text = result.lines[0]
|
|
207
|
+
if (!childLines.length || /^\s/.test(text)) {
|
|
208
|
+
childLines.push(text.trim())
|
|
209
|
+
} else {
|
|
210
|
+
childLines[childLines.length - 1] += text
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
if (isAllChildText === undefined) {
|
|
214
|
+
isAllChildText = false
|
|
215
|
+
}
|
|
216
|
+
childLines.push(...result.lines)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (isAllChildText !== undefined) {
|
|
220
|
+
isChildText = isAllChildText
|
|
175
221
|
}
|
|
176
222
|
}
|
|
177
223
|
|
|
@@ -188,7 +234,7 @@ async function printVNode (vnode: VNode): Promise<string[]> {
|
|
|
188
234
|
const children = vnode.children[key](autoObject.proxy)
|
|
189
235
|
const slotLines: string[] = []
|
|
190
236
|
for (const child of children) {
|
|
191
|
-
slotLines.push(...await printVNode(child))
|
|
237
|
+
slotLines.push(...(await printVNode(child)).lines)
|
|
192
238
|
}
|
|
193
239
|
const slotProps = Object.keys(autoObject.cache)
|
|
194
240
|
if (slotProps.length) {
|
|
@@ -224,23 +270,31 @@ async function printVNode (vnode: VNode): Promise<string[]> {
|
|
|
224
270
|
}
|
|
225
271
|
}
|
|
226
272
|
|
|
273
|
+
const isVoid = voidElements.includes(tagName.toLowerCase())
|
|
274
|
+
|
|
227
275
|
if (childLines.length > 0) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
276
|
+
if (childLines.length === 1 && tag.length === 1 && !attrs.length && isChildText) {
|
|
277
|
+
lines.push(`${tag[0]}${childLines[0]}</${tagName}>`)
|
|
278
|
+
} else {
|
|
279
|
+
lines.push(...tag)
|
|
280
|
+
lines.push(...indent(childLines))
|
|
281
|
+
lines.push(`</${tagName}>`)
|
|
282
|
+
}
|
|
231
283
|
} else if (tag.length > 1) {
|
|
232
284
|
lines.push(...tag)
|
|
233
|
-
lines.push('/>')
|
|
285
|
+
lines.push(isVoid ? '>' : '/>')
|
|
234
286
|
} else {
|
|
235
|
-
lines.push(`${tag[0]}
|
|
287
|
+
lines.push(`${tag[0]}${isVoid ? '' : ' /'}>`)
|
|
236
288
|
}
|
|
237
289
|
} else if (vnode?.shapeFlag & 1 << 4) {
|
|
238
290
|
for (const child of vnode.children) {
|
|
239
|
-
lines.push(...await printVNode(child))
|
|
291
|
+
lines.push(...(await printVNode(child)).lines)
|
|
240
292
|
}
|
|
241
293
|
}
|
|
242
294
|
|
|
243
|
-
return
|
|
295
|
+
return {
|
|
296
|
+
lines,
|
|
297
|
+
}
|
|
244
298
|
}
|
|
245
299
|
|
|
246
300
|
function getTagName (vnode: VNode) {
|
|
@@ -258,7 +312,7 @@ function getTagName (vnode: VNode) {
|
|
|
258
312
|
}
|
|
259
313
|
|
|
260
314
|
function getNameFromFile (file: string) {
|
|
261
|
-
const parts =
|
|
315
|
+
const parts = /([^/]+)\.vue$/.exec(file)
|
|
262
316
|
if (parts) {
|
|
263
317
|
return pascal(parts[1])
|
|
264
318
|
}
|
|
@@ -269,8 +323,12 @@ function serializeAndCleanJs (value: any) {
|
|
|
269
323
|
const isAutoBuildingObject = !!value?.__autoBuildingObject
|
|
270
324
|
const result = serializeJs(value)
|
|
271
325
|
if (isAutoBuildingObject) {
|
|
272
|
-
return [result.__autoBuildingObjectGetKey]
|
|
326
|
+
return [cleanupExpression(result.__autoBuildingObjectGetKey)]
|
|
273
327
|
} else {
|
|
274
|
-
return result
|
|
328
|
+
return cleanupExpression(result).split('\n')
|
|
275
329
|
}
|
|
276
330
|
}
|
|
331
|
+
|
|
332
|
+
function cleanupExpression (expr: string) {
|
|
333
|
+
return expr.replace(/\$setup\./g, '')
|
|
334
|
+
}
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="htw-flex htw-flex-col htw-items-center htw-justify-center htw-space-y-4 htw-py-12 htw-h-full htw-text-center htw-text-gray-400 htw-text-lg">
|
|
2
|
+
<div class="htw-base-empty htw-flex htw-flex-col htw-items-center htw-justify-center htw-space-y-4 htw-py-12 htw-h-full htw-text-center htw-text-gray-400 htw-text-lg">
|
|
3
3
|
<slot />
|
|
4
4
|
</div>
|
|
5
5
|
</template>
|
|
6
|
+
|
|
7
|
+
<style scoped>
|
|
8
|
+
.htw-base-empty {
|
|
9
|
+
animation: htw-base-empty .3s 1s both;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@keyframes htw-base-empty {
|
|
13
|
+
0% {
|
|
14
|
+
opacity: 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
100% {
|
|
18
|
+
opacity: 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { ref, h, onBeforeUnmount, reactive, computed } from 'vue'
|
|
3
|
+
import { useResizeObserver } from '@vueuse/core'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
|
|
6
|
+
// Container
|
|
7
|
+
|
|
8
|
+
const overflowButtonWidth = 32
|
|
9
|
+
|
|
10
|
+
const el = ref<HTMLDivElement>()
|
|
11
|
+
|
|
12
|
+
const availableWidth = ref(0)
|
|
13
|
+
|
|
14
|
+
useResizeObserver(el, (entries) => {
|
|
15
|
+
const containerWidth = entries[0].contentRect.width
|
|
16
|
+
availableWidth.value = containerWidth - overflowButtonWidth
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// Children
|
|
20
|
+
|
|
21
|
+
interface ChildState {
|
|
22
|
+
width: number
|
|
23
|
+
index: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const children = ref(new Map<HTMLElement, ChildState>())
|
|
27
|
+
|
|
28
|
+
const visibleChildrenCount = computed(() => {
|
|
29
|
+
let width = 0
|
|
30
|
+
const c = [...children.value.values()].sort((a, b) => a.index - b.index)
|
|
31
|
+
for (let i = 0; i < c.length; i++) {
|
|
32
|
+
width += c[i].width
|
|
33
|
+
if (width > availableWidth.value) {
|
|
34
|
+
return i
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return c.length
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Watches for the size of each child and automatically hide them
|
|
42
|
+
*/
|
|
43
|
+
const ChildWrapper = {
|
|
44
|
+
props: ['index'],
|
|
45
|
+
setup (props, { slots }) {
|
|
46
|
+
const el = ref<HTMLDivElement>()
|
|
47
|
+
|
|
48
|
+
const state = reactive({ width: 0, index: props.index })
|
|
49
|
+
|
|
50
|
+
useResizeObserver(el, (entries) => {
|
|
51
|
+
const width = entries[0].contentRect.width
|
|
52
|
+
if (!children.value.has(el.value)) {
|
|
53
|
+
children.value.set(el.value, state)
|
|
54
|
+
}
|
|
55
|
+
state.width = width
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
onBeforeUnmount(() => {
|
|
59
|
+
children.value.delete(el.value)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const visible = computed(() => visibleChildrenCount.value > state.index)
|
|
63
|
+
|
|
64
|
+
return () => h('div', { ref: el, style: { visibility: visible.value ? 'visible' : 'hidden' } }, slots.default())
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Wraps each child with a <ChildWrapper>
|
|
70
|
+
*/
|
|
71
|
+
const ChildrenRender = (props, { slots }) => {
|
|
72
|
+
const [fragment] = slots.default()
|
|
73
|
+
return fragment.children.map((vnode, index) => h(ChildWrapper, { index }, [vnode]))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Only renders a part of a children list
|
|
78
|
+
*/
|
|
79
|
+
const ChildrenSlice = (props, { slots }) => {
|
|
80
|
+
const [fragment] = slots.default()
|
|
81
|
+
return fragment.children.slice(props.start, props.end)
|
|
82
|
+
}
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<template>
|
|
86
|
+
<div
|
|
87
|
+
ref="el"
|
|
88
|
+
class="htw-flex htw-overflow-hidden htw-relative"
|
|
89
|
+
>
|
|
90
|
+
<ChildrenRender>
|
|
91
|
+
<slot />
|
|
92
|
+
</ChildrenRender>
|
|
93
|
+
|
|
94
|
+
<VDropdown
|
|
95
|
+
v-if="visibleChildrenCount < children.size"
|
|
96
|
+
>
|
|
97
|
+
<div
|
|
98
|
+
role="button"
|
|
99
|
+
class="htw-cursor-pointer hover:htw-bg-primary-50 dark:hover:htw-bg-primary-900 htw-w-8 htw-h-full htw-flex htw-items-center htw-justify-center htw-absolute htw-top-0 htw-right-0"
|
|
100
|
+
>
|
|
101
|
+
<Icon
|
|
102
|
+
icon="carbon:caret-down"
|
|
103
|
+
class="htw-w-4 htw-h-4 htw-opacity-50 group-hover:htw-opacity-100"
|
|
104
|
+
/>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<template #popper>
|
|
108
|
+
<div class="htw-flex htw-flex-col htw-items-stretch">
|
|
109
|
+
<ChildrenSlice
|
|
110
|
+
:start="visibleChildrenCount"
|
|
111
|
+
>
|
|
112
|
+
<slot name="overflow" />
|
|
113
|
+
</ChildrenSlice>
|
|
114
|
+
</div>
|
|
115
|
+
</template>
|
|
116
|
+
</VDropdown>
|
|
117
|
+
</div>
|
|
118
|
+
</template>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { defineComponent } from 'vue'
|
|
3
|
+
|
|
4
|
+
export default defineComponent({
|
|
5
|
+
inheritAttrs: false,
|
|
6
|
+
|
|
7
|
+
props: {
|
|
8
|
+
exact: {
|
|
9
|
+
type: Boolean,
|
|
10
|
+
default: false,
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
matched: {
|
|
14
|
+
type: Boolean,
|
|
15
|
+
default: null,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<router-link
|
|
23
|
+
v-slot="{ isActive, isExactActive, href, navigate }"
|
|
24
|
+
v-bind="$attrs"
|
|
25
|
+
custom
|
|
26
|
+
>
|
|
27
|
+
<a
|
|
28
|
+
v-bind="$attrs"
|
|
29
|
+
:href="href"
|
|
30
|
+
class="htw-px-4 htw-h-10 htw-min-w-[150px] htw-inline-flex htw-items-center hover:htw-bg-primary-50 dark:hover:htw-bg-primary-900 htw-relative htw-text-gray-900 dark:htw-text-gray-100"
|
|
31
|
+
:class="{
|
|
32
|
+
'htw-text-primary-500 dark:htw-text-primary-400': matched != null ? matched : (exact && isExactActive) || (!exact && isActive),
|
|
33
|
+
}"
|
|
34
|
+
@click="navigate"
|
|
35
|
+
>
|
|
36
|
+
<slot />
|
|
37
|
+
|
|
38
|
+
<transition name="__histoire-scale-y">
|
|
39
|
+
<div
|
|
40
|
+
v-if="matched != null ? matched : (exact && isExactActive) || (!exact && isActive)"
|
|
41
|
+
class="htw-absolute htw-top-0 htw-left-0 htw-h-full htw-w-[2px] htw-bg-primary-500 dark:htw-bg-primary-400"
|
|
42
|
+
/>
|
|
43
|
+
</transition>
|
|
44
|
+
</a>
|
|
45
|
+
</router-link>
|
|
46
|
+
</template>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { computed, defineComponent, provide, useAttrs, VNode, h, PropType } from 'vue'
|
|
2
|
+
import { computed, defineComponent, provide, useAttrs, VNode, h, PropType, getCurrentInstance } from 'vue'
|
|
3
3
|
import { Story } from '../../types.js'
|
|
4
4
|
import Variant from './Variant.vue'
|
|
5
5
|
|
|
@@ -18,6 +18,8 @@ export default defineComponent({
|
|
|
18
18
|
},
|
|
19
19
|
|
|
20
20
|
setup () {
|
|
21
|
+
const vm = getCurrentInstance()
|
|
22
|
+
|
|
21
23
|
const attrs = useAttrs() as {
|
|
22
24
|
story: Story
|
|
23
25
|
}
|
|
@@ -25,12 +27,42 @@ export default defineComponent({
|
|
|
25
27
|
const story = computed(() => attrs.story)
|
|
26
28
|
provide('story', story)
|
|
27
29
|
|
|
30
|
+
const storyComponent: any = vm.parent
|
|
31
|
+
// Allows tracking reactivity with watchers to sync state
|
|
32
|
+
const implicitState = {
|
|
33
|
+
$data: storyComponent.data,
|
|
34
|
+
}
|
|
35
|
+
function addImplicitState (key, value) {
|
|
36
|
+
if (typeof value === 'function' || (value && value.__file)) {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
implicitState[key] = value
|
|
40
|
+
}
|
|
41
|
+
// From `<script setup>`'s `defineExpose`
|
|
42
|
+
for (const key in storyComponent.exposed) {
|
|
43
|
+
addImplicitState(key, storyComponent.exposed[key])
|
|
44
|
+
}
|
|
45
|
+
// We needs __VUE_PROD_DEVTOOLS__ flag set to `true` to enable `devtoolsRawSetupState`
|
|
46
|
+
for (const key in storyComponent.devtoolsRawSetupState) {
|
|
47
|
+
addImplicitState(key, storyComponent.devtoolsRawSetupState[key])
|
|
48
|
+
}
|
|
49
|
+
provide('implicitState', () => implicitState)
|
|
50
|
+
|
|
51
|
+
function updateStory () {
|
|
52
|
+
Object.assign(attrs.story, {
|
|
53
|
+
slots: () => vm.proxy.$slots,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
28
57
|
return {
|
|
29
58
|
story,
|
|
59
|
+
updateStory,
|
|
30
60
|
}
|
|
31
61
|
},
|
|
32
62
|
|
|
33
63
|
render () {
|
|
64
|
+
this.updateStory()
|
|
65
|
+
|
|
34
66
|
const [firstVariant] = this.story.variants
|
|
35
67
|
if (firstVariant.id === '_default') {
|
|
36
68
|
return h(Variant, {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { defineComponent, getCurrentInstance, PropType, useAttrs } from 'vue'
|
|
2
|
+
import { defineComponent, getCurrentInstance, inject, PropType, useAttrs, watch } from 'vue'
|
|
3
3
|
import { Variant } from '../../types'
|
|
4
4
|
|
|
5
|
+
// const logLocation = location.href.includes('__sandbox') ? '[Sandbox]' : '[Host]'
|
|
6
|
+
|
|
5
7
|
export default defineComponent({
|
|
6
8
|
// eslint-disable-next-line vue/multi-word-component-names
|
|
7
9
|
name: 'Variant',
|
|
@@ -22,6 +24,11 @@ export default defineComponent({
|
|
|
22
24
|
type: Boolean,
|
|
23
25
|
default: false,
|
|
24
26
|
},
|
|
27
|
+
|
|
28
|
+
setupApp: {
|
|
29
|
+
type: Function,
|
|
30
|
+
default: null,
|
|
31
|
+
},
|
|
25
32
|
},
|
|
26
33
|
|
|
27
34
|
setup (props) {
|
|
@@ -31,6 +38,16 @@ export default defineComponent({
|
|
|
31
38
|
|
|
32
39
|
const vm = getCurrentInstance()
|
|
33
40
|
|
|
41
|
+
const implicitState = inject<() => any>('implicitState')
|
|
42
|
+
|
|
43
|
+
watch(() => implicitState, value => {
|
|
44
|
+
if (typeof props.initState !== 'function') {
|
|
45
|
+
attrs.variant.state = value()
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
immediate: true,
|
|
49
|
+
})
|
|
50
|
+
|
|
34
51
|
function updateVariant () {
|
|
35
52
|
Object.assign(attrs.variant, {
|
|
36
53
|
initState: async () => {
|
|
@@ -41,6 +58,7 @@ export default defineComponent({
|
|
|
41
58
|
slots: () => vm.proxy.$slots,
|
|
42
59
|
source: props.source,
|
|
43
60
|
responsiveDisabled: props.responsiveDisabled,
|
|
61
|
+
setupApp: props.setupApp,
|
|
44
62
|
configReady: true,
|
|
45
63
|
})
|
|
46
64
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import BaseTab from '../base/BaseTab.vue'
|
|
3
|
+
import { useEventsStore } from '../../stores/events'
|
|
4
|
+
import BaseOverflowMenu from '../base/BaseOverflowMenu.vue'
|
|
5
|
+
import BaseOverflowTab from '../base/BaseOverflowTab.vue'
|
|
6
|
+
|
|
7
|
+
const eventsStore = useEventsStore()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<BaseOverflowMenu class="htw-h-10 htw-flex-none htw-border-b htw-border-gray-100 dark:htw-border-gray-750">
|
|
12
|
+
<BaseTab
|
|
13
|
+
:to="{ ...$route, query: { ...$route.query, tab: '' } }"
|
|
14
|
+
:matched="!$route.query.tab"
|
|
15
|
+
>
|
|
16
|
+
Controls
|
|
17
|
+
</BaseTab>
|
|
18
|
+
<BaseTab
|
|
19
|
+
:to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
|
|
20
|
+
:matched="$route.query.tab === 'docs'"
|
|
21
|
+
>
|
|
22
|
+
Docs
|
|
23
|
+
</BaseTab>
|
|
24
|
+
<BaseTab
|
|
25
|
+
:to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
|
|
26
|
+
:matched="$route.query.tab === 'events'"
|
|
27
|
+
>
|
|
28
|
+
Events
|
|
29
|
+
<span
|
|
30
|
+
v-if="eventsStore.unseen"
|
|
31
|
+
class="htw-text-center htw-text-xs htw-mx-1 htw-px-0.5 htw-h-4 htw-min-w-4 htw-rounded-full active htw-bg-primary-500 htw-text-white dark:htw-text-black"
|
|
32
|
+
>
|
|
33
|
+
{{ eventsStore.unseen <=99 ? eventsStore.unseen : "99+" }}
|
|
34
|
+
</span>
|
|
35
|
+
</BaseTab>
|
|
36
|
+
|
|
37
|
+
<template #overflow>
|
|
38
|
+
<BaseOverflowTab
|
|
39
|
+
:to="{ ...$route, query: { ...$route.query, tab: '' } }"
|
|
40
|
+
:matched="!$route.query.tab"
|
|
41
|
+
>
|
|
42
|
+
Controls
|
|
43
|
+
</BaseOverflowTab>
|
|
44
|
+
<BaseOverflowTab
|
|
45
|
+
:to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
|
|
46
|
+
:matched="$route.query.tab === 'docs'"
|
|
47
|
+
>
|
|
48
|
+
Docs
|
|
49
|
+
</BaseOverflowTab>
|
|
50
|
+
<BaseOverflowTab
|
|
51
|
+
:to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
|
|
52
|
+
:matched="$route.query.tab === 'events'"
|
|
53
|
+
>
|
|
54
|
+
Events
|
|
55
|
+
<span
|
|
56
|
+
v-if="eventsStore.unseen"
|
|
57
|
+
class="htw-text-center htw-text-xs htw-mx-1 htw-px-0.5 htw-h-4 htw-min-w-4 htw-rounded-full active htw-bg-primary-500 htw-text-white dark:htw-text-black"
|
|
58
|
+
>
|
|
59
|
+
{{ eventsStore.unseen <=99 ? eventsStore.unseen : "99+" }}
|
|
60
|
+
</span>
|
|
61
|
+
</BaseOverflowTab>
|
|
62
|
+
</template>
|
|
63
|
+
</BaseOverflowMenu>
|
|
64
|
+
</template>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { PropType } from 'vue'
|
|
3
|
+
import { Icon } from '@iconify/vue'
|
|
3
4
|
import type { Story, Variant } from '../../types'
|
|
4
5
|
import SandboxVue3 from '../sandbox/SandboxVue3.vue'
|
|
5
6
|
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
@@ -21,13 +22,17 @@ defineProps({
|
|
|
21
22
|
<div data-test-id="story-controls">
|
|
22
23
|
<!-- Custom controls -->
|
|
23
24
|
<SandboxVue3
|
|
24
|
-
v-if="variant.slots().controls"
|
|
25
|
+
v-if="variant.slots().controls || story.slots().controls"
|
|
25
26
|
slot-name="controls"
|
|
26
27
|
:variant="variant"
|
|
27
28
|
:story="story"
|
|
28
29
|
/>
|
|
29
30
|
|
|
30
31
|
<BaseEmpty v-else>
|
|
32
|
+
<Icon
|
|
33
|
+
icon="carbon:audio-console"
|
|
34
|
+
class="htw-w-8 htw-h-8 htw-opacity-50 htw-mb-6"
|
|
35
|
+
/>
|
|
31
36
|
<span>No controls available for this story</span>
|
|
32
37
|
</BaseEmpty>
|
|
33
38
|
</div>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { PropType, ref, watchEffect } from 'vue'
|
|
3
|
+
import { Icon } from '@iconify/vue'
|
|
3
4
|
import type { Story } from '../../types'
|
|
4
5
|
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
5
6
|
|
|
@@ -24,15 +25,21 @@ watchEffect(async () => {
|
|
|
24
25
|
</script>
|
|
25
26
|
|
|
26
27
|
<template>
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
<div>
|
|
29
|
+
<BaseEmpty
|
|
30
|
+
v-if="!renderedDoc"
|
|
31
|
+
>
|
|
32
|
+
<Icon
|
|
33
|
+
icon="carbon:document-unknown"
|
|
34
|
+
class="htw-w-8 htw-h-8 htw-opacity-50 htw-mb-6"
|
|
35
|
+
/>
|
|
36
|
+
No documentation available
|
|
37
|
+
</BaseEmpty>
|
|
38
|
+
<div
|
|
39
|
+
v-else
|
|
40
|
+
class="htw-prose dark:htw-prose-invert htw-p-4 htw-max-w-none"
|
|
41
|
+
data-test-id="story-docs"
|
|
42
|
+
v-html="renderedDoc"
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
38
45
|
</template>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { HstEvent } from '../../stores/events'
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{
|
|
6
|
+
event: HstEvent
|
|
7
|
+
}>()
|
|
8
|
+
|
|
9
|
+
const formattedArgument = computed(() => {
|
|
10
|
+
switch (typeof props.event.argument) {
|
|
11
|
+
case 'string':
|
|
12
|
+
return `"${props.event.argument}"`
|
|
13
|
+
case 'object':
|
|
14
|
+
return `{ ${Object.keys(props.event.argument).map((key) => `${key}: ${props.event.argument[key]}`).join(', ')} }`
|
|
15
|
+
default:
|
|
16
|
+
return props.event.argument
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<VDropdown
|
|
23
|
+
class="htw-group"
|
|
24
|
+
placement="right"
|
|
25
|
+
>
|
|
26
|
+
<template #default="{ shown }">
|
|
27
|
+
<div
|
|
28
|
+
class="group-hover:htw-bg-primary-100 dark:group-hover:htw-bg-primary-700 htw-cursor-pointer htw-py-2 htw-px-4 htw-flex htw-items-baseline htw-gap-1 htw-leading-normal"
|
|
29
|
+
:class="[
|
|
30
|
+
shown ? 'htw-bg-primary-50 dark:htw-bg-primary-600' : 'group-odd:htw-bg-gray-100/50 dark:group-odd:htw-bg-gray-750/40',
|
|
31
|
+
]"
|
|
32
|
+
>
|
|
33
|
+
<span
|
|
34
|
+
:class="{
|
|
35
|
+
'htw-text-primary-500': shown,
|
|
36
|
+
}"
|
|
37
|
+
>
|
|
38
|
+
{{ event.name }}
|
|
39
|
+
</span>
|
|
40
|
+
<span
|
|
41
|
+
v-if="event.argument"
|
|
42
|
+
class="htw-text-xs htw-opacity-50 htw-truncate"
|
|
43
|
+
>{{ formattedArgument }}</span>
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<template #popper>
|
|
48
|
+
<div class="htw-overflow-auto htw-max-w-[400px] htw-max-h-[400px]">
|
|
49
|
+
<pre class="htw-p-4">{{ event.argument }}</pre>
|
|
50
|
+
</div>
|
|
51
|
+
</template>
|
|
52
|
+
</VDropdown>
|
|
53
|
+
</template>
|