@histoire/app 0.12.0 → 0.12.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.
@@ -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,
@@ -1,16 +1,4 @@
1
1
 
2
- .htw-base-empty[data-v-c5ecfead]:not(.no-animation) {
3
- animation: htw-base-empty-c5ecfead .15s .2s both;
4
- }
5
- @keyframes htw-base-empty-c5ecfead {
6
- 0% {
7
- opacity: 0;
8
- }
9
- 100% {
10
- opacity: 1;
11
- }
12
- }
13
-
14
2
  .landscape > div > .dragger[data-v-ed925107] {
15
3
  width: .625rem;
16
4
  }
@@ -40,10 +28,26 @@
40
28
  color: var(--5792748b);
41
29
  }
42
30
 
31
+ .htw-base-empty[data-v-c5ecfead]:not(.no-animation) {
32
+ animation: htw-base-empty-c5ecfead .15s .2s both;
33
+ }
34
+ @keyframes htw-base-empty-c5ecfead {
35
+ 0% {
36
+ opacity: 0;
37
+ }
38
+ 100% {
39
+ opacity: 1;
40
+ }
41
+ }
42
+
43
43
  .bind-icon-color[data-v-6046525f] {
44
44
  color: var(--663732b6);
45
45
  }
46
46
 
47
+ .bind-tree-padding[data-v-e161f5e0] {
48
+ padding-left: var(--e605dd68);
49
+ }
50
+
47
51
  .bind-tree-margin[data-v-19810958] {
48
52
  margin-left: var(--444efc12);
49
53
  }
@@ -51,6 +55,10 @@
51
55
  color: var(--ae892164);
52
56
  }
53
57
 
58
+ .bind-icon-color[data-v-ab890d9c] {
59
+ color: var(--89126aaa);
60
+ }
61
+
54
62
  .__histoire-code-placeholder[data-v-f528bb1b] {
55
63
  color: inherit;
56
64
  font-size: inherit;
@@ -60,17 +68,8 @@
60
68
  color: var(--4d25d048);
61
69
  }
62
70
 
63
- .bind-tree-padding[data-v-e161f5e0] {
64
- padding-left: var(--e605dd68);
65
- }
66
-
67
- .bind-icon-color[data-v-ab890d9c] {
68
- color: var(--89126aaa);
69
- }
70
-
71
- .bind-preview-bg[data-v-c48fb2b2] {
72
- background-color: var(--627bec82);
73
- color: var(--35068428);
71
+ .bind-icon-color[data-v-d95fcb03] {
72
+ color: var(--beebbd52);
74
73
  }
75
74
 
76
75
  .bind-icon-color[data-v-f7c98176] {
@@ -80,8 +79,9 @@
80
79
  background-color: var(--f4b27ac2);
81
80
  }
82
81
 
83
- .bind-icon-color[data-v-d95fcb03] {
84
- color: var(--beebbd52);
82
+ .bind-preview-bg[data-v-c48fb2b2] {
83
+ background-color: var(--627bec82);
84
+ color: var(--35068428);
85
85
  }
86
86
 
87
87
  .bind-preview-bg[data-v-a83b1911] {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@histoire/app",
3
- "version": "0.12.0",
3
+ "version": "0.12.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.12.0",
28
- "@histoire/shared": "^0.12.0",
29
- "@histoire/vendors": "^0.12.0",
27
+ "@histoire/controls": "^0.12.1",
28
+ "@histoire/shared": "^0.12.1",
29
+ "@histoire/vendors": "^0.12.1",
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">
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,