histoire 0.8.1 → 0.8.4

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.
@@ -2,12 +2,12 @@ import { pushScopeId, popScopeId, openBlock, createElementBlock, renderSlot } fr
2
2
  import "./BaseEmpty.vue_vue_type_style_index_0_scoped_true_lang.js";
3
3
  import _export_sfc from "../../_virtual/plugin-vue_export-helper.js";
4
4
  const _sfc_main = {};
5
- const _withScopeId = (n) => (pushScopeId("data-v-552cc113"), n = n(), popScopeId(), n);
5
+ const _withScopeId = (n) => (pushScopeId("data-v-046d52e2"), n = n(), popScopeId(), n);
6
6
  const _hoisted_1 = { class: "htw-base-empty htw-flex htw-flex-col htw-items-center htw-justify-center htw-space-y-4 htw-py-12 htw-h-full htw-text-center htw-text-gray-400 htw-text-lg" };
7
7
  function _sfc_render(_ctx, _cache) {
8
8
  return openBlock(), createElementBlock("div", _hoisted_1, [
9
9
  renderSlot(_ctx.$slots, "default", {}, void 0, true)
10
10
  ]);
11
11
  }
12
- var BaseEmpty = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-552cc113"]]);
12
+ var BaseEmpty = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-046d52e2"]]);
13
13
  export { BaseEmpty as default };
@@ -17,11 +17,12 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { createTextVNode, defineComponent, openBlock, createBlock, withCtx, createVNode, unref, createElementBlock, toDisplayString, createCommentVNode } from "@histoire/vendors/dist/client/vue.js";
20
+ import { createTextVNode, defineComponent, toRefs, computed, openBlock, createBlock, withCtx, createVNode, normalizeClass, unref, createElementBlock, toDisplayString, createCommentVNode } from "@histoire/vendors/dist/client/vue.js";
21
21
  import BaseTab from "../base/BaseTab.js";
22
22
  import { useEventsStore } from "../../stores/events.js";
23
23
  import _sfc_main$1 from "../base/BaseOverflowMenu.js";
24
24
  import BaseOverflowTab from "../base/BaseOverflowTab.js";
25
+ import { useStoryDoc } from "./StoryDocs.js";
25
26
  const _hoisted_1 = /* @__PURE__ */ createTextVNode(" Controls ");
26
27
  const _hoisted_2 = /* @__PURE__ */ createTextVNode(" Docs ");
27
28
  const _hoisted_3 = /* @__PURE__ */ createTextVNode(" Events ");
@@ -38,8 +39,16 @@ const _hoisted_8 = {
38
39
  };
39
40
  const _sfc_main = /* @__PURE__ */ defineComponent({
40
41
  name: "PaneTabs",
42
+ props: {
43
+ story: null,
44
+ variant: null
45
+ },
41
46
  setup(__props) {
47
+ const props = __props;
48
+ const { story } = toRefs(props);
49
+ const { renderedDoc } = useStoryDoc(story);
42
50
  const eventsStore = useEventsStore();
51
+ const hasEvents = computed(() => eventsStore.events.length);
43
52
  return (_ctx, _cache) => {
44
53
  return openBlock(), createBlock(_sfc_main$1, { class: "htw-h-10 htw-flex-none htw-border-b htw-border-gray-100 dark:htw-border-gray-750" }, {
45
54
  overflow: withCtx(() => [
@@ -54,23 +63,29 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
54
63
  }, 8, ["to", "matched"]),
55
64
  createVNode(BaseOverflowTab, {
56
65
  to: __spreadProps(__spreadValues({}, _ctx.$route), { query: __spreadProps(__spreadValues({}, _ctx.$route.query), { tab: "docs" }) }),
57
- matched: _ctx.$route.query.tab === "docs"
66
+ matched: _ctx.$route.query.tab === "docs",
67
+ class: normalizeClass({
68
+ "opacity-50": !unref(renderedDoc)
69
+ })
58
70
  }, {
59
71
  default: withCtx(() => [
60
72
  _hoisted_6
61
73
  ]),
62
74
  _: 1
63
- }, 8, ["to", "matched"]),
75
+ }, 8, ["to", "matched", "class"]),
64
76
  createVNode(BaseOverflowTab, {
65
77
  to: __spreadProps(__spreadValues({}, _ctx.$route), { query: __spreadProps(__spreadValues({}, _ctx.$route.query), { tab: "events" }) }),
66
- matched: _ctx.$route.query.tab === "events"
78
+ matched: _ctx.$route.query.tab === "events",
79
+ class: normalizeClass({
80
+ "htw-opacity-50": !unref(hasEvents)
81
+ })
67
82
  }, {
68
83
  default: withCtx(() => [
69
84
  _hoisted_7,
70
85
  unref(eventsStore).unseen ? (openBlock(), createElementBlock("span", _hoisted_8, toDisplayString(unref(eventsStore).unseen <= 99 ? unref(eventsStore).unseen : "99+"), 1)) : createCommentVNode("", true)
71
86
  ]),
72
87
  _: 1
73
- }, 8, ["to", "matched"])
88
+ }, 8, ["to", "matched", "class"])
74
89
  ]),
75
90
  default: withCtx(() => [
76
91
  createVNode(BaseTab, {
@@ -84,23 +99,29 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
84
99
  }, 8, ["to", "matched"]),
85
100
  createVNode(BaseTab, {
86
101
  to: __spreadProps(__spreadValues({}, _ctx.$route), { query: __spreadProps(__spreadValues({}, _ctx.$route.query), { tab: "docs" }) }),
87
- matched: _ctx.$route.query.tab === "docs"
102
+ matched: _ctx.$route.query.tab === "docs",
103
+ class: normalizeClass({
104
+ "htw-opacity-50": !unref(renderedDoc)
105
+ })
88
106
  }, {
89
107
  default: withCtx(() => [
90
108
  _hoisted_2
91
109
  ]),
92
110
  _: 1
93
- }, 8, ["to", "matched"]),
111
+ }, 8, ["to", "matched", "class"]),
94
112
  createVNode(BaseTab, {
95
113
  to: __spreadProps(__spreadValues({}, _ctx.$route), { query: __spreadProps(__spreadValues({}, _ctx.$route.query), { tab: "events" }) }),
96
- matched: _ctx.$route.query.tab === "events"
114
+ matched: _ctx.$route.query.tab === "events",
115
+ class: normalizeClass({
116
+ "htw-opacity-50": !unref(hasEvents)
117
+ })
97
118
  }, {
98
119
  default: withCtx(() => [
99
120
  _hoisted_3,
100
121
  unref(eventsStore).unseen ? (openBlock(), createElementBlock("span", _hoisted_4, toDisplayString(unref(eventsStore).unseen <= 99 ? unref(eventsStore).unseen : "99+"), 1)) : createCommentVNode("", true)
101
122
  ]),
102
123
  _: 1
103
- }, 8, ["to", "matched"])
124
+ }, 8, ["to", "matched", "class"])
104
125
  ]),
105
126
  _: 1
106
127
  });
@@ -1,9 +1,28 @@
1
- import { createTextVNode, defineComponent, ref, watchEffect, openBlock, createElementBlock, createBlock, withCtx, createVNode, unref } from "@histoire/vendors/dist/client/vue.js";
1
+ import { createTextVNode, ref, watchEffect, defineComponent, toRefs, openBlock, createElementBlock, unref, createBlock, withCtx, createVNode } from "@histoire/vendors/dist/client/vue.js";
2
2
  import { Icon } from "@histoire/vendors/dist/client/iconify.js";
3
3
  import BaseEmpty from "../base/BaseEmpty.js";
4
4
  const _hoisted_1 = /* @__PURE__ */ createTextVNode(" No documentation available ");
5
5
  const _hoisted_2 = ["innerHTML"];
6
- const _sfc_main = /* @__PURE__ */ defineComponent({
6
+ function useStoryDoc(story) {
7
+ const renderedDoc = ref("");
8
+ watchEffect(async () => {
9
+ var _a;
10
+ let comp = (_a = story.value.file) == null ? void 0 : _a.component;
11
+ console.log(comp);
12
+ if (comp) {
13
+ if (comp.__asyncResolved) {
14
+ comp = comp.__asyncResolved;
15
+ } else if (comp.__asyncLoader) {
16
+ comp = await comp.__asyncLoader();
17
+ }
18
+ renderedDoc.value = comp.doc;
19
+ }
20
+ });
21
+ return {
22
+ renderedDoc
23
+ };
24
+ }
25
+ const _sfc_main = defineComponent({
7
26
  name: "StoryDocs",
8
27
  props: {
9
28
  story: {
@@ -13,20 +32,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
13
32
  },
14
33
  setup(__props) {
15
34
  const props = __props;
16
- const renderedDoc = ref("");
17
- watchEffect(async () => {
18
- var _a;
19
- let comp = (_a = props.story.file) == null ? void 0 : _a.component;
20
- if (comp.__asyncResolved) {
21
- comp = comp.__asyncResolved;
22
- } else if (comp.__asyncLoader) {
23
- comp = await comp.__asyncLoader();
24
- }
25
- renderedDoc.value = comp.doc;
26
- });
35
+ const { story } = toRefs(props);
36
+ const { renderedDoc } = useStoryDoc(story);
27
37
  return (_ctx, _cache) => {
28
38
  return openBlock(), createElementBlock("div", null, [
29
- !renderedDoc.value ? (openBlock(), createBlock(BaseEmpty, { key: 0 }, {
39
+ !unref(renderedDoc) ? (openBlock(), createBlock(BaseEmpty, { key: 0 }, {
30
40
  default: withCtx(() => [
31
41
  createVNode(unref(Icon), {
32
42
  icon: "carbon:document-unknown",
@@ -39,10 +49,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
39
49
  key: 1,
40
50
  class: "htw-prose dark:htw-prose-invert htw-p-4 htw-max-w-none",
41
51
  "data-test-id": "story-docs",
42
- innerHTML: renderedDoc.value
52
+ innerHTML: unref(renderedDoc)
43
53
  }, null, 8, _hoisted_2))
44
54
  ]);
45
55
  };
46
56
  }
47
57
  });
48
- export { _sfc_main as default };
58
+ export { _sfc_main as default, useStoryDoc };
@@ -46,7 +46,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
46
46
  }, {
47
47
  first: withCtx(() => [
48
48
  createElementVNode("div", _hoisted_3, [
49
- createVNode(_sfc_main$4),
49
+ createVNode(_sfc_main$4, {
50
+ story: unref(storyStore).currentStory,
51
+ variant: unref(storyStore).currentVariant
52
+ }, null, 8, ["story", "variant"]),
50
53
  (openBlock(), createBlock(resolveDynamicComponent(unref(panelContentComponent)), {
51
54
  story: unref(storyStore).currentStory,
52
55
  variant: unref(storyStore).currentVariant,
@@ -6,7 +6,7 @@ import { generateSourceCode } from "@histoire/plugin-vue/client";
6
6
  import { isDark } from "../../util/dark.js";
7
7
  import "./StorySourceCode.vue_vue_type_style_index_0_scoped_true_lang.js";
8
8
  import _export_sfc from "../../_virtual/plugin-vue_export-helper.js";
9
- const _withScopeId = (n) => (pushScopeId("data-v-8b318638"), n = n(), popScopeId(), n);
9
+ const _withScopeId = (n) => (pushScopeId("data-v-19579c98"), n = n(), popScopeId(), n);
10
10
  const _hoisted_1 = { class: "htw-bg-gray-100 dark:htw-bg-gray-800 htw-h-full htw-overflow-hidden htw-flex htw-flex-col" };
11
11
  const _hoisted_2 = {
12
12
  key: 0,
@@ -39,7 +39,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
39
39
  const highlighter = shallowRef();
40
40
  const error = ref(null);
41
41
  onMounted(async () => {
42
- setCDN("https://unpkg.com/shiki/");
42
+ setCDN("https://unpkg.com/shiki@0.10.1/");
43
43
  highlighter.value = await getHighlighter({
44
44
  langs: [
45
45
  "html",
@@ -106,5 +106,5 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
106
106
  };
107
107
  }
108
108
  });
109
- var StorySourceCode = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-8b318638"]]);
109
+ var StorySourceCode = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-19579c98"]]);
110
110
  export { StorySourceCode as default };
@@ -1,9 +1,9 @@
1
1
 
2
- .htw-base-empty[data-v-552cc113]:not(.no-animation) {
3
- -webkit-animation: htw-base-empty-552cc113 .3s 1s both;
4
- animation: htw-base-empty-552cc113 .3s 1s both;
2
+ .htw-base-empty[data-v-046d52e2]:not(.no-animation) {
3
+ -webkit-animation: htw-base-empty-046d52e2 .15s .2s both;
4
+ animation: htw-base-empty-046d52e2 .15s .2s both;
5
5
  }
6
- @-webkit-keyframes htw-base-empty-552cc113 {
6
+ @-webkit-keyframes htw-base-empty-046d52e2 {
7
7
  0% {
8
8
  opacity: 0;
9
9
  }
@@ -11,7 +11,7 @@
11
11
  opacity: 1;
12
12
  }
13
13
  }
14
- @keyframes htw-base-empty-552cc113 {
14
+ @keyframes htw-base-empty-046d52e2 {
15
15
  0% {
16
16
  opacity: 0;
17
17
  }
@@ -20,6 +20,14 @@
20
20
  }
21
21
  }
22
22
 
23
+ .bind-icon-color[data-v-356879fc] {
24
+ color: var(--578fcd62);
25
+ }
26
+
27
+ .bind-icon-color[data-v-67187ed0] {
28
+ color: var(--5e381dde);
29
+ }
30
+
23
31
  .landscape > div > .dragger[data-v-7c5763cc] {
24
32
  width: .625rem;
25
33
  }
@@ -45,14 +53,6 @@
45
53
  bottom: -.625rem;
46
54
  }
47
55
 
48
- .bind-icon-color[data-v-67187ed0] {
49
- color: var(--5e381dde);
50
- }
51
-
52
- .bind-icon-color[data-v-356879fc] {
53
- color: var(--578fcd62);
54
- }
55
-
56
56
  .bind-tree-margin[data-v-1b0b957a] {
57
57
  margin-left: var(--2101d9b6);
58
58
  }
@@ -60,31 +60,31 @@
60
60
  color: var(--0fbedaf2);
61
61
  }
62
62
 
63
- .bind-tree-padding[data-v-1a78012e] {
64
- padding-left: var(--27f98670);
65
- }
66
-
67
- .bind-icon-color[data-v-30bcb922] {
68
- color: var(--33d9fc01);
69
- }
70
-
71
63
  .bind-icon-color[data-v-2cdc2ac0] {
72
64
  color: var(--3c4190ff);
73
65
  }
74
66
 
75
- .__histoire-code-placeholder[data-v-8b318638] {
67
+ .__histoire-code-placeholder[data-v-19579c98] {
76
68
  color: inherit;
77
69
  font-size: inherit;
78
70
  }
79
71
 
80
- .bind-icon-color[data-v-7856c5b0] {
81
- color: var(--0e1c785e);
72
+ .bind-tree-padding[data-v-1a78012e] {
73
+ padding-left: var(--27f98670);
74
+ }
75
+
76
+ .bind-icon-color[data-v-30bcb922] {
77
+ color: var(--33d9fc01);
82
78
  }
83
79
 
84
80
  .bind-icon-color[data-v-307653da] {
85
81
  color: var(--5f94a358);
86
82
  }
87
83
 
84
+ .bind-icon-color[data-v-7856c5b0] {
85
+ color: var(--0e1c785e);
86
+ }
87
+
88
88
  .bind-preview-bg[data-v-bde73868] {
89
89
  background-color: var(--b797c7ca);
90
90
  }
@@ -67,7 +67,7 @@ function mapVariant(variant, existingVariant) {
67
67
  }
68
68
  } else {
69
69
  result = __spreadProps(__spreadValues({}, variant), {
70
- state: reactive({}),
70
+ state: reactive(createVariantState()),
71
71
  setupApp: null,
72
72
  slots: () => ({}),
73
73
  previewReady: false
@@ -75,4 +75,20 @@ function mapVariant(variant, existingVariant) {
75
75
  }
76
76
  return result;
77
77
  }
78
+ function createVariantState() {
79
+ const obj = {};
80
+ Object.defineProperty(obj, "_hPropState", {
81
+ value: null,
82
+ writable: true,
83
+ configurable: true,
84
+ enumerable: false
85
+ });
86
+ Object.defineProperty(obj, "_hPropDefs", {
87
+ value: null,
88
+ writable: true,
89
+ configurable: true,
90
+ enumerable: false
91
+ });
92
+ return obj;
93
+ }
78
94
  export { mapFile, mapVariant };
@@ -1,25 +1,31 @@
1
1
  import { isRef, unref } from "@histoire/vendors/dist/client/vue.js";
2
2
  const isObject = (val) => val !== null && typeof val === "object";
3
- function toRawDeep(val, seen = /* @__PURE__ */ new Set()) {
3
+ function toRawDeep(val, seen = /* @__PURE__ */ new WeakMap()) {
4
4
  const unwrappedValue = isRef(val) ? unref(val) : val;
5
- const valueType = typeof unwrappedValue;
6
- if (valueType === "symbol" || valueType === "function") {
5
+ if (typeof unwrappedValue === "symbol") {
7
6
  return unwrappedValue.toString();
8
7
  }
9
8
  if (!isObject(unwrappedValue)) {
10
9
  return unwrappedValue;
11
10
  }
12
11
  if (seen.has(unwrappedValue)) {
13
- return Array.isArray(unwrappedValue) ? [] : {};
12
+ return seen.get(unwrappedValue);
14
13
  }
15
- seen.add(unwrappedValue);
16
14
  if (Array.isArray(unwrappedValue)) {
17
- return unwrappedValue.map((value) => toRawDeep(value, seen));
15
+ const result = [];
16
+ seen.set(unwrappedValue, result);
17
+ result.push(...unwrappedValue.map((value) => toRawDeep(value, seen)));
18
+ return result;
19
+ } else {
20
+ const result = {};
21
+ seen.set(unwrappedValue, result);
22
+ toRawObject(unwrappedValue, result, seen);
23
+ return result;
18
24
  }
19
- return toRawObject(unwrappedValue, seen);
20
25
  }
21
- const toRawObject = (obj, seen = /* @__PURE__ */ new Set()) => Object.keys(obj).reduce((raw, key) => {
22
- raw[key] = toRawDeep(obj[key], seen);
23
- return raw;
24
- }, {});
26
+ const toRawObject = (obj, target, seen = /* @__PURE__ */ new WeakMap()) => {
27
+ Object.keys(obj).forEach((key) => {
28
+ target[key] = toRawDeep(obj[key], seen);
29
+ });
30
+ };
25
31
  export { toRawDeep };
@@ -6,7 +6,7 @@
6
6
 
7
7
  <style scoped>
8
8
  .htw-base-empty:not(.no-animation) {
9
- animation: htw-base-empty .3s 1s both;
9
+ animation: htw-base-empty .15s .2s both;
10
10
  }
11
11
 
12
12
  @keyframes htw-base-empty {
@@ -1,10 +1,23 @@
1
1
  <script lang="ts" setup>
2
+ import { computed, toRefs } from 'vue'
2
3
  import BaseTab from '../base/BaseTab.vue'
3
4
  import { useEventsStore } from '../../stores/events'
5
+ import type { Story, Variant } from '../../types'
4
6
  import BaseOverflowMenu from '../base/BaseOverflowMenu.vue'
5
7
  import BaseOverflowTab from '../base/BaseOverflowTab.vue'
8
+ import { useStoryDoc } from './StoryDocs.vue'
9
+
10
+ const props = defineProps<{
11
+ story: Story
12
+ variant: Variant
13
+ }>()
14
+
15
+ const { story } = toRefs(props)
16
+
17
+ const { renderedDoc } = useStoryDoc(story)
6
18
 
7
19
  const eventsStore = useEventsStore()
20
+ const hasEvents = computed(() => eventsStore.events.length)
8
21
  </script>
9
22
 
10
23
  <template>
@@ -18,12 +31,18 @@ const eventsStore = useEventsStore()
18
31
  <BaseTab
19
32
  :to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
20
33
  :matched="$route.query.tab === 'docs'"
34
+ :class="{
35
+ 'htw-opacity-50': !renderedDoc,
36
+ }"
21
37
  >
22
38
  Docs
23
39
  </BaseTab>
24
40
  <BaseTab
25
41
  :to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
26
42
  :matched="$route.query.tab === 'events'"
43
+ :class="{
44
+ 'htw-opacity-50': !hasEvents,
45
+ }"
27
46
  >
28
47
  Events
29
48
  <span
@@ -44,19 +63,25 @@ const eventsStore = useEventsStore()
44
63
  <BaseOverflowTab
45
64
  :to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
46
65
  :matched="$route.query.tab === 'docs'"
66
+ :class="{
67
+ 'opacity-50': !renderedDoc,
68
+ }"
47
69
  >
48
70
  Docs
49
71
  </BaseOverflowTab>
50
72
  <BaseOverflowTab
51
73
  :to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
52
74
  :matched="$route.query.tab === 'events'"
75
+ :class="{
76
+ 'htw-opacity-50': !hasEvents,
77
+ }"
53
78
  >
54
79
  Events
55
80
  <span
56
81
  v-if="eventsStore.unseen"
57
82
  class="htw-text-center htw-text-xs htw-mx-1 htw-px-0.5 htw-h-4 htw-min-w-4 htw-rounded-full active htw-bg-primary-500 htw-text-white dark:htw-text-black"
58
83
  >
59
- {{ eventsStore.unseen <=99 ? eventsStore.unseen : "99+" }}
84
+ {{ eventsStore.unseen <= 99 ? eventsStore.unseen : "99+" }}
60
85
  </span>
61
86
  </BaseOverflowTab>
62
87
  </template>
@@ -1,7 +1,31 @@
1
+ <script lang="ts">
2
+ import { PropType, Ref, ref, toRefs, watchEffect } from 'vue'
3
+ import type { Story } from '../../types'
4
+
5
+ export function useStoryDoc (story: Ref<Story>) {
6
+ const renderedDoc = ref('')
7
+
8
+ watchEffect(async () => {
9
+ let comp = story.value.file?.component
10
+ console.log(comp)
11
+ if (comp) {
12
+ if (comp.__asyncResolved) {
13
+ comp = comp.__asyncResolved
14
+ } else if (comp.__asyncLoader) {
15
+ comp = await comp.__asyncLoader()
16
+ }
17
+ renderedDoc.value = comp.doc
18
+ }
19
+ })
20
+
21
+ return {
22
+ renderedDoc,
23
+ }
24
+ }
25
+ </script>
26
+
1
27
  <script lang="ts" setup>
2
- import { PropType, ref, watchEffect } from 'vue'
3
28
  import { Icon } from '@iconify/vue'
4
- import type { Story } from '../../types'
5
29
  import BaseEmpty from '../base/BaseEmpty.vue'
6
30
 
7
31
  const props = defineProps({
@@ -11,17 +35,9 @@ const props = defineProps({
11
35
  },
12
36
  })
13
37
 
14
- const renderedDoc = ref('')
38
+ const { story } = toRefs(props)
15
39
 
16
- watchEffect(async () => {
17
- let comp = props.story.file?.component
18
- if (comp.__asyncResolved) {
19
- comp = comp.__asyncResolved
20
- } else if (comp.__asyncLoader) {
21
- comp = await comp.__asyncLoader()
22
- }
23
- renderedDoc.value = comp.doc
24
- })
40
+ const { renderedDoc } = useStoryDoc(story)
25
41
  </script>
26
42
 
27
43
  <template>
@@ -45,7 +45,10 @@ const panelContentComponent = computed(() => {
45
45
  >
46
46
  <template #first>
47
47
  <div class="htw-flex htw-flex-col htw-h-full">
48
- <PaneTabs />
48
+ <PaneTabs
49
+ :story="storyStore.currentStory"
50
+ :variant="storyStore.currentVariant"
51
+ />
49
52
 
50
53
  <component
51
54
  :is="panelContentComponent"
@@ -19,7 +19,7 @@ const highlighter = shallowRef<Highlighter>()
19
19
  const error = ref<string>(null)
20
20
 
21
21
  onMounted(async () => {
22
- setCDN('https://unpkg.com/shiki/')
22
+ setCDN('https://unpkg.com/shiki@0.10.1/')
23
23
  highlighter.value = await getHighlighter({
24
24
  langs: [
25
25
  'html',
@@ -59,7 +59,7 @@ export function mapVariant(variant, existingVariant) {
59
59
  // Create
60
60
  result = {
61
61
  ...variant,
62
- state: _reactive({}),
62
+ state: _reactive(createVariantState()),
63
63
  setupApp: null,
64
64
  slots: () => ({}),
65
65
  previewReady: false,
@@ -67,3 +67,19 @@ export function mapVariant(variant, existingVariant) {
67
67
  }
68
68
  return result;
69
69
  }
70
+ function createVariantState() {
71
+ const obj = {};
72
+ Object.defineProperty(obj, '_hPropState', {
73
+ value: null,
74
+ writable: true,
75
+ configurable: true,
76
+ enumerable: false,
77
+ });
78
+ Object.defineProperty(obj, '_hPropDefs', {
79
+ value: null,
80
+ writable: true,
81
+ configurable: true,
82
+ enumerable: false,
83
+ });
84
+ return obj;
85
+ }
@@ -1 +1 @@
1
- export declare function toRawDeep(val: any, seen?: Set<unknown>): any;
1
+ export declare function toRawDeep(val: any, seen?: WeakMap<object, any>): any;
@@ -1,24 +1,31 @@
1
1
  import { unref, isRef } from 'vue';
2
2
  const isObject = (val) => val !== null && typeof val === 'object';
3
- export function toRawDeep(val, seen = new Set()) {
3
+ export function toRawDeep(val, seen = new WeakMap()) {
4
4
  const unwrappedValue = isRef(val) ? unref(val) : val;
5
- const valueType = typeof unwrappedValue;
6
- if (valueType === 'symbol' || valueType === 'function') {
5
+ if (typeof unwrappedValue === 'symbol') {
7
6
  return unwrappedValue.toString();
8
7
  }
9
8
  if (!isObject(unwrappedValue)) {
10
9
  return unwrappedValue;
11
10
  }
12
11
  if (seen.has(unwrappedValue)) {
13
- return Array.isArray(unwrappedValue) ? [] : {};
12
+ return seen.get(unwrappedValue);
14
13
  }
15
- seen.add(unwrappedValue);
16
14
  if (Array.isArray(unwrappedValue)) {
17
- return unwrappedValue.map(value => toRawDeep(value, seen));
15
+ const result = [];
16
+ seen.set(unwrappedValue, result);
17
+ result.push(...unwrappedValue.map(value => toRawDeep(value, seen)));
18
+ return result;
19
+ }
20
+ else {
21
+ const result = {};
22
+ seen.set(unwrappedValue, result);
23
+ toRawObject(unwrappedValue, result, seen);
24
+ return result;
18
25
  }
19
- return toRawObject(unwrappedValue, seen);
20
26
  }
21
- const toRawObject = (obj, seen = new Set()) => Object.keys(obj).reduce((raw, key) => {
22
- raw[key] = toRawDeep(obj[key], seen);
23
- return raw;
24
- }, {});
27
+ const toRawObject = (obj, target, seen = new WeakMap()) => {
28
+ Object.keys(obj).forEach((key) => {
29
+ target[key] = toRawDeep(obj[key], seen);
30
+ });
31
+ };
@@ -95,10 +95,20 @@ export function getDefaultConfig() {
95
95
  ],
96
96
  sandboxDarkClass: 'dark',
97
97
  routerMode: 'history',
98
- vite: {
99
- build: {
100
- lib: false,
101
- },
98
+ vite: (config) => {
99
+ // Remove vite:legacy plugins https://github.com/histoire-dev/histoire/issues/156
100
+ const index = config.plugins?.findIndex(plugin => Array.isArray(plugin) &&
101
+ typeof plugin[0] === 'object' &&
102
+ !Array.isArray(plugin[0]) &&
103
+ plugin[0].name.startsWith('vite:legacy'));
104
+ if (index !== -1) {
105
+ config.plugins?.splice(index, 1);
106
+ }
107
+ return {
108
+ build: {
109
+ lib: false,
110
+ },
111
+ };
102
112
  },
103
113
  };
104
114
  }
@@ -145,7 +155,16 @@ export async function loadConfigFile(configFile) {
145
155
  }
146
156
  export const mergeConfig = createDefu((obj, key, value) => {
147
157
  if (obj[key] && key === 'vite') {
148
- obj[key] = mergeViteConfig(obj[key], value);
158
+ const initialValue = obj[key];
159
+ if (typeof value === 'function') {
160
+ obj[key] = async (...args) => {
161
+ const result = await value(...args);
162
+ return mergeViteConfig(initialValue, result);
163
+ };
164
+ }
165
+ else {
166
+ obj[key] = mergeViteConfig(initialValue, value);
167
+ }
149
168
  return true;
150
169
  }
151
170
  if (obj[key] && key === 'plugins') {
package/dist/node/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'module';
2
2
  import { relative, dirname, resolve } from 'pathe';
3
- import { resolveConfig as resolveViteConfigInternal, mergeConfig as mergeViteConfig, } from 'vite';
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, DIST_PATH, TEMP_PATH } from './alias.js';
6
6
  import { notifyStoryChange } from './stories.js';
@@ -48,7 +48,8 @@ async function mergeHistoireViteConfig(viteConfig, ctx) {
48
48
  }
49
49
  export async function getViteConfigWithPlugins(isServer, ctx) {
50
50
  const resolvedViteConfig = await resolveViteConfig(ctx);
51
- const inlineConfig = await mergeHistoireViteConfig({}, ctx);
51
+ const userViteConfig = await loadViteConfigFromFile({ command: ctx.mode === 'dev' ? 'serve' : 'build', mode: ctx.mode });
52
+ const inlineConfig = await mergeHistoireViteConfig(userViteConfig?.config ?? {}, ctx);
52
53
  const plugins = [];
53
54
  plugins.push({
54
55
  name: 'histoire-vite-plugin',
@@ -319,6 +320,7 @@ if (import.meta.hot) {
319
320
  });
320
321
  }
321
322
  return mergeViteConfig(inlineConfig, {
323
+ configFile: false,
322
324
  plugins,
323
325
  });
324
326
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "histoire",
3
- "version": "0.8.1",
3
+ "version": "0.8.4",
4
4
  "description": "A fast story book powered by Vite",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,10 +33,10 @@
33
33
  "histoire": "./bin.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@histoire/controls": "^0.8.1",
37
- "@histoire/plugin-vue": "^0.8.1",
38
- "@histoire/shared": "^0.8.1",
39
- "@histoire/vendors": "^0.8.1",
36
+ "@histoire/controls": "^0.8.4",
37
+ "@histoire/plugin-vue": "^0.8.4",
38
+ "@histoire/shared": "^0.8.4",
39
+ "@histoire/vendors": "^0.8.4",
40
40
  "@types/flexsearch": "^0.7.3",
41
41
  "@types/markdown-it": "^12.2.3",
42
42
  "birpc": "^0.1.1",
@@ -57,7 +57,7 @@
57
57
  "pathe": "^0.2.0",
58
58
  "picocolors": "^1.0.0",
59
59
  "sade": "^1.8.1",
60
- "shiki": "^0.10.1",
60
+ "shiki": "0.10.1",
61
61
  "sirv": "^2.0.2",
62
62
  "tinypool": "^0.1.2",
63
63
  "vite-node": "0.12.1"
@@ -6,7 +6,7 @@
6
6
 
7
7
  <style scoped>
8
8
  .htw-base-empty:not(.no-animation) {
9
- animation: htw-base-empty .3s 1s both;
9
+ animation: htw-base-empty .15s .2s both;
10
10
  }
11
11
 
12
12
  @keyframes htw-base-empty {
@@ -1,10 +1,23 @@
1
1
  <script lang="ts" setup>
2
+ import { computed, toRefs } from 'vue'
2
3
  import BaseTab from '../base/BaseTab.vue'
3
4
  import { useEventsStore } from '../../stores/events'
5
+ import type { Story, Variant } from '../../types'
4
6
  import BaseOverflowMenu from '../base/BaseOverflowMenu.vue'
5
7
  import BaseOverflowTab from '../base/BaseOverflowTab.vue'
8
+ import { useStoryDoc } from './StoryDocs.vue'
9
+
10
+ const props = defineProps<{
11
+ story: Story
12
+ variant: Variant
13
+ }>()
14
+
15
+ const { story } = toRefs(props)
16
+
17
+ const { renderedDoc } = useStoryDoc(story)
6
18
 
7
19
  const eventsStore = useEventsStore()
20
+ const hasEvents = computed(() => eventsStore.events.length)
8
21
  </script>
9
22
 
10
23
  <template>
@@ -18,12 +31,18 @@ const eventsStore = useEventsStore()
18
31
  <BaseTab
19
32
  :to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
20
33
  :matched="$route.query.tab === 'docs'"
34
+ :class="{
35
+ 'htw-opacity-50': !renderedDoc,
36
+ }"
21
37
  >
22
38
  Docs
23
39
  </BaseTab>
24
40
  <BaseTab
25
41
  :to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
26
42
  :matched="$route.query.tab === 'events'"
43
+ :class="{
44
+ 'htw-opacity-50': !hasEvents,
45
+ }"
27
46
  >
28
47
  Events
29
48
  <span
@@ -44,19 +63,25 @@ const eventsStore = useEventsStore()
44
63
  <BaseOverflowTab
45
64
  :to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
46
65
  :matched="$route.query.tab === 'docs'"
66
+ :class="{
67
+ 'opacity-50': !renderedDoc,
68
+ }"
47
69
  >
48
70
  Docs
49
71
  </BaseOverflowTab>
50
72
  <BaseOverflowTab
51
73
  :to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
52
74
  :matched="$route.query.tab === 'events'"
75
+ :class="{
76
+ 'htw-opacity-50': !hasEvents,
77
+ }"
53
78
  >
54
79
  Events
55
80
  <span
56
81
  v-if="eventsStore.unseen"
57
82
  class="htw-text-center htw-text-xs htw-mx-1 htw-px-0.5 htw-h-4 htw-min-w-4 htw-rounded-full active htw-bg-primary-500 htw-text-white dark:htw-text-black"
58
83
  >
59
- {{ eventsStore.unseen <=99 ? eventsStore.unseen : "99+" }}
84
+ {{ eventsStore.unseen <= 99 ? eventsStore.unseen : "99+" }}
60
85
  </span>
61
86
  </BaseOverflowTab>
62
87
  </template>
@@ -1,7 +1,31 @@
1
+ <script lang="ts">
2
+ import { PropType, Ref, ref, toRefs, watchEffect } from 'vue'
3
+ import type { Story } from '../../types'
4
+
5
+ export function useStoryDoc (story: Ref<Story>) {
6
+ const renderedDoc = ref('')
7
+
8
+ watchEffect(async () => {
9
+ let comp = story.value.file?.component
10
+ console.log(comp)
11
+ if (comp) {
12
+ if (comp.__asyncResolved) {
13
+ comp = comp.__asyncResolved
14
+ } else if (comp.__asyncLoader) {
15
+ comp = await comp.__asyncLoader()
16
+ }
17
+ renderedDoc.value = comp.doc
18
+ }
19
+ })
20
+
21
+ return {
22
+ renderedDoc,
23
+ }
24
+ }
25
+ </script>
26
+
1
27
  <script lang="ts" setup>
2
- import { PropType, ref, watchEffect } from 'vue'
3
28
  import { Icon } from '@iconify/vue'
4
- import type { Story } from '../../types'
5
29
  import BaseEmpty from '../base/BaseEmpty.vue'
6
30
 
7
31
  const props = defineProps({
@@ -11,17 +35,9 @@ const props = defineProps({
11
35
  },
12
36
  })
13
37
 
14
- const renderedDoc = ref('')
38
+ const { story } = toRefs(props)
15
39
 
16
- watchEffect(async () => {
17
- let comp = props.story.file?.component
18
- if (comp.__asyncResolved) {
19
- comp = comp.__asyncResolved
20
- } else if (comp.__asyncLoader) {
21
- comp = await comp.__asyncLoader()
22
- }
23
- renderedDoc.value = comp.doc
24
- })
40
+ const { renderedDoc } = useStoryDoc(story)
25
41
  </script>
26
42
 
27
43
  <template>
@@ -45,7 +45,10 @@ const panelContentComponent = computed(() => {
45
45
  >
46
46
  <template #first>
47
47
  <div class="htw-flex htw-flex-col htw-h-full">
48
- <PaneTabs />
48
+ <PaneTabs
49
+ :story="storyStore.currentStory"
50
+ :variant="storyStore.currentVariant"
51
+ />
49
52
 
50
53
  <component
51
54
  :is="panelContentComponent"
@@ -19,7 +19,7 @@ const highlighter = shallowRef<Highlighter>()
19
19
  const error = ref<string>(null)
20
20
 
21
21
  onMounted(async () => {
22
- setCDN('https://unpkg.com/shiki/')
22
+ setCDN('https://unpkg.com/shiki@0.10.1/')
23
23
  highlighter.value = await getHighlighter({
24
24
  langs: [
25
25
  'html',
@@ -63,7 +63,7 @@ export function mapVariant (variant: Variant, existingVariant?: Variant): Varian
63
63
  // Create
64
64
  result = {
65
65
  ...variant,
66
- state: _reactive({}),
66
+ state: _reactive(createVariantState()),
67
67
  setupApp: null,
68
68
  slots: () => ({}),
69
69
  previewReady: false,
@@ -72,3 +72,20 @@ export function mapVariant (variant: Variant, existingVariant?: Variant): Varian
72
72
 
73
73
  return result
74
74
  }
75
+
76
+ function createVariantState () {
77
+ const obj = {}
78
+ Object.defineProperty(obj, '_hPropState', {
79
+ value: null,
80
+ writable: true,
81
+ configurable: true,
82
+ enumerable: false,
83
+ })
84
+ Object.defineProperty(obj, '_hPropDefs', {
85
+ value: null,
86
+ writable: true,
87
+ configurable: true,
88
+ enumerable: false,
89
+ })
90
+ return obj
91
+ }
@@ -2,11 +2,10 @@ import { unref, isRef } from 'vue'
2
2
 
3
3
  const isObject = (val) => val !== null && typeof val === 'object'
4
4
 
5
- export function toRawDeep (val, seen = new Set()) {
5
+ export function toRawDeep (val, seen = new WeakMap()) {
6
6
  const unwrappedValue = isRef(val) ? unref(val) : val
7
- const valueType = typeof unwrappedValue
8
7
 
9
- if (valueType === 'symbol' || valueType === 'function') {
8
+ if (typeof unwrappedValue === 'symbol') {
10
9
  return unwrappedValue.toString()
11
10
  }
12
11
 
@@ -15,19 +14,24 @@ export function toRawDeep (val, seen = new Set()) {
15
14
  }
16
15
 
17
16
  if (seen.has(unwrappedValue)) {
18
- return Array.isArray(unwrappedValue) ? [] : {}
17
+ return seen.get(unwrappedValue)
19
18
  }
20
19
 
21
- seen.add(unwrappedValue)
22
-
23
20
  if (Array.isArray(unwrappedValue)) {
24
- return unwrappedValue.map(value => toRawDeep(value, seen))
21
+ const result = []
22
+ seen.set(unwrappedValue, result)
23
+ result.push(...unwrappedValue.map(value => toRawDeep(value, seen)))
24
+ return result
25
+ } else {
26
+ const result = {}
27
+ seen.set(unwrappedValue, result)
28
+ toRawObject(unwrappedValue, result, seen)
29
+ return result
25
30
  }
26
-
27
- return toRawObject(unwrappedValue, seen)
28
31
  }
29
32
 
30
- const toRawObject = (obj: Record<any, any>, seen = new Set()) => Object.keys(obj).reduce((raw, key) => {
31
- raw[key] = toRawDeep(obj[key], seen)
32
- return raw
33
- }, {})
33
+ const toRawObject = (obj: Record<any, any>, target: Record<any, any>, seen = new WeakMap()) => {
34
+ Object.keys(obj).forEach((key) => {
35
+ target[key] = toRawDeep(obj[key], seen)
36
+ })
37
+ }
@@ -271,10 +271,21 @@ export function getDefaultConfig (): HistoireConfig {
271
271
  ],
272
272
  sandboxDarkClass: 'dark',
273
273
  routerMode: 'history',
274
- vite: {
275
- build: {
276
- lib: false,
277
- },
274
+ vite: (config) => {
275
+ // Remove vite:legacy plugins https://github.com/histoire-dev/histoire/issues/156
276
+ const index = config.plugins?.findIndex(plugin => Array.isArray(plugin) &&
277
+ typeof plugin[0] === 'object' &&
278
+ !Array.isArray(plugin[0]) &&
279
+ plugin[0].name.startsWith('vite:legacy'))
280
+ if (index !== -1) {
281
+ config.plugins?.splice(index, 1)
282
+ }
283
+
284
+ return {
285
+ build: {
286
+ lib: false,
287
+ },
288
+ }
278
289
  },
279
290
  }
280
291
  }
@@ -324,7 +335,15 @@ export async function loadConfigFile (configFile: string): Promise<Partial<Histo
324
335
 
325
336
  export const mergeConfig = createDefu((obj: any, key, value) => {
326
337
  if (obj[key] && key === 'vite') {
327
- obj[key] = mergeViteConfig(obj[key], value)
338
+ const initialValue = obj[key]
339
+ if (typeof value === 'function') {
340
+ obj[key] = async (...args) => {
341
+ const result = await value(...args)
342
+ return mergeViteConfig(initialValue, result)
343
+ }
344
+ } else {
345
+ obj[key] = mergeViteConfig(initialValue, value)
346
+ }
328
347
  return true
329
348
  }
330
349
 
package/src/node/vite.ts CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  ResolvedConfig,
8
8
  InlineConfig,
9
9
  mergeConfig as mergeViteConfig,
10
+ loadConfigFromFile as loadViteConfigFromFile,
10
11
  } from 'vite'
11
12
  import { lookup as lookupMime } from 'mrmime'
12
13
  import { APP_PATH, DIST_PATH, TEMP_PATH } from './alias.js'
@@ -62,7 +63,9 @@ async function mergeHistoireViteConfig (viteConfig: InlineConfig, ctx: Context)
62
63
  export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context): Promise<InlineConfig> {
63
64
  const resolvedViteConfig = await resolveViteConfig(ctx)
64
65
 
65
- const inlineConfig = await mergeHistoireViteConfig({}, ctx)
66
+ const userViteConfig = await loadViteConfigFromFile({ command: ctx.mode === 'dev' ? 'serve' : 'build', mode: ctx.mode })
67
+
68
+ const inlineConfig = await mergeHistoireViteConfig(userViteConfig?.config ?? {}, ctx)
66
69
  const plugins: VitePlugin[] = []
67
70
 
68
71
  plugins.push({
@@ -343,6 +346,7 @@ if (import.meta.hot) {
343
346
  }
344
347
 
345
348
  return mergeViteConfig(inlineConfig, {
349
+ configFile: false,
346
350
  plugins,
347
351
  }) as InlineConfig
348
352
  }