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.
Files changed (107) hide show
  1. package/dist/client/app/codegen/vue3.js +1 -0
  2. package/dist/client/app/codegen/vue3.js.map +1 -0
  3. package/dist/client/app/components/app/AppHeader.vue +2 -1
  4. package/dist/client/app/components/base/BaseCheckbox.vue +76 -0
  5. package/dist/client/app/components/exposed/Story.vue +20 -14
  6. package/dist/client/app/components/sandbox/lib.d.ts +2 -0
  7. package/dist/client/app/components/sandbox/lib.js +6 -0
  8. package/dist/client/app/components/sandbox/lib.ts +8 -0
  9. package/dist/client/app/components/search/SearchItem.vue +4 -1
  10. package/dist/client/app/components/search/SearchModal.vue +4 -4
  11. package/dist/client/app/components/story/StoryControls.vue +1 -1
  12. package/dist/client/app/components/story/StoryDocs.vue +1 -0
  13. package/dist/client/app/components/story/StoryListFolder.vue +1 -1
  14. package/dist/client/app/components/story/StoryListItem.vue +4 -1
  15. package/dist/client/app/components/story/StoryResponsivePreview.vue +3 -4
  16. package/dist/client/app/components/story/StorySidePanel.vue +1 -0
  17. package/dist/client/app/components/story/StorySourceCode.vue +4 -1
  18. package/dist/client/app/components/story/StoryVariantGrid.vue +112 -0
  19. package/dist/client/app/components/story/StoryVariantGridItem.vue +34 -4
  20. package/dist/client/app/components/story/StoryVariantListItem.vue +4 -1
  21. package/dist/client/app/components/story/StoryVariantSingleView.vue +20 -160
  22. package/dist/client/app/components/story/StoryViewer.vue +6 -25
  23. package/dist/client/app/components/story/variant/StoryVariantBackground.vue +67 -0
  24. package/dist/client/app/components/story/variant/StoryVariantNewTab.vue +29 -0
  25. package/dist/client/app/components/story/variant/StoryVariantResponsiveSize.vue +82 -0
  26. package/dist/client/app/components/story/variant/StoryVariantTitle.vue +21 -0
  27. package/dist/client/app/global-components.js +1 -0
  28. package/dist/client/app/global-components.js.map +1 -0
  29. package/dist/client/app/index.js +1 -0
  30. package/dist/client/app/index.js.map +1 -0
  31. package/dist/client/app/sandbox.js +1 -0
  32. package/dist/client/app/sandbox.js.map +1 -0
  33. package/dist/client/app/stores/story.d.ts +6 -6
  34. package/dist/client/app/stores/story.js +1 -0
  35. package/dist/client/app/stores/story.js.map +1 -0
  36. package/dist/client/app/style/main.pcss +9 -5
  37. package/dist/client/app/types.d.ts +1 -1
  38. package/dist/client/app/types.ts +1 -1
  39. package/dist/client/app/util/keyboard.js +1 -0
  40. package/dist/client/app/util/keyboard.js.map +1 -0
  41. package/dist/client/app/util/mapping.js +1 -0
  42. package/dist/client/app/util/mapping.js.map +1 -0
  43. package/dist/client/app/util/preview-settings.js +1 -0
  44. package/dist/client/app/util/preview-settings.js.map +1 -0
  45. package/dist/client/app/util/reactivity.js +1 -0
  46. package/dist/client/app/util/reactivity.js.map +1 -0
  47. package/dist/client/app/util/scroll.d.ts +3 -1
  48. package/dist/client/app/util/scroll.js +4 -0
  49. package/dist/client/app/util/scroll.js.map +1 -0
  50. package/dist/client/app/util/scroll.ts +4 -0
  51. package/dist/client/app/util/variant.js +1 -0
  52. package/dist/client/app/util/variant.js.map +1 -0
  53. package/dist/client/index.js +1 -0
  54. package/dist/client/index.js.map +1 -0
  55. package/dist/client/server/index.js +1 -0
  56. package/dist/client/server/index.js.map +1 -0
  57. package/dist/controls.js +1 -0
  58. package/dist/controls.js.map +1 -0
  59. package/dist/node/bin.js +7 -0
  60. package/dist/node/build.js +1 -1
  61. package/dist/node/{collect.d.ts → collect/index.d.ts} +2 -2
  62. package/dist/node/{collect.js → collect/index.js} +37 -27
  63. package/dist/node/collect/worker.d.ts +14 -0
  64. package/dist/node/collect/worker.js +36 -0
  65. package/dist/node/commands/preview.d.ts +4 -0
  66. package/dist/node/commands/preview.js +36 -0
  67. package/dist/node/config.d.ts +2 -2
  68. package/dist/node/server.js +1 -1
  69. package/dist/node/tree.js +24 -4
  70. package/dist/node/types.d.ts +1 -1
  71. package/dist/style.css +98 -50
  72. package/package.json +10 -6
  73. package/src/client/app/components/app/AppHeader.vue +2 -1
  74. package/src/client/app/components/base/BaseCheckbox.vue +76 -0
  75. package/src/client/app/components/exposed/Story.vue +20 -14
  76. package/src/client/app/components/sandbox/lib.ts +8 -0
  77. package/src/client/app/components/search/SearchItem.vue +4 -1
  78. package/src/client/app/components/search/SearchModal.vue +4 -4
  79. package/src/client/app/components/story/StoryControls.vue +1 -1
  80. package/src/client/app/components/story/StoryDocs.vue +1 -0
  81. package/src/client/app/components/story/StoryListFolder.vue +1 -1
  82. package/src/client/app/components/story/StoryListItem.vue +4 -1
  83. package/src/client/app/components/story/StoryResponsivePreview.vue +3 -4
  84. package/src/client/app/components/story/StorySidePanel.vue +1 -0
  85. package/src/client/app/components/story/StorySourceCode.vue +4 -1
  86. package/src/client/app/components/story/StoryVariantGrid.vue +112 -0
  87. package/src/client/app/components/story/StoryVariantGridItem.vue +34 -4
  88. package/src/client/app/components/story/StoryVariantListItem.vue +4 -1
  89. package/src/client/app/components/story/StoryVariantSingleView.vue +20 -160
  90. package/src/client/app/components/story/StoryViewer.vue +6 -25
  91. package/src/client/app/components/story/variant/StoryVariantBackground.vue +67 -0
  92. package/src/client/app/components/story/variant/StoryVariantNewTab.vue +29 -0
  93. package/src/client/app/components/story/variant/StoryVariantResponsiveSize.vue +82 -0
  94. package/src/client/app/components/story/variant/StoryVariantTitle.vue +21 -0
  95. package/src/client/app/style/main.pcss +9 -5
  96. package/src/client/app/types.ts +1 -1
  97. package/src/client/app/util/scroll.ts +4 -0
  98. package/src/node/bin.ts +8 -0
  99. package/src/node/build.ts +1 -1
  100. package/src/node/{collect.ts → collect/index.ts} +48 -30
  101. package/src/node/collect/worker.ts +61 -0
  102. package/src/node/commands/preview.ts +50 -0
  103. package/src/node/config.ts +2 -2
  104. package/src/node/server.ts +1 -1
  105. package/src/node/tree.spec.ts +61 -0
  106. package/src/node/tree.ts +29 -5
  107. 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
+ }
@@ -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
  *
@@ -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) {
@@ -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 {
package/src/node/types.ts CHANGED
@@ -26,7 +26,7 @@ export interface Story {
26
26
  type: 'single'
27
27
  } | {
28
28
  type: 'grid'
29
- width: number
29
+ width?: number | string
30
30
  }
31
31
  icon?: string
32
32
  iconColor?: string