histoire 0.1.5 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/app/codegen/vue3.js +1 -0
- package/dist/client/app/codegen/vue3.js.map +1 -0
- package/dist/client/app/components/app/AppHeader.vue +2 -1
- package/dist/client/app/components/base/BaseCheckbox.vue +76 -0
- package/dist/client/app/components/exposed/Story.vue +20 -14
- package/dist/client/app/components/sandbox/lib.d.ts +2 -0
- package/dist/client/app/components/sandbox/lib.js +6 -0
- package/dist/client/app/components/sandbox/lib.ts +8 -0
- package/dist/client/app/components/search/SearchItem.vue +4 -1
- package/dist/client/app/components/search/SearchModal.vue +4 -4
- package/dist/client/app/components/story/StoryControls.vue +1 -1
- package/dist/client/app/components/story/StoryDocs.vue +1 -0
- package/dist/client/app/components/story/StoryListFolder.vue +1 -1
- package/dist/client/app/components/story/StoryListItem.vue +4 -1
- package/dist/client/app/components/story/StoryResponsivePreview.vue +3 -4
- package/dist/client/app/components/story/StorySidePanel.vue +1 -0
- package/dist/client/app/components/story/StorySourceCode.vue +4 -1
- package/dist/client/app/components/story/StoryVariantGrid.vue +112 -0
- package/dist/client/app/components/story/StoryVariantGridItem.vue +34 -4
- package/dist/client/app/components/story/StoryVariantListItem.vue +4 -1
- package/dist/client/app/components/story/StoryVariantSingleView.vue +20 -160
- package/dist/client/app/components/story/StoryViewer.vue +6 -25
- package/dist/client/app/components/story/variant/StoryVariantBackground.vue +67 -0
- package/dist/client/app/components/story/variant/StoryVariantNewTab.vue +29 -0
- package/dist/client/app/components/story/variant/StoryVariantResponsiveSize.vue +82 -0
- package/dist/client/app/components/story/variant/StoryVariantTitle.vue +21 -0
- package/dist/client/app/global-components.js +1 -0
- package/dist/client/app/global-components.js.map +1 -0
- package/dist/client/app/index.js +1 -0
- package/dist/client/app/index.js.map +1 -0
- package/dist/client/app/sandbox.js +1 -0
- package/dist/client/app/sandbox.js.map +1 -0
- package/dist/client/app/stores/story.d.ts +6 -6
- package/dist/client/app/stores/story.js +1 -0
- package/dist/client/app/stores/story.js.map +1 -0
- package/dist/client/app/style/main.pcss +9 -5
- package/dist/client/app/types.d.ts +1 -1
- package/dist/client/app/types.ts +1 -1
- package/dist/client/app/util/keyboard.js +1 -0
- package/dist/client/app/util/keyboard.js.map +1 -0
- package/dist/client/app/util/mapping.js +1 -0
- package/dist/client/app/util/mapping.js.map +1 -0
- package/dist/client/app/util/preview-settings.js +1 -0
- package/dist/client/app/util/preview-settings.js.map +1 -0
- package/dist/client/app/util/reactivity.js +1 -0
- package/dist/client/app/util/reactivity.js.map +1 -0
- package/dist/client/app/util/scroll.d.ts +3 -1
- package/dist/client/app/util/scroll.js +4 -0
- package/dist/client/app/util/scroll.js.map +1 -0
- package/dist/client/app/util/scroll.ts +4 -0
- package/dist/client/app/util/variant.js +1 -0
- package/dist/client/app/util/variant.js.map +1 -0
- package/dist/client/index.js +1 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/server/index.js +1 -0
- package/dist/client/server/index.js.map +1 -0
- package/dist/controls.js +1 -0
- package/dist/controls.js.map +1 -0
- package/dist/node/bin.js +7 -0
- package/dist/node/build.js +1 -1
- package/dist/node/{collect.d.ts → collect/index.d.ts} +2 -2
- package/dist/node/{collect.js → collect/index.js} +37 -27
- package/dist/node/collect/worker.d.ts +14 -0
- package/dist/node/collect/worker.js +36 -0
- package/dist/node/commands/preview.d.ts +4 -0
- package/dist/node/commands/preview.js +36 -0
- package/dist/node/config.d.ts +2 -2
- package/dist/node/server.js +1 -1
- package/dist/node/tree.js +24 -4
- package/dist/node/types.d.ts +1 -1
- package/dist/style.css +98 -50
- package/package.json +10 -6
- package/src/client/app/components/app/AppHeader.vue +2 -1
- package/src/client/app/components/base/BaseCheckbox.vue +76 -0
- package/src/client/app/components/exposed/Story.vue +20 -14
- package/src/client/app/components/sandbox/lib.ts +8 -0
- package/src/client/app/components/search/SearchItem.vue +4 -1
- package/src/client/app/components/search/SearchModal.vue +4 -4
- package/src/client/app/components/story/StoryControls.vue +1 -1
- package/src/client/app/components/story/StoryDocs.vue +1 -0
- package/src/client/app/components/story/StoryListFolder.vue +1 -1
- package/src/client/app/components/story/StoryListItem.vue +4 -1
- package/src/client/app/components/story/StoryResponsivePreview.vue +3 -4
- package/src/client/app/components/story/StorySidePanel.vue +1 -0
- package/src/client/app/components/story/StorySourceCode.vue +4 -1
- package/src/client/app/components/story/StoryVariantGrid.vue +112 -0
- package/src/client/app/components/story/StoryVariantGridItem.vue +34 -4
- package/src/client/app/components/story/StoryVariantListItem.vue +4 -1
- package/src/client/app/components/story/StoryVariantSingleView.vue +20 -160
- package/src/client/app/components/story/StoryViewer.vue +6 -25
- package/src/client/app/components/story/variant/StoryVariantBackground.vue +67 -0
- package/src/client/app/components/story/variant/StoryVariantNewTab.vue +29 -0
- package/src/client/app/components/story/variant/StoryVariantResponsiveSize.vue +82 -0
- package/src/client/app/components/story/variant/StoryVariantTitle.vue +21 -0
- package/src/client/app/style/main.pcss +9 -5
- package/src/client/app/types.ts +1 -1
- package/src/client/app/util/scroll.ts +4 -0
- package/src/node/bin.ts +8 -0
- package/src/node/build.ts +1 -1
- package/src/node/{collect.ts → collect/index.ts} +48 -30
- package/src/node/collect/worker.ts +61 -0
- package/src/node/commands/preview.ts +50 -0
- package/src/node/config.ts +2 -2
- package/src/node/server.ts +1 -1
- package/src/node/tree.spec.ts +61 -0
- package/src/node/tree.ts +29 -5
- package/src/node/types.ts +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url'
|
|
2
|
+
import type { MessagePort } from 'worker_threads'
|
|
3
|
+
import { ViteNodeRunner } from 'vite-node/client'
|
|
4
|
+
import { createBirpc } from 'birpc'
|
|
5
|
+
import type { FetchFunction, ResolveIdFunction } from 'vite-node'
|
|
6
|
+
import { dirname, resolve } from 'pathe'
|
|
7
|
+
import { createDomEnv } from '../dom/env.js'
|
|
8
|
+
import type { StoryFile, Story } from '../types.js'
|
|
9
|
+
|
|
10
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
11
|
+
|
|
12
|
+
export interface Payload {
|
|
13
|
+
root: string
|
|
14
|
+
base: string
|
|
15
|
+
port: MessagePort
|
|
16
|
+
storyFile: StoryFile
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ReturnData {
|
|
20
|
+
storyData: Story[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default async (payload: Payload): Promise<ReturnData> => {
|
|
24
|
+
const rpc = createBirpc<{
|
|
25
|
+
fetchModule: FetchFunction
|
|
26
|
+
resolveId: ResolveIdFunction
|
|
27
|
+
}>({}, {
|
|
28
|
+
post: data => payload.port.postMessage(data),
|
|
29
|
+
on: data => payload.port.on('message', data),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const runner = new ViteNodeRunner({
|
|
33
|
+
root: payload.root,
|
|
34
|
+
base: payload.base,
|
|
35
|
+
fetchModule (id) {
|
|
36
|
+
// Alias
|
|
37
|
+
if (id.endsWith('vue.runtime.esm-bundler.js')) {
|
|
38
|
+
id = 'vue'
|
|
39
|
+
}
|
|
40
|
+
return rpc.fetchModule(id)
|
|
41
|
+
},
|
|
42
|
+
resolveId (id, importer) {
|
|
43
|
+
return rpc.resolveId(id, importer)
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const { destroy: destroyDomEnv } = createDomEnv()
|
|
48
|
+
|
|
49
|
+
const el = window.document.createElement('div')
|
|
50
|
+
|
|
51
|
+
// Mount app to collect stories/variants
|
|
52
|
+
const { run } = await runner.executeFile(resolve(__dirname, '../../client/server/index.js'))
|
|
53
|
+
const storyData: Story[] = []
|
|
54
|
+
await run(payload.storyFile, storyData, el)
|
|
55
|
+
|
|
56
|
+
destroyDomEnv()
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
storyData,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import http from 'http'
|
|
2
|
+
import { resolveConfig as resolveViteConfig } from 'vite'
|
|
3
|
+
import connect from 'connect'
|
|
4
|
+
import sirv from 'sirv'
|
|
5
|
+
import pc from 'picocolors'
|
|
6
|
+
import { createContext } from '../context.js'
|
|
7
|
+
import { createVitePlugins } from '../plugin.js'
|
|
8
|
+
|
|
9
|
+
export interface PreviewOptions {
|
|
10
|
+
port?: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function previewCommand (options: PreviewOptions) {
|
|
14
|
+
const ctx = await createContext({
|
|
15
|
+
mode: 'build',
|
|
16
|
+
})
|
|
17
|
+
const viteConfig = await resolveViteConfig({
|
|
18
|
+
plugins: await createVitePlugins(ctx),
|
|
19
|
+
}, 'build')
|
|
20
|
+
|
|
21
|
+
const app = connect()
|
|
22
|
+
|
|
23
|
+
app.use(
|
|
24
|
+
viteConfig.base,
|
|
25
|
+
sirv(ctx.config.outDir, {
|
|
26
|
+
dev: true,
|
|
27
|
+
etag: true,
|
|
28
|
+
single: true,
|
|
29
|
+
}),
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
let port = options.port ?? 3000
|
|
33
|
+
|
|
34
|
+
const httpServer = http.createServer(app)
|
|
35
|
+
|
|
36
|
+
function onError (e: Error & { code?: string }) {
|
|
37
|
+
if (e.code === 'EADDRINUSE') {
|
|
38
|
+
httpServer.listen(++port)
|
|
39
|
+
} else {
|
|
40
|
+
throw e
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
httpServer.on('error', onError)
|
|
45
|
+
|
|
46
|
+
httpServer.listen(port, () => {
|
|
47
|
+
httpServer.off('error', onError)
|
|
48
|
+
console.log(`Preview server listening on ${pc.cyan(`http://localhost:${port}`)}`)
|
|
49
|
+
})
|
|
50
|
+
}
|
package/src/node/config.ts
CHANGED
|
@@ -77,7 +77,7 @@ export interface HistoireConfig {
|
|
|
77
77
|
dark?: string
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
|
-
* Href to the favicon file (**not** processed by Vite). Put the file in the public directory.
|
|
80
|
+
* Href to the favicon file (**not** processed by Vite). Put the file in the `public` directory.
|
|
81
81
|
*
|
|
82
82
|
* Example: `'/favicon.ico'`
|
|
83
83
|
*/
|
|
@@ -102,7 +102,7 @@ export interface HistoireConfig {
|
|
|
102
102
|
logoHref?: string
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
|
-
* Setup file
|
|
105
|
+
* Setup file exporting a default function executed when setting up each story preview.
|
|
106
106
|
*
|
|
107
107
|
* Import custom CSS files from this file.
|
|
108
108
|
*
|
package/src/node/server.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { createServer as createViteServer } from 'vite'
|
|
|
2
2
|
import { Context } from './context.js'
|
|
3
3
|
import { createVitePlugins, RESOLVED_STORIES_ID } from './plugin.js'
|
|
4
4
|
import { notifyStoryChange, onStoryChange, watchStories } from './stories.js'
|
|
5
|
-
import { useCollectStories } from './collect.js'
|
|
5
|
+
import { useCollectStories } from './collect/index.js'
|
|
6
6
|
import type { StoryFile } from './types.js'
|
|
7
7
|
|
|
8
8
|
export async function createServer (ctx: Context, port: number) {
|
package/src/node/tree.spec.ts
CHANGED
|
@@ -25,4 +25,65 @@ describe('makeTree', () => {
|
|
|
25
25
|
{ title: 'hi', index: 0 },
|
|
26
26
|
])
|
|
27
27
|
})
|
|
28
|
+
|
|
29
|
+
test('should handle title conflict', () => {
|
|
30
|
+
const config = getDefaultConfig()
|
|
31
|
+
const files = [
|
|
32
|
+
{ index: 0, path: ['hi'] },
|
|
33
|
+
{ index: 1, path: ['hi'] },
|
|
34
|
+
{ index: 2, path: ['hi'] },
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
const tree = makeTree(config, files)
|
|
38
|
+
|
|
39
|
+
expect(tree).toEqual([
|
|
40
|
+
{ title: 'hi', index: 0 },
|
|
41
|
+
{ title: 'hi-1', index: 1 },
|
|
42
|
+
{ title: 'hi-2', index: 2 },
|
|
43
|
+
])
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('should handle file-folder conflict when folder in first', () => {
|
|
47
|
+
const config = getDefaultConfig()
|
|
48
|
+
const files = [
|
|
49
|
+
{ index: 0, path: ['hi', 'dad'] },
|
|
50
|
+
{ index: 1, path: ['hi'] },
|
|
51
|
+
{ index: 2, path: ['hi', 'mom'] },
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
const tree = makeTree(config, files)
|
|
55
|
+
|
|
56
|
+
expect(tree).toEqual([
|
|
57
|
+
{
|
|
58
|
+
title: 'hi',
|
|
59
|
+
children: [
|
|
60
|
+
{ title: 'dad', index: 0 },
|
|
61
|
+
{ title: 'mom', index: 2 },
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
{ title: 'hi-1', index: 1 },
|
|
65
|
+
])
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('should handle file-folder conflict when file in first', () => {
|
|
69
|
+
const config = getDefaultConfig()
|
|
70
|
+
const files = [
|
|
71
|
+
{ index: 0, path: ['hi'] },
|
|
72
|
+
{ index: 1, path: ['hi', 'dad'] },
|
|
73
|
+
{ index: 2, path: ['hi', 'mom'] },
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
const tree = makeTree(config, files)
|
|
77
|
+
|
|
78
|
+
expect(tree).toEqual([
|
|
79
|
+
{
|
|
80
|
+
title: 'hi',
|
|
81
|
+
children: [
|
|
82
|
+
{ title: 'dad', index: 1 },
|
|
83
|
+
{ title: 'mom', index: 2 },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
{ title: 'hi-1', index: 0 },
|
|
87
|
+
])
|
|
88
|
+
})
|
|
28
89
|
})
|
package/src/node/tree.ts
CHANGED
|
@@ -51,17 +51,41 @@ export function makeTree (config: HistoireConfig, files: { path: string[], index
|
|
|
51
51
|
|
|
52
52
|
return buildTree(treeObject)
|
|
53
53
|
|
|
54
|
-
// Undefined behavior for folder and file that share the same name under the same directory
|
|
55
54
|
function setPath (path: string[], value: unknown, tree: unknown) {
|
|
56
55
|
path.reduce((subtree, key, i) => {
|
|
57
|
-
if (!subtree[key]) {
|
|
58
|
-
subtree[key] = {}
|
|
59
|
-
}
|
|
60
56
|
if (i === path.length - 1) {
|
|
61
|
-
subtree
|
|
57
|
+
setKey(subtree, key, value)
|
|
58
|
+
} else if (isLeaf(subtree[key])) {
|
|
59
|
+
setKey(subtree, key, subtree[key])
|
|
60
|
+
subtree[key] = {}
|
|
61
|
+
} else if (!subtree[key]) {
|
|
62
|
+
subtree[key] = {}
|
|
62
63
|
}
|
|
63
64
|
return subtree[key]
|
|
64
65
|
}, tree)
|
|
66
|
+
|
|
67
|
+
function isLeaf (element) {
|
|
68
|
+
return !isNaN(element)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function setKey (tree, key, value) {
|
|
73
|
+
if (isUndefined(tree[key])) {
|
|
74
|
+
tree[key] = value
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let copyNumber = 1
|
|
79
|
+
|
|
80
|
+
while (!isUndefined(tree[`${key}-${copyNumber}`])) {
|
|
81
|
+
copyNumber++
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
tree[`${key}-${copyNumber}`] = value
|
|
85
|
+
|
|
86
|
+
function isUndefined (element) {
|
|
87
|
+
return element === undefined
|
|
88
|
+
}
|
|
65
89
|
}
|
|
66
90
|
|
|
67
91
|
function buildTree (treeObject: ITreeObject): Tree {
|