histoire 0.4.2 → 0.4.5

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,7 +18,7 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import "$histoire-theme";
21
- import { p as pushScopeId, a as popScopeId, d as defineComponent, u as useCssVars, b as unref, c as computed, r as ref, o as openBlock, e as createElementBlock, f as createVNode, w as withCtx, g as createBaseVNode, n as normalizeClass, t as toDisplayString, h as createCommentVNode, i as watch, j as resolveComponent, k as withKeys, F as Fragment, l as renderList, m as createBlock, q as isRef, s as resolveDirective, v as withDirectives, x as createTextVNode, y as defineAsyncComponent, z as vShow, A as resolveDynamicComponent, B as createApp } from "./vue.runtime.esm-bundler.js";
21
+ import { pushScopeId, popScopeId, defineComponent, useCssVars, unref, computed, ref, openBlock, createElementBlock, createVNode, withCtx, createElementVNode, normalizeClass, toDisplayString, createCommentVNode, watch, resolveComponent, withKeys, Fragment, renderList, createBlock, isRef, resolveDirective, withDirectives, createTextVNode, defineAsyncComponent, vShow, resolveDynamicComponent, createApp } from "vue";
22
22
  import { defineStore, createPinia } from "pinia";
23
23
  import FloatingVue from "floating-vue";
24
24
  import { files, tree, onUpdate } from "$histoire-stories";
@@ -74,7 +74,7 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
74
74
  default: withCtx(({ active: active2 }) => {
75
75
  var _a;
76
76
  return [
77
- createBaseVNode("span", _hoisted_1$9, [
77
+ createElementVNode("span", _hoisted_1$9, [
78
78
  createVNode(unref(Icon), {
79
79
  icon: (_a = __props.story.icon) != null ? _a : "carbon:cube",
80
80
  class: normalizeClass(["base-list-item-link-icon htw-w-5 htw-h-5 sm:htw-w-4 sm:htw-h-4 htw-flex-none", {
@@ -82,7 +82,7 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
82
82
  "bind-icon-color": !active2 && __props.story.iconColor
83
83
  }])
84
84
  }, null, 8, ["icon", "class"]),
85
- createBaseVNode("span", _hoisted_2$7, toDisplayString(__props.story.title), 1)
85
+ createElementVNode("span", _hoisted_2$7, toDisplayString(__props.story.title), 1)
86
86
  ]),
87
87
  !__props.story.docsOnly ? (openBlock(), createElementBlock("span", _hoisted_3$5, toDisplayString(__props.story.variants.length), 1)) : createCommentVNode("", true)
88
88
  ];
@@ -167,7 +167,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
167
167
  return (_ctx, _cache) => {
168
168
  const _component_StoryListFolder = resolveComponent("StoryListFolder", true);
169
169
  return openBlock(), createElementBlock("div", _hoisted_1$8, [
170
- createBaseVNode("div", {
170
+ createElementVNode("div", {
171
171
  role: "button",
172
172
  tabindex: "0",
173
173
  class: "htw-px-0.5 htw-py-2 md:htw-py-1.5 htw-mx-1 htw-rounded-sm hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900 htw-cursor-pointer htw-select-none htw-flex",
@@ -177,8 +177,8 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
177
177
  withKeys(toggleOpen, ["space"])
178
178
  ]
179
179
  }, [
180
- createBaseVNode("span", _hoisted_3$4, [
181
- createBaseVNode("span", _hoisted_4$4, [
180
+ createElementVNode("span", _hoisted_3$4, [
181
+ createElementVNode("span", _hoisted_4$4, [
182
182
  createVNode(unref(Icon), {
183
183
  icon: "carbon:caret-right",
184
184
  class: normalizeClass(["htw-w-4 htw-h-4 htw-transition-transform htw-duration-150 htw-opacity-30", {
@@ -190,7 +190,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
190
190
  class: "htw-w-5 htw-h-5 sm:htw-w-4 sm:htw-h-4"
191
191
  })
192
192
  ]),
193
- createBaseVNode("span", _hoisted_5$1, toDisplayString(__props.folder.title), 1)
193
+ createElementVNode("span", _hoisted_5$1, toDisplayString(__props.folder.title), 1)
194
194
  ])
195
195
  ], 40, _hoisted_2$6),
196
196
  unref(isFolderOpen) ? (openBlock(), createElementBlock("div", _hoisted_6, [
@@ -223,7 +223,7 @@ const _hoisted_1$7 = {
223
223
  };
224
224
  const _hoisted_2$5 = ["onKeyup"];
225
225
  const _hoisted_3$3 = { class: "htw-truncate htw-opacity-50" };
226
- const _hoisted_4$3 = /* @__PURE__ */ createBaseVNode("span", { class: "htw-h-[1px] htw-flex-1 htw-bg-gray-500/10 htw-mx-2" }, null, -1);
226
+ const _hoisted_4$3 = /* @__PURE__ */ createElementVNode("span", { class: "htw-h-[1px] htw-flex-1 htw-bg-gray-500/10 htw-mx-2" }, null, -1);
227
227
  const _hoisted_5 = { key: 1 };
228
228
  const _sfc_main$7 = /* @__PURE__ */ defineComponent({
229
229
  props: {
@@ -258,7 +258,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
258
258
  "htw-rotate-90": unref(isFolderOpen)
259
259
  }])
260
260
  }, null, 8, ["class"]),
261
- createBaseVNode("span", _hoisted_3$3, toDisplayString(__props.group.title), 1),
261
+ createElementVNode("span", _hoisted_3$3, toDisplayString(__props.group.title), 1),
262
262
  _hoisted_4$3
263
263
  ], 40, _hoisted_2$5)) : createCommentVNode("", true),
264
264
  unref(isFolderOpen) ? (openBlock(), createElementBlock("div", _hoisted_5, [
@@ -447,8 +447,8 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
447
447
  var _a;
448
448
  const _directive_tooltip = resolveDirective("tooltip");
449
449
  return openBlock(), createElementBlock("div", _hoisted_1$4, [
450
- createBaseVNode("div", _hoisted_2$4, [
451
- createBaseVNode("a", {
450
+ createElementVNode("div", _hoisted_2$4, [
451
+ createElementVNode("a", {
452
452
  href: (_a = unref(histoireConfig).theme) == null ? void 0 : _a.logoHref,
453
453
  target: "_blank",
454
454
  class: "htw-w-full htw-h-full htw-flex htw-items-center"
@@ -456,7 +456,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
456
456
  createVNode(_sfc_main$5, { class: "htw-max-w-full htw-max-h-full" })
457
457
  ], 8, _hoisted_3$2)
458
458
  ]),
459
- createBaseVNode("div", _hoisted_4$2, [
459
+ createElementVNode("div", _hoisted_4$2, [
460
460
  withDirectives((openBlock(), createElementBlock("a", {
461
461
  class: "htw-p-2 sm:htw-p-1 hover:htw-text-primary-500 dark:hover:htw-text-primary-400 htw-cursor-pointer htw-text-gray-900 dark:htw-text-gray-100",
462
462
  "data-test-id": "search-btn",
@@ -487,7 +487,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
487
487
  });
488
488
  var Breadcrumb_vue_vue_type_style_index_0_scoped_true_lang = "";
489
489
  const _withScopeId = (n) => (pushScopeId("data-v-5fe505b0"), n = n(), popScopeId(), n);
490
- const _hoisted_1$3 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createBaseVNode("span", { class: "htw-opacity-40" }, " / ", -1));
490
+ const _hoisted_1$3 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("span", { class: "htw-opacity-40" }, " / ", -1));
491
491
  const _hoisted_2$3 = { class: "htw-flex htw-items-center htw-gap-2" };
492
492
  const _hoisted_3$1 = { class: "htw-opacity-40 htw-text-sm" };
493
493
  const _hoisted_4$1 = /* @__PURE__ */ createTextVNode(" Select a story... ");
@@ -522,19 +522,19 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
522
522
  return (_ctx, _cache) => {
523
523
  var _a;
524
524
  return openBlock(), createElementBlock(Fragment, null, [
525
- createBaseVNode("div", null, [
526
- createBaseVNode("a", {
525
+ createElementVNode("div", null, [
526
+ createElementVNode("a", {
527
527
  class: "htw-px-6 htw-h-12 hover:htw-text-primary-500 dark:hover:htw-text-primary-400 htw-cursor-pointer htw-flex htw-gap-2 htw-flex-wrap htw-w-full htw-items-center",
528
528
  onClick: openMenu
529
529
  }, [
530
530
  unref(story) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
531
531
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(folders), (file, key) => {
532
532
  return openBlock(), createElementBlock(Fragment, { key }, [
533
- createBaseVNode("span", null, toDisplayString(file), 1),
533
+ createElementVNode("span", null, toDisplayString(file), 1),
534
534
  _hoisted_1$3
535
535
  ], 64);
536
536
  }), 128)),
537
- createBaseVNode("span", _hoisted_2$3, [
537
+ createElementVNode("span", _hoisted_2$3, [
538
538
  createVNode(unref(Icon), {
539
539
  icon: (_a = unref(story).icon) != null ? _a : "carbon:cube",
540
540
  class: normalizeClass(["base-list-item-link-icon htw-w-5 htw-h-5 htw-flex-none", {
@@ -543,7 +543,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
543
543
  }])
544
544
  }, null, 8, ["icon", "class"]),
545
545
  createTextVNode(" " + toDisplayString(unref(story).title) + " ", 1),
546
- createBaseVNode("span", _hoisted_3$1, toDisplayString(unref(story).variants.length), 1)
546
+ createElementVNode("span", _hoisted_3$1, toDisplayString(unref(story).variants.length), 1)
547
547
  ])
548
548
  ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
549
549
  _hoisted_4$1
@@ -614,11 +614,11 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
614
614
  }
615
615
  return (_ctx, _cache) => {
616
616
  return withDirectives((openBlock(), createElementBlock("div", _hoisted_1$1, [
617
- createBaseVNode("div", {
617
+ createElementVNode("div", {
618
618
  class: "htw-absolute htw-inset-0",
619
619
  onClick: _cache[0] || (_cache[0] = ($event) => close())
620
620
  }),
621
- createBaseVNode("div", _hoisted_2$1, [
621
+ createElementVNode("div", _hoisted_2$1, [
622
622
  createVNode(unref(SearchPane), {
623
623
  shown: __props.shown,
624
624
  onClose: _cache[1] || (_cache[1] = ($event) => close())
@@ -693,7 +693,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({
693
693
  story: unref(storyStore).currentStory
694
694
  }, null, 8, ["story"]))
695
695
  ])) : createCommentVNode("", true),
696
- createBaseVNode("div", _hoisted_2, [
696
+ createElementVNode("div", _hoisted_2, [
697
697
  unref(isMobile) ? (openBlock(), createElementBlock("div", _hoisted_3, [
698
698
  createVNode(_sfc_main$4, {
699
699
  onSearch: _cache[0] || (_cache[0] = ($event) => isSearchOpen.value = true)
@@ -712,7 +712,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({
712
712
  class: "htw-h-full"
713
713
  }, {
714
714
  first: withCtx(() => [
715
- createBaseVNode("div", _hoisted_4, [
715
+ createElementVNode("div", _hoisted_4, [
716
716
  createVNode(_sfc_main$4, {
717
717
  class: "htw-flex-none",
718
718
  onSearch: _cache[1] || (_cache[1] = ($event) => isSearchOpen.value = true)
@@ -758,5 +758,8 @@ function mountMainApp() {
758
758
  app.use(router);
759
759
  registerGlobalComponents(app);
760
760
  app.mount("#app");
761
+ if (import.meta.hot) {
762
+ import.meta.hot.send("histoire:mount", {});
763
+ }
761
764
  }
762
765
  export { mountMainApp as m, onKeyboardShortcut as o };
@@ -1,4 +1,4 @@
1
- import { d as defineComponent, r as ref, B as createApp, L as onMounted, i as watch, M as onUnmounted, o as openBlock, e as createElementBlock, q as isRef, b as unref } from "./vue.runtime.esm-bundler.js";
1
+ import { defineComponent, ref, createApp, onMounted, watch, onUnmounted, openBlock, createElementBlock, isRef, unref } from "vue";
2
2
  import * as setup from "$histoire-setup";
3
3
  const _sfc_main = /* @__PURE__ */ defineComponent({
4
4
  props: {
@@ -1,5 +1,5 @@
1
1
  import { parseQuery } from "vue-router";
2
- import { P as reactive, r as ref, B as createApp, c as computed, i as watch, L as onMounted, I as h } from "./vue.runtime.esm-bundler.js";
2
+ import { reactive, ref, createApp, computed, watch, onMounted, h } from "vue";
3
3
  import { createPinia } from "pinia";
4
4
  import { m as mapFile, r as registerGlobalComponents } from "./global-components.js";
5
5
  import { t as toRawDeep, _ as _sfc_main } from "./reactivity.js";
@@ -1,4 +1,4 @@
1
- import { C as markRaw } from "./vue.runtime.esm-bundler.js";
1
+ import { markRaw } from "vue";
2
2
  import { searchData as searchData$1, onUpdate as onUpdate$1 } from "$histoire-search-docs-data";
3
3
  const searchData = markRaw(searchData$1);
4
4
  function onUpdate(cb) {
@@ -1,7 +1,7 @@
1
1
  import { defineStore } from "pinia";
2
- import { r as ref, c as computed } from "./vue.runtime.esm-bundler.js";
2
+ import { ref, computed } from "vue";
3
3
  import { createRouter, createWebHistory } from "vue-router";
4
- const base = "/";
4
+ const base = import.meta.env.BASE_URL;
5
5
  const router = createRouter({
6
6
  history: createWebHistory(base),
7
7
  routes: [
@@ -26,4 +26,9 @@ export function mountMainApp() {
26
26
  app.use(router);
27
27
  registerGlobalComponents(app);
28
28
  app.mount('#app');
29
+ // @ts-expect-error vite hot api
30
+ if (import.meta.hot) {
31
+ // @ts-expect-error vite hot api
32
+ import.meta.hot.send('histoire:mount', {});
33
+ }
29
34
  }
@@ -1,4 +1,14 @@
1
1
  import { markRaw } from 'vue';
2
+ const copiedFromExistingVariant = [
3
+ 'state',
4
+ 'slots',
5
+ 'initState',
6
+ 'source',
7
+ 'responsiveDisabled',
8
+ 'setupApp',
9
+ 'configReady',
10
+ 'previewReady',
11
+ ];
2
12
  export function mapFile(file, existingFile) {
3
13
  const result = {
4
14
  ...file,
@@ -16,7 +26,7 @@ export function mapFile(file, existingFile) {
16
26
  const variant = result.story.variants[index];
17
27
  const existingVariant = existingFile.story.variants[index];
18
28
  if (existingVariant) {
19
- for (const key in existingVariant) {
29
+ for (const key of copiedFromExistingVariant) {
20
30
  if (typeof existingVariant[key] !== 'undefined') {
21
31
  if (key === 'state') {
22
32
  variant.state = existingVariant.state;
@@ -23,7 +23,7 @@ export async function build(ctx) {
23
23
  const startTime = performance.now();
24
24
  await findAllStories(ctx);
25
25
  const server = await createViteServer({
26
- plugins: await createVitePlugins(ctx),
26
+ plugins: await createVitePlugins(true, ctx),
27
27
  });
28
28
  await server.pluginContainer.buildStart({});
29
29
  const moduleLoader = useModuleLoader({
@@ -53,7 +53,7 @@ export async function build(ctx) {
53
53
  const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0);
54
54
  const emptyStoryCount = ctx.storyFiles.length - storyCount;
55
55
  const results = await viteBuild({
56
- plugins: await createVitePlugins(ctx),
56
+ plugins: await createVitePlugins(false, ctx),
57
57
  build: {
58
58
  rollupOptions: {
59
59
  input: [
@@ -76,7 +76,7 @@ export async function build(ctx) {
76
76
  });
77
77
  const result = Array.isArray(results) ? results[0] : results;
78
78
  const resolvedViteConfig = await resolveViteConfig({
79
- plugins: await createVitePlugins(ctx),
79
+ plugins: await createVitePlugins(false, ctx),
80
80
  }, 'build');
81
81
  const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset');
82
82
  // Preload
@@ -13,10 +13,6 @@ export default async (payload) => {
13
13
  root: payload.root,
14
14
  base: payload.base,
15
15
  fetchModule(id) {
16
- // Alias
17
- if (id.endsWith('vue.runtime.esm-bundler.js')) {
18
- id = 'vue';
19
- }
20
16
  return rpc.fetchModule(id);
21
17
  },
22
18
  resolveId(id, importer) {
@@ -8,7 +8,7 @@ export async function previewCommand(options) {
8
8
  mode: 'build',
9
9
  });
10
10
  const viteConfig = await resolveViteConfig({
11
- plugins: await createVitePlugins(ctx),
11
+ plugins: await createVitePlugins(false, ctx),
12
12
  }, 'build');
13
13
  const { baseUrl } = await startPreview(viteConfig, options.port, ctx);
14
14
  console.log(`Preview server listening on ${pc.cyan(baseUrl)}`);
@@ -156,6 +156,11 @@ export const mergeConfig = createDefu((obj, key, value) => {
156
156
  }
157
157
  return true;
158
158
  }
159
+ // By default, arrays should be replaced
160
+ if (obj[key] && Array.isArray(obj[key])) {
161
+ obj[key] = value;
162
+ return true;
163
+ }
159
164
  });
160
165
  export async function resolveConfig(cwd = process.cwd(), mode) {
161
166
  let result;
@@ -1,21 +1,20 @@
1
1
  import { createServer as createViteServer } from 'vite';
2
2
  import { createVitePlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js';
3
- import { notifyStoryChange, onStoryChange, watchStories } from './stories.js';
3
+ import { onStoryChange, watchStories } from './stories.js';
4
4
  import { useCollectStories } from './collect/index.js';
5
5
  import { DevPluginApi } from './plugin.js';
6
6
  import { useModuleLoader } from './load.js';
7
7
  export async function createServer(ctx, port) {
8
8
  const server = await createViteServer({
9
- plugins: await createVitePlugins(ctx),
10
- server: {
11
- watch: {
12
- usePolling: true,
13
- },
14
- },
9
+ plugins: await createVitePlugins(false, ctx),
15
10
  });
16
11
  await server.pluginContainer.buildStart({});
12
+ const nodeServer = await createViteServer({
13
+ plugins: await createVitePlugins(true, ctx),
14
+ });
15
+ await nodeServer.pluginContainer.buildStart({});
17
16
  const moduleLoader = useModuleLoader({
18
- server,
17
+ server: nodeServer,
19
18
  });
20
19
  const pluginOnCleanups = [];
21
20
  for (const plugin of ctx.config.plugins) {
@@ -31,17 +30,49 @@ export async function createServer(ctx, port) {
31
30
  // Wait for pre-bundling (in `listen()`)
32
31
  await server.listen(port);
33
32
  const { clearCache, executeStoryFile, destroy: destroyCollectStories, } = useCollectStories({
34
- server,
33
+ server: nodeServer,
35
34
  }, ctx);
36
35
  // onStoryChange debouncing
37
36
  let queue;
38
37
  let queueResolve;
39
38
  let queued = false;
40
39
  let queuedFiles = [];
40
+ let queuedAll = false;
41
+ let didAllStoriesYet = false;
42
+ // Invalidate modules
43
+ const invalidateModule = (id) => {
44
+ const mod = server.moduleGraph.getModuleById(id);
45
+ if (!mod) {
46
+ return;
47
+ }
48
+ server.moduleGraph.invalidateModule(mod);
49
+ // Send HMR update
50
+ const timestamp = Date.now();
51
+ mod.lastHMRTimestamp = timestamp;
52
+ server.ws.send({
53
+ type: 'update',
54
+ updates: [
55
+ {
56
+ type: 'js-update',
57
+ acceptedPath: mod.url,
58
+ path: mod.url,
59
+ timestamp: timestamp,
60
+ },
61
+ ],
62
+ });
63
+ };
41
64
  onStoryChange(async (changedFile) => {
65
+ if (changedFile && !didAllStoriesYet) {
66
+ return;
67
+ }
42
68
  if (queue) {
43
- if (queued && changedFile) {
44
- queuedFiles.push(changedFile);
69
+ if (queued) {
70
+ if (changedFile) {
71
+ queuedFiles.push(changedFile);
72
+ }
73
+ else {
74
+ queuedAll = true;
75
+ }
45
76
  return;
46
77
  }
47
78
  else {
@@ -55,44 +86,27 @@ export async function createServer(ctx, port) {
55
86
  queueResolve = resolve;
56
87
  });
57
88
  clearCache();
58
- if (changedFile) {
89
+ console.log('Collect stories start', changedFile?.path ?? 'all');
90
+ const time = Date.now();
91
+ if (changedFile && !queuedAll) {
59
92
  // Granular update
60
93
  await executeStoryFile(changedFile);
94
+ // Queued updates
95
+ for (const storyFile of queuedFiles) {
96
+ await executeStoryFile(storyFile);
97
+ }
61
98
  }
62
99
  else {
63
100
  // Full update
64
101
  for (const storyFile of ctx.storyFiles) {
65
102
  await executeStoryFile(storyFile);
66
103
  }
104
+ didAllStoriesYet = true;
67
105
  }
68
- // Queued updates
69
- for (const storyFile of queuedFiles) {
70
- await executeStoryFile(storyFile);
71
- }
106
+ console.log('Collect stories end', Date.now() - time, 'ms');
72
107
  queuedFiles = [];
108
+ queuedAll = false;
73
109
  queueResolve();
74
- // Invalidate modules
75
- function invalidateModule(id) {
76
- const mod = server.moduleGraph.getModuleById(id);
77
- if (!mod) {
78
- return;
79
- }
80
- server.moduleGraph.invalidateModule(mod);
81
- // Send HMR update
82
- const timestamp = Date.now();
83
- mod.lastHMRTimestamp = timestamp;
84
- server.ws.send({
85
- type: 'update',
86
- updates: [
87
- {
88
- type: 'js-update',
89
- acceptedPath: mod.url,
90
- path: mod.url,
91
- timestamp: timestamp,
92
- },
93
- ],
94
- });
95
- }
96
110
  invalidateModule(RESOLVED_STORIES_ID);
97
111
  invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
98
112
  });
@@ -101,15 +115,9 @@ export async function createServer(ctx, port) {
101
115
  await cb();
102
116
  }
103
117
  await server.close();
118
+ await nodeServer.close();
104
119
  await destroyCollectStories();
105
120
  }
106
- // On page refresh, refresh stories
107
- // Useful when vite optimizes new dependencies
108
- server.ws.on('connection', (socket) => {
109
- if (socket.protocol === 'vite-hmr') {
110
- notifyStoryChange();
111
- }
112
- });
113
121
  return {
114
122
  server,
115
123
  close,
@@ -12,4 +12,4 @@ 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 function createVitePlugins(ctx: Context): Promise<VitePlugin[]>;
15
+ export declare function createVitePlugins(server: boolean, ctx: Context): Promise<VitePlugin[]>;
package/dist/node/vite.js CHANGED
@@ -21,7 +21,7 @@ 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 async function createVitePlugins(ctx) {
24
+ export async function createVitePlugins(server, ctx) {
25
25
  const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
26
26
  const plugins = [];
27
27
  if (ctx.config.vite) {
@@ -37,9 +37,15 @@ export async function createVitePlugins(ctx) {
37
37
  config() {
38
38
  return {
39
39
  optimizeDeps: {
40
- // force include vue to avoid duplicated copies when linked + optimized
40
+ disabled: server,
41
+ entries: [
42
+ `${APP_PATH}/bundle-main.js`,
43
+ `${APP_PATH}/bundle-sandbox.js`,
44
+ `${APP_PATH}/server/index.js`,
45
+ ],
41
46
  include: [
42
47
  'vue',
48
+ dirname(require.resolve('@vue/runtime-core/package.json')),
43
49
  dirname(require.resolve('shiki/package.json')),
44
50
  dirname(require.resolve('vscode-textmate/package.json')),
45
51
  dirname(require.resolve('vscode-oniguruma/package.json')),
@@ -159,6 +165,9 @@ if (import.meta.hot) {
159
165
  }
160
166
  },
161
167
  configureServer(server) {
168
+ server.ws.on('histoire:mount', () => {
169
+ notifyStoryChange();
170
+ });
162
171
  server.middlewares.use(async (req, res, next) => {
163
172
  if (req.url.startsWith(`${server.config.base}__sandbox`)) {
164
173
  res.statusCode = 200;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.4.2",
3
+ "version": "0.4.5",
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.4.2",
36
+ "@histoire/controls": "^0.4.5",
37
37
  "@iconify/vue": "^3.2.1",
38
38
  "@types/markdown-it": "^12.2.3",
39
39
  "@vueuse/core": "^8.2.5",
@@ -61,12 +61,12 @@
61
61
  "shiki": "^0.10.1",
62
62
  "sirv": "^2.0.2",
63
63
  "tinypool": "^0.1.2",
64
- "vite-node": "0.7.6",
65
- "vue-router": "^4.0.14"
64
+ "vite-node": "0.12.1",
65
+ "vue-router": "^4.0.14",
66
+ "vue": "^3.2.31"
66
67
  },
67
68
  "peerDependencies": {
68
- "vite": "^2.9.0",
69
- "vue": "^3.2.31"
69
+ "vite": "^2.9.0"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@peeky/test": "^0.13.5",
@@ -29,4 +29,10 @@ export function mountMainApp () {
29
29
  app.use(router)
30
30
  registerGlobalComponents(app)
31
31
  app.mount('#app')
32
+
33
+ // @ts-expect-error vite hot api
34
+ if (import.meta.hot) {
35
+ // @ts-expect-error vite hot api
36
+ import.meta.hot.send('histoire:mount', {})
37
+ }
32
38
  }
@@ -1,6 +1,17 @@
1
1
  import { markRaw } from 'vue'
2
2
  import type { StoryFile, Variant } from '../types'
3
3
 
4
+ const copiedFromExistingVariant = [
5
+ 'state',
6
+ 'slots',
7
+ 'initState',
8
+ 'source',
9
+ 'responsiveDisabled',
10
+ 'setupApp',
11
+ 'configReady',
12
+ 'previewReady',
13
+ ]
14
+
4
15
  export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
5
16
  const result: StoryFile = {
6
17
  ...file,
@@ -19,7 +30,7 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
19
30
  const variant = result.story.variants[index]
20
31
  const existingVariant = existingFile.story.variants[index]
21
32
  if (existingVariant) {
22
- for (const key in existingVariant) {
33
+ for (const key of copiedFromExistingVariant) {
23
34
  if (typeof existingVariant[key] !== 'undefined') {
24
35
  if (key === 'state') {
25
36
  variant.state = existingVariant.state
package/src/node/build.ts CHANGED
@@ -29,7 +29,7 @@ export async function build (ctx: Context) {
29
29
  await findAllStories(ctx)
30
30
 
31
31
  const server = await createViteServer({
32
- plugins: await createVitePlugins(ctx),
32
+ plugins: await createVitePlugins(true, ctx),
33
33
  })
34
34
  await server.pluginContainer.buildStart({})
35
35
 
@@ -63,7 +63,7 @@ export async function build (ctx: Context) {
63
63
  const emptyStoryCount = ctx.storyFiles.length - storyCount
64
64
 
65
65
  const results = await viteBuild({
66
- plugins: await createVitePlugins(ctx),
66
+ plugins: await createVitePlugins(false, ctx),
67
67
  build: {
68
68
  rollupOptions: {
69
69
  input: [
@@ -87,7 +87,7 @@ export async function build (ctx: Context) {
87
87
  const result = Array.isArray(results) ? results[0] : results as RollupOutput
88
88
 
89
89
  const resolvedViteConfig = await resolveViteConfig({
90
- plugins: await createVitePlugins(ctx),
90
+ plugins: await createVitePlugins(false, ctx),
91
91
  }, 'build')
92
92
 
93
93
  const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset')
@@ -34,10 +34,6 @@ export default async (payload: Payload): Promise<ReturnData> => {
34
34
  root: payload.root,
35
35
  base: payload.base,
36
36
  fetchModule (id) {
37
- // Alias
38
- if (id.endsWith('vue.runtime.esm-bundler.js')) {
39
- id = 'vue'
40
- }
41
37
  return rpc.fetchModule(id)
42
38
  },
43
39
  resolveId (id, importer) {
@@ -13,7 +13,7 @@ export async function previewCommand (options: PreviewOptions) {
13
13
  mode: 'build',
14
14
  })
15
15
  const viteConfig = await resolveViteConfig({
16
- plugins: await createVitePlugins(ctx),
16
+ plugins: await createVitePlugins(false, ctx),
17
17
  }, 'build')
18
18
 
19
19
  const { baseUrl } = await startPreview(viteConfig, options.port, ctx)
@@ -302,6 +302,12 @@ export const mergeConfig = createDefu((obj: any, key, value) => {
302
302
  }
303
303
  return true
304
304
  }
305
+
306
+ // By default, arrays should be replaced
307
+ if (obj[key] && Array.isArray(obj[key])) {
308
+ obj[key] = value
309
+ return true
310
+ }
305
311
  })
306
312
 
307
313
  export async function resolveConfig (cwd: string = process.cwd(), mode: ConfigMode): Promise<HistoireConfig> {