histoire 0.1.3 → 0.2.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 (76) hide show
  1. package/dist/client/app/App.vue +16 -1
  2. package/dist/client/app/components/app/AppHeader.vue +7 -6
  3. package/dist/client/app/components/app/Breadcrumb.vue +98 -0
  4. package/dist/client/app/components/app/MobileOverlay.vue +34 -0
  5. package/dist/client/app/components/base/BaseCheckbox.vue +76 -0
  6. package/dist/client/app/components/misc/HatchedPattern.vue +11 -23
  7. package/dist/client/app/components/search/SearchItem.vue +5 -2
  8. package/dist/client/app/components/search/SearchModal.vue +6 -6
  9. package/dist/client/app/components/story/StoryControls.vue +1 -1
  10. package/dist/client/app/components/story/StoryDocs.vue +1 -0
  11. package/dist/client/app/components/story/StoryListFolder.vue +3 -3
  12. package/dist/client/app/components/story/StoryListItem.vue +6 -3
  13. package/dist/client/app/components/story/StoryResponsivePreview.vue +53 -8
  14. package/dist/client/app/components/story/StorySidePanel.vue +69 -0
  15. package/dist/client/app/components/story/StorySourceCode.vue +4 -1
  16. package/dist/client/app/components/story/StoryVariantListItem.vue +6 -3
  17. package/dist/client/app/components/story/StoryVariantSingleView.vue +14 -10
  18. package/dist/client/app/components/story/StoryView.vue +10 -121
  19. package/dist/client/app/components/story/StoryViewer.vue +175 -0
  20. package/dist/client/app/stores/story.d.ts +6 -6
  21. package/dist/client/app/stores/story.js +2 -1
  22. package/dist/client/app/stores/story.ts +6 -2
  23. package/dist/client/app/style/{floating-vue.css → floating-vue.pcss} +0 -0
  24. package/dist/client/app/style/{main.css → main.pcss} +13 -3
  25. package/dist/client/app/style/transitions.pcss +26 -0
  26. package/dist/client/app/types.d.ts +1 -1
  27. package/dist/client/app/types.ts +1 -1
  28. package/dist/client/app/util/responsive.d.ts +1 -0
  29. package/dist/client/app/util/responsive.js +2 -0
  30. package/dist/client/app/util/responsive.ts +3 -0
  31. package/dist/node/bin.js +7 -0
  32. package/dist/node/build.js +1 -1
  33. package/dist/node/{collect.d.ts → collect/index.d.ts} +2 -2
  34. package/dist/node/{collect.js → collect/index.js} +37 -27
  35. package/dist/node/collect/worker.d.ts +14 -0
  36. package/dist/node/collect/worker.js +36 -0
  37. package/dist/node/commands/preview.d.ts +4 -0
  38. package/dist/node/commands/preview.js +36 -0
  39. package/dist/node/server.js +1 -1
  40. package/dist/node/types.d.ts +1 -1
  41. package/dist/style.css +231 -104
  42. package/package.json +8 -4
  43. package/src/client/app/App.vue +16 -1
  44. package/src/client/app/components/app/AppHeader.vue +7 -6
  45. package/src/client/app/components/app/Breadcrumb.vue +98 -0
  46. package/src/client/app/components/app/MobileOverlay.vue +34 -0
  47. package/src/client/app/components/base/BaseCheckbox.vue +76 -0
  48. package/src/client/app/components/misc/HatchedPattern.vue +11 -23
  49. package/src/client/app/components/search/SearchItem.vue +5 -2
  50. package/src/client/app/components/search/SearchModal.vue +6 -6
  51. package/src/client/app/components/story/StoryControls.vue +1 -1
  52. package/src/client/app/components/story/StoryDocs.vue +1 -0
  53. package/src/client/app/components/story/StoryListFolder.vue +3 -3
  54. package/src/client/app/components/story/StoryListItem.vue +6 -3
  55. package/src/client/app/components/story/StoryResponsivePreview.vue +53 -8
  56. package/src/client/app/components/story/StorySidePanel.vue +69 -0
  57. package/src/client/app/components/story/StorySourceCode.vue +4 -1
  58. package/src/client/app/components/story/StoryVariantListItem.vue +6 -3
  59. package/src/client/app/components/story/StoryVariantSingleView.vue +14 -10
  60. package/src/client/app/components/story/StoryView.vue +10 -121
  61. package/src/client/app/components/story/StoryViewer.vue +175 -0
  62. package/src/client/app/stores/story.ts +6 -2
  63. package/src/client/app/style/{floating-vue.css → floating-vue.pcss} +0 -0
  64. package/src/client/app/style/{main.css → main.pcss} +13 -3
  65. package/src/client/app/style/transitions.pcss +26 -0
  66. package/src/client/app/types.ts +1 -1
  67. package/src/client/app/util/responsive.ts +3 -0
  68. package/src/node/bin.ts +8 -0
  69. package/src/node/build.ts +1 -1
  70. package/src/node/{collect.ts → collect/index.ts} +48 -30
  71. package/src/node/collect/worker.ts +61 -0
  72. package/src/node/commands/preview.ts +50 -0
  73. package/src/node/server.ts +1 -1
  74. package/src/node/types.ts +1 -1
  75. package/dist/client/app/style/transitions.css +0 -12
  76. package/src/client/app/style/transitions.css +0 -12
@@ -1,14 +1,12 @@
1
- import { fileURLToPath } from 'url';
1
+ import { MessageChannel } from 'worker_threads';
2
2
  import { ViteNodeServer } from 'vite-node/server';
3
- import { ViteNodeRunner } from 'vite-node/client';
4
- import { dirname, resolve, relative } from 'pathe';
3
+ import { relative } from 'pathe';
5
4
  import pc from 'picocolors';
6
- import { createDomEnv } from './dom/env.js';
7
- import { createPath } from './tree.js';
8
- const __dirname = dirname(fileURLToPath(import.meta.url));
5
+ import Tinypool from 'tinypool';
6
+ import { createBirpc } from 'birpc';
7
+ import { createPath } from '../tree.js';
9
8
  export function useCollectStories(options, ctx) {
10
9
  const { server } = options;
11
- const { destroy: destroyDomEnv } = createDomEnv();
12
10
  const node = new ViteNodeServer(server, {
13
11
  deps: {
14
12
  inline: [
@@ -16,31 +14,43 @@ export function useCollectStories(options, ctx) {
16
14
  ],
17
15
  },
18
16
  });
19
- const runner = new ViteNodeRunner({
20
- root: server.config.root,
21
- base: server.config.base,
22
- fetchModule(id) {
23
- // Alias
24
- if (id.endsWith('vue.runtime.esm-bundler.js')) {
25
- id = 'vue';
26
- }
27
- return node.fetchModule(id);
28
- },
29
- resolveId(id, importer) {
30
- return node.resolveId(id, importer);
31
- },
17
+ const threadPool = new Tinypool({
18
+ filename: new URL('./worker.js', import.meta.url).href,
19
+ // WebContainer compatibility (Stackblitz)
20
+ useAtomics: false,
32
21
  });
33
22
  function clearCache() {
34
23
  node.fetchCache.clear();
35
- runner.moduleCache.clear();
24
+ }
25
+ function createChannel() {
26
+ const channel = new MessageChannel();
27
+ const port = channel.port2;
28
+ const workerPort = channel.port1;
29
+ createBirpc({
30
+ fetchModule: (id) => node.fetchModule(id),
31
+ resolveId: (id, importer) => node.resolveId(id, importer),
32
+ }, {
33
+ post: data => port.postMessage(data),
34
+ on: data => port.on('message', data),
35
+ });
36
+ return {
37
+ port,
38
+ workerPort,
39
+ };
36
40
  }
37
41
  async function executeStoryFile(storyFile) {
38
42
  try {
39
- // Mount app to collect stories/variants
40
- const el = window.document.createElement('div');
41
- const { run } = await runner.executeFile(resolve(__dirname, '../client/server/index.js'));
42
- const storyData = [];
43
- await run(storyFile, storyData, el);
43
+ const { workerPort } = createChannel();
44
+ const { storyData } = await threadPool.run({
45
+ root: server.config.root,
46
+ base: server.config.base,
47
+ storyFile,
48
+ port: workerPort,
49
+ }, {
50
+ transferList: [
51
+ workerPort,
52
+ ],
53
+ });
44
54
  if (storyData.length === 0) {
45
55
  console.warn(pc.yellow(`⚠️ No story found for ${storyFile.path}`));
46
56
  return;
@@ -64,7 +74,7 @@ export function useCollectStories(options, ctx) {
64
74
  }
65
75
  }
66
76
  async function destroy() {
67
- destroyDomEnv();
77
+ await threadPool.destroy();
68
78
  }
69
79
  return {
70
80
  clearCache,
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import type { MessagePort } from 'worker_threads';
3
+ import type { StoryFile, Story } from '../types.js';
4
+ export interface Payload {
5
+ root: string;
6
+ base: string;
7
+ port: MessagePort;
8
+ storyFile: StoryFile;
9
+ }
10
+ export interface ReturnData {
11
+ storyData: Story[];
12
+ }
13
+ declare const _default: (payload: Payload) => Promise<ReturnData>;
14
+ export default _default;
@@ -0,0 +1,36 @@
1
+ import { fileURLToPath } from 'url';
2
+ import { ViteNodeRunner } from 'vite-node/client';
3
+ import { createBirpc } from 'birpc';
4
+ import { dirname, resolve } from 'pathe';
5
+ import { createDomEnv } from '../dom/env.js';
6
+ const __dirname = dirname(fileURLToPath(import.meta.url));
7
+ export default async (payload) => {
8
+ const rpc = createBirpc({}, {
9
+ post: data => payload.port.postMessage(data),
10
+ on: data => payload.port.on('message', data),
11
+ });
12
+ const runner = new ViteNodeRunner({
13
+ root: payload.root,
14
+ base: payload.base,
15
+ fetchModule(id) {
16
+ // Alias
17
+ if (id.endsWith('vue.runtime.esm-bundler.js')) {
18
+ id = 'vue';
19
+ }
20
+ return rpc.fetchModule(id);
21
+ },
22
+ resolveId(id, importer) {
23
+ return rpc.resolveId(id, importer);
24
+ },
25
+ });
26
+ const { destroy: destroyDomEnv } = createDomEnv();
27
+ const el = window.document.createElement('div');
28
+ // Mount app to collect stories/variants
29
+ const { run } = await runner.executeFile(resolve(__dirname, '../../client/server/index.js'));
30
+ const storyData = [];
31
+ await run(payload.storyFile, storyData, el);
32
+ destroyDomEnv();
33
+ return {
34
+ storyData,
35
+ };
36
+ };
@@ -0,0 +1,4 @@
1
+ export interface PreviewOptions {
2
+ port?: number;
3
+ }
4
+ export declare function previewCommand(options: PreviewOptions): Promise<void>;
@@ -0,0 +1,36 @@
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
+ export async function previewCommand(options) {
9
+ const ctx = await createContext({
10
+ mode: 'build',
11
+ });
12
+ const viteConfig = await resolveViteConfig({
13
+ plugins: await createVitePlugins(ctx),
14
+ }, 'build');
15
+ const app = connect();
16
+ app.use(viteConfig.base, sirv(ctx.config.outDir, {
17
+ dev: true,
18
+ etag: true,
19
+ single: true,
20
+ }));
21
+ let port = options.port ?? 3000;
22
+ const httpServer = http.createServer(app);
23
+ function onError(e) {
24
+ if (e.code === 'EADDRINUSE') {
25
+ httpServer.listen(++port);
26
+ }
27
+ else {
28
+ throw e;
29
+ }
30
+ }
31
+ httpServer.on('error', onError);
32
+ httpServer.listen(port, () => {
33
+ httpServer.off('error', onError);
34
+ console.log(`Preview server listening on ${pc.cyan(`http://localhost:${port}`)}`);
35
+ });
36
+ }
@@ -1,7 +1,7 @@
1
1
  import { createServer as createViteServer } from 'vite';
2
2
  import { createVitePlugins, RESOLVED_STORIES_ID } from './plugin.js';
3
3
  import { notifyStoryChange, onStoryChange, watchStories } from './stories.js';
4
- import { useCollectStories } from './collect.js';
4
+ import { useCollectStories } from './collect/index.js';
5
5
  export async function createServer(ctx, port) {
6
6
  await watchStories(ctx);
7
7
  const server = await createViteServer({
@@ -25,7 +25,7 @@ export interface Story {
25
25
  type: 'single';
26
26
  } | {
27
27
  type: 'grid';
28
- width: number;
28
+ width?: number | string;
29
29
  };
30
30
  icon?: string;
31
31
  iconColor?: string;