@histoire/app 0.9.5 → 0.10.1

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 (29) hide show
  1. package/dist/app/style/sandbox.css +1 -1
  2. package/dist/bundled/App.js +4 -3
  3. package/dist/bundled/components/panel/StatePresets.js +1 -1
  4. package/dist/bundled/components/panel/StoryControls.js +12 -5
  5. package/dist/bundled/components/panel/StoryDocs.js +7 -0
  6. package/dist/bundled/components/panel/StorySourceCode.js +16 -8
  7. package/dist/bundled/components/search/SearchPane.js +12 -6
  8. package/dist/bundled/components/story/GenericMountStory.js +7 -3
  9. package/dist/bundled/components/story/GenericRenderStory.js +4 -0
  10. package/dist/bundled/components/story/StoryVariantGridItem.js +8 -6
  11. package/dist/bundled/components/story/StoryVariantSinglePreviewNative.js +3 -1
  12. package/dist/bundled/components/story/StoryVariantSinglePreviewRemote.js +3 -0
  13. package/dist/bundled/sandbox.js +1 -0
  14. package/dist/bundled/style.css +3 -3
  15. package/package.json +4 -4
  16. package/src/app/App.vue +1 -0
  17. package/src/app/components/panel/StatePresets.vue +1 -1
  18. package/src/app/components/panel/StoryControls.vue +12 -2
  19. package/src/app/components/panel/StoryDocs.vue +12 -0
  20. package/src/app/components/panel/StorySourceCode.vue +9 -6
  21. package/src/app/components/search/SearchPane.vue +14 -4
  22. package/src/app/components/story/GenericMountStory.vue +7 -0
  23. package/src/app/components/story/GenericRenderStory.vue +6 -0
  24. package/src/app/components/story/StoryVariantGridItem.vue +2 -0
  25. package/src/app/components/story/StoryVariantSinglePreviewNative.vue +2 -0
  26. package/src/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -0
  27. package/src/app/sandbox.ts +1 -0
  28. package/src/app/style/sandbox.css +1 -1
  29. package/src/app/types.ts +3 -0
@@ -10,7 +10,7 @@ body {
10
10
  }
11
11
 
12
12
  html {
13
- font-size: .875rem;
13
+ font-size: 1rem;
14
14
  font-family: 'Lato', sans-serif;
15
15
  }
16
16
 
@@ -1,4 +1,4 @@
1
- import { defineComponent, ref, computed, watch, onMounted, resolveComponent, openBlock, createElementBlock, Fragment, unref, createVNode, createCommentVNode, createElementVNode, normalizeStyle, createBlock, withCtx, Transition } from "@histoire/vendors/vue";
1
+ import { defineComponent, ref, computed, watch, onMounted, resolveComponent, openBlock, createElementBlock, Fragment, unref, createBlock, createCommentVNode, createElementVNode, normalizeStyle, createVNode, withCtx, Transition } from "@histoire/vendors/vue";
2
2
  import { files, tree, onUpdate } from "$histoire-stories";
3
3
  import _sfc_main$3 from "./components/tree/StoryList.js";
4
4
  import BaseSplitPane from "./components/base/BaseSplitPane.js";
@@ -84,9 +84,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
84
84
  const _component_RouterView = resolveComponent("RouterView");
85
85
  return openBlock(), createElementBlock(Fragment, null, [
86
86
  unref(storyStore).currentStory ? (openBlock(), createElementBlock("div", _hoisted_1, [
87
- createVNode(_sfc_main$1, {
87
+ (openBlock(), createBlock(_sfc_main$1, {
88
+ key: unref(storyStore).currentStory.id,
88
89
  story: unref(storyStore).currentStory
89
- }, null, 8, ["story"])
90
+ }, null, 8, ["story"]))
90
91
  ])) : createCommentVNode("", true),
91
92
  createElementVNode("div", {
92
93
  class: "htw-h-screen htw-bg-white dark:htw-bg-gray-700 dark:htw-text-gray-100",
@@ -48,7 +48,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
48
48
  if (id === DEFAULT_ID) {
49
49
  resetState();
50
50
  } else if (presetStates.value.has(id)) {
51
- applyState(props.variant.state, clone(presetStates.value.get(id).state));
51
+ applyState(props.variant.state, clone(toRawDeep(presetStates.value.get(id).state)));
52
52
  }
53
53
  }
54
54
  onMounted(() => {
@@ -1,4 +1,4 @@
1
- import { createElementVNode, defineComponent, openBlock, createElementBlock, createVNode, createBlock, withCtx, unref, createCommentVNode, Fragment, renderList } from "@histoire/vendors/vue";
1
+ import { createElementVNode, defineComponent, ref, watch, openBlock, createElementBlock, createBlock, createCommentVNode, withCtx, createVNode, unref, Fragment, renderList } from "@histoire/vendors/vue";
2
2
  import { Icon } from "@histoire/vendors/iconify";
3
3
  import _sfc_main$2 from "../story/GenericRenderStory.js";
4
4
  import BaseEmpty from "../base/BaseEmpty.js";
@@ -24,21 +24,28 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
24
24
  }
25
25
  },
26
26
  setup(__props) {
27
+ const props = __props;
28
+ const ready = ref(false);
29
+ watch(() => props.variant, () => {
30
+ ready.value = false;
31
+ });
27
32
  return (_ctx, _cache) => {
28
33
  var _a, _b, _c, _d;
29
34
  return openBlock(), createElementBlock("div", _hoisted_1, [
30
35
  createElementVNode("div", _hoisted_2, [
31
- createVNode(_sfc_main$1, {
36
+ ready.value ? (openBlock(), createBlock(_sfc_main$1, {
37
+ key: 0,
32
38
  story: __props.story,
33
39
  variant: __props.variant
34
- }, null, 8, ["story", "variant"])
40
+ }, null, 8, ["story", "variant"])) : createCommentVNode("", true)
35
41
  ]),
36
42
  __props.variant.slots().controls || __props.story.slots().controls ? (openBlock(), createBlock(_sfc_main$2, {
37
- key: 0,
43
+ key: `${__props.story.id}-${__props.variant.id}`,
38
44
  "slot-name": "controls",
39
45
  variant: __props.variant,
40
46
  story: __props.story,
41
- class: "htw-flex-none"
47
+ class: "htw-flex-none",
48
+ onReady: _cache[0] || (_cache[0] = ($event) => ready.value = true)
42
49
  }, null, 8, ["variant", "story"])) : !((_b = (_a = __props.variant.state) == null ? void 0 : _a._hPropDefs) == null ? void 0 : _b.length) ? (openBlock(), createBlock(BaseEmpty, { key: 1 }, {
43
50
  default: withCtx(() => [
44
51
  createVNode(unref(Icon), {
@@ -1,12 +1,19 @@
1
1
  import { createTextVNode, ref, watchEffect, defineComponent, toRefs, openBlock, createElementBlock, unref, createBlock, withCtx, createVNode } from "@histoire/vendors/vue";
2
2
  import { Icon } from "@histoire/vendors/iconify";
3
3
  import BaseEmpty from "../base/BaseEmpty.js";
4
+ import { markdownFiles } from "virtual:$histoire-markdown-files";
4
5
  const _hoisted_1 = /* @__PURE__ */ createTextVNode(" No documentation available ");
5
6
  const _hoisted_2 = ["innerHTML"];
6
7
  function useStoryDoc(story) {
7
8
  const renderedDoc = ref("");
8
9
  watchEffect(async () => {
9
10
  var _a;
11
+ const mdKey = story.value.file.filePath.replace(/\.(\w*?)$/, ".md");
12
+ if (markdownFiles[mdKey]) {
13
+ const md = await markdownFiles[mdKey]();
14
+ renderedDoc.value = md.html;
15
+ return;
16
+ }
10
17
  let comp = (_a = story.value.file) == null ? void 0 : _a.component;
11
18
  if (comp) {
12
19
  if (comp.__asyncResolved) {
@@ -1,12 +1,14 @@
1
- import { pushScopeId, popScopeId, createElementVNode, defineComponent, ref, watchEffect, markRaw, shallowRef, onMounted, watch, computed, openBlock, createElementBlock, createVNode, unref, createCommentVNode, toDisplayString } from "@histoire/vendors/vue";
1
+ import { pushScopeId, popScopeId, createElementVNode, defineComponent, ref, watchEffect, markRaw, shallowRef, onMounted, watch, computed, openBlock, createElementBlock, createVNode, unref, createCommentVNode, toDisplayString, createBlock, withCtx } from "@histoire/vendors/vue";
2
+ import { Icon } from "@histoire/vendors/iconify";
2
3
  import { setCDN, getHighlighter } from "shiki";
3
4
  import { HstCopyIcon } from "@histoire/controls";
4
5
  import { unindent } from "@histoire/shared";
5
6
  import { clientSupportPlugins } from "virtual:$histoire-support-plugins-client";
6
7
  import { isDark } from "../../util/dark.js";
8
+ import BaseEmpty from "../base/BaseEmpty.js";
7
9
  import "./StorySourceCode.vue_vue_type_style_index_0_scoped_true_lang.js";
8
10
  import _export_sfc from "../../_virtual/plugin-vue_export-helper.js";
9
- const _withScopeId = (n) => (pushScopeId("data-v-ed3a82aa"), n = n(), popScopeId(), n);
11
+ const _withScopeId = (n) => (pushScopeId("data-v-68151bff"), n = n(), popScopeId(), n);
10
12
  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
13
  const _hoisted_2 = {
12
14
  key: 0,
@@ -18,10 +20,7 @@ const _hoisted_5 = {
18
20
  key: 1,
19
21
  class: "htw-text-red-500 htw-h-full htw-p-2 htw-overflow-auto htw-font-mono htw-text-sm"
20
22
  };
21
- const _hoisted_6 = {
22
- key: 2,
23
- class: "htw-opacity-50 htw-p-4"
24
- };
23
+ const _hoisted_6 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ createElementVNode("span", null, "Not available", -1));
25
24
  const _hoisted_7 = ["value"];
26
25
  const _hoisted_8 = {
27
26
  key: 4,
@@ -103,7 +102,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
103
102
  class: "htw-flex-none"
104
103
  }, null, 8, ["content"])
105
104
  ])) : createCommentVNode("", true),
106
- error.value ? (openBlock(), createElementBlock("div", _hoisted_5, " Error: " + toDisplayString(error.value), 1)) : !sourceCode.value ? (openBlock(), createElementBlock("i", _hoisted_6, " Not available ")) : !unref(sourceHtml) ? (openBlock(), createElementBlock("textarea", {
105
+ error.value ? (openBlock(), createElementBlock("div", _hoisted_5, " Error: " + toDisplayString(error.value), 1)) : !sourceCode.value ? (openBlock(), createBlock(BaseEmpty, { key: 2 }, {
106
+ default: withCtx(() => [
107
+ createVNode(unref(Icon), {
108
+ icon: "carbon:code-hide",
109
+ class: "htw-w-8 htw-h-8 htw-opacity-50 htw-mb-6"
110
+ }),
111
+ _hoisted_6
112
+ ]),
113
+ _: 1
114
+ })) : !unref(sourceHtml) ? (openBlock(), createElementBlock("textarea", {
107
115
  key: 3,
108
116
  class: "__histoire-code-placeholder htw-w-full htw-h-full htw-p-4 htw-outline-none htw-bg-transparent htw-resize-none htw-m-0",
109
117
  value: sourceCode.value,
@@ -119,5 +127,5 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
119
127
  };
120
128
  }
121
129
  });
122
- var StorySourceCode = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ed3a82aa"]]);
130
+ var StorySourceCode = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-68151bff"]]);
123
131
  export { StorySourceCode as default };
@@ -135,7 +135,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
135
135
  continue;
136
136
  switch (idMapData.kind) {
137
137
  case "story": {
138
- list.push(storyResultFactory(storyStore.getStoryById(idMapData.id), rank));
138
+ list.push(storyResultFactory(storyStore.getStoryById(idMapData.id), rank, "docs"));
139
139
  rank++;
140
140
  break;
141
141
  }
@@ -146,7 +146,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
146
146
  }
147
147
  }
148
148
  watch(rateLimitedSearch, searchOnDocField);
149
- function storyResultFactory(story, rank) {
149
+ function storyResultFactory(story, rank, type = "title") {
150
150
  return {
151
151
  kind: "story",
152
152
  rank,
@@ -156,14 +156,18 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
156
156
  name: "story",
157
157
  params: {
158
158
  storyId: story.id
159
+ },
160
+ query: {
161
+ ...type === "docs" ? { tab: "docs" } : {}
159
162
  }
160
163
  },
161
164
  path: story.file.path.slice(0, -1),
162
165
  icon: story.icon,
163
- iconColor: story.iconColor
166
+ iconColor: story.iconColor,
167
+ type
164
168
  };
165
169
  }
166
- function variantResultFactory(story, variant, rank) {
170
+ function variantResultFactory(story, variant, rank, type = "title") {
167
171
  var _a;
168
172
  return {
169
173
  kind: "variant",
@@ -176,12 +180,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
176
180
  storyId: story.id
177
181
  },
178
182
  query: {
179
- variantId: variant.id
183
+ variantId: variant.id,
184
+ ...type === "docs" ? { tab: "docs" } : {}
180
185
  }
181
186
  },
182
187
  path: [...(_a = story.file.path) != null ? _a : [], story.title],
183
188
  icon: variant.icon,
184
- iconColor: variant.iconColor
189
+ iconColor: variant.iconColor,
190
+ type
185
191
  };
186
192
  }
187
193
  const results = computed(() => {
@@ -1,6 +1,10 @@
1
- import { defineComponent, ref, watchEffect, markRaw, openBlock, createBlock, resolveDynamicComponent, createCommentVNode } from "@histoire/vendors/vue";
1
+ import { defineComponent, ref, watchEffect, markRaw, openBlock, createBlock, resolveDynamicComponent, mergeProps, createCommentVNode } from "@histoire/vendors/vue";
2
2
  import { clientSupportPlugins } from "virtual:$histoire-support-plugins-client";
3
+ const __default__ = {
4
+ inheritAttrs: false
5
+ };
3
6
  const _sfc_main = /* @__PURE__ */ defineComponent({
7
+ ...__default__,
4
8
  __name: "GenericMountStory",
5
9
  props: {
6
10
  story: null
@@ -17,10 +21,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
17
21
  }
18
22
  });
19
23
  return (_ctx, _cache) => {
20
- return mountComponent.value ? (openBlock(), createBlock(resolveDynamicComponent(mountComponent.value), {
24
+ return mountComponent.value ? (openBlock(), createBlock(resolveDynamicComponent(mountComponent.value), mergeProps({
21
25
  key: 0,
22
26
  story: __props.story
23
- }, null, 8, ["story"])) : createCommentVNode("", true);
27
+ }, _ctx.$attrs), null, 16, ["story"])) : createCommentVNode("", true);
24
28
  };
25
29
  }
26
30
  });
@@ -1,6 +1,10 @@
1
1
  import { defineComponent, ref, watchEffect, markRaw, openBlock, createBlock, resolveDynamicComponent, mergeProps, createCommentVNode } from "@histoire/vendors/vue";
2
2
  import { clientSupportPlugins } from "virtual:$histoire-support-plugins-client";
3
+ const __default__ = {
4
+ inheritAttrs: false
5
+ };
3
6
  const _sfc_main = /* @__PURE__ */ defineComponent({
7
+ ...__default__,
4
8
  __name: "GenericRenderStory",
5
9
  props: {
6
10
  story: null
@@ -1,4 +1,4 @@
1
- import { pushScopeId, popScopeId, defineComponent, useCssVars, unref, toRefs, ref, resolveComponent, openBlock, createElementBlock, createElementVNode, createVNode, normalizeClass, withCtx, toDisplayString, withModifiers } from "@histoire/vendors/vue";
1
+ import { pushScopeId, popScopeId, defineComponent, useCssVars, unref, toRefs, ref, resolveComponent, openBlock, createElementBlock, createElementVNode, createVNode, normalizeClass, withCtx, toDisplayString, withModifiers, createBlock } from "@histoire/vendors/vue";
2
2
  import { Icon } from "@histoire/vendors/iconify";
3
3
  import { useRouter } from "@histoire/vendors/vue-router";
4
4
  import { useResizeObserver } from "@histoire/vendors/vue-use";
@@ -7,7 +7,7 @@ import { useCurrentVariantRoute } from "../../util/variant.js";
7
7
  import { useScrollOnActive } from "../../util/scroll.js";
8
8
  import "./StoryVariantGridItem.vue_vue_type_style_index_0_scoped_true_lang.js";
9
9
  import _export_sfc from "../../_virtual/plugin-vue_export-helper.js";
10
- const _withScopeId = (n) => (pushScopeId("data-v-feb5bbb0"), n = n(), popScopeId(), n);
10
+ const _withScopeId = (n) => (pushScopeId("data-v-2db4d3d2"), n = n(), popScopeId(), n);
11
11
  const _hoisted_1 = { class: "htw-flex-none htw-flex htw-items-center" };
12
12
  const _sfc_main = /* @__PURE__ */ defineComponent({
13
13
  __name: "StoryVariantGridItem",
@@ -27,7 +27,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
27
27
  setup(__props, { emit }) {
28
28
  const props = __props;
29
29
  useCssVars((_ctx) => ({
30
- "7761d6aa": unref(variant).iconColor
30
+ "1eec3e4a": unref(variant).iconColor
31
31
  }));
32
32
  const { variant } = toRefs(props);
33
33
  const { isActive, targetRoute } = useCurrentVariantRoute(variant);
@@ -89,18 +89,20 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
89
89
  "htw-border-gray-100 dark:htw-border-gray-800": !unref(isActive),
90
90
  "htw-border-primary-200 dark:htw-border-primary-900": unref(isActive)
91
91
  }]),
92
+ "data-test-id": "sandbox-render",
92
93
  onClick: _cache[0] || (_cache[0] = withModifiers(($event) => selectVariant(), ["stop"])),
93
94
  onKeyup: _cache[1] || (_cache[1] = ($event) => selectVariant())
94
95
  }, [
95
- createVNode(_sfc_main$1, {
96
+ (openBlock(), createBlock(_sfc_main$1, {
97
+ key: `${__props.story.id}-${unref(variant).id}`,
96
98
  variant: unref(variant),
97
99
  story: __props.story,
98
100
  onReady
99
- }, null, 8, ["variant", "story"])
101
+ }, null, 8, ["variant", "story"]))
100
102
  ], 34)
101
103
  ], 512);
102
104
  };
103
105
  }
104
106
  });
105
- var StoryVariantGridItem = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-feb5bbb0"]]);
107
+ var StoryVariantGridItem = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-2db4d3d2"]]);
106
108
  export { StoryVariantGridItem as default };
@@ -24,7 +24,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
24
24
  style: normalizeStyle(isResponsiveEnabled ? {
25
25
  width: finalWidth ? `${finalWidth}px` : "100%",
26
26
  height: finalHeight ? `${finalHeight}px` : "100%"
27
- } : { width: "100%", height: "100%" })
27
+ } : { width: "100%", height: "100%" }),
28
+ class: "htw-relative",
29
+ "data-test-id": "sandbox-render"
28
30
  }, [
29
31
  (openBlock(), createBlock(_sfc_main$1, {
30
32
  key: `${__props.story.id}-${__props.variant.id}`,
@@ -72,6 +72,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
72
72
  const isIframeLoaded = ref(false);
73
73
  watch(sandboxUrl, () => {
74
74
  isIframeLoaded.value = false;
75
+ Object.assign(props.variant, {
76
+ previewReady: false
77
+ });
75
78
  });
76
79
  function syncSettings() {
77
80
  if (iframe.value) {
@@ -59,6 +59,7 @@ const app = createApp({
59
59
  return [
60
60
  h("div", { class: "htw-sandbox-hidden" }, [
61
61
  h(_sfc_main, {
62
+ key: file.value.story.id,
62
63
  story: file.value.story
63
64
  })
64
65
  ]),
@@ -76,13 +76,13 @@
76
76
  color: var(--0589c2c6);
77
77
  }
78
78
 
79
- .__histoire-code-placeholder[data-v-ed3a82aa] {
79
+ .__histoire-code-placeholder[data-v-68151bff] {
80
80
  color: inherit;
81
81
  font-size: inherit;
82
82
  }
83
83
 
84
- .bind-icon-color[data-v-feb5bbb0] {
85
- color: var(--7761d6aa);
84
+ .bind-icon-color[data-v-2db4d3d2] {
85
+ color: var(--1eec3e4a);
86
86
  }
87
87
 
88
88
  .bind-preview-bg[data-v-bc4883a4] {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@histoire/app",
3
- "version": "0.9.5",
3
+ "version": "0.10.1",
4
4
  "description": "Pre-bundled UI for Histoire",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -24,9 +24,9 @@
24
24
  },
25
25
  "types": "./src/index.ts",
26
26
  "dependencies": {
27
- "@histoire/controls": "^0.9.5",
28
- "@histoire/shared": "^0.9.5",
29
- "@histoire/vendors": "^0.9.5",
27
+ "@histoire/controls": "^0.10.1",
28
+ "@histoire/shared": "^0.10.1",
29
+ "@histoire/vendors": "^0.10.1",
30
30
  "@types/flexsearch": "^0.7.3",
31
31
  "flexsearch": "^0.7.21",
32
32
  "shiki": "0.10.1"
package/src/app/App.vue CHANGED
@@ -97,6 +97,7 @@ onMounted(() => {
97
97
  class="htw-hidden"
98
98
  >
99
99
  <GenericMountStory
100
+ :key="storyStore.currentStory.id"
100
101
  :story="storyStore.currentStory"
101
102
  />
102
103
  </div>
@@ -47,7 +47,7 @@ function applyPreset (id) {
47
47
  if (id === DEFAULT_ID) {
48
48
  resetState()
49
49
  } else if (presetStates.value.has(id)) {
50
- applyState(props.variant.state, clone(presetStates.value.get(id).state))
50
+ applyState(props.variant.state, clone(toRawDeep(presetStates.value.get(id).state)))
51
51
  }
52
52
  }
53
53
 
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" setup>
2
- import { PropType } from 'vue'
2
+ import { PropType, ref, watch } from 'vue'
3
3
  import { Icon } from '@iconify/vue'
4
4
  import GenericRenderStory from '../story/GenericRenderStory.vue'
5
5
  import type { Story, Variant } from '../../types'
@@ -7,7 +7,7 @@ import BaseEmpty from '../base/BaseEmpty.vue'
7
7
  import StatePresets from './StatePresets.vue'
8
8
  import ControlsComponentProps from './ControlsComponentProps.vue'
9
9
 
10
- defineProps({
10
+ const props = defineProps({
11
11
  variant: {
12
12
  type: Object as PropType<Variant>,
13
13
  required: true,
@@ -18,6 +18,13 @@ defineProps({
18
18
  required: true,
19
19
  },
20
20
  })
21
+
22
+ // Wait for controls render before applying presets
23
+ const ready = ref(false)
24
+
25
+ watch(() => props.variant, () => {
26
+ ready.value = false
27
+ })
21
28
  </script>
22
29
 
23
30
  <template>
@@ -30,6 +37,7 @@ defineProps({
30
37
  class="htw-h-9 htw-flex-none htw-px-2 htw-flex htw-items-center"
31
38
  >
32
39
  <StatePresets
40
+ v-if="ready"
33
41
  :story="story"
34
42
  :variant="variant"
35
43
  />
@@ -38,10 +46,12 @@ defineProps({
38
46
  <!-- Custom controls -->
39
47
  <GenericRenderStory
40
48
  v-if="variant.slots().controls || story.slots().controls"
49
+ :key="`${story.id}-${variant.id}`"
41
50
  slot-name="controls"
42
51
  :variant="variant"
43
52
  :story="story"
44
53
  class="htw-flex-none"
54
+ @ready="ready = true"
45
55
  />
46
56
 
47
57
  <BaseEmpty v-else-if="!variant.state?._hPropDefs?.length">
@@ -1,11 +1,23 @@
1
1
  <script lang="ts">
2
2
  import { PropType, Ref, ref, toRefs, watchEffect } from 'vue'
3
3
  import type { Story } from '../../types'
4
+ // @ts-expect-error virtual module
5
+ import { markdownFiles } from 'virtual:$histoire-markdown-files'
4
6
 
5
7
  export function useStoryDoc (story: Ref<Story>) {
6
8
  const renderedDoc = ref('')
7
9
 
8
10
  watchEffect(async () => {
11
+ // Markdown file
12
+ const mdKey = story.value.file.filePath.replace(/\.(\w*?)$/, '.md')
13
+ if (markdownFiles[mdKey]) {
14
+ const md = await markdownFiles[mdKey]()
15
+ renderedDoc.value = md.html
16
+ return
17
+ }
18
+
19
+ // Custom blocks (Vue 3)
20
+ // @TODO extract
9
21
  let comp = story.value.file?.component
10
22
  if (comp) {
11
23
  if (comp.__asyncResolved) {
@@ -1,5 +1,6 @@
1
1
  <script lang="ts" setup>
2
2
  import { computed, markRaw, onMounted, ref, shallowRef, watch, watchEffect } from 'vue'
3
+ import { Icon } from '@iconify/vue'
3
4
  import { getHighlighter, Highlighter, setCDN } from 'shiki'
4
5
  import { HstCopyIcon } from '@histoire/controls'
5
6
  import { unindent } from '@histoire/shared'
@@ -7,6 +8,7 @@ import { unindent } from '@histoire/shared'
7
8
  import { clientSupportPlugins } from 'virtual:$histoire-support-plugins-client'
8
9
  import type { Variant, Story } from '../../types'
9
10
  import { isDark } from '../../util/dark'
11
+ import BaseEmpty from '../base/BaseEmpty.vue'
10
12
 
11
13
  const props = defineProps<{
12
14
  story: Story
@@ -98,12 +100,13 @@ const sourceHtml = computed(() => sourceCode.value
98
100
  Error: {{ error }}
99
101
  </div>
100
102
 
101
- <i
102
- v-else-if="!sourceCode"
103
- class="htw-opacity-50 htw-p-4"
104
- >
105
- Not available
106
- </i>
103
+ <BaseEmpty v-else-if="!sourceCode">
104
+ <Icon
105
+ icon="carbon:code-hide"
106
+ class="htw-w-8 htw-h-8 htw-opacity-50 htw-mb-6"
107
+ />
108
+ <span>Not available</span>
109
+ </BaseEmpty>
107
110
 
108
111
  <textarea
109
112
  v-else-if="!sourceHtml"
@@ -7,7 +7,7 @@ import charset from 'flexsearch/dist/module/lang/latin/advanced.js'
7
7
  import language from 'flexsearch/dist/module/lang/en.js'
8
8
  import { useStoryStore } from '../../stores/story'
9
9
  import BaseEmpty from '../base/BaseEmpty.vue'
10
- import type { SearchResult, Story, Variant } from '../../types'
10
+ import type { SearchResult, SearchResultType, Story, Variant } from '../../types'
11
11
  import SearchItem from './SearchItem.vue'
12
12
  import { searchData, onUpdate } from './search-title-data'
13
13
  import type { SearchData } from './types'
@@ -161,7 +161,7 @@ async function searchOnDocField (query: string) {
161
161
  if (!idMapData) continue
162
162
  switch (idMapData.kind) {
163
163
  case 'story': {
164
- list.push(storyResultFactory(storyStore.getStoryById(idMapData.id), rank))
164
+ list.push(storyResultFactory(storyStore.getStoryById(idMapData.id), rank, 'docs'))
165
165
  rank++
166
166
  break
167
167
  }
@@ -174,7 +174,7 @@ async function searchOnDocField (query: string) {
174
174
 
175
175
  watch(rateLimitedSearch, searchOnDocField)
176
176
 
177
- function storyResultFactory (story: Story, rank: number): SearchResult {
177
+ function storyResultFactory (story: Story, rank: number, type: SearchResultType = 'title'): SearchResult {
178
178
  return {
179
179
  kind: 'story',
180
180
  rank,
@@ -185,14 +185,20 @@ function storyResultFactory (story: Story, rank: number): SearchResult {
185
185
  params: {
186
186
  storyId: story.id,
187
187
  },
188
+ query: {
189
+ ...type === 'docs'
190
+ ? { tab: 'docs' }
191
+ : {},
192
+ },
188
193
  },
189
194
  path: story.file.path.slice(0, -1),
190
195
  icon: story.icon,
191
196
  iconColor: story.iconColor,
197
+ type,
192
198
  }
193
199
  }
194
200
 
195
- function variantResultFactory (story: Story, variant: Variant, rank: number): SearchResult {
201
+ function variantResultFactory (story: Story, variant: Variant, rank: number, type: SearchResultType = 'title'): SearchResult {
196
202
  return {
197
203
  kind: 'variant',
198
204
  rank,
@@ -205,11 +211,15 @@ function variantResultFactory (story: Story, variant: Variant, rank: number): Se
205
211
  },
206
212
  query: {
207
213
  variantId: variant.id,
214
+ ...type === 'docs'
215
+ ? { tab: 'docs' }
216
+ : {},
208
217
  },
209
218
  },
210
219
  path: [...story.file.path ?? [], story.title],
211
220
  icon: variant.icon,
212
221
  iconColor: variant.iconColor,
222
+ type,
213
223
  }
214
224
  }
215
225
 
@@ -1,3 +1,9 @@
1
+ <script lang="ts">
2
+ export default {
3
+ inheritAttrs: false,
4
+ }
5
+ </script>
6
+
1
7
  <script lang="ts" setup>
2
8
  // @ts-expect-error virtual module
3
9
  import { clientSupportPlugins } from 'virtual:$histoire-support-plugins-client'
@@ -24,5 +30,6 @@ watchEffect(async () => {
24
30
  :is="mountComponent"
25
31
  v-if="mountComponent"
26
32
  :story="story"
33
+ v-bind="$attrs"
27
34
  />
28
35
  </template>
@@ -1,3 +1,9 @@
1
+ <script lang="ts">
2
+ export default {
3
+ inheritAttrs: false,
4
+ }
5
+ </script>
6
+
1
7
  <script lang="ts" setup>
2
8
  // @ts-expect-error virtual module
3
9
  import { clientSupportPlugins } from 'virtual:$histoire-support-plugins-client'
@@ -91,10 +91,12 @@ useResizeObserver(el, () => {
91
91
  'htw-border-gray-100 dark:htw-border-gray-800': !isActive,
92
92
  'htw-border-primary-200 dark:htw-border-primary-900': isActive,
93
93
  }"
94
+ data-test-id="sandbox-render"
94
95
  @click.stop="selectVariant()"
95
96
  @keyup="selectVariant()"
96
97
  >
97
98
  <GenericRenderStory
99
+ :key="`${story.id}-${variant.id}`"
98
100
  :variant="variant"
99
101
  :story="story"
100
102
  @ready="onReady"
@@ -29,6 +29,8 @@ function onReady () {
29
29
  width: finalWidth ? `${finalWidth}px` : '100%',
30
30
  height: finalHeight ? `${finalHeight}px` : '100%',
31
31
  } : { width: '100%', height: '100%' }"
32
+ class="htw-relative"
33
+ data-test-id="sandbox-render"
32
34
  >
33
35
  <GenericRenderStory
34
36
  :key="`${story.id}-${variant.id}`"
@@ -85,6 +85,9 @@ const isIframeLoaded = ref(false)
85
85
 
86
86
  watch(sandboxUrl, () => {
87
87
  isIframeLoaded.value = false
88
+ Object.assign(props.variant, {
89
+ previewReady: false,
90
+ })
88
91
  })
89
92
 
90
93
  // Settings
@@ -65,6 +65,7 @@ const app = createApp({
65
65
  return [
66
66
  h('div', { class: 'htw-sandbox-hidden' }, [
67
67
  h(GenericMountStory, {
68
+ key: file.value.story.id,
68
69
  story: file.value.story,
69
70
  }),
70
71
  ]),
@@ -10,7 +10,7 @@ body {
10
10
  }
11
11
 
12
12
  html {
13
- font-size: .875rem;
13
+ font-size: 1rem;
14
14
  font-family: 'Lato', sans-serif;
15
15
  }
16
16
 
package/src/app/types.ts CHANGED
@@ -26,12 +26,15 @@ export interface TreeGroup {
26
26
 
27
27
  export type Tree = (TreeGroup | TreeFolder | TreeLeaf)[]
28
28
 
29
+ export type SearchResultType = 'title' | 'docs'
30
+
29
31
  export interface SearchResult {
30
32
  kind: 'story' | 'variant'
31
33
  rank: number
32
34
  id: string
33
35
  title: string
34
36
  route: RouteLocationRaw
37
+ type: SearchResultType
35
38
  path?: string[]
36
39
  icon?: string
37
40
  iconColor?: string