histoire 0.0.0 → 0.0.3
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 +113 -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 +70 -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 +238 -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 +87 -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 +145 -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.js +0 -1
- package/dist/client/app/composable/variant.ts +20 -0
- package/dist/client/app/global-components.js +0 -1
- package/dist/client/app/global-components.ts +10 -0
- package/dist/client/app/index.d.ts +1 -0
- package/dist/client/app/index.js +10 -2
- package/dist/client/app/index.ts +24 -0
- package/dist/client/app/router.js +0 -1
- package/dist/client/app/router.ts +17 -0
- package/dist/client/app/sandbox.d.ts +1 -0
- package/dist/client/app/sandbox.js +53 -0
- package/dist/client/app/sandbox.ts +60 -0
- package/dist/client/app/stores/story.d.ts +167 -50
- package/dist/client/app/stores/story.js +33 -16
- package/dist/client/app/stores/story.ts +58 -0
- package/dist/client/app/style/floating-vue.css +31 -0
- package/dist/client/app/style/main.css +17 -2
- package/dist/client/app/style/sandbox.css +14 -0
- package/dist/client/app/types.d.ts +36 -4
- package/dist/client/app/types.js +0 -1
- package/dist/client/app/types.ts +59 -0
- package/dist/client/app/util/config.d.ts +3 -0
- package/dist/client/app/util/config.js +4 -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 +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 +3 -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 +1 -0
- package/dist/client/app/util/env.ts +1 -0
- package/dist/client/app/util/keyboard.d.ts +8 -0
- package/dist/client/app/util/keyboard.js +82 -0
- package/dist/client/app/util/keyboard.ts +99 -0
- package/dist/client/app/util/mapping.d.ts +3 -0
- package/dist/client/app/util/mapping.js +39 -0
- package/dist/client/app/util/mapping.ts +41 -0
- package/dist/client/app/util/tooltip.d.ts +6 -0
- package/dist/client/app/util/tooltip.js +11 -0
- package/dist/client/app/util/tooltip.ts +13 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +3 -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 +25 -0
- package/dist/client/server/index.ts +29 -0
- package/dist/client/shim.d.ts +5 -0
- package/dist/node/alias.js +0 -1
- package/dist/node/bin.js +8 -3
- package/dist/node/build.d.ts +2 -0
- package/dist/node/build.js +71 -0
- package/dist/node/collect.d.ts +12 -0
- package/dist/node/collect.js +65 -0
- package/dist/node/colors.d.ts +286 -0
- package/dist/node/colors.js +324 -0
- package/dist/node/commands/build.d.ts +1 -0
- package/dist/node/commands/build.js +10 -0
- package/dist/node/commands/dev.d.ts +1 -1
- package/dist/node/commands/dev.js +45 -13
- package/dist/node/config.d.ts +112 -1
- package/dist/node/config.js +124 -2
- package/dist/node/context.d.ts +13 -0
- package/dist/node/context.js +12 -2
- package/dist/node/dom/dom-keys.d.ts +4 -0
- package/dist/node/dom/dom-keys.js +223 -0
- package/dist/node/dom/env.d.ts +5 -0
- package/dist/node/dom/env.js +22 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +2 -2
- package/dist/node/plugin.d.ts +8 -2
- package/dist/node/plugin.js +150 -22
- package/dist/node/server.d.ts +4 -1
- package/dist/node/server.js +80 -21
- package/dist/node/stories.d.ts +8 -9
- package/dist/node/stories.js +42 -23
- package/dist/node/tree.d.ts +19 -0
- package/dist/node/tree.js +54 -0
- package/dist/node/types.d.ts +38 -0
- package/dist/node/types.js +1 -0
- package/dist/style.css +610 -53
- package/package.json +45 -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 +87 -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 +145 -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 +10 -1
- package/src/client/app/sandbox.ts +60 -0
- package/src/client/app/stores/story.ts +39 -15
- package/src/client/app/style/floating-vue.css +31 -0
- package/src/client/app/style/main.css +17 -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 +41 -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 +340 -0
- package/src/node/commands/build.ts +12 -0
- package/src/node/commands/dev.ts +49 -12
- package/src/node/config.ts +240 -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 +155 -22
- package/src/node/server.ts +95 -20
- package/src/node/stories.ts +53 -31
- package/src/node/tree.spec.ts +28 -0
- package/src/node/tree.ts +88 -0
- package/src/node/types.ts +40 -0
- package/tailwind.config.cjs +41 -1
- package/tsconfig.json +2 -1
- package/dist/client/app/components/StoryVariantItem.vue +0 -29
- package/dist/client/app/composable/variant.js.map +0 -1
- package/dist/client/app/global-components.js.map +0 -1
- package/dist/client/app/index.js.map +0 -1
- package/dist/client/app/router.js.map +0 -1
- package/dist/client/app/stores/story.js.map +0 -1
- package/dist/client/app/types.js.map +0 -1
- package/dist/node/alias.js.map +0 -1
- package/dist/node/bin.js.map +0 -1
- package/dist/node/commands/dev.js.map +0 -1
- package/dist/node/config.js.map +0 -1
- package/dist/node/context.js.map +0 -1
- package/dist/node/index.js.map +0 -1
- package/dist/node/plugin.js.map +0 -1
- package/dist/node/server.js.map +0 -1
- package/dist/node/stories.js.map +0 -1
- package/src/client/app/components/StoryVariantItem.vue +0 -29
package/src/node/commands/dev.ts
CHANGED
|
@@ -1,21 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Context } from '../context.js'
|
|
1
|
+
import { resolveConfigFile } from '../config.js'
|
|
2
|
+
import { createContext } from '../context.js'
|
|
4
3
|
import { createServer } from '../server.js'
|
|
4
|
+
import chokidar from 'chokidar'
|
|
5
|
+
import pc from 'picocolors'
|
|
5
6
|
|
|
6
7
|
export interface DevOptions {
|
|
7
8
|
port: number
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
export async function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export async function devCommand (options: DevOptions) {
|
|
12
|
+
let stop: () => Promise<void>
|
|
13
|
+
|
|
14
|
+
async function start () {
|
|
15
|
+
const ctx = await createContext({
|
|
16
|
+
mode: 'dev',
|
|
17
|
+
})
|
|
18
|
+
const { server, close } = await createServer(ctx, options.port)
|
|
19
|
+
server.printUrls()
|
|
20
|
+
|
|
21
|
+
// Histoire config watcher
|
|
22
|
+
let watcher: chokidar.FSWatcher
|
|
23
|
+
if (server.config.configFile) {
|
|
24
|
+
watcher = chokidar.watch(server.config.configFile, {
|
|
25
|
+
ignoreInitial: true,
|
|
26
|
+
})
|
|
27
|
+
watcher.on('change', () => {
|
|
28
|
+
restart('Vite')
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return async () => {
|
|
33
|
+
await watcher?.close()
|
|
34
|
+
await close()
|
|
35
|
+
}
|
|
14
36
|
}
|
|
15
|
-
|
|
16
|
-
|
|
37
|
+
|
|
38
|
+
async function restart (source: string) {
|
|
39
|
+
if (stop) {
|
|
40
|
+
console.log(pc.blue(`${source} config changed, restarting...`))
|
|
41
|
+
stop()
|
|
42
|
+
stop = null // Don't call stop again until new start() is done
|
|
43
|
+
stop = await start()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
stop = await start()
|
|
48
|
+
|
|
49
|
+
const configFile = await resolveConfigFile()
|
|
50
|
+
if (configFile) {
|
|
51
|
+
const watcher = chokidar.watch(configFile, {
|
|
52
|
+
ignoreInitial: true,
|
|
53
|
+
})
|
|
54
|
+
watcher.on('change', () => {
|
|
55
|
+
restart('Histoire')
|
|
56
|
+
})
|
|
17
57
|
}
|
|
18
|
-
const server = await createServer(ctx)
|
|
19
|
-
await server.listen(options.port)
|
|
20
|
-
server.printUrls()
|
|
21
58
|
}
|
package/src/node/config.ts
CHANGED
|
@@ -1,4 +1,243 @@
|
|
|
1
|
+
import path from 'pathe'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import defu from 'defu'
|
|
4
|
+
import { createServer, resolveConfig as resolveViteConfig, UserConfig as ViteConfig } from 'vite'
|
|
5
|
+
import { ViteNodeServer } from 'vite-node/server'
|
|
6
|
+
import { ViteNodeRunner } from 'vite-node/client'
|
|
7
|
+
import pc from 'picocolors'
|
|
8
|
+
import { TreeFile } from './tree.js'
|
|
9
|
+
import { defaultColors } from './colors.js'
|
|
10
|
+
|
|
11
|
+
type CustomizableColors = 'primary' | 'gray'
|
|
12
|
+
type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'
|
|
13
|
+
type GrayColorKeys = ColorKeys | '750' | '850' | '950'
|
|
14
|
+
|
|
15
|
+
interface ResponsivePreset {
|
|
16
|
+
label: string
|
|
17
|
+
width: number
|
|
18
|
+
}
|
|
19
|
+
|
|
1
20
|
export interface HistoireConfig {
|
|
2
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Output directory.
|
|
23
|
+
*/
|
|
24
|
+
outDir: string
|
|
25
|
+
/**
|
|
26
|
+
* Glob patterns for story files to include.
|
|
27
|
+
*/
|
|
3
28
|
storyMatch: string[]
|
|
29
|
+
/**
|
|
30
|
+
* Glob patterns to ignore files while searching for story files.
|
|
31
|
+
*/
|
|
32
|
+
storyIgnored: string[]
|
|
33
|
+
/**
|
|
34
|
+
* How to generate the story tree.
|
|
35
|
+
*/
|
|
36
|
+
tree: {
|
|
37
|
+
/**
|
|
38
|
+
* Use `'title'` to create the path from the title of the story, using `/` as the separator.
|
|
39
|
+
*
|
|
40
|
+
* Use `'path'` use the real folder structure on your computer.
|
|
41
|
+
*/
|
|
42
|
+
file?: 'title' | 'path' | ((file: TreeFile) => string[])
|
|
43
|
+
order?: 'asc' | ((a: string, b: string) => number)
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Customize the look of the histoire book.
|
|
47
|
+
*/
|
|
48
|
+
theme: {
|
|
49
|
+
/**
|
|
50
|
+
* Main page title. For example: 'Acme Inc.'
|
|
51
|
+
*/
|
|
52
|
+
title?: string
|
|
53
|
+
/**
|
|
54
|
+
* Custom logo files. Should be import paths (processed by Vite).
|
|
55
|
+
*
|
|
56
|
+
* Example: `'/src/assets/my-logo.svg'`
|
|
57
|
+
*/
|
|
58
|
+
logo?: {
|
|
59
|
+
/**
|
|
60
|
+
* Square logo without text.
|
|
61
|
+
*/
|
|
62
|
+
square?: string
|
|
63
|
+
/**
|
|
64
|
+
* Full logo for light theme.
|
|
65
|
+
*/
|
|
66
|
+
light?: string
|
|
67
|
+
/**
|
|
68
|
+
* Full logo for dark theme.
|
|
69
|
+
*/
|
|
70
|
+
dark?: string
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Href to the favicon file (**not** processed by Vite). Put the file in the public directory.
|
|
74
|
+
*
|
|
75
|
+
* Example: `'/favicon.ico'`
|
|
76
|
+
*/
|
|
77
|
+
favicon?: string
|
|
78
|
+
/**
|
|
79
|
+
* Customize the colors. Each color should be an object with shades as keys.
|
|
80
|
+
*
|
|
81
|
+
* Example: ```{ primary: { 50: '#eef2ff', 100: '#e0e7ff', ..., 900: '#312e81' } }```
|
|
82
|
+
*
|
|
83
|
+
* You can import `defaultColors` from `'histoire'` to use predefined colors or you can create your own colors from scratch.
|
|
84
|
+
*/
|
|
85
|
+
colors?: {
|
|
86
|
+
[key in CustomizableColors]?: key extends 'gray' ? {
|
|
87
|
+
[key in GrayColorKeys]?: string
|
|
88
|
+
} :{
|
|
89
|
+
[key in ColorKeys]?: string
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Setup file exposting a default function executed when setting up each story preview.
|
|
95
|
+
*
|
|
96
|
+
* Import custom CSS files from this file.
|
|
97
|
+
*
|
|
98
|
+
* Example: `'/src/histoire-setup.ts'`
|
|
99
|
+
*/
|
|
100
|
+
setupFile?: string
|
|
101
|
+
/**
|
|
102
|
+
* Predefined responsive sizes for story playgrounds.
|
|
103
|
+
*/
|
|
104
|
+
responsivePresets?: ResponsivePreset[]
|
|
105
|
+
/**
|
|
106
|
+
* Vite config override
|
|
107
|
+
*/
|
|
108
|
+
vite?: ViteConfig
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function getDefaultConfig (): HistoireConfig {
|
|
112
|
+
return {
|
|
113
|
+
outDir: 'histoire-dist',
|
|
114
|
+
storyMatch: ['**/*.story.vue'],
|
|
115
|
+
storyIgnored: ['**/node_modules/**'],
|
|
116
|
+
tree: {
|
|
117
|
+
file: 'title',
|
|
118
|
+
order: 'asc',
|
|
119
|
+
},
|
|
120
|
+
theme: {
|
|
121
|
+
title: 'Histoire',
|
|
122
|
+
colors: {
|
|
123
|
+
primary: defaultColors.emerald,
|
|
124
|
+
gray: defaultColors.zinc,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
responsivePresets: [
|
|
128
|
+
{
|
|
129
|
+
label: 'Mobile (Small)',
|
|
130
|
+
width: 320,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
label: 'Mobile (Medium)',
|
|
134
|
+
width: 375,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
label: 'Mobile (Large)',
|
|
138
|
+
width: 425,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
label: 'Tablet',
|
|
142
|
+
width: 768,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
label: 'Laptop (Small)',
|
|
146
|
+
width: 1024,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
label: 'Laptop (Large)',
|
|
150
|
+
width: 1440,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
label: 'Desktop',
|
|
154
|
+
width: 1920,
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
label: '4K',
|
|
158
|
+
width: 3840,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export const configFileNames = [
|
|
165
|
+
'histoire.config.ts',
|
|
166
|
+
'histoire.config.js',
|
|
167
|
+
'.histoire.ts',
|
|
168
|
+
'.histoire.js',
|
|
169
|
+
]
|
|
170
|
+
|
|
171
|
+
export function resolveConfigFile (cwd: string = process.cwd()): string {
|
|
172
|
+
let { root } = path.parse(cwd)
|
|
173
|
+
let dir = cwd
|
|
174
|
+
|
|
175
|
+
// Fix for windows, waiting for pathe to fix this: https://github.com/unjs/pathe/issues/5
|
|
176
|
+
if (root === '' && dir[1] === ':') {
|
|
177
|
+
root = dir.substring(0, 2)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
while (dir !== root) {
|
|
181
|
+
for (const fileName of configFileNames) {
|
|
182
|
+
const searchPath = path.join(dir, fileName)
|
|
183
|
+
if (fs.existsSync(searchPath)) {
|
|
184
|
+
return searchPath
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
dir = path.dirname(dir)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return null
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export async function loadConfigFile (configFile: string): Promise<Partial<HistoireConfig>> {
|
|
194
|
+
try {
|
|
195
|
+
const server = await createServer()
|
|
196
|
+
await server.pluginContainer.buildStart({})
|
|
197
|
+
const node = new ViteNodeServer(server)
|
|
198
|
+
const runner = new ViteNodeRunner({
|
|
199
|
+
root: path.dirname(configFile),
|
|
200
|
+
fetchModule (id) {
|
|
201
|
+
return node.fetchModule(id)
|
|
202
|
+
},
|
|
203
|
+
})
|
|
204
|
+
const result: { default: Partial<HistoireConfig> } = await runner.executeFile(configFile)
|
|
205
|
+
await server.close()
|
|
206
|
+
if (!result.default) {
|
|
207
|
+
throw new Error(`Expected default export in ${configFile}`)
|
|
208
|
+
}
|
|
209
|
+
return result.default
|
|
210
|
+
} catch (e) {
|
|
211
|
+
console.error(pc.red(`Error while loading ${configFile}`))
|
|
212
|
+
throw e
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export async function resolveConfig (cwd: string = process.cwd()): Promise<HistoireConfig> {
|
|
217
|
+
let result: Partial<HistoireConfig>
|
|
218
|
+
const configFile = resolveConfigFile(cwd)
|
|
219
|
+
if (configFile) {
|
|
220
|
+
result = await loadConfigFile(configFile)
|
|
221
|
+
}
|
|
222
|
+
const viteConfig = await resolveViteConfig({}, 'serve')
|
|
223
|
+
const viteHistoireConfig = (viteConfig.histoire ?? {}) as HistoireConfig
|
|
224
|
+
return processConfig(defu(result, viteHistoireConfig, getDefaultConfig()))
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function processConfig (config: HistoireConfig): HistoireConfig {
|
|
228
|
+
config.outDir = path.resolve(process.cwd(), config.outDir)
|
|
229
|
+
return config
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function defineConfig (config: Partial<HistoireConfig>) {
|
|
233
|
+
return config
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
declare module 'vite' {
|
|
237
|
+
interface UserConfig {
|
|
238
|
+
/**
|
|
239
|
+
* Histoire configuration
|
|
240
|
+
*/
|
|
241
|
+
histoire?: Partial<HistoireConfig>
|
|
242
|
+
}
|
|
4
243
|
}
|
package/src/node/context.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveConfig as resolveViteConfig } from 'vite'
|
|
2
|
+
import { resolveConfig, HistoireConfig } from './config.js'
|
|
3
|
+
import type { StoryFile } from './types.js'
|
|
2
4
|
|
|
3
5
|
export interface Context {
|
|
6
|
+
root: string
|
|
4
7
|
config: HistoireConfig
|
|
8
|
+
mode: 'dev' | 'build'
|
|
9
|
+
storyFiles: StoryFile[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CreateContextOptions {
|
|
13
|
+
mode: Context['mode']
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function createContext (options: CreateContextOptions) {
|
|
17
|
+
const config = await resolveConfig()
|
|
18
|
+
const viteConfig = await resolveViteConfig({}, 'build')
|
|
19
|
+
return {
|
|
20
|
+
root: viteConfig.root,
|
|
21
|
+
config,
|
|
22
|
+
mode: options.mode,
|
|
23
|
+
storyFiles: [],
|
|
24
|
+
}
|
|
5
25
|
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code from vitest https://github.com/antfu-sponsors/vitest/blob/6066fdbf3b1d17021aac20591b5ef3603056fa5f/src/integrations/dom/keys.ts by @antfu and @patak
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
|
|
6
|
+
|
|
7
|
+
const LIVING_KEYS = [
|
|
8
|
+
'DOMException',
|
|
9
|
+
'URL',
|
|
10
|
+
'URLSearchParams',
|
|
11
|
+
'EventTarget',
|
|
12
|
+
'NamedNodeMap',
|
|
13
|
+
'Node',
|
|
14
|
+
'Attr',
|
|
15
|
+
'Element',
|
|
16
|
+
'DocumentFragment',
|
|
17
|
+
'DOMImplementation',
|
|
18
|
+
'Document',
|
|
19
|
+
'XMLDocument',
|
|
20
|
+
'CharacterData',
|
|
21
|
+
'Text',
|
|
22
|
+
'CDATASection',
|
|
23
|
+
'ProcessingInstruction',
|
|
24
|
+
'Comment',
|
|
25
|
+
'DocumentType',
|
|
26
|
+
'NodeList',
|
|
27
|
+
'HTMLCollection',
|
|
28
|
+
'HTMLOptionsCollection',
|
|
29
|
+
'DOMStringMap',
|
|
30
|
+
'DOMTokenList',
|
|
31
|
+
'StyleSheetList',
|
|
32
|
+
'HTMLElement',
|
|
33
|
+
'HTMLHeadElement',
|
|
34
|
+
'HTMLTitleElement',
|
|
35
|
+
'HTMLBaseElement',
|
|
36
|
+
'HTMLLinkElement',
|
|
37
|
+
'HTMLMetaElement',
|
|
38
|
+
'HTMLStyleElement',
|
|
39
|
+
'HTMLBodyElement',
|
|
40
|
+
'HTMLHeadingElement',
|
|
41
|
+
'HTMLParagraphElement',
|
|
42
|
+
'HTMLHRElement',
|
|
43
|
+
'HTMLPreElement',
|
|
44
|
+
'HTMLUListElement',
|
|
45
|
+
'HTMLOListElement',
|
|
46
|
+
'HTMLLIElement',
|
|
47
|
+
'HTMLMenuElement',
|
|
48
|
+
'HTMLDListElement',
|
|
49
|
+
'HTMLDivElement',
|
|
50
|
+
'HTMLAnchorElement',
|
|
51
|
+
'HTMLAreaElement',
|
|
52
|
+
'HTMLBRElement',
|
|
53
|
+
'HTMLButtonElement',
|
|
54
|
+
'HTMLCanvasElement',
|
|
55
|
+
'HTMLDataElement',
|
|
56
|
+
'HTMLDataListElement',
|
|
57
|
+
'HTMLDetailsElement',
|
|
58
|
+
'HTMLDialogElement',
|
|
59
|
+
'HTMLDirectoryElement',
|
|
60
|
+
'HTMLFieldSetElement',
|
|
61
|
+
'HTMLFontElement',
|
|
62
|
+
'HTMLFormElement',
|
|
63
|
+
'HTMLHtmlElement',
|
|
64
|
+
'HTMLImageElement',
|
|
65
|
+
'HTMLInputElement',
|
|
66
|
+
'HTMLLabelElement',
|
|
67
|
+
'HTMLLegendElement',
|
|
68
|
+
'HTMLMapElement',
|
|
69
|
+
'HTMLMarqueeElement',
|
|
70
|
+
'HTMLMediaElement',
|
|
71
|
+
'HTMLMeterElement',
|
|
72
|
+
'HTMLModElement',
|
|
73
|
+
'HTMLOptGroupElement',
|
|
74
|
+
'HTMLOptionElement',
|
|
75
|
+
'HTMLOutputElement',
|
|
76
|
+
'HTMLPictureElement',
|
|
77
|
+
'HTMLProgressElement',
|
|
78
|
+
'HTMLQuoteElement',
|
|
79
|
+
'HTMLScriptElement',
|
|
80
|
+
'HTMLSelectElement',
|
|
81
|
+
'HTMLSlotElement',
|
|
82
|
+
'HTMLSourceElement',
|
|
83
|
+
'HTMLSpanElement',
|
|
84
|
+
'HTMLTableCaptionElement',
|
|
85
|
+
'HTMLTableCellElement',
|
|
86
|
+
'HTMLTableColElement',
|
|
87
|
+
'HTMLTableElement',
|
|
88
|
+
'HTMLTimeElement',
|
|
89
|
+
'HTMLTableRowElement',
|
|
90
|
+
'HTMLTableSectionElement',
|
|
91
|
+
'HTMLTemplateElement',
|
|
92
|
+
'HTMLTextAreaElement',
|
|
93
|
+
'HTMLUnknownElement',
|
|
94
|
+
'HTMLFrameElement',
|
|
95
|
+
'HTMLFrameSetElement',
|
|
96
|
+
'HTMLIFrameElement',
|
|
97
|
+
'HTMLEmbedElement',
|
|
98
|
+
'HTMLObjectElement',
|
|
99
|
+
'HTMLParamElement',
|
|
100
|
+
'HTMLVideoElement',
|
|
101
|
+
'HTMLAudioElement',
|
|
102
|
+
'HTMLTrackElement',
|
|
103
|
+
'SVGElement',
|
|
104
|
+
'SVGGraphicsElement',
|
|
105
|
+
'SVGSVGElement',
|
|
106
|
+
'SVGTitleElement',
|
|
107
|
+
'SVGAnimatedString',
|
|
108
|
+
'SVGNumber',
|
|
109
|
+
'SVGStringList',
|
|
110
|
+
'Event',
|
|
111
|
+
'CloseEvent',
|
|
112
|
+
'CustomEvent',
|
|
113
|
+
'MessageEvent',
|
|
114
|
+
'ErrorEvent',
|
|
115
|
+
'HashChangeEvent',
|
|
116
|
+
'PopStateEvent',
|
|
117
|
+
'StorageEvent',
|
|
118
|
+
'ProgressEvent',
|
|
119
|
+
'PageTransitionEvent',
|
|
120
|
+
'UIEvent',
|
|
121
|
+
'FocusEvent',
|
|
122
|
+
'InputEvent',
|
|
123
|
+
'MouseEvent',
|
|
124
|
+
'KeyboardEvent',
|
|
125
|
+
'TouchEvent',
|
|
126
|
+
'CompositionEvent',
|
|
127
|
+
'WheelEvent',
|
|
128
|
+
'BarProp',
|
|
129
|
+
'External',
|
|
130
|
+
'Location',
|
|
131
|
+
'History',
|
|
132
|
+
'Screen',
|
|
133
|
+
'Performance',
|
|
134
|
+
'Navigator',
|
|
135
|
+
'PluginArray',
|
|
136
|
+
'MimeTypeArray',
|
|
137
|
+
'Plugin',
|
|
138
|
+
'MimeType',
|
|
139
|
+
'FileReader',
|
|
140
|
+
'Blob',
|
|
141
|
+
'File',
|
|
142
|
+
'FileList',
|
|
143
|
+
'ValidityState',
|
|
144
|
+
'DOMParser',
|
|
145
|
+
'XMLSerializer',
|
|
146
|
+
'FormData',
|
|
147
|
+
'XMLHttpRequestEventTarget',
|
|
148
|
+
'XMLHttpRequestUpload',
|
|
149
|
+
'XMLHttpRequest',
|
|
150
|
+
'WebSocket',
|
|
151
|
+
'NodeFilter',
|
|
152
|
+
'NodeIterator',
|
|
153
|
+
'TreeWalker',
|
|
154
|
+
'AbstractRange',
|
|
155
|
+
'Range',
|
|
156
|
+
'StaticRange',
|
|
157
|
+
'Selection',
|
|
158
|
+
'Storage',
|
|
159
|
+
'CustomElementRegistry',
|
|
160
|
+
'ShadowRoot',
|
|
161
|
+
'MutationObserver',
|
|
162
|
+
'MutationRecord',
|
|
163
|
+
'Headers',
|
|
164
|
+
'AbortController',
|
|
165
|
+
'AbortSignal',
|
|
166
|
+
]
|
|
167
|
+
|
|
168
|
+
const OTHER_KEYS = [
|
|
169
|
+
'addEventListener',
|
|
170
|
+
'alert',
|
|
171
|
+
'atob',
|
|
172
|
+
'blur',
|
|
173
|
+
'btoa',
|
|
174
|
+
/* 'clearInterval', */
|
|
175
|
+
/* 'clearTimeout', */
|
|
176
|
+
'close',
|
|
177
|
+
'confirm',
|
|
178
|
+
/* 'console', */
|
|
179
|
+
'createPopup',
|
|
180
|
+
'dispatchEvent',
|
|
181
|
+
'document',
|
|
182
|
+
'focus',
|
|
183
|
+
'frames',
|
|
184
|
+
'getComputedStyle',
|
|
185
|
+
'history',
|
|
186
|
+
'innerHeight',
|
|
187
|
+
'innerWidth',
|
|
188
|
+
'length',
|
|
189
|
+
'location',
|
|
190
|
+
'moveBy',
|
|
191
|
+
'moveTo',
|
|
192
|
+
'name',
|
|
193
|
+
'navigator',
|
|
194
|
+
'open',
|
|
195
|
+
'outerHeight',
|
|
196
|
+
'outerWidth',
|
|
197
|
+
'pageXOffset',
|
|
198
|
+
'pageYOffset',
|
|
199
|
+
'parent',
|
|
200
|
+
'postMessage',
|
|
201
|
+
'print',
|
|
202
|
+
'prompt',
|
|
203
|
+
'removeEventListener',
|
|
204
|
+
'resizeBy',
|
|
205
|
+
'resizeTo',
|
|
206
|
+
'screen',
|
|
207
|
+
'screenLeft',
|
|
208
|
+
'screenTop',
|
|
209
|
+
'screenX',
|
|
210
|
+
'screenY',
|
|
211
|
+
'scroll',
|
|
212
|
+
'scrollBy',
|
|
213
|
+
'scrollLeft',
|
|
214
|
+
'scrollTo',
|
|
215
|
+
'scrollTop',
|
|
216
|
+
'scrollX',
|
|
217
|
+
'scrollY',
|
|
218
|
+
'self',
|
|
219
|
+
/* 'setInterval', */
|
|
220
|
+
/* 'setTimeout', */
|
|
221
|
+
'stop',
|
|
222
|
+
/* 'toString', */
|
|
223
|
+
'top',
|
|
224
|
+
'window',
|
|
225
|
+
]
|
|
226
|
+
|
|
227
|
+
export const KEYS = LIVING_KEYS.concat(OTHER_KEYS)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Window } from 'happy-dom'
|
|
2
|
+
import { KEYS } from './dom-keys.js'
|
|
3
|
+
|
|
4
|
+
export function createDomEnv () {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const window = global.window = new Window()
|
|
7
|
+
const globalKeys = KEYS.concat(Object.getOwnPropertyNames(window))
|
|
8
|
+
.filter(k => !k.startsWith('_'))
|
|
9
|
+
.filter(k => !(k in global))
|
|
10
|
+
|
|
11
|
+
for (const key of globalKeys) {
|
|
12
|
+
global[key] = window[key]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function destroy () {
|
|
16
|
+
globalKeys.forEach(key => delete global[key])
|
|
17
|
+
globalKeys.length = 0
|
|
18
|
+
window.happyDOM.cancelAsync()
|
|
19
|
+
delete global.window
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
window,
|
|
24
|
+
destroy,
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/node/index.ts
CHANGED