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
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
const KEY_ESCAPE_REG = /[\s-.:|#@$£*%]/
|
|
2
|
-
const MAX_SINGLE_LINE_ARRAY_LENGTH = 3
|
|
3
|
-
|
|
4
|
-
interface Line {
|
|
5
|
-
spaces: number
|
|
6
|
-
line: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function serializeJs (value: any): string {
|
|
10
|
-
if (value === undefined) {
|
|
11
|
-
return 'undefined'
|
|
12
|
-
}
|
|
13
|
-
if (value === null) {
|
|
14
|
-
return 'null'
|
|
15
|
-
}
|
|
16
|
-
if (typeof value === 'string') {
|
|
17
|
-
return `'${value}'`
|
|
18
|
-
}
|
|
19
|
-
if (typeof value === 'boolean') {
|
|
20
|
-
return value ? 'true' : 'false'
|
|
21
|
-
}
|
|
22
|
-
if (Array.isArray(value)) {
|
|
23
|
-
return printLines(arrayToSourceLines(value))
|
|
24
|
-
}
|
|
25
|
-
if (typeof value === 'object') {
|
|
26
|
-
return printLines(objectToSourceLines(value))
|
|
27
|
-
}
|
|
28
|
-
if (value?.__autoBuildingObject) {
|
|
29
|
-
return value
|
|
30
|
-
}
|
|
31
|
-
if (typeof value === 'function' && value.name) {
|
|
32
|
-
return value.name
|
|
33
|
-
}
|
|
34
|
-
return value.toString()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function printLines (lines: Line[]) {
|
|
38
|
-
return lines.map(line => ' '.repeat(line.spaces) + line.line).join('\n')
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function objectToSourceLines (object, indentCount = 0) {
|
|
42
|
-
return createLines(indentCount, lines => {
|
|
43
|
-
lines.push('{')
|
|
44
|
-
lines.push(...createLines(1, lines => {
|
|
45
|
-
for (const key in object) {
|
|
46
|
-
const value = object[key]
|
|
47
|
-
|
|
48
|
-
let printedKey = key
|
|
49
|
-
if (KEY_ESCAPE_REG.test(key)) {
|
|
50
|
-
printedKey = `'${printedKey}'`
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
addLinesFromValue(lines, value, `${printedKey}: `, ',')
|
|
54
|
-
}
|
|
55
|
-
}))
|
|
56
|
-
lines.push('}')
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function arrayToSourceLines (array: any[], indentCount = 0) {
|
|
61
|
-
return createLines(indentCount, lines => {
|
|
62
|
-
const contentLines = createLines(1, lines => {
|
|
63
|
-
for (const value of array) {
|
|
64
|
-
addLinesFromValue(lines, value, '', ',')
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
if (contentLines.length === 0) {
|
|
68
|
-
lines.push('[]')
|
|
69
|
-
} else if (contentLines.length <= MAX_SINGLE_LINE_ARRAY_LENGTH) {
|
|
70
|
-
const [first] = contentLines
|
|
71
|
-
first.line = contentLines.map(({ line }) => line.substring(0, line.length - 1)).join(', ')
|
|
72
|
-
first.line = `[${first.line}]`
|
|
73
|
-
first.spaces--
|
|
74
|
-
lines.push(first)
|
|
75
|
-
} else {
|
|
76
|
-
lines.push('[', ...contentLines, ']')
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function createLines (indentCount: number, handler: (lines: any[]) => unknown) {
|
|
82
|
-
const lines: any[] = []
|
|
83
|
-
handler(lines)
|
|
84
|
-
return lines.map(line => {
|
|
85
|
-
if (line.spaces != null) {
|
|
86
|
-
line.spaces += indentCount
|
|
87
|
-
return line
|
|
88
|
-
}
|
|
89
|
-
return { spaces: indentCount, line }
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function addLinesFromValue (lines: Line[], value, before, after) {
|
|
94
|
-
let result
|
|
95
|
-
if (Array.isArray(value)) {
|
|
96
|
-
lines.push(...wrap(arrayToSourceLines(value), before, after))
|
|
97
|
-
return
|
|
98
|
-
} else if (value && typeof value === 'object') {
|
|
99
|
-
lines.push(...wrap(objectToSourceLines(value), before, after))
|
|
100
|
-
return
|
|
101
|
-
} else if (typeof value === 'string') {
|
|
102
|
-
result = value.includes('\'') ? `\`${value}\`` : `'${value}'`
|
|
103
|
-
} else if (typeof value === 'undefined') {
|
|
104
|
-
result = 'undefined'
|
|
105
|
-
} else if (value === null) {
|
|
106
|
-
result = 'null'
|
|
107
|
-
} else if (typeof value === 'boolean') {
|
|
108
|
-
result = value ? 'true' : 'false'
|
|
109
|
-
} else {
|
|
110
|
-
result = value
|
|
111
|
-
}
|
|
112
|
-
lines.push(before + result + after)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function wrap (lines: Line[], before: string, after: string) {
|
|
116
|
-
lines[0].line = before + lines[0].line
|
|
117
|
-
lines[lines.length - 1].line += after
|
|
118
|
-
return lines
|
|
119
|
-
}
|
|
@@ -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
|
-
})
|