histoire 0.6.6 → 0.7.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 (34) hide show
  1. package/dist/bundled/MobileOverlay.js +2 -2
  2. package/dist/bundled/SandboxVue3.js +41 -1
  3. package/dist/bundled/index2.js +2 -0
  4. package/dist/bundled/style.css +14 -14
  5. package/dist/client/app/App.vue +2 -0
  6. package/dist/client/app/components/base/BaseSplitPane.vue +6 -6
  7. package/dist/client/app/components/sandbox/RouterLinkStub.d.ts +21 -0
  8. package/dist/client/app/components/sandbox/RouterLinkStub.js +43 -0
  9. package/dist/client/app/components/sandbox/SandboxVue3.vue +4 -0
  10. package/dist/client/app/style/main.pcss +3 -3
  11. package/dist/client/app/style/sandbox.css +1 -1
  12. package/dist/client/server/vue3/Story.vue +17 -2
  13. package/dist/client/server/vue3/Variant.vue +3 -1
  14. package/dist/node/build.js +29 -2
  15. package/dist/node/collect/index.js +1 -0
  16. package/dist/node/config.d.ts +20 -0
  17. package/dist/node/stories.js +2 -2
  18. package/dist/node/vite.js +3 -0
  19. package/dist/style.css +4 -4
  20. package/package.json +2 -2
  21. package/src/client/app/App.vue +2 -0
  22. package/src/client/app/components/base/BaseSplitPane.vue +6 -6
  23. package/src/client/app/components/sandbox/RouterLinkStub.ts +49 -0
  24. package/src/client/app/components/sandbox/SandboxVue3.vue +4 -0
  25. package/src/client/app/style/main.pcss +3 -3
  26. package/src/client/app/style/sandbox.css +1 -1
  27. package/src/client/server/vue3/Story.vue +17 -2
  28. package/src/client/server/vue3/Variant.vue +3 -1
  29. package/src/node/build.ts +31 -2
  30. package/src/node/collect/index.ts +1 -0
  31. package/src/node/config.ts +20 -0
  32. package/src/node/stories.ts +3 -3
  33. package/src/node/vite.ts +3 -0
  34. package/tailwind.config.cjs +1 -1
@@ -82,7 +82,7 @@ function useScrollOnActive(active, el) {
82
82
  };
83
83
  }
84
84
  var BaseSplitPane_vue_vue_type_style_index_0_scoped_true_lang = "";
85
- const _withScopeId = (n) => (pushScopeId("data-v-4de97f66"), n = n(), popScopeId(), n);
85
+ const _withScopeId = (n) => (pushScopeId("data-v-4cd3cd6c"), n = n(), popScopeId(), n);
86
86
  const _hoisted_1$1 = ["onMousedown"];
87
87
  const _sfc_main$1 = /* @__PURE__ */ defineComponent({
88
88
  name: "BaseSplitPane",
@@ -261,7 +261,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
261
261
  };
262
262
  }
263
263
  });
264
- var BaseSplitPane = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-4de97f66"]]);
264
+ var BaseSplitPane = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-4cd3cd6c"]]);
265
265
  const isMobile = useMediaQuery("(max-width: 640px)");
266
266
  const _hoisted_1 = {
267
267
  key: 0,
@@ -14,7 +14,7 @@ var __spreadValues = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
- import { Text, vModelText, vModelSelect, vModelRadio, vModelCheckbox, vModelDynamic, defineComponent, ref, createApp, onMounted, watch, onUnmounted, openBlock, createElementBlock } from "vue";
17
+ import { Text, vModelText, vModelSelect, vModelRadio, vModelCheckbox, vModelDynamic, defineComponent, computed, h, ref, createApp, onMounted, watch, onUnmounted, openBlock, createElementBlock } from "vue";
18
18
  import { pascal } from "case";
19
19
  import { a as applyStateToVariant } from "./state.js";
20
20
  import * as setup from "$histoire-setup";
@@ -509,6 +509,45 @@ function serializeAndCleanJs(value) {
509
509
  function cleanupExpression(expr) {
510
510
  return expr.replace(/\$setup\./g, "");
511
511
  }
512
+ const defaultRoute = {
513
+ path: "/",
514
+ name: void 0,
515
+ redirectedFrom: void 0,
516
+ params: {},
517
+ query: {},
518
+ hash: "",
519
+ fullPath: "/",
520
+ matched: [],
521
+ meta: {},
522
+ href: "/"
523
+ };
524
+ const RouterLinkStub = defineComponent({
525
+ name: "RouterLinkStub",
526
+ compatConfig: { MODE: 3 },
527
+ props: {
528
+ to: {
529
+ type: [String, Object],
530
+ required: true
531
+ },
532
+ custom: {
533
+ type: Boolean,
534
+ default: false
535
+ }
536
+ },
537
+ render() {
538
+ var _a, _b;
539
+ const route = computed(() => defaultRoute);
540
+ const children = (_b = (_a = this.$slots) == null ? void 0 : _a.default) == null ? void 0 : _b.call(_a, {
541
+ route,
542
+ href: computed(() => route.value.href),
543
+ isActive: computed(() => false),
544
+ isExactActive: computed(() => false),
545
+ navigate: async () => {
546
+ }
547
+ });
548
+ return this.custom ? children : h("a", void 0, children);
549
+ }
550
+ });
512
551
  const _sfc_main = /* @__PURE__ */ defineComponent({
513
552
  name: "SandboxVue3",
514
553
  props: {
@@ -615,6 +654,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
615
654
  return vnodes;
616
655
  }
617
656
  });
657
+ app.component("RouterLink", RouterLinkStub);
618
658
  if (typeof (generatedSetup == null ? void 0 : generatedSetup.setupVue3) === "function") {
619
659
  await generatedSetup.setupVue3({
620
660
  app,
@@ -702,6 +702,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({
702
702
  const files$1 = ref(files.map((file) => mapFile(file)));
703
703
  const tree$1 = ref(tree);
704
704
  onUpdate((newFiles, newTree) => {
705
+ loading.value = false;
705
706
  files$1.value = newFiles.map((file) => {
706
707
  const existingFile = files$1.value.find((f) => f.id === file.id);
707
708
  return mapFile(file, existingFile);
@@ -742,6 +743,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({
742
743
  const loading = ref(false);
743
744
  if (import.meta.hot && !files.length) {
744
745
  loading.value = true;
746
+ console.log("loading...");
745
747
  import.meta.hot.on("histoire:all-stories-loaded", () => {
746
748
  loading.value = false;
747
749
  });
@@ -14,29 +14,29 @@
14
14
  color: var(--7fa476a0);
15
15
  }
16
16
 
17
- .landscape > div > .dragger[data-v-4de97f66] {
18
- width: 10px;
17
+ .landscape > div > .dragger[data-v-4cd3cd6c] {
18
+ width: .625rem;
19
19
  }
20
- .portrait > div > .dragger[data-v-4de97f66] {
21
- height: 10px;
20
+ .portrait > div > .dragger[data-v-4cd3cd6c] {
21
+ height: .625rem;
22
22
  }
23
- .landscape > div > .dragger.dragger-offset-before[data-v-4de97f66] {
23
+ .landscape > div > .dragger.dragger-offset-before[data-v-4cd3cd6c] {
24
24
  right: 0;
25
25
  }
26
- .portrait > div > .dragger.dragger-offset-before[data-v-4de97f66] {
26
+ .portrait > div > .dragger.dragger-offset-before[data-v-4cd3cd6c] {
27
27
  bottom: 0;
28
28
  }
29
- .landscape > div > .dragger.dragger-offset-center[data-v-4de97f66] {
30
- right: -5px;
29
+ .landscape > div > .dragger.dragger-offset-center[data-v-4cd3cd6c] {
30
+ right: -.3125rem;
31
31
  }
32
- .portrait > div > .dragger.dragger-offset-center[data-v-4de97f66] {
33
- bottom: -5px;
32
+ .portrait > div > .dragger.dragger-offset-center[data-v-4cd3cd6c] {
33
+ bottom: -.3125rem;
34
34
  }
35
- .landscape > div > .dragger.dragger-offset-after[data-v-4de97f66] {
36
- right: -10px;
35
+ .landscape > div > .dragger.dragger-offset-after[data-v-4cd3cd6c] {
36
+ right: -.625rem;
37
37
  }
38
- .portrait > div > .dragger.dragger-offset-after[data-v-4de97f66] {
39
- bottom: -10px;
38
+ .portrait > div > .dragger.dragger-offset-after[data-v-4cd3cd6c] {
39
+ bottom: -.625rem;
40
40
  }
41
41
 
42
42
  .bind-icon-color[data-v-2cdc2ac0] {
@@ -26,6 +26,7 @@ const files = ref<StoryFile[]>(rawFiles.map(file => mapFile(file)))
26
26
  const tree = ref<Tree>(rawTree)
27
27
 
28
28
  onUpdate((newFiles: StoryFile[], newTree: Tree) => {
29
+ loading.value = false
29
30
  files.value = newFiles.map(file => {
30
31
  const existingFile = files.value.find(f => f.id === file.id)
31
32
  return mapFile(file, existingFile)
@@ -78,6 +79,7 @@ const loading = ref(false)
78
79
 
79
80
  if (import.meta.hot && !rawFiles.length) {
80
81
  loading.value = true
82
+ console.log('loading...')
81
83
  import.meta.hot.on('histoire:all-stories-loaded', () => {
82
84
  loading.value = false
83
85
  })
@@ -206,11 +206,11 @@ onUnmounted(() => {
206
206
 
207
207
  <style lang="postcss" scoped>
208
208
  .landscape > div > .dragger {
209
- width: 10px;
209
+ width: .625rem;
210
210
  }
211
211
 
212
212
  .portrait > div > .dragger {
213
- height: 10px;
213
+ height: .625rem;
214
214
  }
215
215
 
216
216
  .landscape > div > .dragger.dragger-offset-before {
@@ -222,18 +222,18 @@ onUnmounted(() => {
222
222
  }
223
223
 
224
224
  .landscape > div > .dragger.dragger-offset-center {
225
- right: -5px;
225
+ right: -.3125rem;
226
226
  }
227
227
 
228
228
  .portrait > div > .dragger.dragger-offset-center {
229
- bottom: -5px;
229
+ bottom: -.3125rem;
230
230
  }
231
231
 
232
232
  .landscape > div > .dragger.dragger-offset-after {
233
- right: -10px;
233
+ right: -.625rem;
234
234
  }
235
235
 
236
236
  .portrait > div > .dragger.dragger-offset-after {
237
- bottom: -10px;
237
+ bottom: -.625rem;
238
238
  }
239
239
  </style>
@@ -0,0 +1,21 @@
1
+ export declare const RouterLinkStub: import("vue").DefineComponent<{
2
+ to: {
3
+ type: (ObjectConstructor | StringConstructor)[];
4
+ required: true;
5
+ };
6
+ custom: {
7
+ type: BooleanConstructor;
8
+ default: boolean;
9
+ };
10
+ }, unknown, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
11
+ to: {
12
+ type: (ObjectConstructor | StringConstructor)[];
13
+ required: true;
14
+ };
15
+ custom: {
16
+ type: BooleanConstructor;
17
+ default: boolean;
18
+ };
19
+ }>>, {
20
+ custom: boolean;
21
+ }>;
@@ -0,0 +1,43 @@
1
+ // From: https://github.com/vuejs/test-utils/blob/main/src/components/RouterLinkStub.ts
2
+ import { defineComponent, h, computed } from 'vue';
3
+ // match return type of router.resolve: RouteLocation & { href: string }
4
+ const defaultRoute = {
5
+ path: '/',
6
+ name: undefined,
7
+ redirectedFrom: undefined,
8
+ params: {},
9
+ query: {},
10
+ hash: '',
11
+ fullPath: '/',
12
+ matched: [],
13
+ meta: {},
14
+ href: '/',
15
+ };
16
+ // TODO: Borrow typings from vue-router-next
17
+ export const RouterLinkStub = defineComponent({
18
+ name: 'RouterLinkStub',
19
+ compatConfig: { MODE: 3 },
20
+ props: {
21
+ to: {
22
+ type: [String, Object],
23
+ required: true,
24
+ },
25
+ custom: {
26
+ type: Boolean,
27
+ default: false,
28
+ },
29
+ },
30
+ render() {
31
+ const route = computed(() => defaultRoute);
32
+ // mock reasonable return values to mimic vue-router's useLink
33
+ const children = this.$slots?.default?.({
34
+ route,
35
+ href: computed(() => route.value.href),
36
+ isActive: computed(() => false),
37
+ isExactActive: computed(() => false),
38
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
39
+ navigate: async () => { },
40
+ });
41
+ return this.custom ? children : h('a', undefined, children);
42
+ },
43
+ });
@@ -3,6 +3,7 @@ import { App, createApp, onMounted, onUnmounted, PropType, ref, watch } from 'vu
3
3
  import { Story, Variant, PropDefinition, AutoPropComponentDefinition } from '../../types'
4
4
  import { getTagName } from '../../codegen/vue3'
5
5
  import { applyStateToVariant } from '../../util/state'
6
+ import { RouterLinkStub } from './RouterLinkStub'
6
7
  // @ts-expect-error virtual module id
7
8
  import * as setup from '$histoire-setup'
8
9
  // @ts-expect-error virtual module id
@@ -125,6 +126,9 @@ async function mountVariant () {
125
126
  },
126
127
  })
127
128
 
129
+ // Stubs
130
+ app.component('RouterLink', RouterLinkStub)
131
+
128
132
  if (typeof generatedSetup?.setupVue3 === 'function') {
129
133
  await generatedSetup.setupVue3({
130
134
  app,
@@ -50,16 +50,16 @@ body,
50
50
 
51
51
  html {
52
52
  font-family: 'Lato', sans-serif;
53
- font-size: 16px;
53
+ font-size: 1rem;
54
54
  }
55
55
 
56
56
  body {
57
- font-size: 18px;
57
+ font-size: 1.125rem;
58
58
  }
59
59
 
60
60
  @media (min-width: 640px) {
61
61
  body {
62
- font-size: 14px;
62
+ font-size: .875rem;
63
63
  }
64
64
  }
65
65
 
@@ -10,7 +10,7 @@ body {
10
10
  }
11
11
 
12
12
  html {
13
- font-size: 14px;
13
+ font-size: .875rem;
14
14
  font-family: 'Lato', sans-serif;
15
15
  }
16
16
 
@@ -1,8 +1,12 @@
1
1
  <script lang="ts">
2
2
  import { defineComponent, inject, onMounted, PropType, provide, useAttrs } from 'vue'
3
- import type { StoryFile, Story, Variant } from '../../node/types'
3
+ import type { StoryFile, Story, Variant } from '../../../node/types'
4
+
5
+ const stub = { name: 'StubbedComponent', render: () => null }
4
6
 
5
7
  export default defineComponent({
8
+ name: 'HistoireStory',
9
+
6
10
  inheritAttrs: false,
7
11
 
8
12
  props: {
@@ -87,13 +91,24 @@ export default defineComponent({
87
91
  render () {
88
92
  let suppressError = false
89
93
  try {
90
- return this.$slots.default?.({
94
+ const vnodes = this.$slots.default?.({
91
95
  get state () {
92
96
  // No variant tags
93
97
  suppressError = true
94
98
  return {}
95
99
  },
96
100
  })
101
+
102
+ // Auto stub components
103
+ if (Array.isArray(vnodes)) {
104
+ for (const vnode of vnodes) {
105
+ if (typeof vnode.type === 'object' && (vnode.type as any).name !== 'HistoireVariant') {
106
+ vnode.type = stub
107
+ }
108
+ }
109
+ }
110
+
111
+ return vnodes
97
112
  } catch (e) {
98
113
  if (!suppressError) {
99
114
  console.error(e)
@@ -1,8 +1,10 @@
1
1
  <script lang="ts">
2
2
  import { defineComponent, inject } from 'vue'
3
- import type { Story, Variant } from '../../node/types'
3
+ import type { Story, Variant } from '../../../node/types'
4
4
 
5
5
  export default defineComponent({
6
+ name: 'HistoireVariant',
7
+
6
8
  props: {
7
9
  title: {
8
10
  type: String,
@@ -49,7 +49,7 @@ export async function build(ctx) {
49
49
  const storyCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ? 1 : 0), 0);
50
50
  const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0);
51
51
  const emptyStoryCount = ctx.storyFiles.length - storyCount;
52
- const results = await viteBuild(mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
52
+ const buildViteConfig = mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
53
53
  mode: 'development',
54
54
  build: {
55
55
  rollupOptions: {
@@ -70,7 +70,34 @@ export async function build(ctx) {
70
70
  cssCodeSplit: false,
71
71
  minify: false,
72
72
  },
73
- }));
73
+ });
74
+ // For @vite/plugin-vue: Always put our vite server
75
+ // Disable template inlining
76
+ // (so that we no longer need defineExpose)
77
+ // Nuxt: replaces the Nuxt vite dev server
78
+ buildViteConfig.plugins.push({
79
+ name: 'histoire-vue-plugin-override',
80
+ config(config) {
81
+ const vuePlugin = config.plugins.find((p) => p.name === 'vite:vue');
82
+ if (vuePlugin) {
83
+ const original = vuePlugin.configureServer.bind(vuePlugin);
84
+ vuePlugin.configureServer = () => {
85
+ original({
86
+ ...server,
87
+ config: {
88
+ ...server.config,
89
+ server: {
90
+ ...server.config.server,
91
+ hmr: false,
92
+ },
93
+ },
94
+ });
95
+ };
96
+ vuePlugin.configureServer();
97
+ }
98
+ },
99
+ });
100
+ const results = await viteBuild(buildViteConfig);
74
101
  const result = Array.isArray(results) ? results[0] : results;
75
102
  const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset');
76
103
  // Preload
@@ -16,6 +16,7 @@ export function useCollectStories(options, ctx) {
16
16
  ...ctx.config.viteNodeInlineDeps ?? [],
17
17
  ],
18
18
  },
19
+ transformMode: ctx.config.viteNodeTransformMode,
19
20
  });
20
21
  const threadsCount = ctx.mode === 'dev'
21
22
  ? Math.max(cpus().length / 2, 1)
@@ -134,6 +134,26 @@ export interface HistoireConfig {
134
134
  * Transpile dependencies when collecting stories on Node.js
135
135
  */
136
136
  viteNodeInlineDeps?: RegExp[];
137
+ /**
138
+ * Determine the transform method of modules
139
+ */
140
+ viteNodeTransformMode?: {
141
+ /**
142
+ * Use SSR transform pipeline for the specified files.
143
+ * Vite plugins will receive `ssr: true` flag when processing those files.
144
+ *
145
+ * @default [/\.([cm]?[jt]sx?|json)$/]
146
+ */
147
+ ssr?: RegExp[];
148
+ /**
149
+ * First do a normal transform pipeline (targeting browser),
150
+ * then then do a SSR rewrite to run the code in Node.
151
+ * Vite plugins will receive `ssr: false` flag when processing those files.
152
+ *
153
+ * @default other than `ssr`
154
+ */
155
+ web?: RegExp[];
156
+ };
137
157
  }
138
158
  export declare type ConfigMode = 'build' | 'dev';
139
159
  export declare function getDefaultConfig(): HistoireConfig;
@@ -49,8 +49,8 @@ export function addStory(relativeFilePath) {
49
49
  return file;
50
50
  }
51
51
  export function removeStory(relativeFilePath) {
52
- const fileId = Case.kebab(relativeFilePath);
53
- const index = context.storyFiles.findIndex((file) => file.id === fileId);
52
+ const absoluteFilePath = getAbsoluteFilePath(relativeFilePath);
53
+ const index = context.storyFiles.findIndex((file) => file.path === absoluteFilePath);
54
54
  if (index !== -1)
55
55
  context.storyFiles.splice(index, 1);
56
56
  }
package/dist/node/vite.js CHANGED
@@ -77,6 +77,9 @@ export async function getViteConfigWithPlugins(server, ctx) {
77
77
  fs: {
78
78
  allow: [DIST_PATH, TEMP_PATH, resolvedViteConfig.root, process.cwd()],
79
79
  },
80
+ watch: {
81
+ ignored: [`!**/node_modules/.histoire/**`],
82
+ },
80
83
  },
81
84
  define: {
82
85
  // We need to force this to be able to use `devtoolsRawSetupState`
package/dist/style.css CHANGED
@@ -506,7 +506,7 @@ button {
506
506
  margin-left:0;
507
507
  margin-right:0;
508
508
  background-color:rgb(var(--_histoire-color-gray-100));
509
- padding:4px 6px;
509
+ padding:.25rem .375rem;
510
510
  }
511
511
 
512
512
  .htw-prose :where(blockquote):not(:where([class~="htw-not-prose"] *)) p:first-child{
@@ -1917,16 +1917,16 @@ body,
1917
1917
 
1918
1918
  html {
1919
1919
  font-family: 'Lato', sans-serif;
1920
- font-size: 16px;
1920
+ font-size: 1rem;
1921
1921
  }
1922
1922
 
1923
1923
  body {
1924
- font-size: 18px;
1924
+ font-size: 1.125rem;
1925
1925
  }
1926
1926
 
1927
1927
  @media (min-width: 640px) {
1928
1928
  body {
1929
- font-size: 14px;
1929
+ font-size: .875rem;
1930
1930
  }
1931
1931
  }
1932
1932
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.6.6",
3
+ "version": "0.7.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.6",
36
+ "@histoire/controls": "^0.7.2",
37
37
  "@iconify/vue": "^3.2.1",
38
38
  "@types/markdown-it": "^12.2.3",
39
39
  "@vueuse/core": "^8.2.5",
@@ -26,6 +26,7 @@ const files = ref<StoryFile[]>(rawFiles.map(file => mapFile(file)))
26
26
  const tree = ref<Tree>(rawTree)
27
27
 
28
28
  onUpdate((newFiles: StoryFile[], newTree: Tree) => {
29
+ loading.value = false
29
30
  files.value = newFiles.map(file => {
30
31
  const existingFile = files.value.find(f => f.id === file.id)
31
32
  return mapFile(file, existingFile)
@@ -78,6 +79,7 @@ const loading = ref(false)
78
79
 
79
80
  if (import.meta.hot && !rawFiles.length) {
80
81
  loading.value = true
82
+ console.log('loading...')
81
83
  import.meta.hot.on('histoire:all-stories-loaded', () => {
82
84
  loading.value = false
83
85
  })
@@ -206,11 +206,11 @@ onUnmounted(() => {
206
206
 
207
207
  <style lang="postcss" scoped>
208
208
  .landscape > div > .dragger {
209
- width: 10px;
209
+ width: .625rem;
210
210
  }
211
211
 
212
212
  .portrait > div > .dragger {
213
- height: 10px;
213
+ height: .625rem;
214
214
  }
215
215
 
216
216
  .landscape > div > .dragger.dragger-offset-before {
@@ -222,18 +222,18 @@ onUnmounted(() => {
222
222
  }
223
223
 
224
224
  .landscape > div > .dragger.dragger-offset-center {
225
- right: -5px;
225
+ right: -.3125rem;
226
226
  }
227
227
 
228
228
  .portrait > div > .dragger.dragger-offset-center {
229
- bottom: -5px;
229
+ bottom: -.3125rem;
230
230
  }
231
231
 
232
232
  .landscape > div > .dragger.dragger-offset-after {
233
- right: -10px;
233
+ right: -.625rem;
234
234
  }
235
235
 
236
236
  .portrait > div > .dragger.dragger-offset-after {
237
- bottom: -10px;
237
+ bottom: -.625rem;
238
238
  }
239
239
  </style>
@@ -0,0 +1,49 @@
1
+ // From: https://github.com/vuejs/test-utils/blob/main/src/components/RouterLinkStub.ts
2
+
3
+ import { defineComponent, h, computed } from 'vue'
4
+
5
+ // match return type of router.resolve: RouteLocation & { href: string }
6
+ const defaultRoute = {
7
+ path: '/',
8
+ name: undefined as string | undefined,
9
+ redirectedFrom: undefined as object | undefined,
10
+ params: {},
11
+ query: {},
12
+ hash: '',
13
+ fullPath: '/',
14
+ matched: [] as object[],
15
+ meta: {},
16
+ href: '/',
17
+ }
18
+
19
+ // TODO: Borrow typings from vue-router-next
20
+ export const RouterLinkStub = defineComponent({
21
+ name: 'RouterLinkStub',
22
+
23
+ compatConfig: { MODE: 3 },
24
+
25
+ props: {
26
+ to: {
27
+ type: [String, Object],
28
+ required: true,
29
+ },
30
+ custom: {
31
+ type: Boolean,
32
+ default: false,
33
+ },
34
+ },
35
+
36
+ render () {
37
+ const route = computed(() => defaultRoute)
38
+ // mock reasonable return values to mimic vue-router's useLink
39
+ const children = this.$slots?.default?.({
40
+ route,
41
+ href: computed(() => route.value.href),
42
+ isActive: computed(() => false),
43
+ isExactActive: computed(() => false),
44
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
45
+ navigate: async () => {},
46
+ })
47
+ return this.custom ? children : h('a', undefined, children)
48
+ },
49
+ })
@@ -3,6 +3,7 @@ import { App, createApp, onMounted, onUnmounted, PropType, ref, watch } from 'vu
3
3
  import { Story, Variant, PropDefinition, AutoPropComponentDefinition } from '../../types'
4
4
  import { getTagName } from '../../codegen/vue3'
5
5
  import { applyStateToVariant } from '../../util/state'
6
+ import { RouterLinkStub } from './RouterLinkStub'
6
7
  // @ts-expect-error virtual module id
7
8
  import * as setup from '$histoire-setup'
8
9
  // @ts-expect-error virtual module id
@@ -125,6 +126,9 @@ async function mountVariant () {
125
126
  },
126
127
  })
127
128
 
129
+ // Stubs
130
+ app.component('RouterLink', RouterLinkStub)
131
+
128
132
  if (typeof generatedSetup?.setupVue3 === 'function') {
129
133
  await generatedSetup.setupVue3({
130
134
  app,
@@ -50,16 +50,16 @@ body,
50
50
 
51
51
  html {
52
52
  font-family: 'Lato', sans-serif;
53
- font-size: 16px;
53
+ font-size: 1rem;
54
54
  }
55
55
 
56
56
  body {
57
- font-size: 18px;
57
+ font-size: 1.125rem;
58
58
  }
59
59
 
60
60
  @media (min-width: 640px) {
61
61
  body {
62
- font-size: 14px;
62
+ font-size: .875rem;
63
63
  }
64
64
  }
65
65
 
@@ -10,7 +10,7 @@ body {
10
10
  }
11
11
 
12
12
  html {
13
- font-size: 14px;
13
+ font-size: .875rem;
14
14
  font-family: 'Lato', sans-serif;
15
15
  }
16
16
 
@@ -1,8 +1,12 @@
1
1
  <script lang="ts">
2
2
  import { defineComponent, inject, onMounted, PropType, provide, useAttrs } from 'vue'
3
- import type { StoryFile, Story, Variant } from '../../node/types'
3
+ import type { StoryFile, Story, Variant } from '../../../node/types'
4
+
5
+ const stub = { name: 'StubbedComponent', render: () => null }
4
6
 
5
7
  export default defineComponent({
8
+ name: 'HistoireStory',
9
+
6
10
  inheritAttrs: false,
7
11
 
8
12
  props: {
@@ -87,13 +91,24 @@ export default defineComponent({
87
91
  render () {
88
92
  let suppressError = false
89
93
  try {
90
- return this.$slots.default?.({
94
+ const vnodes = this.$slots.default?.({
91
95
  get state () {
92
96
  // No variant tags
93
97
  suppressError = true
94
98
  return {}
95
99
  },
96
100
  })
101
+
102
+ // Auto stub components
103
+ if (Array.isArray(vnodes)) {
104
+ for (const vnode of vnodes) {
105
+ if (typeof vnode.type === 'object' && (vnode.type as any).name !== 'HistoireVariant') {
106
+ vnode.type = stub
107
+ }
108
+ }
109
+ }
110
+
111
+ return vnodes
97
112
  } catch (e) {
98
113
  if (!suppressError) {
99
114
  console.error(e)
@@ -1,8 +1,10 @@
1
1
  <script lang="ts">
2
2
  import { defineComponent, inject } from 'vue'
3
- import type { Story, Variant } from '../../node/types'
3
+ import type { Story, Variant } from '../../../node/types'
4
4
 
5
5
  export default defineComponent({
6
+ name: 'HistoireVariant',
7
+
6
8
  props: {
7
9
  title: {
8
10
  type: String,
package/src/node/build.ts CHANGED
@@ -65,7 +65,7 @@ export async function build (ctx: Context) {
65
65
  const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0)
66
66
  const emptyStoryCount = ctx.storyFiles.length - storyCount
67
67
 
68
- const results = await viteBuild(mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
68
+ const buildViteConfig = mergeViteConfig(await getViteConfigWithPlugins(false, ctx), {
69
69
  mode: 'development',
70
70
  build: {
71
71
  rollupOptions: {
@@ -86,7 +86,36 @@ export async function build (ctx: Context) {
86
86
  cssCodeSplit: false,
87
87
  minify: false,
88
88
  },
89
- }))
89
+ })
90
+
91
+ // For @vite/plugin-vue: Always put our vite server
92
+ // Disable template inlining
93
+ // (so that we no longer need defineExpose)
94
+ // Nuxt: replaces the Nuxt vite dev server
95
+ buildViteConfig.plugins.push({
96
+ name: 'histoire-vue-plugin-override',
97
+ config (config) {
98
+ const vuePlugin = config.plugins.find((p: any) => p.name === 'vite:vue')
99
+ if (vuePlugin) {
100
+ const original = vuePlugin.configureServer.bind(vuePlugin)
101
+ vuePlugin.configureServer = () => {
102
+ original({
103
+ ...server,
104
+ config: {
105
+ ...server.config,
106
+ server: {
107
+ ...server.config.server,
108
+ hmr: false,
109
+ },
110
+ },
111
+ })
112
+ }
113
+ vuePlugin.configureServer()
114
+ }
115
+ },
116
+ })
117
+
118
+ const results = await viteBuild(buildViteConfig)
90
119
  const result = Array.isArray(results) ? results[0] : results as RollupOutput
91
120
 
92
121
  const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset')
@@ -28,6 +28,7 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
28
28
  ...ctx.config.viteNodeInlineDeps ?? [],
29
29
  ],
30
30
  },
31
+ transformMode: ctx.config.viteNodeTransformMode,
31
32
  })
32
33
 
33
34
  const threadsCount = ctx.mode === 'dev'
@@ -153,6 +153,26 @@ export interface HistoireConfig {
153
153
  * Transpile dependencies when collecting stories on Node.js
154
154
  */
155
155
  viteNodeInlineDeps?: RegExp[]
156
+ /**
157
+ * Determine the transform method of modules
158
+ */
159
+ viteNodeTransformMode?: {
160
+ /**
161
+ * Use SSR transform pipeline for the specified files.
162
+ * Vite plugins will receive `ssr: true` flag when processing those files.
163
+ *
164
+ * @default [/\.([cm]?[jt]sx?|json)$/]
165
+ */
166
+ ssr?: RegExp[]
167
+ /**
168
+ * First do a normal transform pipeline (targeting browser),
169
+ * then then do a SSR rewrite to run the code in Node.
170
+ * Vite plugins will receive `ssr: false` flag when processing those files.
171
+ *
172
+ * @default other than `ssr`
173
+ */
174
+ web?: RegExp[]
175
+ }
156
176
  }
157
177
 
158
178
  export type ConfigMode = 'build' | 'dev'
@@ -53,7 +53,7 @@ export function addStory (relativeFilePath: string) {
53
53
  }
54
54
 
55
55
  const file: StoryFile = {
56
- id: fileId,
56
+ id: fileId, // The file id will be changed by the story id after it is collected
57
57
  path: absoluteFilePath,
58
58
  fileName,
59
59
  moduleId: `/${relativeFilePath}`,
@@ -63,8 +63,8 @@ export function addStory (relativeFilePath: string) {
63
63
  }
64
64
 
65
65
  export function removeStory (relativeFilePath: string) {
66
- const fileId = Case.kebab(relativeFilePath)
67
- const index = context.storyFiles.findIndex((file) => file.id === fileId)
66
+ const absoluteFilePath = getAbsoluteFilePath(relativeFilePath)
67
+ const index = context.storyFiles.findIndex((file) => file.path === absoluteFilePath)
68
68
  if (index !== -1) context.storyFiles.splice(index, 1)
69
69
  }
70
70
 
package/src/node/vite.ts CHANGED
@@ -93,6 +93,9 @@ export async function getViteConfigWithPlugins (server: boolean, ctx: Context):
93
93
  fs: {
94
94
  allow: [DIST_PATH, TEMP_PATH, resolvedViteConfig.root, process.cwd()],
95
95
  },
96
+ watch: {
97
+ ignored: [`!**/node_modules/.histoire/**`],
98
+ },
96
99
  },
97
100
  define: {
98
101
  // We need to force this to be able to use `devtoolsRawSetupState`
@@ -100,7 +100,7 @@ module.exports.theme.extend.typography = (theme) => ({
100
100
  marginLeft: 0,
101
101
  marginRight: 0,
102
102
  backgroundColor: theme('colors.gray-100'),
103
- padding: '4px 6px',
103
+ padding: '.25rem .375rem',
104
104
 
105
105
  '& p:first-child': {
106
106
  marginTop: 0,