histoire 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +82 -21
- package/dist/client/app/components/base/BaseEmpty.vue +17 -1
- package/dist/client/app/components/exposed/Story.vue +22 -1
- package/dist/client/app/components/exposed/Variant.vue +13 -1
- package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -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 +7 -0
- package/dist/client/app/components/story/StoryControls.vue +5 -0
- package/dist/client/app/components/story/StoryDocs.vue +18 -11
- package/dist/client/app/components/story/StoryEvent.vue +53 -0
- package/dist/client/app/components/story/StoryEvents.vue +45 -0
- package/dist/client/app/components/story/StoryResponsivePreview.vue +41 -8
- package/dist/client/app/components/story/StorySidePanel.vue +28 -3
- package/dist/client/app/components/story/StorySourceCode.vue +24 -14
- package/dist/client/app/components/story/StoryView.vue +16 -2
- 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/router.d.ts +1 -0
- package/dist/client/app/router.js +3 -1
- package/dist/client/app/sandbox.js +11 -1
- package/dist/client/app/stores/events.d.ts +29 -0
- package/dist/client/app/stores/events.js +25 -0
- package/dist/client/app/stores/folder.d.ts +10 -0
- package/dist/client/app/stores/folder.js +47 -0
- package/dist/client/app/stores/story.d.ts +14 -8
- package/dist/client/app/stores/story.js +20 -33
- package/dist/client/app/style/main.pcss +5 -0
- package/dist/client/app/style/sandbox.css +2 -0
- package/dist/client/app/types.d.ts +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 +31 -0
- package/dist/client/app/util/mapping.js +2 -2
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.js +2 -1
- package/dist/client/server/Story.server.vue +13 -2
- 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/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 +111 -47
- package/package.json +5 -3
- 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/exposed/Story.vue +22 -1
- package/src/client/app/components/exposed/Variant.vue +13 -1
- package/src/client/app/components/sandbox/SandboxVue3.vue +6 -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/StoryControls.vue +5 -0
- package/src/client/app/components/story/StoryDocs.vue +18 -11
- package/src/client/app/components/story/StoryEvent.vue +53 -0
- package/src/client/app/components/story/StoryEvents.vue +45 -0
- package/src/client/app/components/story/StoryResponsivePreview.vue +41 -8
- package/src/client/app/components/story/StorySidePanel.vue +28 -3
- package/src/client/app/components/story/StorySourceCode.vue +24 -14
- package/src/client/app/components/story/StoryView.vue +16 -2
- 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 +12 -2
- 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/types.ts +1 -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 +2 -2
- package/src/client/index.ts +2 -1
- package/src/client/server/Story.server.vue +13 -2
- 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/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/server/index.ts +0 -32
- package/dist/client/shim.d.ts +0 -5
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -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().replace(/'/g, '\\\'').replace(/"/g, '\'')]
|
|
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,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
|
-
}
|
package/dist/client/app/index.ts
DELETED
|
@@ -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
|
-
})
|
package/dist/client/app/types.ts
DELETED
|
@@ -1,78 +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
|
-
group?: string
|
|
15
|
-
variants: Variant[]
|
|
16
|
-
layout?: {
|
|
17
|
-
type: 'single'
|
|
18
|
-
} | {
|
|
19
|
-
type: 'grid'
|
|
20
|
-
width?: number | string
|
|
21
|
-
}
|
|
22
|
-
icon?: string
|
|
23
|
-
iconColor?: string
|
|
24
|
-
file?: StoryFile
|
|
25
|
-
lastSelectedVariant?: Variant
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface Variant {
|
|
29
|
-
id: string
|
|
30
|
-
title: string
|
|
31
|
-
icon?: string
|
|
32
|
-
iconColor?: string
|
|
33
|
-
initState?: () => any
|
|
34
|
-
slots?: () => Readonly<any>
|
|
35
|
-
state?: any
|
|
36
|
-
source?: string
|
|
37
|
-
responsiveDisabled?: boolean
|
|
38
|
-
configReady?: boolean
|
|
39
|
-
previewReady?: boolean
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export type TreeLeaf = {
|
|
43
|
-
title: string
|
|
44
|
-
index: number
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type TreeFolder = {
|
|
48
|
-
title: string
|
|
49
|
-
children: (TreeFolder | TreeLeaf)[]
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface TreeGroup {
|
|
53
|
-
group: true
|
|
54
|
-
id: string
|
|
55
|
-
title: string
|
|
56
|
-
children: (TreeFolder | TreeLeaf)[]
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export type Tree = (TreeGroup | TreeFolder | TreeLeaf)[]
|
|
60
|
-
|
|
61
|
-
export interface SearchResult {
|
|
62
|
-
kind: 'story' | 'variant'
|
|
63
|
-
rank: number
|
|
64
|
-
id: string
|
|
65
|
-
title: string
|
|
66
|
-
route: RouteLocationRaw
|
|
67
|
-
path?: string[]
|
|
68
|
-
icon?: string
|
|
69
|
-
iconColor?: string
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface PreviewSettings {
|
|
73
|
-
responsiveWidth: number
|
|
74
|
-
responsiveHeight: number
|
|
75
|
-
rotate: boolean
|
|
76
|
-
backgroundColor: string
|
|
77
|
-
checkerboard: boolean
|
|
78
|
-
}
|
|
@@ -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 +0,0 @@
|
|
|
1
|
-
export const isMac = navigator.platform.toLowerCase().includes('mac')
|