histoire 0.9.1 → 0.9.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 (30) hide show
  1. package/dist/node/builtin-plugins/tailwind-tokens.js +390 -383
  2. package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts +14 -0
  3. package/dist/node/builtin-plugins/vanilla-support/MountStory.js +39 -0
  4. package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts +38 -0
  5. package/dist/node/builtin-plugins/vanilla-support/RenderStory.js +131 -0
  6. package/dist/node/builtin-plugins/vanilla-support/client.d.ts +3 -0
  7. package/dist/node/builtin-plugins/vanilla-support/client.js +5 -0
  8. package/dist/node/builtin-plugins/vanilla-support/collect.d.ts +2 -0
  9. package/dist/node/builtin-plugins/vanilla-support/collect.js +33 -0
  10. package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts +2 -0
  11. package/dist/node/builtin-plugins/vanilla-support/plugin.js +29 -0
  12. package/dist/node/builtin-plugins/vanilla-support/types.d.ts +35 -0
  13. package/dist/node/builtin-plugins/vanilla-support/types.js +3 -0
  14. package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts +3 -0
  15. package/dist/node/builtin-plugins/vanilla-support/vanilla.story.js +55 -0
  16. package/dist/node/config.js +2 -0
  17. package/dist/node/server.js +1 -1
  18. package/dist/node/vite.js +7 -11
  19. package/package.json +5 -5
  20. package/src/node/builtin-plugins/tailwind-tokens.ts +393 -383
  21. package/src/node/builtin-plugins/vanilla-support/MountStory.ts +50 -0
  22. package/src/node/builtin-plugins/vanilla-support/RenderStory.ts +166 -0
  23. package/src/node/builtin-plugins/vanilla-support/client.ts +6 -0
  24. package/src/node/builtin-plugins/vanilla-support/collect.ts +42 -0
  25. package/src/node/builtin-plugins/vanilla-support/plugin.ts +35 -0
  26. package/src/node/builtin-plugins/vanilla-support/types.ts +40 -0
  27. package/src/node/builtin-plugins/vanilla-support/vanilla.story.ts +63 -0
  28. package/src/node/config.ts +2 -0
  29. package/src/node/server.ts +2 -2
  30. package/src/node/vite.ts +7 -11
@@ -0,0 +1,14 @@
1
+ import { PropType as _PropType } from '@histoire/vendors/vue';
2
+ import type { Story } from '@histoire/shared';
3
+ declare const _default: import("@histoire/vendors/vue").DefineComponent<{
4
+ story: {
5
+ type: _PropType<Story>;
6
+ required: true;
7
+ };
8
+ }, void, unknown, {}, {}, import("@histoire/vendors/vue").ComponentOptionsMixin, import("@histoire/vendors/vue").ComponentOptionsMixin, Record<string, any>, string, import("@histoire/vendors/vue").VNodeProps & import("@histoire/vendors/vue").AllowedComponentProps & import("@histoire/vendors/vue").ComponentCustomProps, Readonly<import("@histoire/vendors/vue").ExtractPropTypes<{
9
+ story: {
10
+ type: _PropType<Story>;
11
+ required: true;
12
+ };
13
+ }>>, {}>;
14
+ export default _default;
@@ -0,0 +1,39 @@
1
+ import { defineComponent as _defineComponent, } from '@histoire/vendors/vue';
2
+ export default _defineComponent({
3
+ name: 'MountStory',
4
+ props: {
5
+ story: {
6
+ type: Object,
7
+ required: true,
8
+ },
9
+ },
10
+ setup(props) {
11
+ const options = props.story.file.component;
12
+ let rawVariants = [];
13
+ if (options.onMount) {
14
+ rawVariants = [{
15
+ id: '_default',
16
+ title: 'default',
17
+ onMount: options.onMount,
18
+ onMountControls: options.onMountControls,
19
+ }];
20
+ }
21
+ else {
22
+ rawVariants = options.variants;
23
+ }
24
+ for (const index in props.story.variants) {
25
+ const rawVariant = rawVariants[index];
26
+ Object.assign(props.story.variants[index], {
27
+ slots: () => ({ default: rawVariant.onMount, controls: rawVariant.onMountControls }),
28
+ source: rawVariant.source ?? options.source,
29
+ responsiveDisabled: rawVariant.responsiveDisabled ?? options.responsiveDisabled,
30
+ autoPropsDisabled: rawVariant.autoPropsDisabled ?? options.autoPropsDisabled,
31
+ setupApp: rawVariant.setupApp ?? options.setupApp,
32
+ configReady: true,
33
+ });
34
+ }
35
+ },
36
+ render() {
37
+ return null;
38
+ },
39
+ });
@@ -0,0 +1,38 @@
1
+ import { PropType as _PropType } from '@histoire/vendors/vue';
2
+ import type { Story, Variant } from '@histoire/shared';
3
+ declare const _default: import("@histoire/vendors/vue").DefineComponent<{
4
+ variant: {
5
+ type: _PropType<Variant>;
6
+ required: true;
7
+ };
8
+ story: {
9
+ type: _PropType<Story>;
10
+ required: true;
11
+ };
12
+ slotName: {
13
+ type: StringConstructor;
14
+ default: string;
15
+ };
16
+ }, {
17
+ sandbox: import("@vue/reactivity").Ref<HTMLDivElement>;
18
+ }, unknown, {}, {}, import("@histoire/vendors/vue").ComponentOptionsMixin, import("@histoire/vendors/vue").ComponentOptionsMixin, {
19
+ ready: () => true;
20
+ }, string, import("@histoire/vendors/vue").VNodeProps & import("@histoire/vendors/vue").AllowedComponentProps & import("@histoire/vendors/vue").ComponentCustomProps, Readonly<import("@histoire/vendors/vue").ExtractPropTypes<{
21
+ variant: {
22
+ type: _PropType<Variant>;
23
+ required: true;
24
+ };
25
+ story: {
26
+ type: _PropType<Story>;
27
+ required: true;
28
+ };
29
+ slotName: {
30
+ type: StringConstructor;
31
+ default: string;
32
+ };
33
+ }>> & {
34
+ onReady?: () => any;
35
+ }, {
36
+ slotName: string;
37
+ }>;
38
+ export default _default;
@@ -0,0 +1,131 @@
1
+ /* eslint-disable vue/one-component-per-file */
2
+ import { defineComponent as _defineComponent, onBeforeUnmount as _onBeforeUnmount, onMounted as _onMounted, ref as _ref, watch as _watch, h as _h, } from '@histoire/vendors/vue';
3
+ // @ts-expect-error virtual module id
4
+ import * as setup from '$histoire-setup';
5
+ // @ts-expect-error virtual module id
6
+ import * as generatedSetup from '$histoire-generated-global-setup';
7
+ export default _defineComponent({
8
+ name: 'RenderStory',
9
+ props: {
10
+ variant: {
11
+ type: Object,
12
+ required: true,
13
+ },
14
+ story: {
15
+ type: Object,
16
+ required: true,
17
+ },
18
+ slotName: {
19
+ type: String,
20
+ default: 'default',
21
+ },
22
+ },
23
+ emits: {
24
+ ready: () => true,
25
+ },
26
+ setup(props, { emit }) {
27
+ const sandbox = _ref();
28
+ let mounting = false;
29
+ let app;
30
+ let appHooks;
31
+ async function unmountVariant() {
32
+ if (app) {
33
+ await app.onUnmount?.();
34
+ if (appHooks) {
35
+ for (const hook of appHooks.onUnmount) {
36
+ await hook();
37
+ }
38
+ }
39
+ app.el.parentNode.removeChild(app.el);
40
+ app = null;
41
+ }
42
+ }
43
+ async function mountVariant() {
44
+ if (mounting)
45
+ return;
46
+ mounting = true;
47
+ await unmountVariant();
48
+ app = {
49
+ el: document.createElement('div'),
50
+ };
51
+ if (typeof generatedSetup?.setupVanilla === 'function') {
52
+ await generatedSetup.setupVanilla({
53
+ app,
54
+ story: props.story,
55
+ variant: props.variant,
56
+ });
57
+ }
58
+ if (typeof setup?.setupVanilla === 'function') {
59
+ await setup.setupVanilla({
60
+ app,
61
+ story: props.story,
62
+ variant: props.variant,
63
+ });
64
+ }
65
+ if (typeof props.variant.setupApp === 'function') {
66
+ await props.variant.setupApp({
67
+ app,
68
+ story: props.story,
69
+ variant: props.variant,
70
+ });
71
+ }
72
+ await app.onMount?.();
73
+ appHooks = {
74
+ onUpdate: [],
75
+ onUnmount: [],
76
+ };
77
+ const api = {
78
+ el: app.el,
79
+ state: props.variant.state,
80
+ onUpdate: (cb) => {
81
+ appHooks.onUpdate.push(cb);
82
+ },
83
+ onUnmount: (cb) => {
84
+ appHooks.onUnmount.push(cb);
85
+ },
86
+ };
87
+ const onMount = props.variant.slots()[props.slotName];
88
+ await onMount(api);
89
+ sandbox.value.appendChild(app.el);
90
+ emit('ready');
91
+ }
92
+ _onMounted(async () => {
93
+ if (props.variant.configReady) {
94
+ await mountVariant();
95
+ }
96
+ });
97
+ _watch(() => props.variant, async (value) => {
98
+ if (value.configReady && !mounting) {
99
+ if (!app) {
100
+ await mountVariant();
101
+ }
102
+ else {
103
+ // @TODO check if need to refresh here
104
+ }
105
+ }
106
+ }, {
107
+ deep: true,
108
+ });
109
+ _watch(() => props.variant.state, async () => {
110
+ if (appHooks) {
111
+ for (const hook of appHooks.onUpdate) {
112
+ await hook();
113
+ }
114
+ }
115
+ }, {
116
+ deep: true,
117
+ });
118
+ _onBeforeUnmount(() => {
119
+ unmountVariant();
120
+ });
121
+ return {
122
+ sandbox,
123
+ };
124
+ },
125
+ render() {
126
+ return _h('div', {
127
+ ref: 'sandbox',
128
+ class: '__histoire-sandbox htw-overflow-auto',
129
+ });
130
+ },
131
+ });
@@ -0,0 +1,3 @@
1
+ export { default as MountStory } from './MountStory';
2
+ export { default as RenderStory } from './RenderStory';
3
+ export declare function generateSourceCode(): void;
@@ -0,0 +1,5 @@
1
+ export { default as MountStory } from './MountStory';
2
+ export { default as RenderStory } from './RenderStory';
3
+ export function generateSourceCode() {
4
+ // noop
5
+ }
@@ -0,0 +1,2 @@
1
+ import type { ServerRunPayload } from '@histoire/shared';
2
+ export declare function run({ file, storyData }: ServerRunPayload): Promise<void>;
@@ -0,0 +1,33 @@
1
+ export async function run({ file, storyData }) {
2
+ const { default: Comp } = await import(file.moduleId);
3
+ const options = Comp;
4
+ let rawVariants = [];
5
+ if (options.onMount) {
6
+ // Implicit variant
7
+ rawVariants = [{
8
+ id: '_default',
9
+ title: 'default',
10
+ }];
11
+ }
12
+ else {
13
+ rawVariants = options.variants;
14
+ }
15
+ const story = {
16
+ id: options.id ?? file.id,
17
+ title: options.title ?? file.fileName,
18
+ group: options.group,
19
+ layout: options.layout ?? { type: 'single', iframe: true },
20
+ icon: options.icon,
21
+ iconColor: options.iconColor,
22
+ docsOnly: options.docsOnly ?? false,
23
+ variants: null,
24
+ };
25
+ const variants = rawVariants.map((v, index) => ({
26
+ id: v.id ?? `${story.id}-${index}`,
27
+ title: v.title ?? 'untitled',
28
+ icon: v.icon ?? options.icon,
29
+ iconColor: v.iconColor ?? options.iconColor,
30
+ }));
31
+ story.variants = variants;
32
+ storyData.push(story);
33
+ }
@@ -0,0 +1,2 @@
1
+ import { Plugin } from '../../plugin.js';
2
+ export declare function vanillaSupport(): Plugin;
@@ -0,0 +1,29 @@
1
+ import { dirname } from 'pathe';
2
+ import { fileURLToPath } from 'url';
3
+ const __dirname = dirname(fileURLToPath(import.meta.url));
4
+ export function vanillaSupport() {
5
+ return {
6
+ name: 'builtin:vanilla-support',
7
+ config() {
8
+ return {
9
+ supportMatch: [
10
+ {
11
+ id: 'vanilla',
12
+ patterns: ['**/*.js'],
13
+ pluginIds: ['vanilla'],
14
+ },
15
+ ],
16
+ };
17
+ },
18
+ supportPlugin: {
19
+ id: 'vanilla',
20
+ moduleName: __dirname,
21
+ setupFn: 'setupVanilla',
22
+ importStoryComponent: (file, index) => `import Comp${index} from '${file.path}'`,
23
+ },
24
+ // onDev (api) {
25
+ // // Test vanilla story
26
+ // api.addStoryFile(resolve(__dirname, './vanilla.story.js'))
27
+ // },
28
+ };
29
+ }
@@ -0,0 +1,35 @@
1
+ import type { StoryProps, VariantProps, Story, Variant, Awaitable } from '@histoire/shared';
2
+ export interface App {
3
+ el: HTMLElement;
4
+ onMount?: () => void;
5
+ onUpdate?: () => void;
6
+ onUnmount?: () => void;
7
+ }
8
+ export interface MountApi {
9
+ el: HTMLElement;
10
+ state: Record<string, any>;
11
+ onUpdate: (cb: () => unknown) => Awaitable<void>;
12
+ onUnmount: (cb: () => unknown) => Awaitable<void>;
13
+ }
14
+ export interface VanillaApi {
15
+ onMount?: (api: MountApi) => Awaitable<void>;
16
+ onMountControls?: (api: MountApi) => Awaitable<void>;
17
+ }
18
+ interface CommonProps {
19
+ setupApp?: (payload: {
20
+ app: App;
21
+ story: Story;
22
+ variant: Variant;
23
+ }) => unknown;
24
+ }
25
+ export declare type StoryOptions = Omit<StoryProps, 'setupApp'> & CommonProps & ((VanillaApi & {
26
+ variants?: never;
27
+ }) | {
28
+ variants?: VariantOptions[];
29
+ onMount?: never;
30
+ onMountControls?: never;
31
+ });
32
+ export interface VariantOptions extends Omit<VariantProps, 'setupApp'>, CommonProps, VanillaApi {
33
+ }
34
+ export declare function defineStory(story: StoryOptions): StoryOptions;
35
+ export {};
@@ -0,0 +1,3 @@
1
+ export function defineStory(story) {
2
+ return story;
3
+ }
@@ -0,0 +1,3 @@
1
+ import type { StoryOptions } from './types';
2
+ declare const _default: StoryOptions;
3
+ export default _default;
@@ -0,0 +1,55 @@
1
+ export default {
2
+ title: 'Vanilla story',
3
+ icon: 'ion:logo-nodejs',
4
+ variants: [
5
+ {
6
+ title: 'Hello',
7
+ onMount: ({ el, state, onUpdate }) => {
8
+ state.count = 0;
9
+ const div = document.createElement('div');
10
+ div.innerHTML = '<h1>Hello World</h1>';
11
+ el.appendChild(div);
12
+ const counter = document.createElement('pre');
13
+ counter.innerHTML = `Counter: ${state.counter}`;
14
+ div.appendChild(counter);
15
+ onUpdate(() => {
16
+ counter.innerHTML = `Counter: ${state.count}`;
17
+ });
18
+ },
19
+ onMountControls: ({ el, state, onUnmount }) => {
20
+ const add = () => {
21
+ state.count++;
22
+ };
23
+ Object.assign(el.style, {
24
+ padding: '8px',
25
+ });
26
+ const btn = document.createElement('button');
27
+ btn.innerHTML = '+1';
28
+ Object.assign(btn.style, {
29
+ padding: '6px',
30
+ borderRadius: '3px',
31
+ backgroundColor: '#a7f3d0',
32
+ });
33
+ btn.addEventListener('click', add);
34
+ el.appendChild(btn);
35
+ onUnmount(() => {
36
+ btn.removeEventListener('click', add);
37
+ });
38
+ },
39
+ },
40
+ {
41
+ title: 'Meow',
42
+ onMount: ({ el, onUpdate, onUnmount }) => {
43
+ const div = document.createElement('div');
44
+ div.innerHTML = '<h1>Meow</h1>';
45
+ el.appendChild(div);
46
+ onUpdate(() => {
47
+ console.log('update');
48
+ });
49
+ onUnmount(() => {
50
+ el.removeChild(div);
51
+ });
52
+ },
53
+ },
54
+ ],
55
+ };
@@ -7,9 +7,11 @@ import pc from 'picocolors';
7
7
  import { defaultColors } from './colors.js';
8
8
  import { findUp } from './util/find-up.js';
9
9
  import { tailwindTokens } from './builtin-plugins/tailwind-tokens.js';
10
+ import { vanillaSupport } from './builtin-plugins/vanilla-support/plugin.js';
10
11
  export function getDefaultConfig() {
11
12
  return {
12
13
  plugins: [
14
+ vanillaSupport(),
13
15
  tailwindTokens(),
14
16
  ],
15
17
  outDir: '.histoire/dist',
@@ -13,6 +13,7 @@ export async function createServer(ctx, port) {
13
13
  const moduleLoader = useModuleLoader({
14
14
  server: nodeServer,
15
15
  });
16
+ await watchStories(ctx);
16
17
  const pluginOnCleanups = [];
17
18
  for (const plugin of ctx.config.plugins) {
18
19
  if (plugin.onDev) {
@@ -23,7 +24,6 @@ export async function createServer(ctx, port) {
23
24
  await plugin.onDev(api, onCleanup);
24
25
  }
25
26
  }
26
- await watchStories(ctx);
27
27
  // Wait for pre-bundling (in `listen()`)
28
28
  await server.listen(port);
29
29
  const { clearCache, executeStoryFile, destroy: destroyCollectStories, } = useCollectStories({
package/dist/node/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'module';
2
- import { relative, dirname, resolve, join } from 'pathe';
2
+ import { relative, resolve, join } from 'pathe';
3
3
  import { resolveConfig as resolveViteConfigInternal, mergeConfig as mergeViteConfig, loadConfigFromFile as loadViteConfigFromFile, } from 'vite';
4
4
  import { lookup as lookupMime } from 'mrmime';
5
5
  import { APP_PATH, TEMP_PATH } from './alias.js';
@@ -72,15 +72,6 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
72
72
  entries: [
73
73
  `${APP_PATH}/bundle-main.js`,
74
74
  `${APP_PATH}/bundle-sandbox.js`,
75
- // `${APP_PATH}/server/index.js`,
76
- ],
77
- include: [
78
- 'vue',
79
- dirname(require.resolve('@vue/runtime-core/package.json')),
80
- dirname(require.resolve('shiki/package.json')),
81
- dirname(require.resolve('vscode-textmate/package.json')),
82
- dirname(require.resolve('vscode-oniguruma/package.json')),
83
- dirname(require.resolve('case/package.json')),
84
75
  ],
85
76
  exclude: [
86
77
  'histoire',
@@ -89,7 +80,12 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
89
80
  },
90
81
  server: {
91
82
  fs: {
92
- allow: [APP_PATH, TEMP_PATH, resolvedViteConfig.root, process.cwd()],
83
+ allow: [
84
+ APP_PATH,
85
+ TEMP_PATH,
86
+ resolvedViteConfig.root,
87
+ process.cwd(),
88
+ ],
93
89
  },
94
90
  watch: {
95
91
  ignored: [`!**/node_modules/.histoire/**`, '**/vite.config.*'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -29,10 +29,10 @@
29
29
  "histoire": "./bin.mjs"
30
30
  },
31
31
  "dependencies": {
32
- "@histoire/app": "^0.9.1",
33
- "@histoire/controls": "^0.9.1",
34
- "@histoire/shared": "^0.9.1",
35
- "@histoire/vendors": "^0.9.1",
32
+ "@histoire/app": "^0.9.2",
33
+ "@histoire/controls": "^0.9.2",
34
+ "@histoire/shared": "^0.9.2",
35
+ "@histoire/vendors": "^0.9.2",
36
36
  "@types/flexsearch": "^0.7.3",
37
37
  "@types/markdown-it": "^12.2.3",
38
38
  "birpc": "^0.1.1",