histoire 0.0.0 → 0.0.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.
- package/LICENSE +21 -0
- package/client.d.ts +2 -0
- package/dist/client/app/App.vue +84 -21
- package/dist/client/app/assets/histoire-text-dark.svg +89 -0
- package/dist/client/app/assets/histoire-text.svg +89 -0
- package/dist/client/app/assets/histoire.svg +51 -0
- package/dist/client/app/codegen/serialize-js.d.ts +1 -0
- package/dist/client/app/codegen/serialize-js.js +114 -0
- package/dist/client/app/codegen/serialize-js.js.map +1 -0
- package/dist/client/app/codegen/serialize-js.ts +119 -0
- package/dist/client/app/codegen/util.d.ts +10 -0
- package/dist/client/app/codegen/util.js +71 -0
- package/dist/client/app/codegen/util.js.map +1 -0
- package/dist/client/app/codegen/util.ts +79 -0
- package/dist/client/app/codegen/vue3.d.ts +2 -0
- package/dist/client/app/codegen/vue3.js +239 -0
- package/dist/client/app/codegen/vue3.js.map +1 -0
- package/dist/client/app/codegen/vue3.ts +240 -0
- package/dist/client/app/components/HomeView.vue +15 -1
- package/dist/client/app/components/StoryControls.vue +7 -2
- package/dist/client/app/components/StoryList.vue +20 -13
- package/dist/client/app/components/StoryListFolder.vue +80 -0
- package/dist/client/app/components/StoryListItem.vue +38 -12
- package/dist/client/app/components/StorySourceCode.vue +121 -0
- package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
- package/dist/client/app/components/StoryVariantListItem.vue +46 -0
- package/dist/client/app/components/StoryVariantSingleView.vue +117 -15
- package/dist/client/app/components/StoryView.vue +88 -54
- package/dist/client/app/components/app/AppHeader.vue +56 -0
- package/dist/client/app/components/app/AppLogo.vue +24 -0
- package/dist/client/app/components/base/BaseEmpty.vue +1 -1
- package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
- package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
- package/dist/client/app/components/exposed/Story.vue +23 -58
- package/dist/client/app/components/exposed/Variant.vue +24 -47
- package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
- package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
- package/dist/client/app/components/search/SearchItem.vue +110 -0
- package/dist/client/app/components/search/SearchModal.vue +179 -0
- package/dist/client/app/composable/variant.ts +20 -0
- package/dist/client/app/global-components.ts +10 -0
- package/dist/client/app/index.d.ts +1 -0
- package/dist/client/app/index.js +4 -1
- package/dist/client/app/index.js.map +1 -1
- package/dist/client/app/index.ts +18 -0
- package/dist/client/app/router.ts +17 -0
- package/dist/client/app/sandbox.d.ts +1 -0
- package/dist/client/app/sandbox.js +54 -0
- package/dist/client/app/sandbox.js.map +1 -0
- package/dist/client/app/sandbox.ts +60 -0
- package/dist/client/app/stores/story.d.ts +161 -50
- package/dist/client/app/stores/story.js +5 -16
- package/dist/client/app/stores/story.js.map +1 -1
- package/dist/client/app/stores/story.ts +22 -0
- package/dist/client/app/style/main.css +16 -2
- package/dist/client/app/style/sandbox.css +14 -0
- package/dist/client/app/types.d.ts +36 -4
- package/dist/client/app/types.ts +45 -0
- package/dist/client/app/util/config.d.ts +3 -0
- package/dist/client/app/util/config.js +5 -0
- package/dist/client/app/util/config.js.map +1 -0
- package/dist/client/app/util/config.ts +6 -0
- package/dist/client/app/util/const.d.ts +1 -0
- package/dist/client/app/util/const.js +2 -0
- package/dist/client/app/util/const.js.map +1 -0
- package/dist/client/app/util/const.ts +1 -0
- package/dist/client/app/util/dark.d.ts +2 -0
- package/dist/client/app/util/dark.js +4 -0
- package/dist/client/app/util/dark.js.map +1 -0
- package/dist/client/app/util/dark.ts +4 -0
- package/dist/client/app/util/env.d.ts +1 -0
- package/dist/client/app/util/env.js +2 -0
- package/dist/client/app/util/env.js.map +1 -0
- package/dist/client/app/util/keyboard.d.ts +8 -0
- package/dist/client/app/util/keyboard.js +83 -0
- package/dist/client/app/util/keyboard.js.map +1 -0
- package/dist/client/app/util/mapping.d.ts +3 -0
- package/dist/client/app/util/mapping.js +37 -0
- package/dist/client/app/util/mapping.js.map +1 -0
- package/dist/client/app/util/mapping.ts +38 -0
- package/dist/client/app/util/tooltip.d.ts +6 -0
- package/dist/client/app/util/tooltip.js +12 -0
- package/dist/client/app/util/tooltip.js.map +1 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +4 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.ts +12 -0
- package/dist/client/server/Story.server.vue +65 -0
- package/dist/client/server/Variant.server.vue +50 -0
- package/dist/client/server/index.d.ts +2 -0
- package/dist/client/server/index.js +26 -0
- package/dist/client/server/index.js.map +1 -0
- package/dist/client/server/index.ts +29 -0
- package/dist/client/shim.d.ts +5 -0
- package/dist/node/bin.js +8 -2
- package/dist/node/bin.js.map +1 -1
- package/dist/node/build.d.ts +2 -0
- package/dist/node/build.js +72 -0
- package/dist/node/build.js.map +1 -0
- package/dist/node/collect.d.ts +12 -0
- package/dist/node/collect.js +66 -0
- package/dist/node/collect.js.map +1 -0
- package/dist/node/colors.d.ts +274 -0
- package/dist/node/colors.js +313 -0
- package/dist/node/colors.js.map +1 -0
- package/dist/node/commands/build.d.ts +1 -0
- package/dist/node/commands/build.js +11 -0
- package/dist/node/commands/build.js.map +1 -0
- package/dist/node/commands/dev.d.ts +1 -1
- package/dist/node/commands/dev.js +6 -11
- package/dist/node/commands/dev.js.map +1 -1
- package/dist/node/config.d.ts +99 -1
- package/dist/node/config.js +90 -1
- package/dist/node/config.js.map +1 -1
- package/dist/node/context.d.ts +13 -0
- package/dist/node/context.js +12 -1
- package/dist/node/context.js.map +1 -1
- package/dist/node/dom/dom-keys.d.ts +4 -0
- package/dist/node/dom/dom-keys.js +224 -0
- package/dist/node/dom/dom-keys.js.map +1 -0
- package/dist/node/dom/env.d.ts +5 -0
- package/dist/node/dom/env.js +23 -0
- package/dist/node/dom/env.js.map +1 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +2 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/plugin.d.ts +8 -2
- package/dist/node/plugin.js +142 -21
- package/dist/node/plugin.js.map +1 -1
- package/dist/node/server.d.ts +4 -1
- package/dist/node/server.js +80 -20
- package/dist/node/server.js.map +1 -1
- package/dist/node/stories.d.ts +8 -9
- package/dist/node/stories.js +42 -22
- package/dist/node/stories.js.map +1 -1
- package/dist/node/tree.d.ts +19 -0
- package/dist/node/tree.js +55 -0
- package/dist/node/tree.js.map +1 -0
- package/dist/node/types.d.ts +38 -0
- package/dist/node/types.js +2 -0
- package/dist/node/types.js.map +1 -0
- package/dist/style.css +558 -52
- package/package.json +42 -25
- package/scripts/copy.mjs +11 -0
- package/src/client/app/App.vue +84 -21
- package/src/client/app/assets/histoire-text-dark.svg +89 -0
- package/src/client/app/assets/histoire-text.svg +89 -0
- package/src/client/app/assets/histoire.svg +51 -0
- package/src/client/app/codegen/serialize-js.ts +119 -0
- package/src/client/app/codegen/util.ts +79 -0
- package/src/client/app/codegen/vue3.ts +240 -0
- package/src/client/app/components/HomeView.vue +15 -1
- package/src/client/app/components/StoryControls.vue +7 -2
- package/src/client/app/components/StoryList.vue +20 -13
- package/src/client/app/components/StoryListFolder.vue +80 -0
- package/src/client/app/components/StoryListItem.vue +38 -12
- package/src/client/app/components/StorySourceCode.vue +121 -0
- package/src/client/app/components/StoryVariantGridItem.vue +32 -17
- package/src/client/app/components/StoryVariantListItem.vue +46 -0
- package/src/client/app/components/StoryVariantSingleView.vue +117 -15
- package/src/client/app/components/StoryView.vue +88 -54
- package/src/client/app/components/app/AppHeader.vue +56 -0
- package/src/client/app/components/app/AppLogo.vue +24 -0
- package/src/client/app/components/base/BaseEmpty.vue +1 -1
- package/src/client/app/components/base/BaseListItemLink.vue +55 -0
- package/src/client/app/components/base/BaseSplitPane.vue +57 -21
- package/src/client/app/components/exposed/Story.vue +23 -58
- package/src/client/app/components/exposed/Variant.vue +24 -47
- package/src/client/app/components/misc/HatchedPattern.vue +25 -0
- package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
- package/src/client/app/components/search/SearchItem.vue +110 -0
- package/src/client/app/components/search/SearchModal.vue +179 -0
- package/src/client/app/index.ts +4 -1
- package/src/client/app/sandbox.ts +60 -0
- package/src/client/app/stores/story.ts +6 -18
- package/src/client/app/style/main.css +16 -2
- package/src/client/app/style/sandbox.css +14 -0
- package/src/client/app/types.ts +42 -4
- package/src/client/app/util/config.ts +6 -0
- package/src/client/app/util/const.ts +1 -0
- package/src/client/app/util/dark.ts +4 -0
- package/src/client/app/util/env.ts +1 -0
- package/src/client/app/util/keyboard.ts +99 -0
- package/src/client/app/util/mapping.ts +38 -0
- package/src/client/app/util/tooltip.ts +13 -0
- package/src/client/index.ts +12 -0
- package/src/client/server/Story.server.vue +65 -0
- package/src/client/server/Variant.server.vue +50 -0
- package/src/client/server/index.ts +29 -0
- package/src/node/bin.ts +9 -2
- package/src/node/build.ts +80 -0
- package/src/node/collect.ts +78 -0
- package/src/node/colors.ts +328 -0
- package/src/node/commands/build.ts +12 -0
- package/src/node/commands/dev.ts +6 -13
- package/src/node/config.ts +193 -1
- package/src/node/context.ts +21 -1
- package/src/node/dom/dom-keys.ts +227 -0
- package/src/node/dom/env.ts +26 -0
- package/src/node/index.ts +2 -0
- package/src/node/plugin.ts +146 -22
- package/src/node/server.ts +95 -20
- package/src/node/stories.ts +53 -31
- package/src/node/tree.ts +88 -0
- package/src/node/types.ts +40 -0
- package/tailwind.config.cjs +41 -1
- package/dist/client/app/components/StoryVariantItem.vue +0 -29
- package/src/client/app/components/StoryVariantItem.vue +0 -29
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
+
|
|
3
|
+
export function indent (lines: string[], count = 1) {
|
|
4
|
+
return lines.map(line => `${' '.repeat(count)}${line}`)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function unindent (code: string) {
|
|
8
|
+
const lines = code.split('\n')
|
|
9
|
+
let indentLevel = -1
|
|
10
|
+
let indentText: string
|
|
11
|
+
const linesToAnalyze = lines.filter(line => line.trim().length > 0)
|
|
12
|
+
for (const line of linesToAnalyze) {
|
|
13
|
+
const match = /^\s*/.exec(line)
|
|
14
|
+
if (match && (indentLevel === -1 || indentLevel > match[0].length)) {
|
|
15
|
+
indentLevel = match[0].length
|
|
16
|
+
indentText = match[0]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const result: string[] = []
|
|
20
|
+
for (const line of lines) {
|
|
21
|
+
result.push(line.replace(indentText, ''))
|
|
22
|
+
}
|
|
23
|
+
return result.join('\n').trim()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface AutoBuildingOject {
|
|
27
|
+
key: string
|
|
28
|
+
cache: Record<string | symbol, AutoBuildingOject>
|
|
29
|
+
target: any
|
|
30
|
+
proxy: any
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function createAutoBuildingObject (format?: (key: string) => string, specialKeysHandler?: (target: any, p: string | symbol) => (() => unknown) | null, key = '', depth = 0): AutoBuildingOject {
|
|
34
|
+
const cache: Record<string | symbol, AutoBuildingOject> = {}
|
|
35
|
+
if (depth > 32) return { key, cache, target: {}, proxy: () => key }
|
|
36
|
+
const target: any = () => {
|
|
37
|
+
const k = key + '()'
|
|
38
|
+
return format ? format(k) : k
|
|
39
|
+
}
|
|
40
|
+
const proxy = new Proxy(target, {
|
|
41
|
+
get (_, p) {
|
|
42
|
+
if (p === '__autoBuildingObject') {
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
if (p === '__autoBuildingObjectGetKey') {
|
|
46
|
+
return key
|
|
47
|
+
}
|
|
48
|
+
if (specialKeysHandler) {
|
|
49
|
+
const fn = specialKeysHandler(target, p)
|
|
50
|
+
if (fn) {
|
|
51
|
+
return fn()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (p === 'toString') {
|
|
55
|
+
const k = key + '.toString()'
|
|
56
|
+
return () => format ? format(k) : k
|
|
57
|
+
}
|
|
58
|
+
if (p === Symbol.toPrimitive) {
|
|
59
|
+
return () => format ? format(key) : key
|
|
60
|
+
}
|
|
61
|
+
if (!cache[p]) {
|
|
62
|
+
const childKey = key ? `${key}.${p.toString()}` : p.toString()
|
|
63
|
+
const child = createAutoBuildingObject(format, specialKeysHandler, childKey, depth + 1)
|
|
64
|
+
cache[p] = { key: childKey, ...child }
|
|
65
|
+
}
|
|
66
|
+
return cache[p].proxy
|
|
67
|
+
},
|
|
68
|
+
apply (_, thisArg, args) {
|
|
69
|
+
const k = `${key}(${args.join(', ')})`
|
|
70
|
+
return format ? format(k) : k
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
return {
|
|
74
|
+
key,
|
|
75
|
+
cache,
|
|
76
|
+
target,
|
|
77
|
+
proxy,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
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, kebab } 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
|
+
|
|
38
|
+
// Directives
|
|
39
|
+
function genDirective (dirName: string, dir, valueCode: string = null) {
|
|
40
|
+
let modifiers = ''
|
|
41
|
+
for (const key in dir.modifiers) {
|
|
42
|
+
if (dir.modifiers[key]) {
|
|
43
|
+
modifiers += `.${key}`
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
let arg = ''
|
|
47
|
+
if (dir.arg) {
|
|
48
|
+
arg = `:${dir.arg}`
|
|
49
|
+
}
|
|
50
|
+
const valueLines = valueCode ? [valueCode] : serializeAndCleanJs(dir.value)
|
|
51
|
+
const attr: string[] = []
|
|
52
|
+
const dirAttr = `v-${dirName}${modifiers}${arg}="`
|
|
53
|
+
if (valueLines.length > 1) {
|
|
54
|
+
attr.push(`${dirAttr}${valueLines[0]}`)
|
|
55
|
+
attr.push(...valueLines.slice(1, valueLines.length - 1))
|
|
56
|
+
attr.push(`${valueLines[valueLines.length - 1]}"`)
|
|
57
|
+
multilineAttrs = true
|
|
58
|
+
} else {
|
|
59
|
+
attr.push(`${dirAttr}${valueLines[0] ?? ''}"`)
|
|
60
|
+
}
|
|
61
|
+
attrs.push(attr)
|
|
62
|
+
}
|
|
63
|
+
if (vnode.dirs) {
|
|
64
|
+
for (const dir of vnode.dirs) {
|
|
65
|
+
// Vmodel
|
|
66
|
+
if (dir.dir === vModelText || dir.dir === vModelSelect || dir.dir === vModelRadio || dir.dir === vModelCheckbox || dir.dir === vModelDynamic) {
|
|
67
|
+
const listenerKey = `onUpdate:${dir.arg ?? 'modelValue'}`
|
|
68
|
+
const listener = vnode.props[listenerKey]
|
|
69
|
+
let valueCode: string = null
|
|
70
|
+
if (listener) {
|
|
71
|
+
skipProps.push(listenerKey)
|
|
72
|
+
const listenerSource = listener.toString()
|
|
73
|
+
const result = /\(\$event\) => (.*?) = \$event/.exec(listenerSource)
|
|
74
|
+
if (result) {
|
|
75
|
+
valueCode = result[1]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
genDirective('model', dir, valueCode)
|
|
79
|
+
} else {
|
|
80
|
+
let dirName: string
|
|
81
|
+
for (const directives of [dir.instance._.directives, dir.instance._.appContext.directives]) {
|
|
82
|
+
for (const key in directives) {
|
|
83
|
+
if (dir.instance._.directives[key] === dir.dir) {
|
|
84
|
+
dirName = key
|
|
85
|
+
break
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (dirName) break
|
|
89
|
+
}
|
|
90
|
+
if (dirName) {
|
|
91
|
+
genDirective(dirName, dir)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Attributes
|
|
98
|
+
for (const prop in vnode.props) {
|
|
99
|
+
if (skipProps.includes(prop)) {
|
|
100
|
+
continue
|
|
101
|
+
}
|
|
102
|
+
const value = vnode.props[prop]
|
|
103
|
+
if (typeof value !== 'string' || vnode.dynamicProps?.includes(prop)) {
|
|
104
|
+
let directive = ':'
|
|
105
|
+
if (prop.startsWith('on')) {
|
|
106
|
+
directive = '@'
|
|
107
|
+
}
|
|
108
|
+
const arg = kebab(directive === '@' ? prop.slice(2) : prop)
|
|
109
|
+
let serialized: string[]
|
|
110
|
+
if (typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}')) {
|
|
111
|
+
// It was formatted from auto building object (slot props)
|
|
112
|
+
serialized = [value.substring(2, value.length - 2).trim()]
|
|
113
|
+
} else {
|
|
114
|
+
serialized = serializeAndCleanJs(value)
|
|
115
|
+
}
|
|
116
|
+
if (serialized.length > 1) {
|
|
117
|
+
multilineAttrs = true
|
|
118
|
+
const indented: string[] = [`${directive}${arg}="${serialized[0]}`]
|
|
119
|
+
indented.push(...serialized.slice(1, serialized.length - 1))
|
|
120
|
+
indented.push(`${serialized[serialized.length - 1]}"`)
|
|
121
|
+
attrs.push(indented)
|
|
122
|
+
} else {
|
|
123
|
+
attrs.push([`${directive}${arg}="${serialized[0]}"`])
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
attrs.push([`${kebab(prop)}="${value}"`])
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (attrs.length > 1) {
|
|
130
|
+
multilineAttrs = true
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Tags
|
|
134
|
+
const tagName = getTagName(vnode)
|
|
135
|
+
|
|
136
|
+
// Children
|
|
137
|
+
const childLines: string[] = []
|
|
138
|
+
if (typeof vnode.children === 'string') {
|
|
139
|
+
childLines.push(vnode.children)
|
|
140
|
+
} else if (Array.isArray(vnode.children)) {
|
|
141
|
+
for (const child of vnode.children) {
|
|
142
|
+
childLines.push(...await printVNode(child))
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Slots
|
|
147
|
+
if (vnode.children && typeof vnode.children === 'object' && !Array.isArray(vnode.children)) {
|
|
148
|
+
for (const key in vnode.children) {
|
|
149
|
+
if (typeof vnode.children[key] === 'function') {
|
|
150
|
+
const autoObject = createAutoBuildingObject(key => `{{ ${key} }}`, (target, p) => {
|
|
151
|
+
// Vue 3
|
|
152
|
+
if (p === '__v_isRef') {
|
|
153
|
+
return () => false
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
const children = vnode.children[key](autoObject.proxy)
|
|
157
|
+
const slotLines: string[] = []
|
|
158
|
+
for (const child of children) {
|
|
159
|
+
slotLines.push(...await printVNode(child))
|
|
160
|
+
}
|
|
161
|
+
const slotProps = Object.keys(autoObject.cache)
|
|
162
|
+
if (slotProps.length) {
|
|
163
|
+
childLines.push(`<template #${key}="{ ${slotProps.join(', ')} }">`)
|
|
164
|
+
childLines.push(...indent(slotLines))
|
|
165
|
+
childLines.push('</template>')
|
|
166
|
+
} else if (key === 'default') {
|
|
167
|
+
childLines.push(...slotLines)
|
|
168
|
+
} else {
|
|
169
|
+
childLines.push(`<template #${key}>`)
|
|
170
|
+
childLines.push(...indent(slotLines))
|
|
171
|
+
childLines.push(`</template>`)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Template
|
|
178
|
+
const tag = [`<${tagName}`]
|
|
179
|
+
if (multilineAttrs) {
|
|
180
|
+
for (const attrLines of attrs) {
|
|
181
|
+
tag.push(...indent(attrLines))
|
|
182
|
+
}
|
|
183
|
+
if (childLines.length > 0) {
|
|
184
|
+
tag.push('>')
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
if (attrs.length === 1) {
|
|
188
|
+
tag[0] += ` ${attrs[0]}`
|
|
189
|
+
}
|
|
190
|
+
if (childLines.length > 0) {
|
|
191
|
+
tag[0] += '>'
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (childLines.length > 0) {
|
|
196
|
+
lines.push(...tag)
|
|
197
|
+
lines.push(...indent(childLines))
|
|
198
|
+
lines.push(`</${tagName}>`)
|
|
199
|
+
} else if (tag.length > 1) {
|
|
200
|
+
lines.push(...tag)
|
|
201
|
+
lines.push('/>')
|
|
202
|
+
} else {
|
|
203
|
+
lines.push(`${tag[0]} />`)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return lines
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function getTagName (vnode: VNode) {
|
|
211
|
+
if (typeof vnode.type === 'string') {
|
|
212
|
+
return vnode.type
|
|
213
|
+
} else if (vnode.type?.__asyncResolved) {
|
|
214
|
+
const asyncComp = vnode.type?.__asyncResolved
|
|
215
|
+
return asyncComp.name ?? getNameFromFile(asyncComp.__file)
|
|
216
|
+
} else if (vnode.type?.name) {
|
|
217
|
+
return vnode.type.name
|
|
218
|
+
} else if (vnode.type?.__file) {
|
|
219
|
+
return getNameFromFile(vnode.type.__file)
|
|
220
|
+
}
|
|
221
|
+
return 'Anonymous'
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function getNameFromFile (file: string) {
|
|
225
|
+
const parts = /\/([^/]+)\.vue$/.exec(file)
|
|
226
|
+
if (parts) {
|
|
227
|
+
return pascal(parts[1])
|
|
228
|
+
}
|
|
229
|
+
return 'Anonymous'
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function serializeAndCleanJs (value: any) {
|
|
233
|
+
const isAutoBuildingObject = !!value?.__autoBuildingObject
|
|
234
|
+
const result = serializeJs(value)
|
|
235
|
+
if (isAutoBuildingObject) {
|
|
236
|
+
return [result.__autoBuildingObjectGetKey]
|
|
237
|
+
} else {
|
|
238
|
+
return result.replace(/\$setup\./g, '').split('\n')
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { histoireConfig, customLogos } from '../util/config.js'
|
|
4
|
+
import HistoireLogo from '../assets/histoire.svg'
|
|
5
|
+
|
|
6
|
+
const logoUrl = computed(() => histoireConfig.theme?.logo?.square ? customLogos.square : HistoireLogo)
|
|
7
|
+
</script>
|
|
8
|
+
|
|
1
9
|
<template>
|
|
2
|
-
|
|
10
|
+
<div class="htw-flex htw-items-center htw-justify-center htw-h-full">
|
|
11
|
+
<img
|
|
12
|
+
:src="logoUrl"
|
|
13
|
+
alt="Logo"
|
|
14
|
+
class="htw-w-64 htw-h-64 htw-opacity-25"
|
|
15
|
+
>
|
|
16
|
+
</div>
|
|
3
17
|
</template>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { PropType } from 'vue'
|
|
3
3
|
import { Story, Variant } from '../types'
|
|
4
|
-
import
|
|
4
|
+
import SandboxVue3 from './sandbox/SandboxVue3.vue'
|
|
5
|
+
import BaseEmpty from './base/BaseEmpty.vue'
|
|
5
6
|
|
|
6
7
|
defineProps({
|
|
7
8
|
variant: {
|
|
@@ -19,11 +20,15 @@ defineProps({
|
|
|
19
20
|
<template>
|
|
20
21
|
<div>
|
|
21
22
|
<!-- Custom controls -->
|
|
22
|
-
<
|
|
23
|
+
<SandboxVue3
|
|
23
24
|
v-if="variant.slots().controls"
|
|
24
25
|
slot-name="controls"
|
|
25
26
|
:variant="variant"
|
|
26
27
|
:story="story"
|
|
27
28
|
/>
|
|
29
|
+
|
|
30
|
+
<BaseEmpty v-else>
|
|
31
|
+
<span>No controls available for this story</span>
|
|
32
|
+
</BaseEmpty>
|
|
28
33
|
</div>
|
|
29
34
|
</template>
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import {
|
|
3
|
-
import { Story } from '../types'
|
|
2
|
+
import { Story, Tree } from '../types'
|
|
4
3
|
import StoryListItem from './StoryListItem.vue'
|
|
4
|
+
import StoryListFolder from './StoryListFolder.vue'
|
|
5
5
|
|
|
6
|
-
const props = defineProps
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
})
|
|
6
|
+
const props = defineProps<{
|
|
7
|
+
tree: Tree
|
|
8
|
+
stories: Story[]
|
|
9
|
+
}>()
|
|
12
10
|
</script>
|
|
13
11
|
|
|
14
12
|
<template>
|
|
15
13
|
<div class="htw-overflow-y-auto">
|
|
16
|
-
<
|
|
17
|
-
v-for="
|
|
18
|
-
:key="
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
<template
|
|
15
|
+
v-for="element of tree"
|
|
16
|
+
:key="element.title"
|
|
17
|
+
>
|
|
18
|
+
<StoryListFolder
|
|
19
|
+
v-if="element.children"
|
|
20
|
+
:folder="element"
|
|
21
|
+
:stories="stories"
|
|
22
|
+
/>
|
|
23
|
+
<StoryListItem
|
|
24
|
+
v-else
|
|
25
|
+
:story="stories[element.index]"
|
|
26
|
+
/>
|
|
27
|
+
</template>
|
|
21
28
|
</div>
|
|
22
29
|
</template>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { Story, TreeFolder } from '../types'
|
|
3
|
+
import StoryListItem from './StoryListItem.vue'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
import { computed, ref, withDefaults } from 'vue'
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(defineProps<{
|
|
8
|
+
folder: TreeFolder
|
|
9
|
+
stories: Story[]
|
|
10
|
+
depth?: number
|
|
11
|
+
}>(), {
|
|
12
|
+
depth: 0,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const isFolderOpen = ref(false)
|
|
16
|
+
|
|
17
|
+
function toggleOpen () {
|
|
18
|
+
isFolderOpen.value = !isFolderOpen.value
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const folderPadding = computed(() => {
|
|
22
|
+
return (props.depth * 16) + 'px'
|
|
23
|
+
})
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<div class="toast">
|
|
28
|
+
<div
|
|
29
|
+
role="button"
|
|
30
|
+
tabindex="0"
|
|
31
|
+
class="htw-px-0.5 htw-py-1.5 htw-m-1 htw-rounded-sm hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900 htw-cursor-pointer htw-select-none htw-flex"
|
|
32
|
+
@click="toggleOpen"
|
|
33
|
+
@keyup.enter="toggleOpen"
|
|
34
|
+
@keyup.space="toggleOpen"
|
|
35
|
+
>
|
|
36
|
+
<span class="bind-tree-padding htw-flex htw-items-center htw-gap-2 htw-min-w-0">
|
|
37
|
+
<span class="htw-flex htw-gap-1 htw-flex-none htw-items-center">
|
|
38
|
+
<Icon
|
|
39
|
+
icon="carbon:caret-right"
|
|
40
|
+
class="htw-w-4 htw-h-4 htw-transition-transform htw-duration-150 htw-opacity-30"
|
|
41
|
+
:class="{
|
|
42
|
+
'htw-rotate-90': isFolderOpen,
|
|
43
|
+
}"
|
|
44
|
+
/>
|
|
45
|
+
<Icon
|
|
46
|
+
icon="carbon:folder"
|
|
47
|
+
class="htw-w-5 htw-h-5"
|
|
48
|
+
/>
|
|
49
|
+
</span>
|
|
50
|
+
<span class="htw-truncate">{{ folder.title }}</span>
|
|
51
|
+
</span>
|
|
52
|
+
</div>
|
|
53
|
+
<div
|
|
54
|
+
v-if="isFolderOpen"
|
|
55
|
+
>
|
|
56
|
+
<template
|
|
57
|
+
v-for="element of folder.children"
|
|
58
|
+
:key="element.title"
|
|
59
|
+
>
|
|
60
|
+
<StoryListFolder
|
|
61
|
+
v-if="element.children"
|
|
62
|
+
:folder="element"
|
|
63
|
+
:stories="stories"
|
|
64
|
+
:depth="depth + 1"
|
|
65
|
+
/>
|
|
66
|
+
<StoryListItem
|
|
67
|
+
v-else
|
|
68
|
+
:story="stories[element.index]"
|
|
69
|
+
:depth="depth + 1"
|
|
70
|
+
/>
|
|
71
|
+
</template>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
</template>
|
|
75
|
+
|
|
76
|
+
<style scoped>
|
|
77
|
+
.bind-tree-padding {
|
|
78
|
+
padding-left: v-bind(folderPadding);
|
|
79
|
+
}
|
|
80
|
+
</style>
|
|
@@ -1,34 +1,60 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import { PropType } from 'vue'
|
|
3
2
|
import { Story } from '../types'
|
|
3
|
+
import BaseListItemLink from './base/BaseListItemLink.vue'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
import { computed, withDefaults } from 'vue'
|
|
4
6
|
|
|
5
|
-
defineProps
|
|
6
|
-
story:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const props = withDefaults(defineProps<{
|
|
8
|
+
story: Story
|
|
9
|
+
depth?: number
|
|
10
|
+
}>(), {
|
|
11
|
+
depth: 0,
|
|
10
12
|
})
|
|
13
|
+
|
|
14
|
+
const filePadding = computed(() => {
|
|
15
|
+
return (props.depth * 16) + 'px'
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const iconColor = computed(() => props.story.iconColor)
|
|
11
19
|
</script>
|
|
12
20
|
|
|
13
21
|
<template>
|
|
14
22
|
<div>
|
|
15
|
-
<
|
|
23
|
+
<BaseListItemLink
|
|
24
|
+
v-slot="{ active }"
|
|
16
25
|
:to="{
|
|
17
26
|
name: 'story',
|
|
18
27
|
params: {
|
|
19
28
|
storyId: story.id,
|
|
20
29
|
},
|
|
21
30
|
}"
|
|
22
|
-
class="htw-
|
|
23
|
-
active-class="htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white htw-font-bold"
|
|
31
|
+
class="htw-pl-0.5 htw-pr-2 htw-py-1.5 htw-m-1 htw-rounded-sm"
|
|
24
32
|
>
|
|
25
|
-
<span>
|
|
26
|
-
|
|
33
|
+
<span class="bind-tree-margin htw-flex htw-items-center htw-gap-2 htw-pl-5 htw-min-w-0">
|
|
34
|
+
<Icon
|
|
35
|
+
:icon="story.icon ?? 'carbon:cube'"
|
|
36
|
+
class="base-list-item-link-icon htw-w-5 htw-h-5 htw-flex-none"
|
|
37
|
+
:class="{
|
|
38
|
+
'htw-text-primary-500': !active && !story.iconColor,
|
|
39
|
+
'bind-icon-color': !active && story.iconColor,
|
|
40
|
+
}"
|
|
41
|
+
/>
|
|
42
|
+
<span class="htw-truncate">{{ story.title }}</span>
|
|
27
43
|
</span>
|
|
28
44
|
|
|
29
45
|
<span class="htw-opacity-40 htw-text-sm">
|
|
30
46
|
{{ story.variants.length }}
|
|
31
47
|
</span>
|
|
32
|
-
</
|
|
48
|
+
</BaseListItemLink>
|
|
33
49
|
</div>
|
|
34
50
|
</template>
|
|
51
|
+
|
|
52
|
+
<style scoped>
|
|
53
|
+
.bind-tree-margin {
|
|
54
|
+
margin-left: v-bind(filePadding);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.bind-icon-color {
|
|
58
|
+
color: v-bind(iconColor);
|
|
59
|
+
}
|
|
60
|
+
</style>
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed, onMounted, PropType, ref, shallowRef, watch } from 'vue'
|
|
3
|
+
import { getHighlighter, Highlighter, setCDN } from 'shiki'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
import { generateSourceCode } from '../codegen/vue3'
|
|
6
|
+
import { Variant } from '../types'
|
|
7
|
+
import { isDark } from '../util/dark'
|
|
8
|
+
import { unindent } from '../codegen/util'
|
|
9
|
+
import { useClipboard } from '@vueuse/core'
|
|
10
|
+
|
|
11
|
+
const props = defineProps({
|
|
12
|
+
variant: {
|
|
13
|
+
type: Object as PropType<Variant>,
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const sourceCode = ref('')
|
|
19
|
+
const highlighter = shallowRef<Highlighter>()
|
|
20
|
+
const error = ref<string>(null)
|
|
21
|
+
|
|
22
|
+
onMounted(async () => {
|
|
23
|
+
setCDN('https://unpkg.com/shiki/')
|
|
24
|
+
highlighter.value = await getHighlighter({
|
|
25
|
+
langs: [
|
|
26
|
+
'html',
|
|
27
|
+
'jsx',
|
|
28
|
+
],
|
|
29
|
+
themes: [
|
|
30
|
+
'github-light',
|
|
31
|
+
'github-dark',
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
watch(() => props.variant, async (value) => {
|
|
37
|
+
error.value = null
|
|
38
|
+
try {
|
|
39
|
+
if (value.source) {
|
|
40
|
+
sourceCode.value = value.source
|
|
41
|
+
} else if (value.slots?.().source) {
|
|
42
|
+
const source = value.slots?.().source()[0].children
|
|
43
|
+
if (source) {
|
|
44
|
+
sourceCode.value = await unindent(source)
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
sourceCode.value = await generateSourceCode(value)
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.error(e)
|
|
51
|
+
error.value = e.message
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
deep: true,
|
|
55
|
+
immediate: true,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const sourceHtml = computed(() => highlighter.value?.codeToHtml(sourceCode.value, {
|
|
59
|
+
lang: 'html',
|
|
60
|
+
theme: isDark.value ? 'github-dark' : 'github-light',
|
|
61
|
+
}))
|
|
62
|
+
|
|
63
|
+
// Copy
|
|
64
|
+
const { copy, copied } = useClipboard()
|
|
65
|
+
|
|
66
|
+
const copySourceCode = () => copy(sourceCode.value)
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<div class="htw-bg-gray-100 dark:htw-bg-gray-800 htw-h-full htw-overflow-hidden htw-relative">
|
|
71
|
+
<div
|
|
72
|
+
v-if="error"
|
|
73
|
+
class="htw-text-red-500 htw-h-full htw-p-2 htw-overflow-auto htw-font-mono htw-text-sm"
|
|
74
|
+
>
|
|
75
|
+
Error: {{ error }}
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<textarea
|
|
79
|
+
v-else-if="!sourceHtml"
|
|
80
|
+
class="__histoire-code-placeholder htw-w-full htw-h-full htw-p-2.5 htw-outline-none htw-bg-transparent htw-resize-none htw-m-0"
|
|
81
|
+
:value="sourceCode"
|
|
82
|
+
readonly
|
|
83
|
+
/>
|
|
84
|
+
<!-- eslint-disable vue/no-v-html -->
|
|
85
|
+
<div
|
|
86
|
+
v-else
|
|
87
|
+
class="__histoire-code htw-w-full htw-h-full htw-p-2.5 htw-overflow-auto"
|
|
88
|
+
v-html="sourceHtml"
|
|
89
|
+
/>
|
|
90
|
+
<!-- eslint-enable vue/no-v-html -->
|
|
91
|
+
|
|
92
|
+
<!-- Toolbar -->
|
|
93
|
+
<div
|
|
94
|
+
v-if="!error"
|
|
95
|
+
class="htw-absolute htw-top-2 htw-right-6 htw-p-1 htw-bg-gray-100 dark:htw-bg-gray-800"
|
|
96
|
+
>
|
|
97
|
+
<Icon
|
|
98
|
+
v-tooltip="{
|
|
99
|
+
content: 'Copied!',
|
|
100
|
+
triggers: [],
|
|
101
|
+
shown: copied,
|
|
102
|
+
distance: 12,
|
|
103
|
+
}"
|
|
104
|
+
icon="cil:copy"
|
|
105
|
+
class="htw-w-4 htw-h-4 hover:htw-text-primary-500 dark:hover:htw-text-primary-400 htw-cursor-pointer"
|
|
106
|
+
@click="copySourceCode()"
|
|
107
|
+
/>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
</template>
|
|
111
|
+
|
|
112
|
+
<style scoped>
|
|
113
|
+
.__histoire-code-placeholder {
|
|
114
|
+
color: inherit;
|
|
115
|
+
font-size: inherit;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.__histoire-code:deep(.shiki) {
|
|
119
|
+
background: transparent !important;
|
|
120
|
+
}
|
|
121
|
+
</style>
|