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
@@ -1,8 +1,8 @@
1
1
  <script lang="ts" setup>
2
2
  import { Icon } from '@iconify/vue'
3
- import { usePreviewSettingsStore } from '../../../stores/preview-settings'
4
- import { histoireConfig } from '../../../util/config'
5
- import BaseCheckbox from '../../base/BaseCheckbox.vue'
3
+ import { usePreviewSettingsStore } from '../../stores/preview-settings'
4
+ import { histoireConfig } from '../../util/config'
5
+ import BaseCheckbox from '../base/BaseCheckbox.vue'
6
6
 
7
7
  const settings = usePreviewSettingsStore().currentSettings
8
8
  </script>
@@ -1,6 +1,6 @@
1
1
  <script lang="ts" setup>
2
2
  import { Icon } from '@iconify/vue'
3
- import type { Variant } from '../../../types'
3
+ import type { Variant } from '../../types'
4
4
 
5
5
  defineProps<{
6
6
  variant: Variant
@@ -4,7 +4,7 @@ import BaseListItemLink from '../base/BaseListItemLink.vue'
4
4
  import { Icon } from '@iconify/vue'
5
5
  import { computed, ref, withDefaults } from 'vue'
6
6
  import { useRoute } from 'vue-router'
7
- import { useScrollOnActive } from '../../util/scroll.js'
7
+ import { useScrollOnActive } from '../../util/scroll'
8
8
 
9
9
  const props = withDefaults(defineProps<{
10
10
  story: Story
@@ -1,6 +1,8 @@
1
- import '$histoire-theme'
2
- import '../../style.css'
1
+ /* eslint-disable import/first */
2
+
3
+ // export * from 'vue'
3
4
 
5
+ import '$histoire-theme'
4
6
  import { createApp } from 'vue'
5
7
  import { createPinia } from 'pinia'
6
8
  import FloatingVue from 'floating-vue'
@@ -8,21 +10,23 @@ import App from './App.vue'
8
10
  import { registerGlobalComponents } from './global-components.js'
9
11
  import { router } from './router'
10
12
 
11
- const app = createApp(App)
12
- app.use(createPinia())
13
- app.use(FloatingVue, {
14
- overflowPadding: 4,
15
- arrowPadding: 8,
16
- themes: {
17
- tooltip: {
18
- distance: 8,
19
- },
20
- dropdown: {
21
- computeTransformOrigin: true,
22
- distance: 8,
13
+ export function mountMainApp () {
14
+ const app = createApp(App)
15
+ app.use(createPinia())
16
+ app.use(FloatingVue, {
17
+ overflowPadding: 4,
18
+ arrowPadding: 8,
19
+ themes: {
20
+ tooltip: {
21
+ distance: 8,
22
+ },
23
+ dropdown: {
24
+ computeTransformOrigin: true,
25
+ distance: 8,
26
+ },
23
27
  },
24
- },
25
- })
26
- app.use(router)
27
- registerGlobalComponents(app)
28
- app.mount('#app')
28
+ })
29
+ app.use(router)
30
+ registerGlobalComponents(app)
31
+ app.mount('#app')
32
+ }
@@ -1,6 +1,5 @@
1
- import './style/sandbox.css'
2
1
  import { parseQuery } from 'vue-router'
3
- import { computed, createApp, h, onMounted, ref, watch, isRef } from 'vue'
2
+ import { computed, createApp, h, onMounted, ref, watch } from 'vue'
4
3
  import { createPinia } from 'pinia'
5
4
  import { registerGlobalComponents } from './global-components'
6
5
  import SandboxVue3 from './components/sandbox/SandboxVue3.vue'
@@ -23,7 +23,7 @@ export const useEventsStore = defineStore('events', () => {
23
23
  unseen.value = 0
24
24
  }
25
25
 
26
- watch(() => storyStore.currentVariant, () => {
26
+ watch(() => storyStore.currentVariant?.id, () => {
27
27
  reset()
28
28
  })
29
29
 
@@ -11,6 +11,19 @@
11
11
  }
12
12
  }
13
13
 
14
+ .__histoire-scale-y {
15
+ &-enter-active,
16
+ &-leave-active {
17
+ transition: transform .15s, opacity .15s;
18
+ }
19
+
20
+ &-enter-from,
21
+ &-leave-to {
22
+ transform: scaleY(0);
23
+ opacity: 0;
24
+ }
25
+ }
26
+
14
27
  .__histoire-fade {
15
28
  &-enter-active,
16
29
  &-leave-active {
@@ -1,3 +1,4 @@
1
+ import { App } from 'vue'
1
2
  import type { RouteLocationRaw } from 'vue-router'
2
3
 
3
4
  export interface StoryFile {
@@ -15,6 +16,7 @@ export interface Story {
15
16
  variants: Variant[]
16
17
  layout?: {
17
18
  type: 'single'
19
+ iframe?: boolean
18
20
  } | {
19
21
  type: 'grid'
20
22
  width?: number | string
@@ -24,6 +26,7 @@ export interface Story {
24
26
  docsOnly?: boolean
25
27
  file?: StoryFile
26
28
  lastSelectedVariant?: Variant
29
+ slots?: () => Readonly<any>
27
30
  }
28
31
 
29
32
  export interface Variant {
@@ -32,6 +35,7 @@ export interface Variant {
32
35
  icon?: string
33
36
  iconColor?: string
34
37
  initState?: () => any
38
+ setupApp?: (payload: any) => unknown
35
39
  slots?: () => Readonly<any>
36
40
  state?: any
37
41
  source?: string
@@ -1,7 +1,6 @@
1
- import { useEventsStore } from '../stores/events.js'
2
1
  import { EVENT_SEND } from './const'
3
2
 
4
- export function hstEvent (name: string, argument) {
3
+ export async function hstEvent (name: string, argument) {
5
4
  console.log('[histoire] Event fired', { name, argument })
6
5
  const event = {
7
6
  name,
@@ -13,6 +12,7 @@ export function hstEvent (name: string, argument) {
13
12
  event,
14
13
  })
15
14
  } else {
15
+ const { useEventsStore } = await import('../stores/events.js')
16
16
  useEventsStore().addEvent(event)
17
17
  }
18
18
  }
@@ -10,6 +10,7 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
10
10
  title: file.story.title,
11
11
  file: markRaw(file),
12
12
  variants: file.story.variants.map(v => mapVariant(v)),
13
+ slots: () => ({}),
13
14
  },
14
15
  }
15
16
 
@@ -42,6 +43,7 @@ export function mapVariant (variant: Variant): Variant {
42
43
  ...variant,
43
44
  state: null,
44
45
  initState: null,
46
+ setupApp: null,
45
47
  slots: () => ({}),
46
48
  previewReady: false,
47
49
  }
@@ -0,0 +1,5 @@
1
+ export * from '../bundled/api.js'
2
+
3
+ export function defineSetupVue3 (handler) {
4
+ return handler
5
+ }
@@ -0,0 +1,5 @@
1
+ import '../style.css'
2
+ import '../bundled/style.css'
3
+ import { mountMainApp } from '../bundled/index.js'
4
+
5
+ mountMainApp()
@@ -0,0 +1,3 @@
1
+ import '../style.css'
2
+ import './app/style/sandbox.css'
3
+ import '../bundled/sandbox.js'
@@ -1,6 +1,6 @@
1
1
  import type { App } from 'vue'
2
2
  import type { Story, Variant } from './app/types.js'
3
- export { hstEvent } from './app/util/events'
3
+ export * from './app/api.js'
4
4
 
5
5
  export type Vue3StorySetupHandler = (payload: {
6
6
  app: App
@@ -23,7 +23,7 @@ export default defineComponent({
23
23
 
24
24
  layout: {
25
25
  type: Object as PropType<Story['layout']>,
26
- default: () => ({ type: 'single' }),
26
+ default: () => ({ type: 'single', iframe: true }),
27
27
  },
28
28
 
29
29
  icon: {
@@ -8,6 +8,7 @@ import * as setup from '$histoire-setup'
8
8
 
9
9
  export async function run ({ file, storyData, el }: ServerRunPayload) {
10
10
  const { default: Comp } = await import(file.moduleId)
11
+
11
12
  const app = createApp({
12
13
  provide: {
13
14
  addStory (data) {
@@ -34,5 +35,15 @@ export async function run ({ file, storyData, el }: ServerRunPayload) {
34
35
  registerVueComponents(app)
35
36
 
36
37
  app.mount(el)
38
+
39
+ if (Comp.doc) {
40
+ const el = document.createElement('div')
41
+ el.innerHTML = Comp.doc
42
+ const text = el.textContent
43
+ storyData.forEach(s => {
44
+ s.docsText = text
45
+ })
46
+ }
47
+
37
48
  app.unmount()
38
49
  }
package/src/node/alias.ts CHANGED
@@ -4,6 +4,6 @@ import { fileURLToPath } from 'url'
4
4
  const __dirname = dirname(fileURLToPath(import.meta.url))
5
5
 
6
6
  export const DIST_PATH = join(__dirname, '../')
7
- export const APP_PATH = join(DIST_PATH, 'client', 'app')
7
+ export const APP_PATH = join(DIST_PATH, 'client')
8
8
 
9
9
  export const TEMP_PATH = join(process.cwd(), 'node_modules', '.histoire')
package/src/node/build.ts CHANGED
@@ -67,8 +67,8 @@ export async function build (ctx: Context) {
67
67
  build: {
68
68
  rollupOptions: {
69
69
  input: [
70
- join(APP_PATH, 'index.js'),
71
- join(APP_PATH, 'sandbox.js'),
70
+ join(APP_PATH, 'bundle-main.js'),
71
+ join(APP_PATH, 'bundle-sandbox.js'),
72
72
  ],
73
73
  output: {
74
74
  manualChunks (id) {
@@ -101,14 +101,14 @@ export async function build (ctx: Context) {
101
101
  const prefetchHtml = generateScriptLinks(prefetchOutputs.map(o => o.fileName), 'prefetch', ctx, resolvedViteConfig)
102
102
 
103
103
  // Index
104
- const indexOutput = result.output.find(o => o.name === 'index' && o.type === 'chunk')
104
+ const indexOutput = result.output.find(o => o.name === 'bundle-main' && o.type === 'chunk')
105
105
  const indexHtml = generateEntryHtml(indexOutput.fileName, styleOutput.fileName, {
106
106
  HEAD: `${preloadHtml}${prefetchHtml}`,
107
107
  }, ctx, resolvedViteConfig)
108
108
  await writeFile('index.html', indexHtml, ctx)
109
109
 
110
110
  // Sandbox
111
- const sandboxOutput = result.output.find(o => o.name === 'sandbox' && o.type === 'chunk')
111
+ const sandboxOutput = result.output.find(o => o.name === 'bundle-sandbox' && o.type === 'chunk')
112
112
  const sandboxHtml = generateEntryHtml(sandboxOutput.fileName, styleOutput.fileName, {}, ctx, resolvedViteConfig)
113
113
  await writeFile('__sandbox.html', sandboxHtml, ctx)
114
114
 
@@ -94,7 +94,7 @@ defineExpose({
94
94
  })
95
95
  </script>
96
96
  <template>
97
- <Story id="tailwind" title="Tailwind" group="design-system" icon="mdi:tailwind" responsiveDisabled>
97
+ <Story id="tailwind" title="Tailwind" group="design-system" icon="mdi:tailwind" responsiveDisabled :layout="{ type: 'single', iframe: false }">
98
98
  <Variant id="background-color" title="Background Color" icon="carbon:color-palette">
99
99
  <HstColorShades
100
100
  v-for="(shades, key) of config.theme.backgroundColor"
@@ -1,60 +1,93 @@
1
1
  import { createRequire } from 'module'
2
2
  import flexsearch from 'flexsearch'
3
3
  import path from 'pathe'
4
+ import Case from 'case'
4
5
  import { Context } from './context.js'
5
6
  import { loadModule } from './load.js'
6
7
 
7
8
  const require = createRequire(import.meta.url)
8
9
 
9
- export async function generateSearchData (ctx: Context) {
10
+ export async function generateTitleSearchData (ctx: Context) {
11
+ const searchIndex = await createIndex()
12
+ const { idMap, addToIdMap } = createIdMap()
13
+
14
+ for (const storyFile of ctx.storyFiles) {
15
+ if (storyFile.story) {
16
+ searchIndex.add({
17
+ id: addToIdMap(storyFile.story.id, 'story'),
18
+ text: convertTitleToSentence(storyFile.story.title),
19
+ })
20
+ for (const variant of storyFile.story.variants) {
21
+ searchIndex.add({
22
+ id: addToIdMap(`${storyFile.story.id}:${variant.id}`, 'variant'),
23
+ text: convertTitleToSentence(`${storyFile.story.title} ${variant.title}`),
24
+ })
25
+ }
26
+ }
27
+ }
28
+
29
+ return {
30
+ index: await exportSearchIndex(searchIndex),
31
+ idMap,
32
+ }
33
+ }
34
+
35
+ export async function generateDocSearchData (ctx: Context) {
36
+ const searchIndex = await createIndex()
37
+ const { idMap, addToIdMap } = createIdMap()
38
+
39
+ for (const storyFile of ctx.storyFiles) {
40
+ if (storyFile.story && storyFile.story.docsText) {
41
+ searchIndex.add({
42
+ id: addToIdMap(storyFile.story.id, 'story'),
43
+ text: storyFile.story.docsText,
44
+ })
45
+ }
46
+ }
47
+
48
+ return {
49
+ index: await exportSearchIndex(searchIndex),
50
+ idMap,
51
+ }
52
+ }
53
+
54
+ async function createIndex () {
10
55
  const flexsearchRoot = path.dirname(require.resolve('flexsearch/package.json'))
11
- const searchIndex = new flexsearch.Document({
56
+ return new flexsearch.Document({
12
57
  preset: 'match',
13
58
  document: {
14
59
  id: 'id',
15
60
  index: [
16
- 'title',
17
- 'docs',
18
- ],
19
- store: [
20
- 'kind',
61
+ 'text',
21
62
  ],
22
63
  },
23
64
  charset: await loadModule(`${flexsearchRoot}/dist/module/lang/latin/advanced.js`),
24
65
  language: await loadModule(`${flexsearchRoot}/dist/module/lang/en.js`),
25
- tokenize: 'full',
66
+ tokenize: 'forward',
26
67
  })
68
+ }
27
69
 
28
- for (const storyFile of ctx.storyFiles) {
29
- if (storyFile.story) {
30
- searchIndex.add({
31
- id: storyFile.story.id,
32
- kind: 'story',
33
- title: storyFile.story.title,
34
- docs: '', // @TODO
35
- })
36
- for (const variant of storyFile.story.variants) {
37
- searchIndex.add({
38
- id: `${storyFile.story.id}:${variant.id}`,
39
- kind: 'variant',
40
- title: `${storyFile.story.title} ${variant.title}`,
41
- docs: '', // @TODO
42
- })
43
- }
44
- }
70
+ function createIdMap () {
71
+ let uid = 0
72
+ const idMap: Record<number, { id: string, kind: string }> = {}
73
+
74
+ function addToIdMap (id: string, kind: string) {
75
+ const n = uid++
76
+ idMap[n] = { id, kind }
77
+ return n
45
78
  }
46
79
 
47
- return exportSearchIndex(searchIndex)
80
+ return {
81
+ idMap,
82
+ addToIdMap,
83
+ }
48
84
  }
49
85
 
50
86
  const exportKeys = new Set([
51
87
  'reg',
52
- 'title.cfg',
53
- 'title.map',
54
- 'title.ctx',
55
- 'docs.cfg',
56
- 'docs.map',
57
- 'docs.ctx',
88
+ 'text.cfg',
89
+ 'text.map',
90
+ 'text.ctx',
58
91
  'tag',
59
92
  'store',
60
93
  ])
@@ -73,3 +106,25 @@ async function exportSearchIndex (index) {
73
106
  })
74
107
  })
75
108
  }
109
+
110
+ function convertTitleToSentence (text: string) {
111
+ return text.split(' ').map(str => Case.lower(str)).join(' ')
112
+ }
113
+
114
+ // @TODO clear handlers when SearchPane unmounts
115
+ export function getSearchDataJS (data: any) {
116
+ return `export let searchData = ${JSON.stringify(data)}
117
+ const handlers = []
118
+ export function onUpdate (cb) {
119
+ handlers.push(cb)
120
+ }
121
+ if (import.meta.hot) {
122
+ import.meta.hot.accept(newModule => {
123
+ searchData = newModule.searchData
124
+ handlers.forEach(h => {
125
+ h(newModule.searchData)
126
+ newModule.onUpdate(h)
127
+ })
128
+ })
129
+ }`
130
+ }
@@ -1,6 +1,6 @@
1
1
  import { createServer as createViteServer } from 'vite'
2
2
  import { Context } from './context.js'
3
- import { createVitePlugins, RESOLVED_SEARCH_DATA_ID, RESOLVED_STORIES_ID } from './vite.js'
3
+ import { createVitePlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js'
4
4
  import { notifyStoryChange, onStoryChange, watchStories } from './stories.js'
5
5
  import { useCollectStories } from './collect/index.js'
6
6
  import type { StoryFile } from './types.js'
@@ -112,7 +112,7 @@ export async function createServer (ctx: Context, port: number) {
112
112
  }
113
113
 
114
114
  invalidateModule(RESOLVED_STORIES_ID)
115
- invalidateModule(RESOLVED_SEARCH_DATA_ID)
115
+ invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID)
116
116
  })
117
117
 
118
118
  async function close () {
package/src/node/types.ts CHANGED
@@ -42,6 +42,7 @@ export interface Story {
42
42
  icon?: string
43
43
  iconColor?: string
44
44
  docsOnly?: boolean
45
+ docsText?: string
45
46
  }
46
47
 
47
48
  export interface Variant {
package/src/node/vite.ts CHANGED
@@ -8,7 +8,7 @@ import { notifyStoryChange } from './stories.js'
8
8
  import { makeTree } from './tree.js'
9
9
  import { parseColor } from './colors.js'
10
10
  import { createMarkdownRenderer } from './markdown.js'
11
- import { generateSearchData } from './search.js'
11
+ import { getSearchDataJS, generateDocSearchData, generateTitleSearchData } from './search.js'
12
12
 
13
13
  const require = createRequire(import.meta.url)
14
14
 
@@ -20,19 +20,16 @@ export const CONFIG_ID = '$histoire-config'
20
20
  export const RESOLVED_CONFIG_ID = `/${CONFIG_ID}-resolved`
21
21
  export const THEME_ID = '$histoire-theme'
22
22
  export const RESOLVED_THEME_ID = `/${THEME_ID}-resolved.css`
23
- export const SEARCH_DATA_ID = '$histoire-search-data'
24
- export const RESOLVED_SEARCH_DATA_ID = `/${SEARCH_DATA_ID}-resolved`
23
+ export const SEARCH_TITLE_DATA_ID = '$histoire-search-title-data'
24
+ export const RESOLVED_SEARCH_TITLE_DATA_ID = `/${SEARCH_TITLE_DATA_ID}-resolved`
25
+ export const SEARCH_DOCS_DATA_ID = '$histoire-search-docs-data'
26
+ export const RESOLVED_SEARCH_DOCS_DATA_ID = `/${SEARCH_DOCS_DATA_ID}-resolved`
25
27
 
26
28
  export async function createVitePlugins (ctx: Context): Promise<VitePlugin[]> {
27
29
  const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build')
28
- const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue')
29
30
 
30
31
  const plugins: VitePlugin[] = []
31
32
 
32
- if (!hasVuePlugin) {
33
- plugins.push((await import('@vitejs/plugin-vue')).default())
34
- }
35
-
36
33
  if (ctx.config.vite) {
37
34
  plugins.push({
38
35
  name: 'histoire-vite-config-override',
@@ -51,12 +48,14 @@ export async function createVitePlugins (ctx: Context): Promise<VitePlugin[]> {
51
48
  // force include vue to avoid duplicated copies when linked + optimized
52
49
  include: [
53
50
  'vue',
54
- dirname(require.resolve('@vue/runtime-core/package.json')),
55
51
  dirname(require.resolve('shiki/package.json')),
56
52
  dirname(require.resolve('vscode-textmate/package.json')),
57
53
  dirname(require.resolve('vscode-oniguruma/package.json')),
58
54
  dirname(require.resolve('case/package.json')),
59
55
  ],
56
+ exclude: [
57
+ 'histoire',
58
+ ],
60
59
  },
61
60
  server: {
62
61
  fs: {
@@ -89,8 +88,11 @@ export async function createVitePlugins (ctx: Context): Promise<VitePlugin[]> {
89
88
  if (id.startsWith(THEME_ID)) {
90
89
  return RESOLVED_THEME_ID
91
90
  }
92
- if (id.startsWith(SEARCH_DATA_ID)) {
93
- return RESOLVED_SEARCH_DATA_ID
91
+ if (id.startsWith(SEARCH_TITLE_DATA_ID)) {
92
+ return RESOLVED_SEARCH_TITLE_DATA_ID
93
+ }
94
+ if (id.startsWith(SEARCH_DOCS_DATA_ID)) {
95
+ return RESOLVED_SEARCH_DOCS_DATA_ID
94
96
  }
95
97
  },
96
98
 
@@ -101,7 +103,10 @@ export async function createVitePlugins (ctx: Context): Promise<VitePlugin[]> {
101
103
  return {
102
104
  id: file.id,
103
105
  path: file.treePath,
104
- story: file.story,
106
+ story: {
107
+ ...file.story,
108
+ docsText: undefined,
109
+ },
105
110
  framework: 'vue3',
106
111
  index,
107
112
  }
@@ -149,21 +154,11 @@ if (import.meta.hot) {
149
154
  css += '}'
150
155
  return css
151
156
  }
152
- if (id === RESOLVED_SEARCH_DATA_ID) {
153
- return `export let searchData = ${JSON.stringify(await generateSearchData(ctx))}
154
- const handlers = []
155
- export function onUpdate (cb) {
156
- handlers.push(cb)
157
- }
158
- if (import.meta.hot) {
159
- import.meta.hot.accept(newModule => {
160
- searchData = newModule.searchData
161
- handlers.forEach(h => {
162
- h(newModule.searchData)
163
- newModule.onUpdate(h)
164
- })
165
- })
166
- }`
157
+ if (id === RESOLVED_SEARCH_TITLE_DATA_ID) {
158
+ return getSearchDataJS(await generateTitleSearchData(ctx))
159
+ }
160
+ if (id === RESOLVED_SEARCH_DOCS_DATA_ID) {
161
+ return getSearchDataJS(await generateDocSearchData(ctx))
167
162
  }
168
163
  },
169
164
 
@@ -198,7 +193,7 @@ if (import.meta.hot) {
198
193
  }
199
194
  }
200
195
  </script>
201
- <script type="module" src="/@fs/${APP_PATH}/sandbox.js"></script>
196
+ <script type="module" src="/@fs/${APP_PATH}/bundle-sandbox.js"></script>
202
197
  </body>
203
198
  </html>`
204
199
  // Apply Vite HTML transforms. This injects the Vite HMR client, and
@@ -229,7 +224,7 @@ if (import.meta.hot) {
229
224
  </head>
230
225
  <body>
231
226
  <div id="app"></div>
232
- <script type="module" src="/@fs/${APP_PATH}/index.js"></script>
227
+ <script type="module" src="/@fs/${APP_PATH}/bundle-main.js"></script>
233
228
  </body>
234
229
  </html>`
235
230
  // Apply Vite HTML transforms. This injects the Vite HMR client, and
package/vite.config.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { defineConfig } from 'vite'
2
+ import vue from '@vitejs/plugin-vue'
3
+
4
+ export default defineConfig({
5
+ plugins: [
6
+ vue(),
7
+ ],
8
+
9
+ build: {
10
+ emptyOutDir: false,
11
+ outDir: 'dist/bundled',
12
+ lib: {
13
+ entry: '',
14
+ formats: ['es'],
15
+ },
16
+ rollupOptions: {
17
+ external: [
18
+ /\$histoire/,
19
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
20
+ ...Object.keys(require('./package.json').dependencies),
21
+ ],
22
+
23
+ input: [
24
+ 'src/client/app/api.ts',
25
+ 'src/client/app/index.ts',
26
+ 'src/client/app/sandbox.ts',
27
+ ],
28
+
29
+ output: {
30
+ // manualChunks (id) {
31
+ // if (id.includes('node_modules')) {
32
+ // return 'vendor'
33
+ // }
34
+ // },
35
+ entryFileNames: '[name].js',
36
+ chunkFileNames: '[name].js',
37
+ assetFileNames: '[name][extname]',
38
+ hoistTransitiveImports: false,
39
+ },
40
+ treeshake: false,
41
+ preserveEntrySignatures: 'strict',
42
+ },
43
+ cssCodeSplit: false,
44
+ minify: false,
45
+ },
46
+ })
@@ -1,2 +0,0 @@
1
- export declare const searchData: Record<string, any>;
2
- export declare function onUpdate(cb: (data: typeof searchData) => unknown): void;
@@ -1,9 +0,0 @@
1
- import { markRaw } from 'vue'
2
- // @ts-expect-error virtual module
3
- import { searchData as _searchData, onUpdate as _onUpdate } from '$histoire-search-data'
4
-
5
- export const searchData: Record<string, any> = markRaw(_searchData)
6
-
7
- export function onUpdate (cb: (data: typeof searchData) => unknown) {
8
- _onUpdate(cb)
9
- }