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.
Files changed (67) hide show
  1. package/dist/client/app/App.vue +1 -1
  2. package/dist/client/app/codegen/vue3.js +11 -1
  3. package/dist/client/app/codegen/vue3.ts +9 -1
  4. package/dist/client/app/components/app/AppHeader.vue +1 -1
  5. package/dist/client/app/components/exposed/Story.vue +25 -14
  6. package/dist/client/app/components/exposed/Variant.vue +7 -0
  7. package/dist/client/app/components/sandbox/lib.d.ts +2 -0
  8. package/dist/client/app/components/sandbox/lib.js +6 -0
  9. package/dist/client/app/components/sandbox/lib.ts +8 -0
  10. package/dist/client/app/components/story/StoryResponsivePreview.vue +74 -81
  11. package/dist/client/app/components/story/StorySidePanel.vue +1 -1
  12. package/dist/client/app/components/story/StorySourceCode.vue +3 -17
  13. package/dist/client/app/components/story/StoryVariantGrid.vue +112 -0
  14. package/dist/client/app/components/story/StoryVariantGridItem.vue +36 -6
  15. package/dist/client/app/components/story/StoryVariantSingleView.vue +20 -161
  16. package/dist/client/app/components/story/StoryViewer.vue +7 -42
  17. package/dist/client/app/components/story/toolbar/StoryVariantBackground.vue +67 -0
  18. package/dist/client/app/components/story/toolbar/StoryVariantNewTab.vue +29 -0
  19. package/dist/client/app/components/story/toolbar/StoryVariantResponsiveSize.vue +82 -0
  20. package/dist/client/app/components/story/toolbar/StoryVariantTitle.vue +21 -0
  21. package/dist/client/app/stores/preview-settings.d.ts +8 -0
  22. package/dist/client/app/stores/preview-settings.js +14 -0
  23. package/dist/client/app/stores/preview-settings.ts +17 -0
  24. package/dist/client/app/stores/story.d.ts +45 -15
  25. package/dist/client/app/style/main.pcss +4 -0
  26. package/dist/client/app/types.d.ts +10 -1
  27. package/dist/client/app/types.ts +11 -1
  28. package/dist/client/app/util/mapping.js +10 -9
  29. package/dist/client/app/util/mapping.ts +10 -5
  30. package/dist/client/app/util/preview-settings.d.ts +1 -8
  31. package/dist/client/app/util/preview-settings.js +0 -10
  32. package/dist/client/app/util/preview-settings.ts +1 -19
  33. package/dist/client/app/util/scroll.d.ts +3 -1
  34. package/dist/client/app/util/scroll.js +3 -0
  35. package/dist/client/app/util/scroll.ts +4 -0
  36. package/dist/node/config.d.ts +2 -2
  37. package/dist/node/plugin.js +14 -6
  38. package/dist/node/tree.js +24 -4
  39. package/dist/style.css +70 -4
  40. package/package.json +21 -21
  41. package/src/client/app/App.vue +1 -1
  42. package/src/client/app/codegen/vue3.ts +9 -1
  43. package/src/client/app/components/app/AppHeader.vue +1 -1
  44. package/src/client/app/components/exposed/Story.vue +25 -14
  45. package/src/client/app/components/exposed/Variant.vue +7 -0
  46. package/src/client/app/components/sandbox/lib.ts +8 -0
  47. package/src/client/app/components/story/StoryResponsivePreview.vue +74 -81
  48. package/src/client/app/components/story/StorySidePanel.vue +1 -1
  49. package/src/client/app/components/story/StorySourceCode.vue +3 -17
  50. package/src/client/app/components/story/StoryVariantGrid.vue +112 -0
  51. package/src/client/app/components/story/StoryVariantGridItem.vue +36 -6
  52. package/src/client/app/components/story/StoryVariantSingleView.vue +20 -161
  53. package/src/client/app/components/story/StoryViewer.vue +7 -42
  54. package/src/client/app/components/story/toolbar/StoryVariantBackground.vue +67 -0
  55. package/src/client/app/components/story/toolbar/StoryVariantNewTab.vue +29 -0
  56. package/src/client/app/components/story/toolbar/StoryVariantResponsiveSize.vue +82 -0
  57. package/src/client/app/components/story/toolbar/StoryVariantTitle.vue +21 -0
  58. package/src/client/app/stores/preview-settings.ts +17 -0
  59. package/src/client/app/style/main.pcss +4 -0
  60. package/src/client/app/types.ts +11 -1
  61. package/src/client/app/util/mapping.ts +10 -5
  62. package/src/client/app/util/preview-settings.ts +1 -19
  63. package/src/client/app/util/scroll.ts +4 -0
  64. package/src/node/config.ts +2 -2
  65. package/src/node/plugin.ts +15 -6
  66. package/src/node/tree.spec.ts +61 -0
  67. package/src/node/tree.ts +29 -5
@@ -24,4 +24,8 @@ export function useScrollOnActive (active: Ref<boolean>, el: Ref<HTMLElement>) {
24
24
  autoScroll()
25
25
  }
26
26
  })
27
+
28
+ return {
29
+ autoScroll,
30
+ }
27
31
  }
@@ -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 exposting a default function executed when setting up each story preview.
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
  *
@@ -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
- res.end(`
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
- res.end(`
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()
@@ -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[key] = value
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 {