histoire 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/app/App.vue +8 -3
- package/dist/client/app/codegen/const.d.ts +1 -0
- package/dist/client/app/codegen/const.js +3 -0
- package/dist/client/app/codegen/vue3.js +82 -21
- package/dist/client/app/components/base/BaseEmpty.vue +17 -1
- package/dist/client/app/components/exposed/Story.vue +22 -1
- package/dist/client/app/components/exposed/Variant.vue +13 -1
- package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -4
- package/dist/client/app/components/sandbox/lib.js +2 -1
- package/dist/client/app/components/search/SearchLoading.vue +16 -0
- package/dist/client/app/components/search/SearchModal.vue +12 -149
- package/dist/client/app/components/search/SearchPane.vue +210 -0
- package/dist/client/app/components/search/search-data.d.ts +2 -0
- package/dist/client/app/components/search/search-data.js +7 -0
- package/dist/client/app/components/story/StoryControls.vue +5 -0
- package/dist/client/app/components/story/StoryDocs.vue +18 -11
- package/dist/client/app/components/story/StoryEvent.vue +53 -0
- package/dist/client/app/components/story/StoryEvents.vue +45 -0
- package/dist/client/app/components/story/StoryResponsivePreview.vue +41 -8
- package/dist/client/app/components/story/StorySidePanel.vue +28 -3
- package/dist/client/app/components/story/StorySourceCode.vue +24 -14
- package/dist/client/app/components/story/StoryView.vue +16 -2
- package/dist/client/app/components/tree/StoryGroup.vue +4 -4
- package/dist/client/app/components/tree/StoryListFolder.vue +4 -4
- package/dist/client/app/components/tree/StoryListItem.vue +4 -1
- package/dist/client/app/router.d.ts +1 -0
- package/dist/client/app/router.js +3 -1
- package/dist/client/app/sandbox.js +11 -1
- package/dist/client/app/stores/events.d.ts +29 -0
- package/dist/client/app/stores/events.js +25 -0
- package/dist/client/app/stores/folder.d.ts +10 -0
- package/dist/client/app/stores/folder.js +47 -0
- package/dist/client/app/stores/story.d.ts +14 -8
- package/dist/client/app/stores/story.js +20 -33
- package/dist/client/app/style/main.pcss +5 -0
- package/dist/client/app/style/sandbox.css +2 -0
- package/dist/client/app/types.d.ts +1 -0
- package/dist/client/app/util/const.d.ts +1 -0
- package/dist/client/app/util/const.js +1 -0
- package/dist/client/app/util/events.d.ts +1 -0
- package/dist/client/app/util/events.js +31 -0
- package/dist/client/app/util/mapping.js +2 -2
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.js +2 -1
- package/dist/client/server/Story.server.vue +13 -2
- package/dist/node/alias.d.ts +2 -1
- package/dist/node/alias.js +3 -2
- package/dist/node/build.js +74 -21
- package/dist/node/builtin-plugins/tailwind-tokens.d.ts +5 -0
- package/dist/node/builtin-plugins/tailwind-tokens.js +510 -0
- package/dist/node/collect/index.js +3 -1
- package/dist/node/commands/preview.js +4 -25
- package/dist/node/config.d.ts +103 -3
- package/dist/node/config.js +40 -23
- package/dist/node/context.d.ts +3 -3
- package/dist/node/context.js +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/load.d.ts +12 -0
- package/dist/node/load.js +42 -0
- package/dist/node/plugin.d.ts +67 -11
- package/dist/node/plugin.js +42 -245
- package/dist/node/preview.d.ts +8 -0
- package/dist/node/preview.js +41 -0
- package/dist/node/search.d.ts +2 -0
- package/dist/node/search.js +68 -0
- package/dist/node/server.js +43 -21
- package/dist/node/stories.d.ts +2 -0
- package/dist/node/stories.js +4 -4
- package/dist/node/types.d.ts +1 -0
- package/dist/node/util/find-up.d.ts +1 -0
- package/dist/node/util/find-up.js +20 -0
- package/dist/node/vite.d.ts +13 -0
- package/dist/node/vite.js +278 -0
- package/dist/style.css +111 -47
- package/package.json +5 -3
- package/scripts/copy.mjs +2 -1
- package/src/client/app/App.vue +8 -3
- package/src/client/app/codegen/const.ts +3 -0
- package/src/client/app/codegen/vue3.ts +80 -22
- package/src/client/app/components/base/BaseEmpty.vue +17 -1
- package/src/client/app/components/exposed/Story.vue +22 -1
- package/src/client/app/components/exposed/Variant.vue +13 -1
- package/src/client/app/components/sandbox/SandboxVue3.vue +6 -4
- package/src/client/app/components/sandbox/lib.ts +3 -1
- package/src/client/app/components/search/SearchLoading.vue +16 -0
- package/src/client/app/components/search/SearchModal.vue +12 -149
- package/src/client/app/components/search/SearchPane.vue +210 -0
- package/src/client/app/components/search/search-data.ts +9 -0
- package/src/client/app/components/story/StoryControls.vue +5 -0
- package/src/client/app/components/story/StoryDocs.vue +18 -11
- package/src/client/app/components/story/StoryEvent.vue +53 -0
- package/src/client/app/components/story/StoryEvents.vue +45 -0
- package/src/client/app/components/story/StoryResponsivePreview.vue +41 -8
- package/src/client/app/components/story/StorySidePanel.vue +28 -3
- package/src/client/app/components/story/StorySourceCode.vue +24 -14
- package/src/client/app/components/story/StoryView.vue +16 -2
- package/src/client/app/components/tree/StoryGroup.vue +4 -4
- package/src/client/app/components/tree/StoryListFolder.vue +4 -4
- package/src/client/app/components/tree/StoryListItem.vue +4 -1
- package/src/client/app/router.ts +4 -1
- package/src/client/app/sandbox.ts +12 -2
- package/src/client/app/stores/events.ts +36 -0
- package/{dist/client/app/stores/story.ts → src/client/app/stores/folder.ts} +16 -23
- package/src/client/app/stores/story.ts +21 -40
- package/src/client/app/style/main.pcss +5 -0
- package/src/client/app/style/sandbox.css +2 -0
- package/src/client/app/types.ts +1 -0
- package/src/client/app/util/const.ts +1 -0
- package/src/client/app/util/events.ts +30 -0
- package/src/client/app/util/mapping.ts +2 -2
- package/src/client/index.ts +2 -1
- package/src/client/server/Story.server.vue +13 -2
- package/src/node/alias.ts +4 -2
- package/src/node/build.ts +86 -21
- package/src/node/builtin-plugins/tailwind-tokens.ts +521 -0
- package/src/node/collect/index.ts +3 -1
- package/src/node/commands/preview.ts +4 -33
- package/src/node/config.ts +53 -27
- package/src/node/context.ts +3 -3
- package/src/node/index.ts +1 -0
- package/src/node/load.ts +63 -0
- package/src/node/plugin.ts +75 -252
- package/src/node/preview.ts +56 -0
- package/src/node/search.ts +75 -0
- package/src/node/server.ts +49 -23
- package/src/node/stories.ts +4 -4
- package/src/node/types.ts +1 -0
- package/src/node/util/find-up.ts +24 -0
- package/src/node/vite.ts +296 -0
- package/tailwind.config.cjs +1 -0
- package/dist/client/app/codegen/serialize-js.ts +0 -119
- package/dist/client/app/codegen/util.ts +0 -79
- package/dist/client/app/codegen/vue3.ts +0 -276
- package/dist/client/app/components/sandbox/lib.ts +0 -8
- package/dist/client/app/global-components.ts +0 -13
- package/dist/client/app/index.ts +0 -28
- package/dist/client/app/router.ts +0 -17
- package/dist/client/app/sandbox.ts +0 -94
- package/dist/client/app/stores/preview-settings.ts +0 -17
- package/dist/client/app/types.ts +0 -78
- package/dist/client/app/util/config.ts +0 -6
- package/dist/client/app/util/const.ts +0 -3
- package/dist/client/app/util/dark.ts +0 -4
- package/dist/client/app/util/env.ts +0 -1
- package/dist/client/app/util/keyboard.ts +0 -99
- package/dist/client/app/util/mapping.ts +0 -48
- package/dist/client/app/util/preview-settings.ts +0 -8
- package/dist/client/app/util/reactivity.ts +0 -22
- package/dist/client/app/util/responsive.ts +0 -3
- package/dist/client/app/util/scroll.ts +0 -31
- package/dist/client/app/util/tooltip.ts +0 -13
- package/dist/client/app/util/variant.ts +0 -20
- package/dist/client/index.ts +0 -12
- package/dist/client/server/index.ts +0 -32
- package/dist/client/shim.d.ts +0 -5
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createRequire } from 'module'
|
|
2
|
+
import flexsearch from 'flexsearch'
|
|
3
|
+
import path from 'pathe'
|
|
4
|
+
import { Context } from './context.js'
|
|
5
|
+
import { loadModule } from './load.js'
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
|
+
|
|
9
|
+
export async function generateSearchData (ctx: Context) {
|
|
10
|
+
const flexsearchRoot = path.dirname(require.resolve('flexsearch/package.json'))
|
|
11
|
+
const searchIndex = new flexsearch.Document({
|
|
12
|
+
preset: 'match',
|
|
13
|
+
document: {
|
|
14
|
+
id: 'id',
|
|
15
|
+
index: [
|
|
16
|
+
'title',
|
|
17
|
+
'docs',
|
|
18
|
+
],
|
|
19
|
+
store: [
|
|
20
|
+
'kind',
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
charset: await loadModule(`${flexsearchRoot}/dist/module/lang/latin/advanced.js`),
|
|
24
|
+
language: await loadModule(`${flexsearchRoot}/dist/module/lang/en.js`),
|
|
25
|
+
tokenize: 'full',
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
for (const storyFile of ctx.storyFiles) {
|
|
29
|
+
if (storyFile.story) {
|
|
30
|
+
searchIndex.add({
|
|
31
|
+
id: storyFile.story.id,
|
|
32
|
+
kind: 'story',
|
|
33
|
+
title: storyFile.story.title,
|
|
34
|
+
docs: '', // @TODO
|
|
35
|
+
})
|
|
36
|
+
for (const variant of storyFile.story.variants) {
|
|
37
|
+
searchIndex.add({
|
|
38
|
+
id: `${storyFile.story.id}:${variant.id}`,
|
|
39
|
+
kind: 'variant',
|
|
40
|
+
title: `${storyFile.story.title} ${variant.title}`,
|
|
41
|
+
docs: '', // @TODO
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return exportSearchIndex(searchIndex)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const exportKeys = new Set([
|
|
51
|
+
'reg',
|
|
52
|
+
'title.cfg',
|
|
53
|
+
'title.map',
|
|
54
|
+
'title.ctx',
|
|
55
|
+
'docs.cfg',
|
|
56
|
+
'docs.map',
|
|
57
|
+
'docs.ctx',
|
|
58
|
+
'tag',
|
|
59
|
+
'store',
|
|
60
|
+
])
|
|
61
|
+
|
|
62
|
+
async function exportSearchIndex (index) {
|
|
63
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
64
|
+
return new Promise(async (resolve, reject) => {
|
|
65
|
+
const exportedData: Record<string, any> = {}
|
|
66
|
+
const exportedKeys = new Set<string>()
|
|
67
|
+
await index.export((key, data) => {
|
|
68
|
+
exportedData[key] = data
|
|
69
|
+
exportedKeys.add(key)
|
|
70
|
+
if (exportedKeys.size === exportKeys.size) {
|
|
71
|
+
resolve(exportedData)
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
}
|
package/src/node/server.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createServer as createViteServer } from 'vite'
|
|
2
2
|
import { Context } from './context.js'
|
|
3
|
-
import { createVitePlugins, RESOLVED_STORIES_ID } from './
|
|
3
|
+
import { createVitePlugins, RESOLVED_SEARCH_DATA_ID, RESOLVED_STORIES_ID } from './vite.js'
|
|
4
4
|
import { notifyStoryChange, onStoryChange, watchStories } from './stories.js'
|
|
5
5
|
import { useCollectStories } from './collect/index.js'
|
|
6
6
|
import type { StoryFile } from './types.js'
|
|
7
|
+
import { DevPluginApi } from './plugin.js'
|
|
8
|
+
import { useModuleLoader } from './load.js'
|
|
7
9
|
|
|
8
10
|
export async function createServer (ctx: Context, port: number) {
|
|
9
|
-
await watchStories(ctx)
|
|
10
|
-
|
|
11
11
|
const server = await createViteServer({
|
|
12
12
|
plugins: await createVitePlugins(ctx),
|
|
13
13
|
server: {
|
|
@@ -17,6 +17,24 @@ export async function createServer (ctx: Context, port: number) {
|
|
|
17
17
|
},
|
|
18
18
|
})
|
|
19
19
|
await server.pluginContainer.buildStart({})
|
|
20
|
+
|
|
21
|
+
const moduleLoader = useModuleLoader({
|
|
22
|
+
server,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const pluginOnCleanups: (() => void | Promise<void>)[] = []
|
|
26
|
+
for (const plugin of ctx.config.plugins) {
|
|
27
|
+
if (plugin.onDev) {
|
|
28
|
+
const api = new DevPluginApi(ctx, plugin, moduleLoader)
|
|
29
|
+
const onCleanup = (cb: () => void | Promise<void>) => {
|
|
30
|
+
pluginOnCleanups.push(cb)
|
|
31
|
+
}
|
|
32
|
+
await plugin.onDev(api, onCleanup)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
await watchStories(ctx)
|
|
37
|
+
|
|
20
38
|
// Wait for pre-bundling (in `listen()`)
|
|
21
39
|
await server.listen(port)
|
|
22
40
|
|
|
@@ -69,30 +87,38 @@ export async function createServer (ctx: Context, port: number) {
|
|
|
69
87
|
queuedFiles = []
|
|
70
88
|
queueResolve()
|
|
71
89
|
|
|
72
|
-
// Invalidate
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
90
|
+
// Invalidate modules
|
|
91
|
+
function invalidateModule (id: string) {
|
|
92
|
+
const mod = server.moduleGraph.getModuleById(id)
|
|
93
|
+
if (!mod) {
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
server.moduleGraph.invalidateModule(mod)
|
|
97
|
+
|
|
98
|
+
// Send HMR update
|
|
99
|
+
const timestamp = Date.now()
|
|
100
|
+
mod.lastHMRTimestamp = timestamp
|
|
101
|
+
server.ws.send({
|
|
102
|
+
type: 'update',
|
|
103
|
+
updates: [
|
|
104
|
+
{
|
|
105
|
+
type: 'js-update',
|
|
106
|
+
acceptedPath: mod.url,
|
|
107
|
+
path: mod.url,
|
|
108
|
+
timestamp: timestamp,
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
})
|
|
76
112
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
})
|
|
113
|
+
|
|
114
|
+
invalidateModule(RESOLVED_STORIES_ID)
|
|
115
|
+
invalidateModule(RESOLVED_SEARCH_DATA_ID)
|
|
93
116
|
})
|
|
94
117
|
|
|
95
118
|
async function close () {
|
|
119
|
+
for (const cb of pluginOnCleanups) {
|
|
120
|
+
await cb()
|
|
121
|
+
}
|
|
96
122
|
await server.close()
|
|
97
123
|
await destroyCollectStories()
|
|
98
124
|
}
|
package/src/node/stories.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import chokidar from 'chokidar'
|
|
2
2
|
import { globby } from 'globby'
|
|
3
3
|
import Case from 'case'
|
|
4
|
-
import {
|
|
4
|
+
import { resolve, basename } from 'pathe'
|
|
5
5
|
import { Context } from './context.js'
|
|
6
6
|
import type { StoryFile } from './types.js'
|
|
7
7
|
|
|
@@ -41,10 +41,10 @@ export function notifyStoryChange (file?: StoryFile) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function getAbsoluteFilePath (relativeFilePath: string) {
|
|
44
|
-
return
|
|
44
|
+
return resolve(context.root, relativeFilePath)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function addStory (relativeFilePath: string) {
|
|
47
|
+
export function addStory (relativeFilePath: string) {
|
|
48
48
|
const absoluteFilePath = getAbsoluteFilePath(relativeFilePath)
|
|
49
49
|
const fileId = Case.kebab(relativeFilePath)
|
|
50
50
|
let fileName = basename(relativeFilePath)
|
|
@@ -62,7 +62,7 @@ function addStory (relativeFilePath: string) {
|
|
|
62
62
|
return file
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function removeStory (relativeFilePath: string) {
|
|
65
|
+
export function removeStory (relativeFilePath: string) {
|
|
66
66
|
const fileId = Case.kebab(relativeFilePath)
|
|
67
67
|
const index = context.storyFiles.findIndex((file) => file.id === fileId)
|
|
68
68
|
if (index !== -1) context.storyFiles.splice(index, 1)
|
package/src/node/types.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import path from 'pathe'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
|
|
4
|
+
export function findUp (cwd: string = process.cwd(), fileNames: string[]): string {
|
|
5
|
+
let { root } = path.parse(cwd)
|
|
6
|
+
let dir = cwd
|
|
7
|
+
|
|
8
|
+
// Fix for windows, waiting for pathe to fix this: https://github.com/unjs/pathe/issues/5
|
|
9
|
+
if (root === '' && dir[1] === ':') {
|
|
10
|
+
root = dir.substring(0, 2)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
while (dir !== root) {
|
|
14
|
+
for (const fileName of fileNames) {
|
|
15
|
+
const searchPath = path.join(dir, fileName)
|
|
16
|
+
if (fs.existsSync(searchPath)) {
|
|
17
|
+
return searchPath
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
dir = path.dirname(dir)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null
|
|
24
|
+
}
|
package/src/node/vite.ts
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { createRequire } from 'module'
|
|
2
|
+
import { relative, dirname } from 'pathe'
|
|
3
|
+
import { resolveConfig as resolveViteConfig, Plugin as VitePlugin } from 'vite'
|
|
4
|
+
import { lookup as lookupMime } from 'mrmime'
|
|
5
|
+
import { APP_PATH, DIST_PATH, TEMP_PATH } from './alias.js'
|
|
6
|
+
import { Context } from './context.js'
|
|
7
|
+
import { notifyStoryChange } from './stories.js'
|
|
8
|
+
import { makeTree } from './tree.js'
|
|
9
|
+
import { parseColor } from './colors.js'
|
|
10
|
+
import { createMarkdownRenderer } from './markdown.js'
|
|
11
|
+
import { generateSearchData } from './search.js'
|
|
12
|
+
|
|
13
|
+
const require = createRequire(import.meta.url)
|
|
14
|
+
|
|
15
|
+
export const STORIES_ID = '$histoire-stories'
|
|
16
|
+
export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`
|
|
17
|
+
export const SETUP_ID = '$histoire-setup'
|
|
18
|
+
export const NOOP_ID = '/$histoire-noop'
|
|
19
|
+
export const CONFIG_ID = '$histoire-config'
|
|
20
|
+
export const RESOLVED_CONFIG_ID = `/${CONFIG_ID}-resolved`
|
|
21
|
+
export const THEME_ID = '$histoire-theme'
|
|
22
|
+
export const RESOLVED_THEME_ID = `/${THEME_ID}-resolved.css`
|
|
23
|
+
export const SEARCH_DATA_ID = '$histoire-search-data'
|
|
24
|
+
export const RESOLVED_SEARCH_DATA_ID = `/${SEARCH_DATA_ID}-resolved`
|
|
25
|
+
|
|
26
|
+
export async function createVitePlugins (ctx: Context): Promise<VitePlugin[]> {
|
|
27
|
+
const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build')
|
|
28
|
+
const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue')
|
|
29
|
+
|
|
30
|
+
const plugins: VitePlugin[] = []
|
|
31
|
+
|
|
32
|
+
if (!hasVuePlugin) {
|
|
33
|
+
plugins.push((await import('@vitejs/plugin-vue')).default())
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (ctx.config.vite) {
|
|
37
|
+
plugins.push({
|
|
38
|
+
name: 'histoire-vite-config-override',
|
|
39
|
+
config (config, env) {
|
|
40
|
+
return typeof ctx.config.vite === 'function' ? ctx.config.vite(config, env) : ctx.config.vite
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
plugins.push({
|
|
46
|
+
name: 'histoire-vite-plugin',
|
|
47
|
+
|
|
48
|
+
config () {
|
|
49
|
+
return {
|
|
50
|
+
optimizeDeps: {
|
|
51
|
+
// force include vue to avoid duplicated copies when linked + optimized
|
|
52
|
+
include: [
|
|
53
|
+
'vue',
|
|
54
|
+
dirname(require.resolve('@vue/runtime-core/package.json')),
|
|
55
|
+
dirname(require.resolve('shiki/package.json')),
|
|
56
|
+
dirname(require.resolve('vscode-textmate/package.json')),
|
|
57
|
+
dirname(require.resolve('vscode-oniguruma/package.json')),
|
|
58
|
+
dirname(require.resolve('case/package.json')),
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
server: {
|
|
62
|
+
fs: {
|
|
63
|
+
allow: [DIST_PATH, TEMP_PATH, viteConfig.root, process.cwd()],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
define: {
|
|
67
|
+
// We need to force this to be able to use `devtoolsRawSetupState`
|
|
68
|
+
__VUE_PROD_DEVTOOLS__: 'true',
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
async resolveId (id, importer) {
|
|
74
|
+
if (id.startsWith(STORIES_ID)) {
|
|
75
|
+
return RESOLVED_STORIES_ID
|
|
76
|
+
}
|
|
77
|
+
if (id.startsWith(SETUP_ID)) {
|
|
78
|
+
if (ctx.config.setupFile) {
|
|
79
|
+
return this.resolve(ctx.config.setupFile, importer, {
|
|
80
|
+
skipSelf: true,
|
|
81
|
+
})
|
|
82
|
+
} else {
|
|
83
|
+
return NOOP_ID
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (id.startsWith(CONFIG_ID)) {
|
|
87
|
+
return RESOLVED_CONFIG_ID
|
|
88
|
+
}
|
|
89
|
+
if (id.startsWith(THEME_ID)) {
|
|
90
|
+
return RESOLVED_THEME_ID
|
|
91
|
+
}
|
|
92
|
+
if (id.startsWith(SEARCH_DATA_ID)) {
|
|
93
|
+
return RESOLVED_SEARCH_DATA_ID
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
async load (id) {
|
|
98
|
+
if (id === RESOLVED_STORIES_ID) {
|
|
99
|
+
const resolvedStories = ctx.storyFiles.filter(s => !!s.story)
|
|
100
|
+
const files = resolvedStories.map((file, index) => {
|
|
101
|
+
return {
|
|
102
|
+
id: file.id,
|
|
103
|
+
path: file.treePath,
|
|
104
|
+
story: file.story,
|
|
105
|
+
framework: 'vue3',
|
|
106
|
+
index,
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
return `import { defineAsyncComponent } from 'vue'
|
|
110
|
+
${resolvedStories.map((file, index) => `const Comp${index} = defineAsyncComponent(() => import('${file.path}'))`).join('\n')}
|
|
111
|
+
export let files = [${files.map((file) => `{${JSON.stringify(file).slice(1, -1)}, component: Comp${file.index}}`).join(',\n')}]
|
|
112
|
+
export let tree = ${JSON.stringify(makeTree(ctx.config, resolvedStories))}
|
|
113
|
+
const handlers = []
|
|
114
|
+
export function onUpdate (cb) {
|
|
115
|
+
handlers.push(cb)
|
|
116
|
+
}
|
|
117
|
+
if (import.meta.hot) {
|
|
118
|
+
import.meta.hot.accept(newModule => {
|
|
119
|
+
files = newModule.files
|
|
120
|
+
tree = newModule.tree
|
|
121
|
+
handlers.forEach(h => {
|
|
122
|
+
h(newModule.files, newModule.tree)
|
|
123
|
+
newModule.onUpdate(h)
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
}`
|
|
127
|
+
}
|
|
128
|
+
if (id === NOOP_ID) {
|
|
129
|
+
return `export default () => {}`
|
|
130
|
+
}
|
|
131
|
+
if (id === RESOLVED_CONFIG_ID) {
|
|
132
|
+
let js = `export const config = ${JSON.stringify(ctx.config)}\n`
|
|
133
|
+
if (ctx.config.theme?.logo) {
|
|
134
|
+
for (const key in ctx.config.theme.logo) {
|
|
135
|
+
js += `import Logo_${key} from '${ctx.config.theme.logo[key]}'\n`
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
js += `export const logos = {${Object.keys(ctx.config.theme?.logo ?? {}).map(key => `${key}: Logo_${key}`).join(', ')}}\n`
|
|
139
|
+
return js
|
|
140
|
+
}
|
|
141
|
+
if (id === RESOLVED_THEME_ID) {
|
|
142
|
+
let css = '*, ::before, ::after {'
|
|
143
|
+
// Colors
|
|
144
|
+
for (const color in ctx.config.theme?.colors ?? {}) {
|
|
145
|
+
for (const key in ctx.config.theme.colors[color]) {
|
|
146
|
+
css += `--_histoire-color-${color}-${key}: ${parseColor(ctx.config.theme.colors[color][key]).color.join(' ')};`
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
css += '}'
|
|
150
|
+
return css
|
|
151
|
+
}
|
|
152
|
+
if (id === RESOLVED_SEARCH_DATA_ID) {
|
|
153
|
+
return `export let searchData = ${JSON.stringify(await generateSearchData(ctx))}
|
|
154
|
+
const handlers = []
|
|
155
|
+
export function onUpdate (cb) {
|
|
156
|
+
handlers.push(cb)
|
|
157
|
+
}
|
|
158
|
+
if (import.meta.hot) {
|
|
159
|
+
import.meta.hot.accept(newModule => {
|
|
160
|
+
searchData = newModule.searchData
|
|
161
|
+
handlers.forEach(h => {
|
|
162
|
+
h(newModule.searchData)
|
|
163
|
+
newModule.onUpdate(h)
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
}`
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
handleHotUpdate (updateContext) {
|
|
171
|
+
const story = ctx.storyFiles.find(file => file.path === updateContext.file)
|
|
172
|
+
if (story) {
|
|
173
|
+
notifyStoryChange(story)
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
configureServer (server) {
|
|
178
|
+
server.middlewares.use(async (req, res, next) => {
|
|
179
|
+
if (req.url!.startsWith(`${server.config.base}__sandbox`)) {
|
|
180
|
+
res.statusCode = 200
|
|
181
|
+
let html = `
|
|
182
|
+
<!DOCTYPE html>
|
|
183
|
+
<html>
|
|
184
|
+
<head>
|
|
185
|
+
<title></title>
|
|
186
|
+
<meta charset="utf-8">
|
|
187
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
188
|
+
<meta name="description" content="">
|
|
189
|
+
</head>
|
|
190
|
+
<body>
|
|
191
|
+
<div id="app"></div>
|
|
192
|
+
<script>
|
|
193
|
+
// Hide spammy vite messages
|
|
194
|
+
const origConsoleLog = console.log
|
|
195
|
+
console.log = (...args) => {
|
|
196
|
+
if (typeof args[0] !== 'string' || !args[0].startsWith('[vite] connect')) {
|
|
197
|
+
origConsoleLog(...args)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
</script>
|
|
201
|
+
<script type="module" src="/@fs/${APP_PATH}/sandbox.js"></script>
|
|
202
|
+
</body>
|
|
203
|
+
</html>`
|
|
204
|
+
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
|
205
|
+
// also applies HTML transforms from Vite plugins
|
|
206
|
+
html = await server.transformIndexHtml(req.url, html)
|
|
207
|
+
res.end(html)
|
|
208
|
+
return
|
|
209
|
+
}
|
|
210
|
+
next()
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
// serve our index.html after vite history fallback
|
|
214
|
+
return () => {
|
|
215
|
+
server.middlewares.use(async (req, res, next) => {
|
|
216
|
+
if (req.url!.endsWith('.html')) {
|
|
217
|
+
res.statusCode = 200
|
|
218
|
+
|
|
219
|
+
let html = `
|
|
220
|
+
<!DOCTYPE html>
|
|
221
|
+
<html>
|
|
222
|
+
<head>
|
|
223
|
+
<title></title>
|
|
224
|
+
<link rel="icon" href=""/>
|
|
225
|
+
<meta charset="utf-8">
|
|
226
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
227
|
+
<meta name="description" content="">
|
|
228
|
+
${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${server.config.base}${ctx.config.theme.favicon}"/>` : ''}
|
|
229
|
+
</head>
|
|
230
|
+
<body>
|
|
231
|
+
<div id="app"></div>
|
|
232
|
+
<script type="module" src="/@fs/${APP_PATH}/index.js"></script>
|
|
233
|
+
</body>
|
|
234
|
+
</html>`
|
|
235
|
+
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
|
236
|
+
// also applies HTML transforms from Vite plugins
|
|
237
|
+
html = await server.transformIndexHtml(req.url, html)
|
|
238
|
+
res.end(html)
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
next()
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
// Custom blocks
|
|
248
|
+
plugins.push(...await createCustomBlocksPlugins(ctx))
|
|
249
|
+
|
|
250
|
+
if (ctx.mode === 'build') {
|
|
251
|
+
// Add file name in build mode to have components names instead of <Anonymous>
|
|
252
|
+
const include = [/\.vue$/]
|
|
253
|
+
const exclude = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/]
|
|
254
|
+
plugins.push({
|
|
255
|
+
name: 'histoire-file-name-plugin',
|
|
256
|
+
enforce: 'post',
|
|
257
|
+
|
|
258
|
+
transform (code, id) {
|
|
259
|
+
if (exclude.some(r => r.test(id))) return
|
|
260
|
+
if (include.some(r => r.test(id))) {
|
|
261
|
+
const file = relative(viteConfig.root, id)
|
|
262
|
+
const index = code.indexOf('export default')
|
|
263
|
+
const result = `${code.substring(0, index)}_sfc_main.__file = '${file}'\n${code.substring(index)}`
|
|
264
|
+
return result
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return plugins
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
async function createCustomBlocksPlugins (ctx) {
|
|
274
|
+
const plugins: VitePlugin[] = []
|
|
275
|
+
|
|
276
|
+
let md = await createMarkdownRenderer()
|
|
277
|
+
if (ctx.config.markdown) {
|
|
278
|
+
const result = await ctx.config.markdown(md)
|
|
279
|
+
if (result) {
|
|
280
|
+
md = result
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
plugins.push({
|
|
284
|
+
name: 'histoire-vue-docs-block',
|
|
285
|
+
transform (code, id) {
|
|
286
|
+
if (!id.includes('?vue&type=docs')) return
|
|
287
|
+
if (!id.includes('lang.md')) return
|
|
288
|
+
const html = md.render(code)
|
|
289
|
+
return `export default Comp => {
|
|
290
|
+
Comp.doc = ${JSON.stringify(html)}
|
|
291
|
+
}`
|
|
292
|
+
},
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
return plugins
|
|
296
|
+
}
|
package/tailwind.config.cjs
CHANGED
|
@@ -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
|
-
}
|