histoire 0.3.1 → 0.4.0

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 (150) hide show
  1. package/dist/bundled/BaseEmpty.js +13 -0
  2. package/dist/bundled/HomeView.js +23 -0
  3. package/dist/bundled/MobileOverlay.js +303 -0
  4. package/dist/bundled/SearchPane.js +504 -0
  5. package/dist/bundled/StoryView.js +2330 -0
  6. package/dist/bundled/api.js +32 -0
  7. package/dist/bundled/config.js +4 -0
  8. package/dist/bundled/const.js +5 -0
  9. package/dist/bundled/dark.js +4 -0
  10. package/dist/bundled/events.js +29 -0
  11. package/dist/bundled/global-components.js +203 -0
  12. package/dist/bundled/index.js +7 -0
  13. package/dist/bundled/index2.js +762 -0
  14. package/dist/bundled/reactivity.js +96 -0
  15. package/dist/bundled/sandbox.js +97 -0
  16. package/dist/bundled/search-docs-data.js +7 -0
  17. package/dist/bundled/story.js +59 -0
  18. package/dist/bundled/style.css +102 -0
  19. package/dist/client/app/App.vue +2 -2
  20. package/dist/client/app/api.d.ts +1 -0
  21. package/dist/client/app/api.js +1 -0
  22. package/dist/client/app/codegen/vue3.js +1 -2
  23. package/dist/client/app/components/HomeView.vue +1 -1
  24. package/dist/client/app/components/app/AppLogo.vue +1 -1
  25. package/dist/client/app/components/app/MobileOverlay.vue +0 -1
  26. package/dist/client/app/components/base/BaseEmpty.vue +1 -1
  27. package/dist/client/app/components/base/BaseOverflowMenu.vue +118 -0
  28. package/dist/client/app/components/base/BaseOverflowTab.vue +46 -0
  29. package/dist/client/app/components/exposed/Story.vue +13 -2
  30. package/dist/client/app/components/exposed/Variant.vue +6 -0
  31. package/dist/client/app/components/panel/PaneTabs.vue +64 -0
  32. package/{src/client/app/components/story → dist/client/app/components/panel}/StoryControls.vue +1 -1
  33. package/dist/client/app/components/{story → panel}/StoryDocs.vue +0 -0
  34. package/dist/client/app/components/{story → panel}/StoryEvent.vue +1 -0
  35. package/dist/client/app/components/{story → panel}/StoryEvents.vue +0 -0
  36. package/dist/client/app/components/{story → panel}/StorySidePanel.vue +3 -31
  37. package/dist/client/app/components/{story → panel}/StorySourceCode.vue +0 -0
  38. package/dist/client/app/components/sandbox/SandboxVue3.vue +10 -0
  39. package/dist/client/app/components/search/SearchItem.vue +1 -1
  40. package/dist/client/app/components/search/SearchPane.vue +108 -25
  41. package/dist/client/app/components/search/search-docs-data.d.ts +3 -0
  42. package/dist/client/app/components/search/{search-data.js → search-docs-data.js} +1 -1
  43. package/dist/client/app/components/search/search-title-data.d.ts +3 -0
  44. package/dist/client/app/components/search/search-title-data.js +7 -0
  45. package/dist/client/app/components/search/types.d.ts +7 -0
  46. package/dist/client/app/components/search/types.js +1 -0
  47. package/dist/client/app/components/story/StoryResponsivePreview.vue +9 -131
  48. package/dist/client/app/components/story/StoryVariantGridItem.vue +1 -1
  49. package/dist/client/app/components/story/StoryVariantListItem.vue +1 -1
  50. package/dist/client/app/components/story/StoryVariantSingle.vue +109 -0
  51. package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +42 -0
  52. package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
  53. package/dist/client/app/components/story/StoryVariantSingleView.vue +13 -6
  54. package/dist/client/app/components/story/StoryView.vue +2 -2
  55. package/dist/client/app/components/story/StoryViewer.vue +2 -92
  56. package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantBackground.vue +3 -3
  57. package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantNewTab.vue +2 -2
  58. package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantResponsiveSize.vue +3 -3
  59. package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantTitle.vue +1 -1
  60. package/dist/client/app/components/tree/StoryListItem.vue +1 -1
  61. package/dist/client/app/index.d.ts +1 -1
  62. package/dist/client/app/index.js +21 -18
  63. package/dist/client/app/sandbox.d.ts +1 -1
  64. package/dist/client/app/sandbox.js +0 -1
  65. package/dist/client/app/stores/events.js +1 -1
  66. package/dist/client/app/stores/story.d.ts +27 -0
  67. package/dist/client/app/style/transitions.pcss +13 -0
  68. package/dist/client/app/types.d.ts +3 -0
  69. package/dist/client/app/util/events.d.ts +1 -1
  70. package/dist/client/app/util/events.js +2 -2
  71. package/dist/client/app/util/mapping.js +2 -0
  72. package/dist/client/bundle-index.js +5 -0
  73. package/dist/client/bundle-main.js +5 -0
  74. package/dist/client/bundle-sandbox.js +3 -0
  75. package/dist/client/index.d.ts +1 -1
  76. package/dist/client/index.js +1 -1
  77. package/dist/client/server/vue3/Story.vue +1 -1
  78. package/dist/client/server/vue3/run.js +8 -0
  79. package/dist/node/alias.js +1 -1
  80. package/dist/node/build.js +4 -4
  81. package/dist/node/builtin-plugins/tailwind-tokens.js +1 -1
  82. package/dist/node/search.d.ts +15 -1
  83. package/dist/node/search.js +78 -32
  84. package/dist/node/server.js +2 -2
  85. package/dist/node/types.d.ts +1 -0
  86. package/dist/node/vite.d.ts +4 -2
  87. package/dist/node/vite.js +24 -28
  88. package/dist/style.css +93 -69
  89. package/package.json +10 -10
  90. package/src/client/app/App.vue +2 -2
  91. package/src/client/app/api.ts +1 -0
  92. package/src/client/app/codegen/vue3.ts +1 -2
  93. package/src/client/app/components/HomeView.vue +1 -1
  94. package/src/client/app/components/app/AppLogo.vue +1 -1
  95. package/src/client/app/components/app/MobileOverlay.vue +0 -1
  96. package/src/client/app/components/base/BaseEmpty.vue +1 -1
  97. package/src/client/app/components/base/BaseOverflowMenu.vue +118 -0
  98. package/src/client/app/components/base/BaseOverflowTab.vue +46 -0
  99. package/src/client/app/components/exposed/Story.vue +13 -2
  100. package/src/client/app/components/exposed/Variant.vue +6 -0
  101. package/src/client/app/components/panel/PaneTabs.vue +64 -0
  102. package/{dist/client/app/components/story → src/client/app/components/panel}/StoryControls.vue +1 -1
  103. package/src/client/app/components/{story → panel}/StoryDocs.vue +0 -0
  104. package/src/client/app/components/{story → panel}/StoryEvent.vue +1 -0
  105. package/src/client/app/components/{story → panel}/StoryEvents.vue +0 -0
  106. package/src/client/app/components/{story → panel}/StorySidePanel.vue +3 -31
  107. package/src/client/app/components/{story → panel}/StorySourceCode.vue +0 -0
  108. package/src/client/app/components/sandbox/SandboxVue3.vue +10 -0
  109. package/src/client/app/components/search/SearchItem.vue +1 -1
  110. package/src/client/app/components/search/SearchPane.vue +108 -25
  111. package/src/client/app/components/search/search-docs-data.ts +10 -0
  112. package/src/client/app/components/search/search-title-data.ts +10 -0
  113. package/src/client/app/components/search/types.ts +4 -0
  114. package/src/client/app/components/story/StoryResponsivePreview.vue +9 -131
  115. package/src/client/app/components/story/StoryVariantGridItem.vue +1 -1
  116. package/src/client/app/components/story/StoryVariantListItem.vue +1 -1
  117. package/src/client/app/components/story/StoryVariantSingle.vue +109 -0
  118. package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +42 -0
  119. package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
  120. package/src/client/app/components/story/StoryVariantSingleView.vue +13 -6
  121. package/src/client/app/components/story/StoryView.vue +2 -2
  122. package/src/client/app/components/story/StoryViewer.vue +2 -92
  123. package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantBackground.vue +3 -3
  124. package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantNewTab.vue +2 -2
  125. package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantResponsiveSize.vue +3 -3
  126. package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantTitle.vue +1 -1
  127. package/src/client/app/components/tree/StoryListItem.vue +1 -1
  128. package/src/client/app/index.ts +23 -19
  129. package/src/client/app/sandbox.ts +1 -2
  130. package/src/client/app/stores/events.ts +1 -1
  131. package/src/client/app/style/transitions.pcss +13 -0
  132. package/src/client/app/types.ts +4 -0
  133. package/src/client/app/util/events.ts +2 -2
  134. package/src/client/app/util/mapping.ts +2 -0
  135. package/src/client/bundle-index.js +5 -0
  136. package/src/client/bundle-main.js +5 -0
  137. package/src/client/bundle-sandbox.js +3 -0
  138. package/src/client/index.ts +1 -1
  139. package/src/client/server/vue3/Story.vue +1 -1
  140. package/src/client/server/vue3/run.ts +11 -0
  141. package/src/node/alias.ts +1 -1
  142. package/src/node/build.ts +4 -4
  143. package/src/node/builtin-plugins/tailwind-tokens.ts +1 -1
  144. package/src/node/search.ts +87 -32
  145. package/src/node/server.ts +2 -2
  146. package/src/node/types.ts +1 -0
  147. package/src/node/vite.ts +24 -29
  148. package/vite.config.ts +46 -0
  149. package/dist/client/app/components/search/search-data.d.ts +0 -2
  150. package/src/client/app/components/search/search-data.ts +0 -9
@@ -0,0 +1,118 @@
1
+ <script lang="ts" setup>
2
+ import { ref, h, onBeforeUnmount, reactive, computed } from 'vue'
3
+ import { useResizeObserver } from '@vueuse/core'
4
+ import { Icon } from '@iconify/vue'
5
+
6
+ // Container
7
+
8
+ const overflowButtonWidth = 32
9
+
10
+ const el = ref<HTMLDivElement>()
11
+
12
+ const availableWidth = ref(0)
13
+
14
+ useResizeObserver(el, (entries) => {
15
+ const containerWidth = entries[0].contentRect.width
16
+ availableWidth.value = containerWidth - overflowButtonWidth
17
+ })
18
+
19
+ // Children
20
+
21
+ interface ChildState {
22
+ width: number
23
+ index: number
24
+ }
25
+
26
+ const children = ref(new Map<HTMLElement, ChildState>())
27
+
28
+ const visibleChildrenCount = computed(() => {
29
+ let width = 0
30
+ const c = [...children.value.values()].sort((a, b) => a.index - b.index)
31
+ for (let i = 0; i < c.length; i++) {
32
+ width += c[i].width
33
+ if (width > availableWidth.value) {
34
+ return i
35
+ }
36
+ }
37
+ return c.length
38
+ })
39
+
40
+ /**
41
+ * Watches for the size of each child and automatically hide them
42
+ */
43
+ const ChildWrapper = {
44
+ props: ['index'],
45
+ setup (props, { slots }) {
46
+ const el = ref<HTMLDivElement>()
47
+
48
+ const state = reactive({ width: 0, index: props.index })
49
+
50
+ useResizeObserver(el, (entries) => {
51
+ const width = entries[0].contentRect.width
52
+ if (!children.value.has(el.value)) {
53
+ children.value.set(el.value, state)
54
+ }
55
+ state.width = width
56
+ })
57
+
58
+ onBeforeUnmount(() => {
59
+ children.value.delete(el.value)
60
+ })
61
+
62
+ const visible = computed(() => visibleChildrenCount.value > state.index)
63
+
64
+ return () => h('div', { ref: el, style: { visibility: visible.value ? 'visible' : 'hidden' } }, slots.default())
65
+ },
66
+ }
67
+
68
+ /**
69
+ * Wraps each child with a <ChildWrapper>
70
+ */
71
+ const ChildrenRender = (props, { slots }) => {
72
+ const [fragment] = slots.default()
73
+ return fragment.children.map((vnode, index) => h(ChildWrapper, { index }, () => [vnode]))
74
+ }
75
+
76
+ /**
77
+ * Only renders a part of a children list
78
+ */
79
+ const ChildrenSlice = (props, { slots }) => {
80
+ const [fragment] = slots.default()
81
+ return fragment.children.slice(props.start, props.end)
82
+ }
83
+ </script>
84
+
85
+ <template>
86
+ <div
87
+ ref="el"
88
+ class="htw-flex htw-overflow-hidden htw-relative"
89
+ >
90
+ <ChildrenRender>
91
+ <slot />
92
+ </ChildrenRender>
93
+
94
+ <VDropdown
95
+ v-if="visibleChildrenCount < children.size"
96
+ >
97
+ <div
98
+ role="button"
99
+ class="htw-cursor-pointer hover:htw-bg-primary-50 dark:hover:htw-bg-primary-900 htw-w-8 htw-h-full htw-flex htw-items-center htw-justify-center htw-absolute htw-top-0 htw-right-0"
100
+ >
101
+ <Icon
102
+ icon="carbon:caret-down"
103
+ class="htw-w-4 htw-h-4 htw-opacity-50 group-hover:htw-opacity-100"
104
+ />
105
+ </div>
106
+
107
+ <template #popper>
108
+ <div class="htw-flex htw-flex-col htw-items-stretch">
109
+ <ChildrenSlice
110
+ :start="visibleChildrenCount"
111
+ >
112
+ <slot name="overflow" />
113
+ </ChildrenSlice>
114
+ </div>
115
+ </template>
116
+ </VDropdown>
117
+ </div>
118
+ </template>
@@ -0,0 +1,46 @@
1
+ <script lang="ts">
2
+ import { defineComponent } from 'vue'
3
+
4
+ export default defineComponent({
5
+ inheritAttrs: false,
6
+
7
+ props: {
8
+ exact: {
9
+ type: Boolean,
10
+ default: false,
11
+ },
12
+
13
+ matched: {
14
+ type: Boolean,
15
+ default: null,
16
+ },
17
+ },
18
+ })
19
+ </script>
20
+
21
+ <template>
22
+ <router-link
23
+ v-slot="{ isActive, isExactActive, href, navigate }"
24
+ v-bind="$attrs"
25
+ custom
26
+ >
27
+ <a
28
+ v-bind="$attrs"
29
+ :href="href"
30
+ class="htw-px-4 htw-h-10 htw-min-w-[150px] htw-inline-flex htw-items-center hover:htw-bg-primary-50 dark:hover:htw-bg-primary-900 htw-relative htw-text-gray-900 dark:htw-text-gray-100"
31
+ :class="{
32
+ 'htw-text-primary-500 dark:htw-text-primary-400': matched != null ? matched : (exact && isExactActive) || (!exact && isActive),
33
+ }"
34
+ @click="navigate"
35
+ >
36
+ <slot />
37
+
38
+ <transition name="__histoire-scale-y">
39
+ <div
40
+ v-if="matched != null ? matched : (exact && isExactActive) || (!exact && isActive)"
41
+ class="htw-absolute htw-top-0 htw-left-0 htw-h-full htw-w-[2px] htw-bg-primary-500 dark:htw-bg-primary-400"
42
+ />
43
+ </transition>
44
+ </a>
45
+ </router-link>
46
+ </template>
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { computed, defineComponent, provide, useAttrs, VNode, h, PropType, getCurrentInstance } from 'vue'
3
- import { Story } from '../../types.js'
3
+ import type { Story } from '../../types.js'
4
4
  import Variant from './Variant.vue'
5
5
 
6
6
  export default defineComponent({
@@ -18,6 +18,8 @@ export default defineComponent({
18
18
  },
19
19
 
20
20
  setup () {
21
+ const vm = getCurrentInstance()
22
+
21
23
  const attrs = useAttrs() as {
22
24
  story: Story
23
25
  }
@@ -25,7 +27,7 @@ export default defineComponent({
25
27
  const story = computed(() => attrs.story)
26
28
  provide('story', story)
27
29
 
28
- const storyComponent: any = getCurrentInstance().parent
30
+ const storyComponent: any = vm.parent
29
31
  // Allows tracking reactivity with watchers to sync state
30
32
  const implicitState = {
31
33
  $data: storyComponent.data,
@@ -46,12 +48,21 @@ export default defineComponent({
46
48
  }
47
49
  provide('implicitState', () => implicitState)
48
50
 
51
+ function updateStory () {
52
+ Object.assign(attrs.story, {
53
+ slots: () => vm.proxy.$slots,
54
+ })
55
+ }
56
+
49
57
  return {
50
58
  story,
59
+ updateStory,
51
60
  }
52
61
  },
53
62
 
54
63
  render () {
64
+ this.updateStory()
65
+
55
66
  const [firstVariant] = this.story.variants
56
67
  if (firstVariant.id === '_default') {
57
68
  return h(Variant, {
@@ -24,6 +24,11 @@ export default defineComponent({
24
24
  type: Boolean,
25
25
  default: false,
26
26
  },
27
+
28
+ setupApp: {
29
+ type: Function,
30
+ default: null,
31
+ },
27
32
  },
28
33
 
29
34
  setup (props) {
@@ -53,6 +58,7 @@ export default defineComponent({
53
58
  slots: () => vm.proxy.$slots,
54
59
  source: props.source,
55
60
  responsiveDisabled: props.responsiveDisabled,
61
+ setupApp: props.setupApp,
56
62
  configReady: true,
57
63
  })
58
64
  }
@@ -0,0 +1,64 @@
1
+ <script lang="ts" setup>
2
+ import BaseTab from '../base/BaseTab.vue'
3
+ import { useEventsStore } from '../../stores/events'
4
+ import BaseOverflowMenu from '../base/BaseOverflowMenu.vue'
5
+ import BaseOverflowTab from '../base/BaseOverflowTab.vue'
6
+
7
+ const eventsStore = useEventsStore()
8
+ </script>
9
+
10
+ <template>
11
+ <BaseOverflowMenu class="htw-h-10 htw-flex-none htw-border-b htw-border-gray-100 dark:htw-border-gray-750">
12
+ <BaseTab
13
+ :to="{ ...$route, query: { ...$route.query, tab: '' } }"
14
+ :matched="!$route.query.tab"
15
+ >
16
+ Controls
17
+ </BaseTab>
18
+ <BaseTab
19
+ :to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
20
+ :matched="$route.query.tab === 'docs'"
21
+ >
22
+ Docs
23
+ </BaseTab>
24
+ <BaseTab
25
+ :to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
26
+ :matched="$route.query.tab === 'events'"
27
+ >
28
+ Events
29
+ <span
30
+ v-if="eventsStore.unseen"
31
+ 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"
32
+ >
33
+ {{ eventsStore.unseen <=99 ? eventsStore.unseen : "99+" }}
34
+ </span>
35
+ </BaseTab>
36
+
37
+ <template #overflow>
38
+ <BaseOverflowTab
39
+ :to="{ ...$route, query: { ...$route.query, tab: '' } }"
40
+ :matched="!$route.query.tab"
41
+ >
42
+ Controls
43
+ </BaseOverflowTab>
44
+ <BaseOverflowTab
45
+ :to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
46
+ :matched="$route.query.tab === 'docs'"
47
+ >
48
+ Docs
49
+ </BaseOverflowTab>
50
+ <BaseOverflowTab
51
+ :to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
52
+ :matched="$route.query.tab === 'events'"
53
+ >
54
+ Events
55
+ <span
56
+ v-if="eventsStore.unseen"
57
+ 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
+ >
59
+ {{ eventsStore.unseen <=99 ? eventsStore.unseen : "99+" }}
60
+ </span>
61
+ </BaseOverflowTab>
62
+ </template>
63
+ </BaseOverflowMenu>
64
+ </template>
@@ -22,7 +22,7 @@ defineProps({
22
22
  <div data-test-id="story-controls">
23
23
  <!-- Custom controls -->
24
24
  <SandboxVue3
25
- v-if="variant.slots().controls"
25
+ v-if="variant.slots().controls || story.slots().controls"
26
26
  slot-name="controls"
27
27
  :variant="variant"
28
28
  :story="story"
@@ -22,6 +22,7 @@ const formattedArgument = computed(() => {
22
22
  <VDropdown
23
23
  class="htw-group"
24
24
  placement="right"
25
+ data-test-id="event-item"
25
26
  >
26
27
  <template #default="{ shown }">
27
28
  <div
@@ -1,21 +1,18 @@
1
1
  <script lang="ts" setup>
2
2
  import { computed } from 'vue'
3
- import { useRoute, useRouter } from 'vue-router'
3
+ import { useRoute } from 'vue-router'
4
4
  import { useStoryStore } from '../../stores/story'
5
- import { useEventsStore } from '../../stores/events'
6
5
 
7
6
  import BaseSplitPane from '../base/BaseSplitPane.vue'
8
7
  import BaseEmpty from '../base/BaseEmpty.vue'
9
- import BaseTab from '../base/BaseTab.vue'
10
8
  import StoryControls from './StoryControls.vue'
11
9
  import StoryDocs from './StoryDocs.vue'
12
10
  import StoryEvents from './StoryEvents.vue'
13
11
  import StorySourceCode from './StorySourceCode.vue'
12
+ import PaneTabs from './PaneTabs.vue'
14
13
 
15
14
  const storyStore = useStoryStore()
16
- const eventsStore = useEventsStore()
17
15
 
18
- const router = useRouter()
19
16
  const route = useRoute()
20
17
 
21
18
  const panelContentComponent = computed(() => {
@@ -48,32 +45,7 @@ const panelContentComponent = computed(() => {
48
45
  >
49
46
  <template #first>
50
47
  <div class="htw-flex htw-flex-col htw-h-full">
51
- <nav class="htw-h-10 htw-flex-none htw-border-b htw-border-gray-100 dark:htw-border-gray-750">
52
- <BaseTab
53
- :to="{ ...$route, query: { ...$route.query, tab: '' } }"
54
- :matched="!$route.query.tab"
55
- >
56
- Controls
57
- </BaseTab>
58
- <BaseTab
59
- :to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
60
- :matched="$route.query.tab === 'docs'"
61
- >
62
- Docs
63
- </BaseTab>
64
- <BaseTab
65
- :to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
66
- :matched="$route.query.tab === 'events'"
67
- >
68
- Events
69
- <span
70
- v-if="eventsStore.unseen"
71
- class="htw-text-center htw-text-gray-900 dark:htw-text-gray-100 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"
72
- >
73
- {{ eventsStore.unseen <=99 ? eventsStore.unseen : "99+" }}
74
- </span>
75
- </BaseTab>
76
- </nav>
48
+ <PaneTabs />
77
49
 
78
50
  <component
79
51
  :is="panelContentComponent"
@@ -40,6 +40,8 @@ async function mountVariant () {
40
40
  render: () => {
41
41
  return props.variant.slots()?.[props.slotName]?.({
42
42
  state: props.variant.state ?? {},
43
+ }) ?? props.story.slots()?.[props.slotName]?.({
44
+ state: props.variant.state ?? {},
43
45
  })
44
46
  },
45
47
  })
@@ -52,6 +54,14 @@ async function mountVariant () {
52
54
  })
53
55
  }
54
56
 
57
+ if (typeof props.variant.setupApp === 'function') {
58
+ await props.variant.setupApp({
59
+ app,
60
+ story: props.story,
61
+ variant: props.variant,
62
+ })
63
+ }
64
+
55
65
  const target = document.createElement('div')
56
66
  sandbox.value.appendChild(target)
57
67
  app.mount(target)
@@ -3,7 +3,7 @@ import { PropType, ref, toRefs } from 'vue'
3
3
  import { useRouter } from 'vue-router'
4
4
  import { Icon } from '@iconify/vue'
5
5
  import { SearchResult } from '../../types'
6
- import { onKeyboardShortcut } from '../../util/keyboard.js'
6
+ import { onKeyboardShortcut } from '../../util/keyboard'
7
7
  import BaseListItemLink from '../base/BaseListItemLink.vue'
8
8
  import { useScrollOnActive } from '../../util/scroll'
9
9
 
@@ -1,6 +1,6 @@
1
1
  <script lang="ts" setup>
2
2
  import { useFocus, useDebounce } from '@vueuse/core'
3
- import { ref, watch } from 'vue'
3
+ import { computed, ref, watch } from 'vue'
4
4
  import { Icon } from '@iconify/vue'
5
5
  import flexsearch from 'flexsearch'
6
6
  import charset from 'flexsearch/dist/module/lang/latin/advanced.js'
@@ -9,7 +9,10 @@ import { useStoryStore } from '../../stores/story'
9
9
  import BaseEmpty from '../base/BaseEmpty.vue'
10
10
  import type { SearchResult, Story, Variant } from '../../types'
11
11
  import SearchItem from './SearchItem.vue'
12
- import { searchData, onUpdate } from './search-data.js'
12
+ import { searchData, onUpdate } from './search-title-data'
13
+ import type { SearchData } from './types'
14
+
15
+ const DocSearchData = () => import('./search-docs-data')
13
16
 
14
17
  const props = defineProps({
15
18
  shown: {
@@ -42,34 +45,40 @@ watch(() => props.shown, value => {
42
45
  }
43
46
  })
44
47
 
45
- // Search
48
+ // Index
46
49
 
47
50
  const searchInputText = ref('')
48
51
  const rateLimitedSearch = useDebounce(searchInputText, 50)
49
52
 
50
53
  const storyStore = useStoryStore()
51
54
 
52
- let searchIndex: flexsearch.Document<any, any>
55
+ let titleSearchIndex: flexsearch.Document<any, any>
56
+ let titleIdMap: SearchData['idMap']
53
57
 
54
- async function loadSearchIndex (data) {
55
- searchIndex = new flexsearch.Document({
58
+ function createIndex () {
59
+ return new flexsearch.Document({
56
60
  preset: 'match',
57
61
  document: {
58
62
  id: 'id',
59
63
  index: [
60
- 'title',
61
- 'docs',
64
+ 'text',
62
65
  ],
63
66
  },
64
67
  worker: true,
65
68
  charset,
66
69
  language,
67
- tokenize: 'full',
70
+ tokenize: 'forward',
68
71
  })
72
+ }
69
73
 
70
- for (const key of Object.keys(data)) {
71
- await searchIndex.import(key, data[key])
74
+ async function loadSearchIndex (data: SearchData) {
75
+ titleSearchIndex = createIndex()
76
+
77
+ for (const key of Object.keys(data.index)) {
78
+ await titleSearchIndex.import(key, data.index[key])
72
79
  }
80
+
81
+ titleIdMap = data.idMap
73
82
  }
74
83
 
75
84
  loadSearchIndex(searchData)
@@ -78,26 +87,57 @@ onUpdate(searchData => {
78
87
  loadSearchIndex(searchData)
79
88
  })
80
89
 
81
- const results = ref<SearchResult[]>([])
90
+ let docSearchIndex: flexsearch.Document<any, any>
91
+ let docIdMap: SearchData['idMap']
92
+
93
+ async function loadDocSearchIndex () {
94
+ async function load (data: SearchData) {
95
+ docSearchIndex = createIndex()
96
+
97
+ for (const key of Object.keys(data.index)) {
98
+ await docSearchIndex.import(key, data.index[key])
99
+ }
100
+
101
+ docIdMap = data.idMap
102
+
103
+ if (rateLimitedSearch.value) {
104
+ searchOnDocField(rateLimitedSearch.value)
105
+ }
106
+ }
107
+
108
+ const searchDataModule = await DocSearchData()
109
+
110
+ load(searchDataModule.searchData)
111
+ // Handle HMR
112
+ searchDataModule.onUpdate(searchData => {
113
+ load(searchData)
114
+ })
115
+ }
116
+
117
+ loadDocSearchIndex()
118
+
119
+ // Search
120
+
121
+ const titleResults = ref<SearchResult[]>([])
82
122
 
83
123
  watch(rateLimitedSearch, async value => {
84
124
  const list: SearchResult[] = []
85
- const raw = await searchIndex.search(value, {
86
- enrich: true,
87
- })
125
+ const raw = await titleSearchIndex.search(value)
88
126
  let rank = 0
89
127
  for (const field of raw) {
90
- for (const item of field.result as any[]) {
91
- switch (item.doc.kind) {
128
+ for (const id of field.result) {
129
+ const idMapData = titleIdMap[id]
130
+ if (!idMapData) continue
131
+ switch (idMapData.kind) {
92
132
  case 'story': {
93
- list.push(storyResultFactory(storyStore.getStoryById(item.id), rank))
133
+ list.push(storyResultFactory(storyStore.getStoryById(idMapData.id), rank))
94
134
  rank++
95
135
  break
96
136
  }
97
137
  case 'variant': {
98
- const [storyId] = item.id.split(':')
138
+ const [storyId] = idMapData.id.split(':')
99
139
  const story = storyStore.getStoryById(storyId)
100
- const variant = storyStore.getVariantById(item.id)
140
+ const variant = storyStore.getVariantById(idMapData.id)
101
141
  list.push(variantResultFactory(story, variant, rank))
102
142
  rank++
103
143
  break
@@ -105,14 +145,40 @@ watch(rateLimitedSearch, async value => {
105
145
  }
106
146
  }
107
147
  }
108
- results.value = list
148
+ titleResults.value = list
109
149
  })
110
150
 
151
+ const docsResults = ref<SearchResult[]>([])
152
+
153
+ async function searchOnDocField (query: string) {
154
+ if (docSearchIndex) {
155
+ const list: SearchResult[] = []
156
+ const raw = await docSearchIndex.search(query)
157
+ let rank = 0
158
+ for (const field of raw) {
159
+ for (const id of field.result) {
160
+ const idMapData = docIdMap[id]
161
+ if (!idMapData) continue
162
+ switch (idMapData.kind) {
163
+ case 'story': {
164
+ list.push(storyResultFactory(storyStore.getStoryById(idMapData.id), rank))
165
+ rank++
166
+ break
167
+ }
168
+ }
169
+ }
170
+ }
171
+ docsResults.value = list
172
+ }
173
+ }
174
+
175
+ watch(rateLimitedSearch, searchOnDocField)
176
+
111
177
  function storyResultFactory (story: Story, rank: number): SearchResult {
112
178
  return {
113
179
  kind: 'story',
114
180
  rank,
115
- id: story.id,
181
+ id: `story:${story.id}`,
116
182
  title: story.title,
117
183
  route: {
118
184
  name: 'story',
@@ -130,7 +196,7 @@ function variantResultFactory (story: Story, variant: Variant, rank: number): Se
130
196
  return {
131
197
  kind: 'variant',
132
198
  rank,
133
- id: variant.id,
199
+ id: `variant:${story.id}:${variant.id}`,
134
200
  title: variant.title,
135
201
  route: {
136
202
  name: 'story',
@@ -147,6 +213,20 @@ function variantResultFactory (story: Story, variant: Variant, rank: number): Se
147
213
  }
148
214
  }
149
215
 
216
+ const results = computed(() => {
217
+ const list = [...titleResults.value]
218
+ const seen = {}
219
+ for (const r of titleResults.value) {
220
+ seen[r.id] = true
221
+ }
222
+ for (const r of docsResults.value) {
223
+ if (!seen[r.id]) {
224
+ list.push(r)
225
+ }
226
+ }
227
+ return list
228
+ })
229
+
150
230
  // Selection
151
231
 
152
232
  const selectedIndex = ref(0)
@@ -191,7 +271,10 @@ function selectPrevious () {
191
271
  >
192
272
  </div>
193
273
 
194
- <BaseEmpty v-if="rateLimitedSearch && !results.length">
274
+ <BaseEmpty
275
+ v-if="rateLimitedSearch && !results.length"
276
+ class="no-animation"
277
+ >
195
278
  No results
196
279
  </BaseEmpty>
197
280
 
@@ -201,7 +284,7 @@ function selectPrevious () {
201
284
  >
202
285
  <SearchItem
203
286
  v-for="(result, index) of results"
204
- :key="`${result.kind}-${result.id}`"
287
+ :key="result.id"
205
288
  :result="result"
206
289
  :selected="index === selectedIndex"
207
290
  @close="close()"
@@ -0,0 +1,10 @@
1
+ import { markRaw } from 'vue'
2
+ // @ts-expect-error virtual module
3
+ import { searchData as _searchData, onUpdate as _onUpdate } from '$histoire-search-docs-data'
4
+ import type { SearchData } from './types.js'
5
+
6
+ export const searchData: SearchData = markRaw(_searchData)
7
+
8
+ export function onUpdate (cb: (data: SearchData) => unknown) {
9
+ _onUpdate(cb)
10
+ }
@@ -0,0 +1,10 @@
1
+ import { markRaw } from 'vue'
2
+ // @ts-expect-error virtual module
3
+ import { searchData as _searchData, onUpdate as _onUpdate } from '$histoire-search-title-data'
4
+ import type { SearchData } from './types.js'
5
+
6
+ export const searchData: SearchData = markRaw(_searchData)
7
+
8
+ export function onUpdate (cb: (data: SearchData) => unknown) {
9
+ _onUpdate(cb)
10
+ }
@@ -0,0 +1,4 @@
1
+ export interface SearchData {
2
+ index: Record<string, any>
3
+ idMap: Record<number, { id: string, kind: string }>
4
+ }