histoire 0.6.1 → 0.6.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.
@@ -18,6 +18,7 @@ import { Text, vModelText, vModelSelect, vModelRadio, vModelCheckbox, vModelDyna
18
18
  import { pascal } from "case";
19
19
  import { a as applyStateToVariant } from "./state.js";
20
20
  import * as setup from "$histoire-setup";
21
+ import * as generatedSetup from "$histoire-generated-global-setup";
21
22
  function indent(lines, count = 1) {
22
23
  return lines.map((line) => `${" ".repeat(count)}${line}`);
23
24
  }
@@ -581,6 +582,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
581
582
  });
582
583
  if ((_c2 = (_b2 = (_a2 = props.variant.state) == null ? void 0 : _a2._hPropState) == null ? void 0 : _b2[index]) == null ? void 0 : _c2[key]) {
583
584
  vnode.props[key] = props.variant.state._hPropState[index][key];
585
+ if (!vnode.dynamicProps) {
586
+ vnode.dynamicProps = [];
587
+ }
588
+ if (!vnode.dynamicProps.includes(key)) {
589
+ vnode.dynamicProps.push(key);
590
+ }
584
591
  }
585
592
  }
586
593
  return {
@@ -605,6 +612,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
605
612
  return vnodes;
606
613
  }
607
614
  });
615
+ if (typeof (generatedSetup == null ? void 0 : generatedSetup.setupVue3) === "function") {
616
+ await generatedSetup.setupVue3({
617
+ app,
618
+ story: props.story,
619
+ variant: props.variant
620
+ });
621
+ }
608
622
  if (typeof (setup == null ? void 0 : setup.setupVue3) === "function") {
609
623
  await setup.setupVue3({
610
624
  app,
@@ -5,6 +5,8 @@ import { getTagName } from '../../codegen/vue3'
5
5
  import { applyStateToVariant } from '../../util/state'
6
6
  // @ts-expect-error virtual module id
7
7
  import * as setup from '$histoire-setup'
8
+ // @ts-expect-error virtual module id
9
+ import * as generatedSetup from '$histoire-generated-global-setup'
8
10
 
9
11
  const props = defineProps({
10
12
  variant: {
@@ -86,6 +88,12 @@ async function mountVariant () {
86
88
  // Props overrides
87
89
  if (props.variant.state?._hPropState?.[index]?.[key]) {
88
90
  vnode.props[key] = props.variant.state._hPropState[index][key]
91
+ if (!vnode.dynamicProps) {
92
+ vnode.dynamicProps = []
93
+ }
94
+ if (!vnode.dynamicProps.includes(key)) {
95
+ vnode.dynamicProps.push(key)
96
+ }
89
97
  }
90
98
  }
91
99
 
@@ -114,6 +122,14 @@ async function mountVariant () {
114
122
  },
115
123
  })
116
124
 
125
+ if (typeof generatedSetup?.setupVue3 === 'function') {
126
+ await generatedSetup.setupVue3({
127
+ app,
128
+ story: props.story,
129
+ variant: props.variant,
130
+ })
131
+ }
132
+
117
133
  if (typeof setup?.setupVue3 === 'function') {
118
134
  await setup.setupVue3({
119
135
  app,
@@ -46,10 +46,10 @@ html,
46
46
  body,
47
47
  #app {
48
48
  height: 100%;
49
- font-family: 'Lato', sans-serif;
50
49
  }
51
50
 
52
51
  html {
52
+ font-family: 'Lato', sans-serif;
53
53
  font-size: 16px;
54
54
  }
55
55
 
@@ -9,11 +9,9 @@ body {
9
9
  margin: 0;
10
10
  }
11
11
 
12
- html,
13
- body,
14
- #app {
15
- font-family: 'Lato', sans-serif;
12
+ html {
16
13
  font-size: 14px;
14
+ font-family: 'Lato', sans-serif;
17
15
  }
18
16
 
19
17
  .htw-sandbox-hidden {
@@ -1,3 +1,2 @@
1
- import '../style.css'
2
1
  import './app/style/sandbox.css'
3
2
  import '../bundled/sandbox.js'
@@ -4,6 +4,8 @@ import Story from './Story.vue';
4
4
  import Variant from './Variant.vue';
5
5
  // @ts-expect-error virtual module id
6
6
  import * as setup from '$histoire-setup';
7
+ // @ts-expect-error virtual module id
8
+ import * as generatedSetup from '$histoire-generated-global-setup';
7
9
  export async function run({ file, storyData, el }) {
8
10
  const { default: Comp } = await import(file.moduleId);
9
11
  const app = createApp({
@@ -19,6 +21,9 @@ export async function run({ file, storyData, el }) {
19
21
  });
20
22
  },
21
23
  });
24
+ if (typeof generatedSetup?.setupVue3 === 'function') {
25
+ await generatedSetup.setupVue3({ app });
26
+ }
22
27
  if (typeof setup?.setupVue3 === 'function') {
23
28
  await setup.setupVue3({ app });
24
29
  }
@@ -106,6 +106,10 @@ export interface HistoireConfig {
106
106
  * Example: `'/src/histoire-setup.ts'`
107
107
  */
108
108
  setupFile?: string;
109
+ /**
110
+ * Setup code created by plugins
111
+ */
112
+ setupCode?: string[];
109
113
  /**
110
114
  * Predefined responsive sizes for story playgrounds.
111
115
  */
@@ -156,6 +156,10 @@ export const mergeConfig = createDefu((obj, key, value) => {
156
156
  }
157
157
  return true;
158
158
  }
159
+ if (obj[key] && key === 'setupCode') {
160
+ obj[key] = [...obj[key], ...value];
161
+ return true;
162
+ }
159
163
  // By default, arrays should be replaced
160
164
  if (obj[key] && Array.isArray(obj[key])) {
161
165
  obj[key] = value;
@@ -12,5 +12,9 @@ export declare const SEARCH_TITLE_DATA_ID = "$histoire-search-title-data";
12
12
  export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
13
13
  export declare const SEARCH_DOCS_DATA_ID = "$histoire-search-docs-data";
14
14
  export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
15
+ export declare const GENERATED_GLOBAL_SETUP = "$histoire-generated-global-setup";
16
+ export declare const RESOLVED_GENERATED_GLOBAL_SETUP: string;
17
+ export declare const GENERATED_SETUP_CODE = "$histoire-generated-setup-code";
18
+ export declare const RESOLVED_GENERATED_SETUP_CODE: string;
15
19
  export declare function resolveViteConfig(ctx: Context): Promise<ResolvedConfig>;
16
20
  export declare function getViteConfigWithPlugins(server: boolean, ctx: Context): Promise<InlineConfig>;
package/dist/node/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'module';
2
- import { relative, dirname } from 'pathe';
2
+ import { relative, dirname, resolve } from 'pathe';
3
3
  import { resolveConfig as resolveViteConfigInternal, mergeConfig as mergeViteConfig, } from 'vite';
4
4
  import { lookup as lookupMime } from 'mrmime';
5
5
  import { APP_PATH, DIST_PATH, TEMP_PATH } from './alias.js';
@@ -21,6 +21,10 @@ export const SEARCH_TITLE_DATA_ID = '$histoire-search-title-data';
21
21
  export const RESOLVED_SEARCH_TITLE_DATA_ID = `/${SEARCH_TITLE_DATA_ID}-resolved`;
22
22
  export const SEARCH_DOCS_DATA_ID = '$histoire-search-docs-data';
23
23
  export const RESOLVED_SEARCH_DOCS_DATA_ID = `/${SEARCH_DOCS_DATA_ID}-resolved`;
24
+ export const GENERATED_GLOBAL_SETUP = '$histoire-generated-global-setup';
25
+ export const RESOLVED_GENERATED_GLOBAL_SETUP = `/${GENERATED_GLOBAL_SETUP}-resolved`;
26
+ export const GENERATED_SETUP_CODE = '$histoire-generated-setup-code';
27
+ export const RESOLVED_GENERATED_SETUP_CODE = `/${GENERATED_SETUP_CODE}-resolved`;
24
28
  export async function resolveViteConfig(ctx) {
25
29
  const command = ctx.mode === 'dev' ? 'serve' : 'build';
26
30
  let viteConfig = (await resolveViteConfigInternal({}, command));
@@ -86,7 +90,7 @@ export async function getViteConfigWithPlugins(server, ctx) {
86
90
  }
87
91
  if (id.startsWith(SETUP_ID)) {
88
92
  if (ctx.config.setupFile) {
89
- return this.resolve(ctx.config.setupFile, importer, {
93
+ return this.resolve(resolve(ctx.root, ctx.config.setupFile), importer, {
90
94
  skipSelf: true,
91
95
  });
92
96
  }
@@ -106,6 +110,13 @@ export async function getViteConfigWithPlugins(server, ctx) {
106
110
  if (id.startsWith(SEARCH_DOCS_DATA_ID)) {
107
111
  return RESOLVED_SEARCH_DOCS_DATA_ID;
108
112
  }
113
+ if (id.startsWith(GENERATED_GLOBAL_SETUP)) {
114
+ return RESOLVED_GENERATED_GLOBAL_SETUP;
115
+ }
116
+ if (id.startsWith(GENERATED_SETUP_CODE)) {
117
+ const [, index] = id.split('__');
118
+ return `${RESOLVED_GENERATED_SETUP_CODE}__${index}`;
119
+ }
109
120
  },
110
121
  async load(id) {
111
122
  if (id === RESOLVED_STORIES_ID) {
@@ -171,6 +182,31 @@ if (import.meta.hot) {
171
182
  if (id === RESOLVED_SEARCH_DOCS_DATA_ID) {
172
183
  return getSearchDataJS(await generateDocSearchData(ctx));
173
184
  }
185
+ if (id === RESOLVED_GENERATED_GLOBAL_SETUP) {
186
+ if (ctx.config.setupCode) {
187
+ return [
188
+ // Import
189
+ `${ctx.config.setupCode.map((c, index) => `import * as setup_${index} from '${GENERATED_SETUP_CODE}__${index}'`).join('\n')}`,
190
+ // List
191
+ `const setupList = [${ctx.config.setupCode.map((c, index) => `setup_${index}`).join(', ')}]`,
192
+ // Setups
193
+ ['setupVue3'].map(fnName => `export async function ${fnName} (payload) {
194
+ for (const setup of setupList) {
195
+ if (setup?.${fnName}) {
196
+ await setup.${fnName}(payload)
197
+ }
198
+ }
199
+ }`),
200
+ ].join('\n');
201
+ }
202
+ else {
203
+ return '';
204
+ }
205
+ }
206
+ if (id.startsWith(RESOLVED_GENERATED_SETUP_CODE)) {
207
+ const [, index] = id.split('__');
208
+ return ctx.config.setupCode?.[index] ?? '';
209
+ }
174
210
  },
175
211
  handleHotUpdate(updateContext) {
176
212
  const story = ctx.storyFiles.find(file => file.path === updateContext.file);
package/dist/style.css CHANGED
@@ -1913,10 +1913,10 @@ html,
1913
1913
  body,
1914
1914
  #app {
1915
1915
  height: 100%;
1916
- font-family: 'Lato', sans-serif;
1917
1916
  }
1918
1917
 
1919
1918
  html {
1919
+ font-family: 'Lato', sans-serif;
1920
1920
  font-size: 16px;
1921
1921
  }
1922
1922
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,7 +33,7 @@
33
33
  "histoire": "./bin.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@histoire/controls": "^0.6.1",
36
+ "@histoire/controls": "^0.6.2",
37
37
  "@iconify/vue": "^3.2.1",
38
38
  "@types/markdown-it": "^12.2.3",
39
39
  "@vueuse/core": "^8.2.5",
@@ -5,6 +5,8 @@ import { getTagName } from '../../codegen/vue3'
5
5
  import { applyStateToVariant } from '../../util/state'
6
6
  // @ts-expect-error virtual module id
7
7
  import * as setup from '$histoire-setup'
8
+ // @ts-expect-error virtual module id
9
+ import * as generatedSetup from '$histoire-generated-global-setup'
8
10
 
9
11
  const props = defineProps({
10
12
  variant: {
@@ -86,6 +88,12 @@ async function mountVariant () {
86
88
  // Props overrides
87
89
  if (props.variant.state?._hPropState?.[index]?.[key]) {
88
90
  vnode.props[key] = props.variant.state._hPropState[index][key]
91
+ if (!vnode.dynamicProps) {
92
+ vnode.dynamicProps = []
93
+ }
94
+ if (!vnode.dynamicProps.includes(key)) {
95
+ vnode.dynamicProps.push(key)
96
+ }
89
97
  }
90
98
  }
91
99
 
@@ -114,6 +122,14 @@ async function mountVariant () {
114
122
  },
115
123
  })
116
124
 
125
+ if (typeof generatedSetup?.setupVue3 === 'function') {
126
+ await generatedSetup.setupVue3({
127
+ app,
128
+ story: props.story,
129
+ variant: props.variant,
130
+ })
131
+ }
132
+
117
133
  if (typeof setup?.setupVue3 === 'function') {
118
134
  await setup.setupVue3({
119
135
  app,
@@ -46,10 +46,10 @@ html,
46
46
  body,
47
47
  #app {
48
48
  height: 100%;
49
- font-family: 'Lato', sans-serif;
50
49
  }
51
50
 
52
51
  html {
52
+ font-family: 'Lato', sans-serif;
53
53
  font-size: 16px;
54
54
  }
55
55
 
@@ -9,11 +9,9 @@ body {
9
9
  margin: 0;
10
10
  }
11
11
 
12
- html,
13
- body,
14
- #app {
15
- font-family: 'Lato', sans-serif;
12
+ html {
16
13
  font-size: 14px;
14
+ font-family: 'Lato', sans-serif;
17
15
  }
18
16
 
19
17
  .htw-sandbox-hidden {
@@ -1,3 +1,2 @@
1
- import '../style.css'
2
1
  import './app/style/sandbox.css'
3
2
  import '../bundled/sandbox.js'
@@ -5,6 +5,8 @@ import Story from './Story.vue'
5
5
  import Variant from './Variant.vue'
6
6
  // @ts-expect-error virtual module id
7
7
  import * as setup from '$histoire-setup'
8
+ // @ts-expect-error virtual module id
9
+ import * as generatedSetup from '$histoire-generated-global-setup'
8
10
 
9
11
  export async function run ({ file, storyData, el }: ServerRunPayload) {
10
12
  const { default: Comp } = await import(file.moduleId)
@@ -23,6 +25,10 @@ export async function run ({ file, storyData, el }: ServerRunPayload) {
23
25
  },
24
26
  })
25
27
 
28
+ if (typeof generatedSetup?.setupVue3 === 'function') {
29
+ await generatedSetup.setupVue3({ app })
30
+ }
31
+
26
32
  if (typeof setup?.setupVue3 === 'function') {
27
33
  await setup.setupVue3({ app })
28
34
  }
@@ -125,6 +125,10 @@ export interface HistoireConfig {
125
125
  * Example: `'/src/histoire-setup.ts'`
126
126
  */
127
127
  setupFile?: string
128
+ /**
129
+ * Setup code created by plugins
130
+ */
131
+ setupCode?: string[]
128
132
  /**
129
133
  * Predefined responsive sizes for story playgrounds.
130
134
  */
@@ -303,6 +307,11 @@ export const mergeConfig = createDefu((obj: any, key, value) => {
303
307
  return true
304
308
  }
305
309
 
310
+ if (obj[key] && key === 'setupCode') {
311
+ obj[key] = [...obj[key], ...value]
312
+ return true
313
+ }
314
+
306
315
  // By default, arrays should be replaced
307
316
  if (obj[key] && Array.isArray(obj[key])) {
308
317
  obj[key] = value
package/src/node/vite.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from 'module'
2
- import { relative, dirname } from 'pathe'
2
+ import { relative, dirname, resolve } from 'pathe'
3
3
  import {
4
4
  resolveConfig as resolveViteConfigInternal,
5
5
  Plugin as VitePlugin,
@@ -31,6 +31,10 @@ export const SEARCH_TITLE_DATA_ID = '$histoire-search-title-data'
31
31
  export const RESOLVED_SEARCH_TITLE_DATA_ID = `/${SEARCH_TITLE_DATA_ID}-resolved`
32
32
  export const SEARCH_DOCS_DATA_ID = '$histoire-search-docs-data'
33
33
  export const RESOLVED_SEARCH_DOCS_DATA_ID = `/${SEARCH_DOCS_DATA_ID}-resolved`
34
+ export const GENERATED_GLOBAL_SETUP = '$histoire-generated-global-setup'
35
+ export const RESOLVED_GENERATED_GLOBAL_SETUP = `/${GENERATED_GLOBAL_SETUP}-resolved`
36
+ export const GENERATED_SETUP_CODE = '$histoire-generated-setup-code'
37
+ export const RESOLVED_GENERATED_SETUP_CODE = `/${GENERATED_SETUP_CODE}-resolved`
34
38
 
35
39
  export async function resolveViteConfig (ctx: Context): Promise<ResolvedConfig> {
36
40
  const command = ctx.mode === 'dev' ? 'serve' : 'build'
@@ -103,7 +107,7 @@ export async function getViteConfigWithPlugins (server: boolean, ctx: Context):
103
107
  }
104
108
  if (id.startsWith(SETUP_ID)) {
105
109
  if (ctx.config.setupFile) {
106
- return this.resolve(ctx.config.setupFile, importer, {
110
+ return this.resolve(resolve(ctx.root, ctx.config.setupFile), importer, {
107
111
  skipSelf: true,
108
112
  })
109
113
  } else {
@@ -122,6 +126,13 @@ export async function getViteConfigWithPlugins (server: boolean, ctx: Context):
122
126
  if (id.startsWith(SEARCH_DOCS_DATA_ID)) {
123
127
  return RESOLVED_SEARCH_DOCS_DATA_ID
124
128
  }
129
+ if (id.startsWith(GENERATED_GLOBAL_SETUP)) {
130
+ return RESOLVED_GENERATED_GLOBAL_SETUP
131
+ }
132
+ if (id.startsWith(GENERATED_SETUP_CODE)) {
133
+ const [, index] = id.split('__')
134
+ return `${RESOLVED_GENERATED_SETUP_CODE}__${index}`
135
+ }
125
136
  },
126
137
 
127
138
  async load (id) {
@@ -188,6 +199,30 @@ if (import.meta.hot) {
188
199
  if (id === RESOLVED_SEARCH_DOCS_DATA_ID) {
189
200
  return getSearchDataJS(await generateDocSearchData(ctx))
190
201
  }
202
+ if (id === RESOLVED_GENERATED_GLOBAL_SETUP) {
203
+ if (ctx.config.setupCode) {
204
+ return [
205
+ // Import
206
+ `${ctx.config.setupCode.map((c, index) => `import * as setup_${index} from '${GENERATED_SETUP_CODE}__${index}'`).join('\n')}`,
207
+ // List
208
+ `const setupList = [${ctx.config.setupCode.map((c, index) => `setup_${index}`).join(', ')}]`,
209
+ // Setups
210
+ ['setupVue3'].map(fnName => `export async function ${fnName} (payload) {
211
+ for (const setup of setupList) {
212
+ if (setup?.${fnName}) {
213
+ await setup.${fnName}(payload)
214
+ }
215
+ }
216
+ }`),
217
+ ].join('\n')
218
+ } else {
219
+ return ''
220
+ }
221
+ }
222
+ if (id.startsWith(RESOLVED_GENERATED_SETUP_CODE)) {
223
+ const [, index] = id.split('__')
224
+ return ctx.config.setupCode?.[index] ?? ''
225
+ }
191
226
  },
192
227
 
193
228
  handleHotUpdate (updateContext) {