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
package/src/node/plugin.ts
CHANGED
|
@@ -1,47 +1,88 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { relative } from 'pathe'
|
|
2
|
+
import { resolveConfig as resolveViteConfig, Plugin as VitePlugin } from 'vite'
|
|
3
|
+
import { lookup as lookupMime } from 'mrmime'
|
|
2
4
|
import { APP_PATH, DIST_CLIENT_PATH } from './alias.js'
|
|
3
5
|
import { Context } from './context.js'
|
|
4
|
-
import {
|
|
6
|
+
import { notifyStoryChange } from './stories.js'
|
|
7
|
+
import { makeTree } from './tree.js'
|
|
8
|
+
import { parseColor } from './colors.js'
|
|
5
9
|
|
|
6
10
|
export const STORIES_ID = '$histoire-stories'
|
|
7
11
|
export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`
|
|
12
|
+
export const SETUP_ID = '$histoire-setup'
|
|
13
|
+
export const NOOP_ID = '/$histoire-noop'
|
|
14
|
+
export const CONFIG_ID = '$histoire-config'
|
|
15
|
+
export const RESOLVED_CONFIG_ID = `/${CONFIG_ID}-resolved`
|
|
16
|
+
export const THEME_ID = '$histoire-theme'
|
|
17
|
+
export const RESOLVED_THEME_ID = `/${THEME_ID}-resolved.css`
|
|
8
18
|
|
|
9
|
-
export async function createVitePlugins (ctx: Context): Promise<
|
|
10
|
-
const
|
|
19
|
+
export async function createVitePlugins (ctx: Context): Promise<VitePlugin[]> {
|
|
20
|
+
const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build')
|
|
21
|
+
const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue')
|
|
11
22
|
|
|
12
|
-
const
|
|
23
|
+
const plugins: VitePlugin[] = []
|
|
13
24
|
|
|
14
|
-
|
|
25
|
+
if (!hasVuePlugin) {
|
|
26
|
+
plugins.push((await import('@vitejs/plugin-vue')).default())
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
plugins.push({
|
|
15
30
|
name: 'histoire-vite-plugin',
|
|
16
31
|
|
|
17
32
|
config () {
|
|
18
|
-
|
|
19
|
-
|
|
33
|
+
return {
|
|
20
34
|
optimizeDeps: {
|
|
21
35
|
// force include vue to avoid duplicated copies when linked + optimized
|
|
22
|
-
include: [
|
|
36
|
+
include: [
|
|
37
|
+
'vue',
|
|
38
|
+
'@vue/runtime-core',
|
|
39
|
+
],
|
|
23
40
|
},
|
|
24
41
|
server: {
|
|
25
42
|
fs: {
|
|
26
|
-
allow: [DIST_CLIENT_PATH,
|
|
43
|
+
allow: [DIST_CLIENT_PATH, viteConfig.root, process.cwd()],
|
|
27
44
|
},
|
|
28
45
|
},
|
|
29
|
-
}
|
|
30
|
-
return userViteConfig
|
|
31
|
-
? mergeConfig(userViteConfig, baseConfig)
|
|
32
|
-
: baseConfig
|
|
46
|
+
}
|
|
33
47
|
},
|
|
34
48
|
|
|
35
|
-
resolveId (id) {
|
|
49
|
+
async resolveId (id, importer) {
|
|
36
50
|
if (id.startsWith(STORIES_ID)) {
|
|
37
51
|
return RESOLVED_STORIES_ID
|
|
38
52
|
}
|
|
53
|
+
if (id.startsWith(SETUP_ID)) {
|
|
54
|
+
if (ctx.config.setupFile) {
|
|
55
|
+
return this.resolve(ctx.config.setupFile, importer, {
|
|
56
|
+
skipSelf: true,
|
|
57
|
+
})
|
|
58
|
+
} else {
|
|
59
|
+
return NOOP_ID
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (id.startsWith(CONFIG_ID)) {
|
|
63
|
+
return RESOLVED_CONFIG_ID
|
|
64
|
+
}
|
|
65
|
+
if (id.startsWith(THEME_ID)) {
|
|
66
|
+
return RESOLVED_THEME_ID
|
|
67
|
+
}
|
|
39
68
|
},
|
|
40
69
|
|
|
41
70
|
load (id) {
|
|
42
71
|
if (id === RESOLVED_STORIES_ID) {
|
|
43
|
-
|
|
44
|
-
|
|
72
|
+
const resolvedStories = ctx.storyFiles.filter(s => !!s.story)
|
|
73
|
+
const files = resolvedStories.map((file, index) => {
|
|
74
|
+
return {
|
|
75
|
+
id: file.id,
|
|
76
|
+
path: file.treePath,
|
|
77
|
+
story: file.story,
|
|
78
|
+
framework: 'vue3',
|
|
79
|
+
index,
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
return `import { defineAsyncComponent } from 'vue'
|
|
83
|
+
${resolvedStories.map((file, index) => `const Comp${index} = defineAsyncComponent(() => import('${file.path}'))`).join('\n')}
|
|
84
|
+
export let files = [${files.map((file) => `{${JSON.stringify(file).slice(1, -1)}, component: Comp${file.index}}`).join(',\n')}]
|
|
85
|
+
export let tree = ${JSON.stringify(makeTree(ctx.config, files))}
|
|
45
86
|
const handlers = []
|
|
46
87
|
export function onUpdate (cb) {
|
|
47
88
|
handlers.push(cb)
|
|
@@ -49,16 +90,79 @@ export function onUpdate (cb) {
|
|
|
49
90
|
if (import.meta.hot) {
|
|
50
91
|
import.meta.hot.accept(newModule => {
|
|
51
92
|
files = newModule.files
|
|
93
|
+
tree = newModule.tree
|
|
52
94
|
handlers.forEach(h => {
|
|
53
|
-
h(newModule.files)
|
|
95
|
+
h(newModule.files, newModule.tree)
|
|
54
96
|
newModule.onUpdate(h)
|
|
55
97
|
})
|
|
56
98
|
})
|
|
57
99
|
}`
|
|
58
100
|
}
|
|
101
|
+
if (id === NOOP_ID) {
|
|
102
|
+
return `export default () => {}`
|
|
103
|
+
}
|
|
104
|
+
if (id === RESOLVED_CONFIG_ID) {
|
|
105
|
+
let js = `export const config = ${JSON.stringify(ctx.config)}\n`
|
|
106
|
+
if (ctx.config.theme?.logo) {
|
|
107
|
+
for (const key in ctx.config.theme.logo) {
|
|
108
|
+
js += `import Logo_${key} from '${ctx.config.theme.logo[key]}'\n`
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
js += `export const logos = {${Object.keys(ctx.config.theme?.logo ?? {}).map(key => `${key}: Logo_${key}`).join(', ')}}\n`
|
|
112
|
+
return js
|
|
113
|
+
}
|
|
114
|
+
if (id === RESOLVED_THEME_ID) {
|
|
115
|
+
let css = '*, ::before, ::after {'
|
|
116
|
+
// Colors
|
|
117
|
+
for (const color in ctx.config.theme?.colors ?? {}) {
|
|
118
|
+
for (const key in ctx.config.theme.colors[color]) {
|
|
119
|
+
css += `--_histoire-color-${color}-${key}: ${parseColor(ctx.config.theme.colors[color][key]).color.join(' ')};`
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
css += '}'
|
|
123
|
+
return css
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
handleHotUpdate (updateContext) {
|
|
128
|
+
const story = ctx.storyFiles.find(file => file.path === updateContext.file)
|
|
129
|
+
if (story) {
|
|
130
|
+
notifyStoryChange(story)
|
|
131
|
+
}
|
|
59
132
|
},
|
|
60
133
|
|
|
61
134
|
configureServer (server) {
|
|
135
|
+
server.middlewares.use((req, res, next) => {
|
|
136
|
+
if (req.url!.startsWith('/__sandbox')) {
|
|
137
|
+
res.statusCode = 200
|
|
138
|
+
res.end(`
|
|
139
|
+
<!DOCTYPE html>
|
|
140
|
+
<html>
|
|
141
|
+
<head>
|
|
142
|
+
<title></title>
|
|
143
|
+
<meta charset="utf-8">
|
|
144
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
145
|
+
<meta name="description" content="">
|
|
146
|
+
</head>
|
|
147
|
+
<body>
|
|
148
|
+
<div id="app"></div>
|
|
149
|
+
<script>
|
|
150
|
+
// Hide spammy vite messages
|
|
151
|
+
const origConsoleLog = console.log
|
|
152
|
+
console.log = (...args) => {
|
|
153
|
+
if (typeof args[0] !== 'string' || !args[0].startsWith('[vite] connect')) {
|
|
154
|
+
origConsoleLog(...args)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
</script>
|
|
158
|
+
<script type="module" src="/@fs/${APP_PATH}/sandbox.js"></script>
|
|
159
|
+
</body>
|
|
160
|
+
</html>`)
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
next()
|
|
164
|
+
})
|
|
165
|
+
|
|
62
166
|
// serve our index.html after vite history fallback
|
|
63
167
|
return () => {
|
|
64
168
|
server.middlewares.use((req, res, next) => {
|
|
@@ -69,9 +173,11 @@ if (import.meta.hot) {
|
|
|
69
173
|
<html>
|
|
70
174
|
<head>
|
|
71
175
|
<title></title>
|
|
176
|
+
<link rel="icon" href=""/>
|
|
72
177
|
<meta charset="utf-8">
|
|
73
178
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
74
179
|
<meta name="description" content="">
|
|
180
|
+
${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${ctx.config.theme.favicon}"/>` : ''}
|
|
75
181
|
</head>
|
|
76
182
|
<body>
|
|
77
183
|
<div id="app"></div>
|
|
@@ -84,9 +190,27 @@ if (import.meta.hot) {
|
|
|
84
190
|
})
|
|
85
191
|
}
|
|
86
192
|
},
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
if (ctx.mode === 'build') {
|
|
196
|
+
// Add file name in build mode to have components names instead of <Anonymous>
|
|
197
|
+
const include = [/\.vue$/]
|
|
198
|
+
const exclude = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/]
|
|
199
|
+
plugins.push({
|
|
200
|
+
name: 'histoire-file-name-plugin',
|
|
201
|
+
enforce: 'post',
|
|
202
|
+
|
|
203
|
+
transform (code, id) {
|
|
204
|
+
if (exclude.some(r => r.test(id))) return
|
|
205
|
+
if (include.some(r => r.test(id))) {
|
|
206
|
+
const file = relative(viteConfig.root, id)
|
|
207
|
+
const index = code.indexOf('export default')
|
|
208
|
+
const result = `${code.substring(0, index)}_sfc_main.__file = '${file}'\n${code.substring(index)}`
|
|
209
|
+
return result
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
})
|
|
87
213
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
vuePlugin,
|
|
91
|
-
]
|
|
214
|
+
|
|
215
|
+
return plugins
|
|
92
216
|
}
|
package/src/node/server.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { createServer as createViteServer } from 'vite'
|
|
2
2
|
import { Context } from './context.js'
|
|
3
3
|
import { createVitePlugins, RESOLVED_STORIES_ID } from './plugin.js'
|
|
4
|
-
import { onStoryChange, watchStories } from './stories.js'
|
|
4
|
+
import { notifyStoryChange, onStoryChange, watchStories } from './stories.js'
|
|
5
|
+
import { useCollectStories } from './collect.js'
|
|
6
|
+
import type { StoryFile } from './types.js'
|
|
5
7
|
|
|
6
|
-
export async function createServer (ctx: Context) {
|
|
8
|
+
export async function createServer (ctx: Context, port: number) {
|
|
7
9
|
await watchStories(ctx)
|
|
10
|
+
|
|
8
11
|
const server = await createViteServer({
|
|
9
|
-
root: ctx.config.sourceDir,
|
|
10
12
|
plugins: await createVitePlugins(ctx),
|
|
11
13
|
server: {
|
|
12
14
|
watch: {
|
|
@@ -14,24 +16,97 @@ export async function createServer (ctx: Context) {
|
|
|
14
16
|
},
|
|
15
17
|
},
|
|
16
18
|
})
|
|
17
|
-
|
|
19
|
+
await server.pluginContainer.buildStart({})
|
|
20
|
+
// Wait for pre-bundling (in `listen()`)
|
|
21
|
+
await server.listen(port)
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
clearCache,
|
|
25
|
+
executeStoryFile,
|
|
26
|
+
destroy: destroyCollectStories,
|
|
27
|
+
} = useCollectStories({
|
|
28
|
+
server,
|
|
29
|
+
}, ctx)
|
|
30
|
+
|
|
31
|
+
// onStoryChange debouncing
|
|
32
|
+
let queue: Promise<void>
|
|
33
|
+
let queueResolve: () => void
|
|
34
|
+
let queued = false
|
|
35
|
+
let queuedFiles: StoryFile[] = []
|
|
36
|
+
|
|
37
|
+
onStoryChange(async (changedFile) => {
|
|
38
|
+
if (queue) {
|
|
39
|
+
if (queued && changedFile) {
|
|
40
|
+
queuedFiles.push(changedFile)
|
|
41
|
+
return
|
|
42
|
+
} else {
|
|
43
|
+
queued = true
|
|
44
|
+
// Next call
|
|
45
|
+
await queue
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
queued = false
|
|
49
|
+
queue = new Promise(resolve => {
|
|
50
|
+
queueResolve = resolve
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
clearCache()
|
|
54
|
+
|
|
55
|
+
if (changedFile) {
|
|
56
|
+
// Granular update
|
|
57
|
+
await executeStoryFile(changedFile)
|
|
58
|
+
} else {
|
|
59
|
+
// Full update
|
|
60
|
+
for (const storyFile of ctx.storyFiles) {
|
|
61
|
+
await executeStoryFile(storyFile)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Queued updates
|
|
65
|
+
for (const storyFile of queuedFiles) {
|
|
66
|
+
await executeStoryFile(storyFile)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
queuedFiles = []
|
|
70
|
+
queueResolve()
|
|
71
|
+
|
|
72
|
+
// Invalidate stories data module
|
|
18
73
|
const mod = server.moduleGraph.getModuleById(RESOLVED_STORIES_ID)
|
|
19
|
-
if (mod) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
74
|
+
if (!mod) {
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
server.moduleGraph.invalidateModule(mod)
|
|
78
|
+
|
|
79
|
+
// Send stories data HMR update
|
|
80
|
+
const timestamp = Date.now()
|
|
81
|
+
mod.lastHMRTimestamp = timestamp
|
|
82
|
+
server.ws.send({
|
|
83
|
+
type: 'update',
|
|
84
|
+
updates: [
|
|
85
|
+
{
|
|
86
|
+
type: 'js-update',
|
|
87
|
+
acceptedPath: mod.url,
|
|
88
|
+
path: mod.url,
|
|
89
|
+
timestamp: timestamp,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
async function close () {
|
|
96
|
+
await server.close()
|
|
97
|
+
await destroyCollectStories()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// On page refresh, refresh stories
|
|
101
|
+
// Useful when vite optimizes new dependencies
|
|
102
|
+
server.ws.on('connection', (socket) => {
|
|
103
|
+
if (socket.protocol === 'vite-hmr') {
|
|
104
|
+
notifyStoryChange()
|
|
34
105
|
}
|
|
35
106
|
})
|
|
36
|
-
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
server,
|
|
110
|
+
close,
|
|
111
|
+
}
|
|
37
112
|
}
|
package/src/node/stories.ts
CHANGED
|
@@ -1,54 +1,76 @@
|
|
|
1
|
-
import { Context } from './context.js'
|
|
2
1
|
import chokidar from 'chokidar'
|
|
3
2
|
import { globby } from 'globby'
|
|
4
3
|
import Case from 'case'
|
|
4
|
+
import { join } from 'pathe'
|
|
5
|
+
import { Context } from './context.js'
|
|
6
|
+
import type { StoryFile } from './types.js'
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
file: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const stories: Story[] = []
|
|
8
|
+
type StoryChangeHandler = (file?: StoryFile) => unknown
|
|
9
|
+
const handlers: StoryChangeHandler[] = []
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
let context: Context
|
|
14
12
|
|
|
15
|
-
export function onStoryChange (handler:
|
|
13
|
+
export function onStoryChange (handler: StoryChangeHandler) {
|
|
16
14
|
handlers.push(handler)
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
export async function watchStories (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
addStory(file)
|
|
25
|
-
notifyChange()
|
|
26
|
-
})
|
|
27
|
-
watcher.on('unlink', (file) => {
|
|
28
|
-
stories.splice(stories.findIndex((story) => story.file === file), 1)
|
|
29
|
-
notifyChange()
|
|
17
|
+
export async function watchStories (newContext: Context) {
|
|
18
|
+
context = newContext
|
|
19
|
+
const watcher = chokidar.watch(context.config.storyMatch, {
|
|
20
|
+
cwd: context.root,
|
|
21
|
+
ignored: context.config.storyIgnored,
|
|
30
22
|
})
|
|
23
|
+
|
|
24
|
+
watcher
|
|
25
|
+
.on('add', (file) => {
|
|
26
|
+
const storyFile = addStory(file)
|
|
27
|
+
setTimeout(() => notifyStoryChange(storyFile), 100) // Delay in case file renaming fired Add event before Unlink event
|
|
28
|
+
})
|
|
29
|
+
.on('unlink', (file) => {
|
|
30
|
+
removeStory(file)
|
|
31
|
+
notifyStoryChange()
|
|
32
|
+
})
|
|
33
|
+
|
|
31
34
|
return watcher
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
function
|
|
37
|
+
export function notifyStoryChange (file?: StoryFile) {
|
|
35
38
|
for (const handler of handlers) {
|
|
36
|
-
handler()
|
|
39
|
+
handler(file)
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
function getAbsoluteFilePath (relativeFilePath: string) {
|
|
44
|
+
return join(context.root, relativeFilePath)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function addStory (relativeFilePath: string) {
|
|
48
|
+
const absoluteFilePath = getAbsoluteFilePath(relativeFilePath)
|
|
49
|
+
const fileId = Case.kebab(relativeFilePath)
|
|
50
|
+
|
|
51
|
+
const file: StoryFile = {
|
|
52
|
+
id: fileId,
|
|
53
|
+
path: absoluteFilePath,
|
|
54
|
+
moduleId: `/${relativeFilePath}`,
|
|
55
|
+
}
|
|
56
|
+
context.storyFiles.push(file)
|
|
57
|
+
return file
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function removeStory (relativeFilePath: string) {
|
|
61
|
+
const fileId = Case.kebab(relativeFilePath)
|
|
62
|
+
const index = context.storyFiles.findIndex((file) => file.id === fileId)
|
|
63
|
+
if (index !== -1) context.storyFiles.splice(index, 1)
|
|
45
64
|
}
|
|
46
65
|
|
|
47
|
-
export async function
|
|
48
|
-
|
|
49
|
-
|
|
66
|
+
export async function findAllStories (newContext: Context) {
|
|
67
|
+
context = newContext
|
|
68
|
+
|
|
69
|
+
const files = await globby(context.config.storyMatch, {
|
|
70
|
+
cwd: context.root,
|
|
71
|
+
ignore: context.config.storyIgnored,
|
|
50
72
|
})
|
|
51
|
-
|
|
73
|
+
context.storyFiles.length = 0
|
|
52
74
|
for (const file of files) {
|
|
53
75
|
addStory(file)
|
|
54
76
|
}
|
package/src/node/tree.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { HistoireConfig } from './config.js'
|
|
2
|
+
|
|
3
|
+
export type TreeFile = {
|
|
4
|
+
title: string
|
|
5
|
+
path: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type TreeLeaf = {
|
|
9
|
+
title: string
|
|
10
|
+
index: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type TreeFolder = {
|
|
14
|
+
title: string
|
|
15
|
+
children: (TreeFolder | TreeLeaf)[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type Tree = (TreeFolder | TreeLeaf)[]
|
|
19
|
+
|
|
20
|
+
export function createPath (config: HistoireConfig, file: TreeFile) {
|
|
21
|
+
if (config.tree.file === 'title') {
|
|
22
|
+
return file.title.split('/')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (config.tree.file === 'path') {
|
|
26
|
+
const path = file.path.split('/')
|
|
27
|
+
path.pop()
|
|
28
|
+
path.push(file.title)
|
|
29
|
+
return path
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return config.tree.file(file)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function makeTree (config: HistoireConfig, files: { path: string[], index: number }[]) {
|
|
36
|
+
interface ITreeObject {
|
|
37
|
+
[index: string]: number | ITreeObject
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const treeObject: ITreeObject = {}
|
|
41
|
+
|
|
42
|
+
for (const file of files) {
|
|
43
|
+
setPath(file.path, file.index, treeObject)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let sortingFunction = (a: string, b: string) => a.localeCompare(b)
|
|
47
|
+
|
|
48
|
+
if (config.tree.order !== 'asc') {
|
|
49
|
+
sortingFunction = config.tree.order
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return buildTree(treeObject)
|
|
53
|
+
|
|
54
|
+
// Undefined behavior for folder and file that share the same name under the same directory
|
|
55
|
+
function setPath (path: string[], value: unknown, tree: unknown) {
|
|
56
|
+
path.reduce((subtree, key, i) => {
|
|
57
|
+
if (!subtree[key]) {
|
|
58
|
+
subtree[key] = {}
|
|
59
|
+
}
|
|
60
|
+
if (i === path.length - 1) {
|
|
61
|
+
subtree[key] = value
|
|
62
|
+
}
|
|
63
|
+
return subtree[key]
|
|
64
|
+
}, tree)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function buildTree (treeObject: ITreeObject): Tree {
|
|
68
|
+
const tree: Tree = []
|
|
69
|
+
|
|
70
|
+
for (const [key, element] of Object.entries(treeObject)) {
|
|
71
|
+
if (Number.isInteger(element)) {
|
|
72
|
+
tree.push({
|
|
73
|
+
title: key,
|
|
74
|
+
index: element as number,
|
|
75
|
+
})
|
|
76
|
+
} else {
|
|
77
|
+
tree.push({
|
|
78
|
+
title: key,
|
|
79
|
+
children: buildTree(element as ITreeObject),
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
tree.sort((a, b) => sortingFunction(a.title, b.title))
|
|
85
|
+
|
|
86
|
+
return tree
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface StoryFile {
|
|
2
|
+
id: string
|
|
3
|
+
/**
|
|
4
|
+
* Absolute path
|
|
5
|
+
*/
|
|
6
|
+
path: string
|
|
7
|
+
/**
|
|
8
|
+
* Generated path for tree UI
|
|
9
|
+
*/
|
|
10
|
+
treePath?: string[]
|
|
11
|
+
/**
|
|
12
|
+
* Use the module id in imports to allow HMR
|
|
13
|
+
*/
|
|
14
|
+
moduleId: string
|
|
15
|
+
/**
|
|
16
|
+
* Resolved story data from story file execution
|
|
17
|
+
*/
|
|
18
|
+
story?: Story
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface Story {
|
|
22
|
+
id: string
|
|
23
|
+
title: string
|
|
24
|
+
variants: Variant[]
|
|
25
|
+
layout?: {
|
|
26
|
+
type: 'single'
|
|
27
|
+
} | {
|
|
28
|
+
type: 'grid'
|
|
29
|
+
width: number
|
|
30
|
+
}
|
|
31
|
+
icon?: string
|
|
32
|
+
iconColor?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface Variant {
|
|
36
|
+
id: string
|
|
37
|
+
title: string
|
|
38
|
+
icon?: string
|
|
39
|
+
iconColor?: string
|
|
40
|
+
}
|
package/tailwind.config.cjs
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
const inheritedConfig = require('../../tailwind.config.cjs')
|
|
3
|
+
const defaultColors = require('tailwindcss/colors')
|
|
4
|
+
|
|
5
|
+
// Colors
|
|
6
|
+
|
|
7
|
+
function withOpacityValue (variable) {
|
|
8
|
+
return ({ opacityValue }) => {
|
|
9
|
+
if (opacityValue === undefined) {
|
|
10
|
+
return `rgb(var(${variable}))`
|
|
11
|
+
}
|
|
12
|
+
return `rgb(var(${variable}) / ${opacityValue})`
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const colorKeys = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900]
|
|
17
|
+
const grayKeys = [...colorKeys, 750, 850, 950]
|
|
18
|
+
const themedColors = ['primary', 'gray'].reduce((acc, color) => {
|
|
19
|
+
const keys = (color === 'gray' ? grayKeys : colorKeys)
|
|
20
|
+
for (const key of keys) {
|
|
21
|
+
acc[`${color}-${key}`] = withOpacityValue(`--_histoire-color-${color}-${key}`)
|
|
22
|
+
}
|
|
23
|
+
return acc
|
|
24
|
+
}, {})
|
|
25
|
+
|
|
26
|
+
const colors = {
|
|
27
|
+
...{
|
|
28
|
+
...defaultColors,
|
|
29
|
+
gray: undefined,
|
|
30
|
+
},
|
|
31
|
+
white: '#fff',
|
|
32
|
+
black: '#000',
|
|
33
|
+
transparent: 'transparent',
|
|
34
|
+
...themedColors,
|
|
35
|
+
}
|
|
36
|
+
|
|
1
37
|
module.exports = {
|
|
2
|
-
...
|
|
38
|
+
...inheritedConfig,
|
|
3
39
|
content: [
|
|
4
40
|
'./src/**/*.{vue,js,ts,jsx,tsx,md}',
|
|
5
41
|
],
|
|
@@ -7,3 +43,7 @@ module.exports = {
|
|
|
7
43
|
preflight: false,
|
|
8
44
|
},
|
|
9
45
|
}
|
|
46
|
+
|
|
47
|
+
delete module.exports.theme.extend.colors.primary
|
|
48
|
+
delete module.exports.theme.extend.colors.gray
|
|
49
|
+
module.exports.theme.colors = colors
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { PropType, toRefs } from 'vue'
|
|
3
|
-
import { useCurrentVariantRoute } from '../composable/variant'
|
|
4
|
-
import { Variant } from '../types'
|
|
5
|
-
|
|
6
|
-
const props = defineProps({
|
|
7
|
-
variant: {
|
|
8
|
-
type: Object as PropType<Variant>,
|
|
9
|
-
required: true,
|
|
10
|
-
},
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
const { variant } = toRefs(props)
|
|
14
|
-
const { isActive, targetRoute } = useCurrentVariantRoute(variant)
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
<template>
|
|
18
|
-
<div>
|
|
19
|
-
<RouterLink
|
|
20
|
-
:to="targetRoute"
|
|
21
|
-
class="htw-p-2 htw-flex htw-space-x-2 hover:htw-bg-primary-100 dark:htw-bg-primary-900"
|
|
22
|
-
:class="{
|
|
23
|
-
'htw-bg-primary-200 hover:htw-bg-primary-300 htw-text-primary-800': isActive,
|
|
24
|
-
}"
|
|
25
|
-
>
|
|
26
|
-
{{ variant.title }}
|
|
27
|
-
</RouterLink>
|
|
28
|
-
</div>
|
|
29
|
-
</template>
|