histoire 0.2.3 → 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.
Files changed (178) hide show
  1. package/dist/client/app/App.vue +9 -4
  2. package/dist/client/app/codegen/const.d.ts +1 -0
  3. package/dist/client/app/codegen/const.js +3 -0
  4. package/dist/client/app/codegen/vue3.js +82 -21
  5. package/dist/client/app/components/app/AppHeader.vue +2 -2
  6. package/dist/client/app/components/app/Breadcrumb.vue +1 -1
  7. package/dist/client/app/components/base/BaseEmpty.vue +17 -1
  8. package/dist/client/app/components/base/BaseListItemLink.vue +1 -1
  9. package/dist/client/app/components/base/BaseTab.vue +1 -1
  10. package/dist/client/app/components/exposed/Story.vue +22 -1
  11. package/dist/client/app/components/exposed/Variant.vue +13 -1
  12. package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -4
  13. package/dist/client/app/components/sandbox/lib.js +2 -1
  14. package/dist/client/app/components/search/SearchItem.vue +1 -0
  15. package/dist/client/app/components/search/SearchLoading.vue +16 -0
  16. package/dist/client/app/components/search/SearchModal.vue +12 -148
  17. package/dist/client/app/components/search/SearchPane.vue +210 -0
  18. package/dist/client/app/components/search/search-data.d.ts +2 -0
  19. package/dist/client/app/components/search/search-data.js +7 -0
  20. package/dist/client/app/components/story/StoryControls.vue +5 -0
  21. package/dist/client/app/components/story/StoryDocs.vue +18 -11
  22. package/dist/client/app/components/story/StoryEvent.vue +53 -0
  23. package/dist/client/app/components/story/StoryEvents.vue +45 -0
  24. package/dist/client/app/components/story/StoryResponsivePreview.vue +41 -8
  25. package/dist/client/app/components/story/StorySidePanel.vue +28 -3
  26. package/dist/client/app/components/story/StorySourceCode.vue +24 -14
  27. package/dist/client/app/components/story/StoryView.vue +16 -2
  28. package/dist/client/app/components/story/toolbar/StoryVariantNewTab.vue +1 -1
  29. package/dist/client/app/components/tree/StoryGroup.vue +75 -0
  30. package/dist/client/app/components/{story → tree}/StoryList.vue +8 -2
  31. package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListFolder.vue +10 -8
  32. package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListItem.vue +7 -4
  33. package/dist/client/app/router.d.ts +1 -0
  34. package/dist/client/app/router.js +3 -1
  35. package/dist/client/app/sandbox.js +11 -1
  36. package/dist/client/app/stores/events.d.ts +29 -0
  37. package/dist/client/app/stores/events.js +25 -0
  38. package/dist/client/app/stores/folder.d.ts +10 -0
  39. package/dist/client/app/stores/folder.js +47 -0
  40. package/dist/client/app/stores/story.d.ts +20 -8
  41. package/dist/client/app/stores/story.js +20 -28
  42. package/dist/client/app/style/floating-vue.pcss +3 -1
  43. package/dist/client/app/style/main.pcss +5 -0
  44. package/dist/client/app/style/sandbox.css +2 -0
  45. package/dist/client/app/types.d.ts +9 -1
  46. package/dist/client/app/util/const.d.ts +1 -0
  47. package/dist/client/app/util/const.js +1 -0
  48. package/dist/client/app/util/events.d.ts +1 -0
  49. package/dist/client/app/util/events.js +31 -0
  50. package/dist/client/app/util/mapping.js +2 -2
  51. package/dist/client/index.d.ts +2 -1
  52. package/dist/client/index.js +2 -1
  53. package/dist/client/server/Story.server.vue +21 -4
  54. package/dist/node/alias.d.ts +2 -1
  55. package/dist/node/alias.js +3 -2
  56. package/dist/node/build.js +74 -21
  57. package/dist/node/builtin-plugins/tailwind-tokens.d.ts +5 -0
  58. package/dist/node/builtin-plugins/tailwind-tokens.js +510 -0
  59. package/dist/node/collect/index.js +5 -3
  60. package/dist/node/commands/preview.js +4 -25
  61. package/dist/node/config.d.ts +111 -5
  62. package/dist/node/config.js +40 -23
  63. package/dist/node/context.d.ts +3 -3
  64. package/dist/node/context.js +1 -1
  65. package/dist/node/index.d.ts +1 -0
  66. package/dist/node/index.js +1 -0
  67. package/dist/node/load.d.ts +12 -0
  68. package/dist/node/load.js +42 -0
  69. package/dist/node/plugin.d.ts +67 -11
  70. package/dist/node/plugin.js +42 -245
  71. package/dist/node/preview.d.ts +8 -0
  72. package/dist/node/preview.js +41 -0
  73. package/dist/node/search.d.ts +2 -0
  74. package/dist/node/search.js +68 -0
  75. package/dist/node/server.js +43 -21
  76. package/dist/node/stories.d.ts +2 -0
  77. package/dist/node/stories.js +9 -4
  78. package/dist/node/tree.d.ts +16 -12
  79. package/dist/node/tree.js +45 -5
  80. package/dist/node/types.d.ts +11 -0
  81. package/dist/node/util/find-up.d.ts +1 -0
  82. package/dist/node/util/find-up.js +20 -0
  83. package/dist/node/vite.d.ts +13 -0
  84. package/dist/node/vite.js +278 -0
  85. package/dist/style.css +179 -36
  86. package/package.json +5 -3
  87. package/scripts/copy.mjs +2 -1
  88. package/src/client/app/App.vue +9 -4
  89. package/src/client/app/codegen/const.ts +3 -0
  90. package/src/client/app/codegen/vue3.ts +80 -22
  91. package/src/client/app/components/app/AppHeader.vue +2 -2
  92. package/src/client/app/components/app/Breadcrumb.vue +1 -1
  93. package/src/client/app/components/base/BaseEmpty.vue +17 -1
  94. package/src/client/app/components/base/BaseListItemLink.vue +1 -1
  95. package/src/client/app/components/base/BaseTab.vue +1 -1
  96. package/src/client/app/components/exposed/Story.vue +22 -1
  97. package/src/client/app/components/exposed/Variant.vue +13 -1
  98. package/src/client/app/components/sandbox/SandboxVue3.vue +6 -4
  99. package/src/client/app/components/sandbox/lib.ts +3 -1
  100. package/src/client/app/components/search/SearchItem.vue +1 -0
  101. package/src/client/app/components/search/SearchLoading.vue +16 -0
  102. package/src/client/app/components/search/SearchModal.vue +12 -148
  103. package/src/client/app/components/search/SearchPane.vue +210 -0
  104. package/src/client/app/components/search/search-data.ts +9 -0
  105. package/src/client/app/components/story/StoryControls.vue +5 -0
  106. package/src/client/app/components/story/StoryDocs.vue +18 -11
  107. package/src/client/app/components/story/StoryEvent.vue +53 -0
  108. package/src/client/app/components/story/StoryEvents.vue +45 -0
  109. package/src/client/app/components/story/StoryResponsivePreview.vue +41 -8
  110. package/src/client/app/components/story/StorySidePanel.vue +28 -3
  111. package/src/client/app/components/story/StorySourceCode.vue +24 -14
  112. package/src/client/app/components/story/StoryView.vue +16 -2
  113. package/src/client/app/components/story/toolbar/StoryVariantNewTab.vue +1 -1
  114. package/src/client/app/components/tree/StoryGroup.vue +75 -0
  115. package/src/client/app/components/{story → tree}/StoryList.vue +8 -2
  116. package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListFolder.vue +10 -8
  117. package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListItem.vue +7 -4
  118. package/src/client/app/router.ts +4 -1
  119. package/src/client/app/sandbox.ts +12 -2
  120. package/src/client/app/stores/events.ts +36 -0
  121. package/src/client/app/stores/folder.ts +59 -0
  122. package/src/client/app/stores/story.ts +20 -35
  123. package/src/client/app/style/floating-vue.pcss +3 -1
  124. package/src/client/app/style/main.pcss +5 -0
  125. package/src/client/app/style/sandbox.css +2 -0
  126. package/src/client/app/types.ts +10 -1
  127. package/src/client/app/util/const.ts +1 -0
  128. package/src/client/app/util/events.ts +30 -0
  129. package/src/client/app/util/mapping.ts +2 -2
  130. package/src/client/index.ts +2 -1
  131. package/src/client/server/Story.server.vue +21 -4
  132. package/src/node/alias.ts +4 -2
  133. package/src/node/build.ts +86 -21
  134. package/src/node/builtin-plugins/tailwind-tokens.ts +521 -0
  135. package/src/node/collect/index.ts +6 -4
  136. package/src/node/commands/preview.ts +4 -33
  137. package/src/node/config.ts +62 -29
  138. package/src/node/context.ts +3 -3
  139. package/src/node/index.ts +1 -0
  140. package/src/node/load.ts +63 -0
  141. package/src/node/plugin.ts +75 -252
  142. package/src/node/preview.ts +56 -0
  143. package/src/node/search.ts +75 -0
  144. package/src/node/server.ts +49 -23
  145. package/src/node/stories.ts +9 -4
  146. package/src/node/tree.spec.ts +35 -17
  147. package/src/node/tree.ts +64 -10
  148. package/src/node/types.ts +12 -0
  149. package/src/node/util/find-up.ts +24 -0
  150. package/src/node/vite.ts +296 -0
  151. package/tailwind.config.cjs +1 -0
  152. package/tsconfig.json +2 -0
  153. package/dist/client/app/codegen/serialize-js.ts +0 -119
  154. package/dist/client/app/codegen/util.ts +0 -79
  155. package/dist/client/app/codegen/vue3.ts +0 -276
  156. package/dist/client/app/components/sandbox/lib.ts +0 -8
  157. package/dist/client/app/global-components.ts +0 -13
  158. package/dist/client/app/index.ts +0 -28
  159. package/dist/client/app/router.ts +0 -17
  160. package/dist/client/app/sandbox.ts +0 -94
  161. package/dist/client/app/stores/preview-settings.ts +0 -17
  162. package/dist/client/app/stores/story.ts +0 -62
  163. package/dist/client/app/types.ts +0 -70
  164. package/dist/client/app/util/config.ts +0 -6
  165. package/dist/client/app/util/const.ts +0 -3
  166. package/dist/client/app/util/dark.ts +0 -4
  167. package/dist/client/app/util/env.ts +0 -1
  168. package/dist/client/app/util/keyboard.ts +0 -99
  169. package/dist/client/app/util/mapping.ts +0 -48
  170. package/dist/client/app/util/preview-settings.ts +0 -8
  171. package/dist/client/app/util/reactivity.ts +0 -22
  172. package/dist/client/app/util/responsive.ts +0 -3
  173. package/dist/client/app/util/scroll.ts +0 -31
  174. package/dist/client/app/util/tooltip.ts +0 -13
  175. package/dist/client/app/util/variant.ts +0 -20
  176. package/dist/client/index.ts +0 -12
  177. package/dist/client/server/index.ts +0 -32
  178. package/dist/client/shim.d.ts +0 -5
@@ -18,7 +18,7 @@ export function mapFile(file, existingFile) {
18
18
  for (const key in existingVariant) {
19
19
  if (typeof existingVariant[key] !== 'undefined') {
20
20
  if (key === 'state') {
21
- Object.assign(variant.state, existingVariant.state);
21
+ variant.state = existingVariant.state;
22
22
  continue;
23
23
  }
24
24
  variant[key] = existingVariant[key];
@@ -35,7 +35,7 @@ export function mapFile(file, existingFile) {
35
35
  export function mapVariant(variant) {
36
36
  return {
37
37
  ...variant,
38
- state: {},
38
+ state: null,
39
39
  initState: null,
40
40
  slots: () => ({}),
41
41
  previewReady: false,
@@ -1,8 +1,9 @@
1
1
  import type { App } from 'vue';
2
2
  import type { Story, Variant } from './app/types.js';
3
+ export { hstEvent } from './app/util/events';
3
4
  export declare type Vue3StorySetupHandler = (payload: {
4
5
  app: App;
5
6
  story: Story;
6
7
  variant: Variant;
7
8
  }) => Promise<void> | void;
8
- export declare function defineVue3StorySetup(handler: Vue3StorySetupHandler): Vue3StorySetupHandler;
9
+ export declare function defineSetupVue3(handler: Vue3StorySetupHandler): Vue3StorySetupHandler;
@@ -1,3 +1,4 @@
1
- export function defineVue3StorySetup(handler) {
1
+ export { hstEvent } from './app/util/events';
2
+ export function defineSetupVue3(handler) {
2
3
  return handler;
3
4
  }
@@ -8,7 +8,17 @@ export default defineComponent({
8
8
  props: {
9
9
  title: {
10
10
  type: String,
11
- required: true,
11
+ default: null,
12
+ },
13
+
14
+ id: {
15
+ type: String,
16
+ default: null,
17
+ },
18
+
19
+ group: {
20
+ type: String,
21
+ default: null,
12
22
  },
13
23
 
14
24
  layout: {
@@ -25,6 +35,11 @@ export default defineComponent({
25
35
  type: String,
26
36
  default: null,
27
37
  },
38
+
39
+ docsOnly: {
40
+ type: Boolean,
41
+ default: false,
42
+ },
28
43
  },
29
44
 
30
45
  setup (props) {
@@ -35,11 +50,13 @@ export default defineComponent({
35
50
  // Story
36
51
 
37
52
  const story: Story = {
38
- id: attrs.data.id,
39
- title: props.title,
53
+ id: props.id ?? attrs.data.id,
54
+ title: props.title ?? attrs.data.fileName,
55
+ group: props.group,
40
56
  layout: props.layout,
41
57
  icon: props.icon,
42
58
  iconColor: props.iconColor,
59
+ docsOnly: props.docsOnly,
43
60
  variants: [],
44
61
  }
45
62
  const addStory = inject('addStory', null)
@@ -70,7 +87,7 @@ export default defineComponent({
70
87
  render () {
71
88
  let suppressError = false
72
89
  try {
73
- return this.$slots.default({
90
+ return this.$slots.default?.({
74
91
  get state () {
75
92
  // No variant tags
76
93
  suppressError = true
@@ -1,2 +1,3 @@
1
- export declare const DIST_CLIENT_PATH: string;
1
+ export declare const DIST_PATH: string;
2
2
  export declare const APP_PATH: string;
3
+ export declare const TEMP_PATH: string;
@@ -1,5 +1,6 @@
1
1
  import { dirname, join } from 'pathe';
2
2
  import { fileURLToPath } from 'url';
3
3
  const __dirname = dirname(fileURLToPath(import.meta.url));
4
- export const DIST_CLIENT_PATH = join(__dirname, '../client');
5
- export const APP_PATH = join(DIST_CLIENT_PATH, 'app');
4
+ export const DIST_PATH = join(__dirname, '../');
5
+ export const APP_PATH = join(DIST_PATH, 'client', 'app');
6
+ export const TEMP_PATH = join(process.cwd(), 'node_modules', '.histoire');
@@ -1,13 +1,16 @@
1
1
  import { join } from 'pathe';
2
- import { build as viteBuild, createServer as createViteServer } from 'vite';
2
+ import { build as viteBuild, createServer as createViteServer, resolveConfig as resolveViteConfig } from 'vite';
3
3
  import fs from 'fs-extra';
4
4
  import { lookup as lookupMime } from 'mrmime';
5
5
  import pc from 'picocolors';
6
6
  import { performance } from 'perf_hooks';
7
7
  import { APP_PATH } from './alias.js';
8
- import { createVitePlugins } from './plugin.js';
8
+ import { createVitePlugins } from './vite.js';
9
9
  import { findAllStories } from './stories.js';
10
10
  import { useCollectStories } from './collect/index.js';
11
+ import { BuildPluginApi } from './plugin.js';
12
+ import { useModuleLoader } from './load.js';
13
+ import { startPreview } from './preview.js';
11
14
  const PRELOAD_MODULES = [
12
15
  'vendor',
13
16
  ];
@@ -19,11 +22,25 @@ const PREFETCHED_MODULES = [
19
22
  export async function build(ctx) {
20
23
  const startTime = performance.now();
21
24
  await findAllStories(ctx);
22
- // Collect story data
23
25
  const server = await createViteServer({
24
26
  plugins: await createVitePlugins(ctx),
25
27
  });
26
28
  await server.pluginContainer.buildStart({});
29
+ const moduleLoader = useModuleLoader({
30
+ server,
31
+ throws: true,
32
+ });
33
+ const buildEndCallbacks = [];
34
+ const previewStoryCallbacks = [];
35
+ for (const plugin of ctx.config.plugins) {
36
+ if (plugin.onBuild) {
37
+ const api = new BuildPluginApi(ctx, plugin, moduleLoader);
38
+ await plugin.onBuild(api);
39
+ buildEndCallbacks.push(...api.buildEndCallbacks);
40
+ previewStoryCallbacks.push(...api.previewStoryCallbacks);
41
+ }
42
+ }
43
+ // Collect story data
27
44
  const { executeStoryFile, destroy: destroyCollectStories } = useCollectStories({
28
45
  server,
29
46
  throws: true,
@@ -31,7 +48,6 @@ export async function build(ctx) {
31
48
  for (const storyFile of ctx.storyFiles) {
32
49
  await executeStoryFile(storyFile);
33
50
  }
34
- await server.close();
35
51
  await destroyCollectStories();
36
52
  const storyCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ? 1 : 0), 0);
37
53
  const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0);
@@ -41,8 +57,8 @@ export async function build(ctx) {
41
57
  build: {
42
58
  rollupOptions: {
43
59
  input: [
44
- join(APP_PATH, 'index.ts'),
45
- join(APP_PATH, 'sandbox.ts'),
60
+ join(APP_PATH, 'index.js'),
61
+ join(APP_PATH, 'sandbox.js'),
46
62
  ],
47
63
  output: {
48
64
  manualChunks(id) {
@@ -55,49 +71,86 @@ export async function build(ctx) {
55
71
  outDir: ctx.config.outDir,
56
72
  emptyOutDir: true,
57
73
  cssCodeSplit: false,
74
+ minify: false,
58
75
  },
59
76
  });
60
77
  const result = Array.isArray(results) ? results[0] : results;
78
+ const resolvedViteConfig = await resolveViteConfig({
79
+ plugins: await createVitePlugins(ctx),
80
+ }, 'build');
61
81
  const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset');
62
82
  // Preload
63
83
  const preloadOutputs = result.output.filter(o => PRELOAD_MODULES.includes(o.name) && o.type === 'chunk');
64
- const preloadHtml = generateScriptLinks(preloadOutputs.map(o => o.fileName), 'preload');
84
+ const preloadHtml = generateScriptLinks(preloadOutputs.map(o => o.fileName), 'preload', ctx, resolvedViteConfig);
65
85
  // Prefetch
66
86
  const prefetchOutputs = result.output.filter(o => PREFETCHED_MODULES.includes(o.name) && o.type === 'chunk');
67
- const prefetchHtml = generateScriptLinks(prefetchOutputs.map(o => o.fileName), 'prefetch');
87
+ const prefetchHtml = generateScriptLinks(prefetchOutputs.map(o => o.fileName), 'prefetch', ctx, resolvedViteConfig);
68
88
  // Index
69
89
  const indexOutput = result.output.find(o => o.name === 'index' && o.type === 'chunk');
70
- await writeHtml(indexOutput.fileName, styleOutput.fileName, 'index.html', {
90
+ const indexHtml = generateEntryHtml(indexOutput.fileName, styleOutput.fileName, {
71
91
  HEAD: `${preloadHtml}${prefetchHtml}`,
72
- }, ctx);
92
+ }, ctx, resolvedViteConfig);
93
+ await writeFile('index.html', indexHtml, ctx);
73
94
  // Sandbox
74
95
  const sandboxOutput = result.output.find(o => o.name === 'sandbox' && o.type === 'chunk');
75
- await writeHtml(sandboxOutput.fileName, styleOutput.fileName, '__sandbox.html', {}, ctx);
96
+ const sandboxHtml = generateEntryHtml(sandboxOutput.fileName, styleOutput.fileName, {}, ctx, resolvedViteConfig);
97
+ await writeFile('__sandbox.html', sandboxHtml, ctx);
76
98
  const duration = performance.now() - startTime;
77
99
  if (emptyStoryCount) {
78
100
  console.warn(pc.yellow(`⚠️ ${emptyStoryCount} empty story file`));
79
101
  }
80
102
  console.log(pc.green(`✅ Built ${storyCount} stories (${variantCount} variants) in ${Math.round(duration / 1000 * 100) / 100}s`));
103
+ // Render
104
+ if (previewStoryCallbacks.length) {
105
+ const { baseUrl, close } = await startPreview(resolvedViteConfig, null, ctx);
106
+ for (const storyFile of ctx.storyFiles) {
107
+ const story = storyFile.story;
108
+ for (const variant of story.variants) {
109
+ const query = new URLSearchParams();
110
+ query.append('storyId', story.id);
111
+ query.append('variantId', variant.id);
112
+ const url = `${baseUrl}__sandbox?${query.toString()}`;
113
+ for (const fn of previewStoryCallbacks) {
114
+ await fn({
115
+ file: storyFile.path,
116
+ story,
117
+ variant,
118
+ url,
119
+ });
120
+ }
121
+ }
122
+ }
123
+ await close();
124
+ }
125
+ await server.close();
126
+ for (const fn of buildEndCallbacks) {
127
+ await fn();
128
+ }
81
129
  }
82
- async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, variables, ctx) {
83
- const code = `<!DOCTYPE html>
130
+ function generateBaseHtml(head, body, ctx) {
131
+ return `<!DOCTYPE html>
84
132
  <html>
85
133
  <head>
86
134
  <title>${ctx.config.theme.title}</title>
87
135
  <meta charset="utf-8">
88
136
  <meta name="viewport" content="width=device-width,initial-scale=1">
89
137
  <meta name="description" content="">
90
- <link rel="stylesheet" href="/${cssEntryFile}">
91
- ${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${ctx.config.theme.favicon}"/>` : ''}
92
- ${variables.HEAD ?? ''}
138
+ ${head}
93
139
  </head>
94
140
  <body>
95
- <div id="app"></div>
96
- <script type="module" src="/${jsEntryFile}"></script>
141
+ ${body}
97
142
  </body>
98
143
  </html>`;
99
- await fs.writeFile(join(ctx.config.outDir, htmlFileName), code, 'utf8');
100
144
  }
101
- function generateScriptLinks(prefetchScripts, rel) {
102
- return prefetchScripts.map(s => `<link rel="${rel}" href="${s}" as="script" crossOrigin="anonymous">`).join('');
145
+ function generateEntryHtml(jsEntryFile, cssEntryFile, variables, ctx, resolvedViteConfig) {
146
+ return generateBaseHtml(`<link rel="stylesheet" href="${resolvedViteConfig.base}${cssEntryFile}">
147
+ ${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${ctx.config.theme.favicon}"/>` : ''}
148
+ ${variables.HEAD ?? ''}`, `<div id="app"></div>
149
+ <script type="module" src="${resolvedViteConfig.base}${jsEntryFile}"></script>`, ctx);
150
+ }
151
+ async function writeFile(fileName, content, ctx) {
152
+ await fs.writeFile(join(ctx.config.outDir, fileName), content, 'utf8');
153
+ }
154
+ function generateScriptLinks(prefetchScripts, rel, ctx, resolvedViteConfig) {
155
+ return prefetchScripts.map(s => `<link rel="${rel}" href="${resolvedViteConfig.base}${s}" as="script" crossOrigin="anonymous">`).join('');
103
156
  }
@@ -0,0 +1,5 @@
1
+ import { Plugin } from '../plugin.js';
2
+ export interface TailwindTokensOptions {
3
+ configFile?: string;
4
+ }
5
+ export declare function tailwindTokens(options?: TailwindTokensOptions): Plugin;