@histoire/app 0.12.0 → 0.12.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.
@@ -1,8 +1,9 @@
1
- import { defineComponent, toRefs, openBlock, createElementBlock, unref, createBlock, withCtx, createVNode, createTextVNode, ref, watchEffect } from "@histoire/vendors/vue";
1
+ import { defineComponent, toRefs, watch, ref, openBlock, createElementBlock, unref, createBlock, withCtx, createVNode, createTextVNode, watchEffect, nextTick } from "@histoire/vendors/vue";
2
2
  import { Icon } from "@histoire/vendors/iconify";
3
- import { useRouter } from "@histoire/vendors/vue-router";
3
+ import { useRouter, useRoute } from "@histoire/vendors/vue-router";
4
4
  import BaseEmpty from "../base/BaseEmpty.vue.js";
5
5
  import { markdownFiles } from "virtual:$histoire-markdown-files";
6
+ import { histoireConfig } from "../../util/config.js";
6
7
  "use strict";
7
8
  const _hoisted_1 = ["innerHTML"];
8
9
  function useStoryDoc(story) {
@@ -45,7 +46,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
45
46
  required: true
46
47
  }
47
48
  },
48
- setup(__props) {
49
+ emits: ["scroll-top"],
50
+ setup(__props, { emit }) {
49
51
  const props = __props;
50
52
  const { story } = toRefs(props);
51
53
  const { renderedDoc } = useStoryDoc(story);
@@ -60,6 +62,54 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
60
62
  router.push(targetHref);
61
63
  }
62
64
  }
65
+ function getHash() {
66
+ const hash = location.hash;
67
+ if (histoireConfig.routerMode === "hash") {
68
+ const index = hash.indexOf("#", 1);
69
+ if (index !== -1) {
70
+ return hash.slice(index);
71
+ } else {
72
+ return void 0;
73
+ }
74
+ }
75
+ return hash;
76
+ }
77
+ async function scrollToAnchor() {
78
+ await nextTick();
79
+ const hash = getHash();
80
+ if (hash) {
81
+ const anchor = document.querySelector(hash);
82
+ if (anchor) {
83
+ anchor.scrollIntoView();
84
+ return;
85
+ }
86
+ }
87
+ emit("scroll-top");
88
+ }
89
+ watch(renderedDoc, () => {
90
+ scrollToAnchor();
91
+ }, {
92
+ immediate: true
93
+ });
94
+ const renderedEl = ref();
95
+ const route = useRoute();
96
+ async function patchAnchorLinks() {
97
+ await nextTick();
98
+ if (histoireConfig.routerMode === "hash" && renderedEl.value) {
99
+ const links = renderedEl.value.querySelectorAll("a.header-anchor");
100
+ for (const link of links) {
101
+ const href = link.getAttribute("href");
102
+ if (href) {
103
+ link.setAttribute("href", `#${route.path + href}`);
104
+ }
105
+ }
106
+ }
107
+ }
108
+ watch(renderedDoc, () => {
109
+ patchAnchorLinks();
110
+ }, {
111
+ immediate: true
112
+ });
63
113
  return (_ctx, _cache) => {
64
114
  return openBlock(), createElementBlock("div", {
65
115
  class: "histoire-story-docs",
@@ -76,6 +126,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
76
126
  _: 1
77
127
  })) : (openBlock(), createElementBlock("div", {
78
128
  key: 1,
129
+ ref_key: "renderedEl",
130
+ ref: renderedEl,
79
131
  class: "htw-prose dark:htw-prose-invert htw-p-4 htw-max-w-none",
80
132
  "data-test-id": "story-docs",
81
133
  innerHTML: unref(renderedDoc)
@@ -1,4 +1,4 @@
1
- import { defineComponent, watch, unref, openBlock, createBlock, withCtx, createVNode, createElementBlock } from "@histoire/vendors/vue";
1
+ import { defineComponent, watch, ref, unref, openBlock, createBlock, withCtx, createVNode, createElementBlock } from "@histoire/vendors/vue";
2
2
  import { useRouter, useRoute } from "@histoire/vendors/vue-router";
3
3
  import { Icon } from "@histoire/vendors/iconify";
4
4
  import { useStoryStore } from "../../stores/story.js";
@@ -15,10 +15,6 @@ const _hoisted_1 = {
15
15
  key: 1,
16
16
  class: "histoire-story-view histoire-with-story htw-h-full"
17
17
  };
18
- const _hoisted_2 = {
19
- key: 0,
20
- class: "htw-h-full htw-overflow-auto"
21
- };
22
18
  const _sfc_main = /* @__PURE__ */ defineComponent({
23
19
  __name: "StoryView",
24
20
  setup(__props) {
@@ -55,6 +51,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
55
51
  }
56
52
  });
57
53
  }
54
+ const docsOnlyScroller = ref(null);
55
+ function scrollDocsToTop() {
56
+ var _a;
57
+ (_a = docsOnlyScroller.value) == null ? void 0 : _a.scrollTo(0, 0);
58
+ }
58
59
  return (_ctx, _cache) => {
59
60
  return !unref(storyStore).currentStory ? (openBlock(), createBlock(BaseEmpty, {
60
61
  key: 0,
@@ -68,12 +69,18 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
68
69
  ]),
69
70
  _: 1
70
71
  })) : (openBlock(), createElementBlock("div", _hoisted_1, [
71
- unref(storyStore).currentStory.docsOnly ? (openBlock(), createElementBlock("div", _hoisted_2, [
72
+ unref(storyStore).currentStory.docsOnly ? (openBlock(), createElementBlock("div", {
73
+ key: 0,
74
+ ref_key: "docsOnlyScroller",
75
+ ref: docsOnlyScroller,
76
+ class: "htw-h-full htw-overflow-auto"
77
+ }, [
72
78
  createVNode(_sfc_main$1, {
73
79
  story: unref(storyStore).currentStory,
74
- class: "md:htw-p-12 htw-w-full md:htw-max-w-[600px] lg:htw-max-w-[800px] xl:htw-max-w-[900px]"
80
+ class: "md:htw-p-12 htw-w-full md:htw-max-w-[600px] lg:htw-max-w-[800px] xl:htw-max-w-[900px]",
81
+ onScrollTop: _cache[0] || (_cache[0] = ($event) => scrollDocsToTop())
75
82
  }, null, 8, ["story"])
76
- ])) : unref(isMobile) ? (openBlock(), createBlock(StoryViewer, { key: 1 })) : (openBlock(), createBlock(BaseSplitPane, {
83
+ ], 512)) : unref(isMobile) ? (openBlock(), createBlock(StoryViewer, { key: 1 })) : (openBlock(), createBlock(BaseSplitPane, {
77
84
  key: 2,
78
85
  "save-id": "story-main",
79
86
  min: 30,
@@ -2,7 +2,7 @@ import _sfc_main from "./StoryListFolder.vue2.js";
2
2
  import "./StoryListFolder.vue3.js";
3
3
  import _export_sfc from "../../_virtual/_plugin-vue_export-helper.js";
4
4
  "use strict";
5
- const StoryListFolder = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-e161f5e0"]]);
5
+ const StoryListFolder = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-2d2e4786"]]);
6
6
  export {
7
7
  StoryListFolder as default
8
8
  };
@@ -3,14 +3,14 @@ import StoryListItem from "./StoryListItem.vue.js";
3
3
  import { Icon } from "@histoire/vendors/iconify";
4
4
  import { useFolderStore } from "../../stores/folder.js";
5
5
  "use strict";
6
- const _withScopeId = (n) => (pushScopeId("data-v-e161f5e0"), n = n(), popScopeId(), n);
6
+ const _withScopeId = (n) => (pushScopeId("data-v-2d2e4786"), n = n(), popScopeId(), n);
7
7
  const _hoisted_1 = {
8
8
  "data-test-id": "story-list-folder",
9
9
  class: "histoire-story-list-folder"
10
10
  };
11
11
  const _hoisted_2 = ["onKeyup"];
12
12
  const _hoisted_3 = { class: "bind-tree-padding htw-flex htw-items-center htw-gap-2 htw-min-w-0" };
13
- const _hoisted_4 = { class: "htw-flex htw-flex-none htw-items-center htw-opacity-30 [.histoire-story-list-folder-button:hover_&]:htw-opacity-100 htw-ml-4 htw-rounded-sm htw-border htw-border-gray-500/40" };
13
+ const _hoisted_4 = { class: "htw-flex htw-flex-none htw-items-center htw-opacity-30 [.histoire-story-list-folder-button:hover_&]:htw-opacity-100 htw-ml-4 htw-w-4 htw-h-4 htw-rounded-sm htw-border htw-border-gray-500/40" };
14
14
  const _hoisted_5 = { class: "htw-truncate" };
15
15
  const _hoisted_6 = { key: 0 };
16
16
  const _sfc_main = /* @__PURE__ */ defineComponent({
@@ -24,7 +24,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
24
24
  setup(__props) {
25
25
  const props = __props;
26
26
  useCssVars((_ctx) => ({
27
- "e605dd68": unref(folderPadding)
27
+ "6851b0a7": unref(folderPadding)
28
28
  }));
29
29
  const folderStore = useFolderStore();
30
30
  const folderPath = computed(() => [...props.path, props.folder.title]);
@@ -52,7 +52,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
52
52
  createElementVNode("span", _hoisted_4, [
53
53
  createVNode(unref(Icon), {
54
54
  icon: "carbon:caret-right",
55
- class: normalizeClass(["htw-w-4 htw-h-4 htw-transition-transform htw-duration-150", {
55
+ class: normalizeClass(["htw-w-full htw-h-full htw-transition-transform htw-duration-150", {
56
56
  "htw-rotate-90": unref(isFolderOpen)
57
57
  }])
58
58
  }, null, 8, ["class"])
@@ -1,4 +1,4 @@
1
- const StoryListFolder_vue_vue_type_style_index_0_scoped_e161f5e0_lang = "";
1
+ const StoryListFolder_vue_vue_type_style_index_0_scoped_2d2e4786_lang = "";
2
2
  export {
3
- StoryListFolder_vue_vue_type_style_index_0_scoped_e161f5e0_lang as default
3
+ StoryListFolder_vue_vue_type_style_index_0_scoped_2d2e4786_lang as default
4
4
  };
@@ -44,6 +44,10 @@
44
44
  color: var(--663732b6);
45
45
  }
46
46
 
47
+ .bind-tree-padding[data-v-2d2e4786] {
48
+ padding-left: var(--6851b0a7);
49
+ }
50
+
47
51
  .bind-tree-margin[data-v-19810958] {
48
52
  margin-left: var(--444efc12);
49
53
  }
@@ -51,23 +55,19 @@
51
55
  color: var(--ae892164);
52
56
  }
53
57
 
54
- .__histoire-code-placeholder[data-v-f528bb1b] {
55
- color: inherit;
56
- font-size: inherit;
57
- }
58
-
59
58
  .bind-icon-color[data-v-ddfc5b4f] {
60
59
  color: var(--4d25d048);
61
60
  }
62
61
 
63
- .bind-tree-padding[data-v-e161f5e0] {
64
- padding-left: var(--e605dd68);
65
- }
66
-
67
62
  .bind-icon-color[data-v-ab890d9c] {
68
63
  color: var(--89126aaa);
69
64
  }
70
65
 
66
+ .__histoire-code-placeholder[data-v-f528bb1b] {
67
+ color: inherit;
68
+ font-size: inherit;
69
+ }
70
+
71
71
  .bind-preview-bg[data-v-c48fb2b2] {
72
72
  background-color: var(--627bec82);
73
73
  color: var(--35068428);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@histoire/app",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
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.12.0",
28
- "@histoire/shared": "^0.12.0",
29
- "@histoire/vendors": "^0.12.0",
27
+ "@histoire/controls": "^0.12.2",
28
+ "@histoire/shared": "^0.12.2",
29
+ "@histoire/vendors": "^0.12.2",
30
30
  "@types/flexsearch": "^0.7.3",
31
31
  "flexsearch": "0.7.21",
32
32
  "shiki-es": "^0.1.2"
@@ -1,8 +1,9 @@
1
1
  <script lang="ts">
2
- import { PropType, Ref, ref, toRefs, watchEffect } from 'vue'
2
+ import { nextTick, PropType, Ref, ref, toRefs, watch, watchEffect } from 'vue'
3
3
  import type { Story } from '../../types'
4
4
  // @ts-expect-error virtual module
5
5
  import { markdownFiles } from 'virtual:$histoire-markdown-files'
6
+ import { histoireConfig } from '../../util/config.js'
6
7
 
7
8
  export function useStoryDoc (story: Ref<Story>) {
8
9
  const renderedDoc = ref('')
@@ -47,7 +48,7 @@ export function useStoryDoc (story: Ref<Story>) {
47
48
 
48
49
  <script lang="ts" setup>
49
50
  import { Icon } from '@iconify/vue'
50
- import { useRouter } from '@histoire/vendors/vue-router'
51
+ import { useRoute, useRouter } from 'vue-router'
51
52
  import BaseEmpty from '../base/BaseEmpty.vue'
52
53
 
53
54
  const props = defineProps({
@@ -57,6 +58,10 @@ const props = defineProps({
57
58
  },
58
59
  })
59
60
 
61
+ const emit = defineEmits<{
62
+ (e: 'scroll-top'): void
63
+ }>()
64
+
60
65
  const { story } = toRefs(props)
61
66
 
62
67
  const { renderedDoc } = useStoryDoc(story)
@@ -85,6 +90,64 @@ function onClick (e: MouseEvent) {
85
90
  router.push(targetHref)
86
91
  }
87
92
  }
93
+
94
+ // Handle URL anchor
95
+
96
+ function getHash () {
97
+ const hash = location.hash
98
+ if (histoireConfig.routerMode === 'hash') {
99
+ const index = hash.indexOf('#', 1)
100
+ if (index !== -1) {
101
+ return hash.slice(index)
102
+ } else {
103
+ return undefined
104
+ }
105
+ }
106
+ return hash
107
+ }
108
+
109
+ async function scrollToAnchor () {
110
+ await nextTick()
111
+ const hash = getHash()
112
+ if (hash) {
113
+ const anchor = document.querySelector(hash)
114
+ if (anchor) {
115
+ anchor.scrollIntoView()
116
+ return
117
+ }
118
+ }
119
+ emit('scroll-top')
120
+ }
121
+
122
+ watch(renderedDoc, () => {
123
+ scrollToAnchor()
124
+ }, {
125
+ immediate: true,
126
+ })
127
+
128
+ // Fix anchor links with router mode 'hash'
129
+
130
+ const renderedEl = ref<HTMLElement>()
131
+ const route = useRoute()
132
+
133
+ async function patchAnchorLinks () {
134
+ await nextTick()
135
+ if (histoireConfig.routerMode === 'hash' && renderedEl.value) {
136
+ const links = renderedEl.value.querySelectorAll('a.header-anchor')
137
+ for (const link of links) {
138
+ const href = link.getAttribute('href')
139
+ if (href) {
140
+ link.setAttribute('href', `#${route.path + href}`)
141
+ }
142
+ }
143
+ }
144
+ }
145
+
146
+ watch(renderedDoc, () => {
147
+ patchAnchorLinks()
148
+ }, {
149
+ immediate: true,
150
+ })
88
151
  </script>
89
152
 
90
153
  <template>
@@ -103,6 +166,7 @@ function onClick (e: MouseEvent) {
103
166
  </BaseEmpty>
104
167
  <div
105
168
  v-else
169
+ ref="renderedEl"
106
170
  class="htw-prose dark:htw-prose-invert htw-p-4 htw-max-w-none"
107
171
  data-test-id="story-docs"
108
172
  v-html="renderedDoc"
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" setup>
2
- import { watch } from 'vue'
2
+ import { ref, watch } from 'vue'
3
3
  import { useRoute, useRouter } from 'vue-router'
4
4
  import { Icon } from '@iconify/vue'
5
5
  import { useStoryStore } from '../../stores/story'
@@ -50,6 +50,14 @@ function setVariant (variantId: string) {
50
50
  },
51
51
  })
52
52
  }
53
+
54
+ // Docs auto-scroll to top
55
+
56
+ const docsOnlyScroller = ref<HTMLElement>(null)
57
+
58
+ function scrollDocsToTop () {
59
+ docsOnlyScroller.value?.scrollTo(0, 0)
60
+ }
53
61
  </script>
54
62
 
55
63
  <template>
@@ -69,11 +77,13 @@ function setVariant (variantId: string) {
69
77
  >
70
78
  <div
71
79
  v-if="storyStore.currentStory.docsOnly"
80
+ ref="docsOnlyScroller"
72
81
  class="htw-h-full htw-overflow-auto"
73
82
  >
74
83
  <StoryDocs
75
84
  :story="storyStore.currentStory"
76
85
  class="md:htw-p-12 htw-w-full md:htw-max-w-[600px] lg:htw-max-w-[800px] xl:htw-max-w-[900px]"
86
+ @scroll-top="scrollDocsToTop()"
77
87
  />
78
88
  </div>
79
89
  <template v-else-if="isMobile">
@@ -43,10 +43,10 @@ const folderPadding = computed(() => {
43
43
  @keyup.space="toggleOpen"
44
44
  >
45
45
  <span class="bind-tree-padding htw-flex htw-items-center htw-gap-2 htw-min-w-0">
46
- <span class="htw-flex htw-flex-none htw-items-center htw-opacity-30 [.histoire-story-list-folder-button:hover_&]:htw-opacity-100 htw-ml-4 htw-rounded-sm htw-border htw-border-gray-500/40">
46
+ <span class="htw-flex htw-flex-none htw-items-center htw-opacity-30 [.histoire-story-list-folder-button:hover_&]:htw-opacity-100 htw-ml-4 htw-w-4 htw-h-4 htw-rounded-sm htw-border htw-border-gray-500/40">
47
47
  <Icon
48
48
  icon="carbon:caret-right"
49
- class="htw-w-4 htw-h-4 htw-transition-transform htw-duration-150"
49
+ class="htw-w-full htw-h-full htw-transition-transform htw-duration-150"
50
50
  :class="{
51
51
  'htw-rotate-90': isFolderOpen,
52
52
  }"
package/tsconfig.json CHANGED
@@ -16,7 +16,8 @@
16
16
  ],
17
17
  "lib": [
18
18
  "ESNext",
19
- "DOM"
19
+ "DOM",
20
+ "DOM.Iterable",
20
21
  ],
21
22
  "sourceMap": false,
22
23
  "preserveWatchOutput": true,