histoire 0.2.0 → 0.2.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/dist/client/app/App.vue +1 -1
- package/dist/client/app/codegen/vue3.js +11 -1
- package/dist/client/app/codegen/vue3.ts +9 -1
- package/dist/client/app/components/app/AppHeader.vue +1 -1
- package/dist/client/app/components/exposed/Story.vue +25 -14
- package/dist/client/app/components/exposed/Variant.vue +7 -0
- 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/story/StoryResponsivePreview.vue +74 -81
- package/dist/client/app/components/story/StorySidePanel.vue +1 -1
- package/dist/client/app/components/story/StorySourceCode.vue +3 -17
- package/dist/client/app/components/story/StoryVariantGrid.vue +112 -0
- package/dist/client/app/components/story/StoryVariantGridItem.vue +36 -6
- package/dist/client/app/components/story/StoryVariantSingleView.vue +20 -161
- package/dist/client/app/components/story/StoryViewer.vue +7 -42
- package/dist/client/app/components/story/toolbar/StoryVariantBackground.vue +67 -0
- package/dist/client/app/components/story/toolbar/StoryVariantNewTab.vue +29 -0
- package/dist/client/app/components/story/toolbar/StoryVariantResponsiveSize.vue +82 -0
- package/dist/client/app/components/story/toolbar/StoryVariantTitle.vue +21 -0
- package/dist/client/app/stores/preview-settings.d.ts +8 -0
- package/dist/client/app/stores/preview-settings.js +14 -0
- package/dist/client/app/stores/preview-settings.ts +17 -0
- package/dist/client/app/stores/story.d.ts +45 -15
- package/dist/client/app/style/main.pcss +4 -0
- package/dist/client/app/types.d.ts +10 -1
- package/dist/client/app/types.ts +11 -1
- package/dist/client/app/util/mapping.js +10 -9
- package/dist/client/app/util/mapping.ts +10 -5
- package/dist/client/app/util/preview-settings.d.ts +1 -8
- package/dist/client/app/util/preview-settings.js +0 -10
- package/dist/client/app/util/preview-settings.ts +1 -19
- package/dist/client/app/util/scroll.d.ts +3 -1
- package/dist/client/app/util/scroll.js +3 -0
- package/dist/client/app/util/scroll.ts +4 -0
- package/dist/node/config.d.ts +2 -2
- package/dist/node/plugin.js +14 -6
- package/dist/node/tree.js +24 -4
- package/dist/style.css +70 -4
- package/package.json +21 -21
- package/src/client/app/App.vue +1 -1
- package/src/client/app/codegen/vue3.ts +9 -1
- package/src/client/app/components/app/AppHeader.vue +1 -1
- package/src/client/app/components/exposed/Story.vue +25 -14
- package/src/client/app/components/exposed/Variant.vue +7 -0
- package/src/client/app/components/sandbox/lib.ts +8 -0
- package/src/client/app/components/story/StoryResponsivePreview.vue +74 -81
- package/src/client/app/components/story/StorySidePanel.vue +1 -1
- package/src/client/app/components/story/StorySourceCode.vue +3 -17
- package/src/client/app/components/story/StoryVariantGrid.vue +112 -0
- package/src/client/app/components/story/StoryVariantGridItem.vue +36 -6
- package/src/client/app/components/story/StoryVariantSingleView.vue +20 -161
- package/src/client/app/components/story/StoryViewer.vue +7 -42
- package/src/client/app/components/story/toolbar/StoryVariantBackground.vue +67 -0
- package/src/client/app/components/story/toolbar/StoryVariantNewTab.vue +29 -0
- package/src/client/app/components/story/toolbar/StoryVariantResponsiveSize.vue +82 -0
- package/src/client/app/components/story/toolbar/StoryVariantTitle.vue +21 -0
- package/src/client/app/stores/preview-settings.ts +17 -0
- package/src/client/app/style/main.pcss +4 -0
- package/src/client/app/types.ts +11 -1
- package/src/client/app/util/mapping.ts +10 -5
- package/src/client/app/util/preview-settings.ts +1 -19
- package/src/client/app/util/scroll.ts +4 -0
- package/src/node/config.ts +2 -2
- package/src/node/plugin.ts +15 -6
- package/src/node/tree.spec.ts +61 -0
- package/src/node/tree.ts +29 -5
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/plugin.ts
CHANGED
|
@@ -149,10 +149,10 @@ if (import.meta.hot) {
|
|
|
149
149
|
},
|
|
150
150
|
|
|
151
151
|
configureServer (server) {
|
|
152
|
-
server.middlewares.use((req, res, next) => {
|
|
152
|
+
server.middlewares.use(async (req, res, next) => {
|
|
153
153
|
if (req.url!.startsWith('/__sandbox')) {
|
|
154
154
|
res.statusCode = 200
|
|
155
|
-
|
|
155
|
+
let html = `
|
|
156
156
|
<!DOCTYPE html>
|
|
157
157
|
<html>
|
|
158
158
|
<head>
|
|
@@ -174,7 +174,11 @@ if (import.meta.hot) {
|
|
|
174
174
|
</script>
|
|
175
175
|
<script type="module" src="/@fs/${APP_PATH}/sandbox.js"></script>
|
|
176
176
|
</body>
|
|
177
|
-
</html>`
|
|
177
|
+
</html>`
|
|
178
|
+
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
|
179
|
+
// also applies HTML transforms from Vite plugins
|
|
180
|
+
html = await server.transformIndexHtml(req.url, html)
|
|
181
|
+
res.end(html)
|
|
178
182
|
return
|
|
179
183
|
}
|
|
180
184
|
next()
|
|
@@ -182,10 +186,11 @@ if (import.meta.hot) {
|
|
|
182
186
|
|
|
183
187
|
// serve our index.html after vite history fallback
|
|
184
188
|
return () => {
|
|
185
|
-
server.middlewares.use((req, res, next) => {
|
|
189
|
+
server.middlewares.use(async (req, res, next) => {
|
|
186
190
|
if (req.url!.endsWith('.html')) {
|
|
187
191
|
res.statusCode = 200
|
|
188
|
-
|
|
192
|
+
|
|
193
|
+
let html = `
|
|
189
194
|
<!DOCTYPE html>
|
|
190
195
|
<html>
|
|
191
196
|
<head>
|
|
@@ -200,7 +205,11 @@ if (import.meta.hot) {
|
|
|
200
205
|
<div id="app"></div>
|
|
201
206
|
<script type="module" src="/@fs/${APP_PATH}/index.js"></script>
|
|
202
207
|
</body>
|
|
203
|
-
</html>`
|
|
208
|
+
</html>`
|
|
209
|
+
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
|
210
|
+
// also applies HTML transforms from Vite plugins
|
|
211
|
+
html = await server.transformIndexHtml(req.url, html)
|
|
212
|
+
res.end(html)
|
|
204
213
|
return
|
|
205
214
|
}
|
|
206
215
|
next()
|
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 {
|