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
@@ -10,6 +10,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
10
10
  icon?: string;
11
11
  iconColor?: string;
12
12
  initState?: () => any;
13
+ setupApp?: (payload: any) => unknown;
13
14
  slots?: () => Readonly<any>;
14
15
  state?: any;
15
16
  source?: string;
@@ -19,6 +20,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
19
20
  }[];
20
21
  layout?: {
21
22
  type: "single";
23
+ iframe?: boolean;
22
24
  } | {
23
25
  type: "grid";
24
26
  width?: string | number;
@@ -39,6 +41,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
39
41
  icon?: string;
40
42
  iconColor?: string;
41
43
  initState?: () => any;
44
+ setupApp?: (payload: any) => unknown;
42
45
  slots?: () => Readonly<any>;
43
46
  state?: any;
44
47
  source?: string;
@@ -46,6 +49,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
46
49
  configReady?: boolean;
47
50
  previewReady?: boolean;
48
51
  };
52
+ slots?: () => Readonly<any>;
49
53
  }[]>;
50
54
  setStories: (value: Story[]) => void;
51
55
  currentStory: import("vue").ComputedRef<{
@@ -58,6 +62,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
58
62
  icon?: string;
59
63
  iconColor?: string;
60
64
  initState?: () => any;
65
+ setupApp?: (payload: any) => unknown;
61
66
  slots?: () => Readonly<any>;
62
67
  state?: any;
63
68
  source?: string;
@@ -67,6 +72,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
67
72
  }[];
68
73
  layout?: {
69
74
  type: "single";
75
+ iframe?: boolean;
70
76
  } | {
71
77
  type: "grid";
72
78
  width?: string | number;
@@ -87,6 +93,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
87
93
  icon?: string;
88
94
  iconColor?: string;
89
95
  initState?: () => any;
96
+ setupApp?: (payload: any) => unknown;
90
97
  slots?: () => Readonly<any>;
91
98
  state?: any;
92
99
  source?: string;
@@ -94,6 +101,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
94
101
  configReady?: boolean;
95
102
  previewReady?: boolean;
96
103
  };
104
+ slots?: () => Readonly<any>;
97
105
  }>;
98
106
  currentVariant: import("vue").ComputedRef<{
99
107
  id: string;
@@ -101,6 +109,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
101
109
  icon?: string;
102
110
  iconColor?: string;
103
111
  initState?: () => any;
112
+ setupApp?: (payload: any) => unknown;
104
113
  slots?: () => Readonly<any>;
105
114
  state?: any;
106
115
  source?: string;
@@ -121,6 +130,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
121
130
  icon?: string;
122
131
  iconColor?: string;
123
132
  initState?: () => any;
133
+ setupApp?: (payload: any) => unknown;
124
134
  slots?: () => Readonly<any>;
125
135
  state?: any;
126
136
  source?: string;
@@ -130,6 +140,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
130
140
  }[];
131
141
  layout?: {
132
142
  type: "single";
143
+ iframe?: boolean;
133
144
  } | {
134
145
  type: "grid";
135
146
  width?: string | number;
@@ -150,6 +161,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
150
161
  icon?: string;
151
162
  iconColor?: string;
152
163
  initState?: () => any;
164
+ setupApp?: (payload: any) => unknown;
153
165
  slots?: () => Readonly<any>;
154
166
  state?: any;
155
167
  source?: string;
@@ -157,6 +169,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
157
169
  configReady?: boolean;
158
170
  previewReady?: boolean;
159
171
  };
172
+ slots?: () => Readonly<any>;
160
173
  }[]>;
161
174
  setStories: (value: Story[]) => void;
162
175
  currentStory: import("vue").ComputedRef<{
@@ -169,6 +182,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
169
182
  icon?: string;
170
183
  iconColor?: string;
171
184
  initState?: () => any;
185
+ setupApp?: (payload: any) => unknown;
172
186
  slots?: () => Readonly<any>;
173
187
  state?: any;
174
188
  source?: string;
@@ -178,6 +192,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
178
192
  }[];
179
193
  layout?: {
180
194
  type: "single";
195
+ iframe?: boolean;
181
196
  } | {
182
197
  type: "grid";
183
198
  width?: string | number;
@@ -198,6 +213,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
198
213
  icon?: string;
199
214
  iconColor?: string;
200
215
  initState?: () => any;
216
+ setupApp?: (payload: any) => unknown;
201
217
  slots?: () => Readonly<any>;
202
218
  state?: any;
203
219
  source?: string;
@@ -205,6 +221,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
205
221
  configReady?: boolean;
206
222
  previewReady?: boolean;
207
223
  };
224
+ slots?: () => Readonly<any>;
208
225
  }>;
209
226
  currentVariant: import("vue").ComputedRef<{
210
227
  id: string;
@@ -212,6 +229,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
212
229
  icon?: string;
213
230
  iconColor?: string;
214
231
  initState?: () => any;
232
+ setupApp?: (payload: any) => unknown;
215
233
  slots?: () => Readonly<any>;
216
234
  state?: any;
217
235
  source?: string;
@@ -232,6 +250,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
232
250
  icon?: string;
233
251
  iconColor?: string;
234
252
  initState?: () => any;
253
+ setupApp?: (payload: any) => unknown;
235
254
  slots?: () => Readonly<any>;
236
255
  state?: any;
237
256
  source?: string;
@@ -241,6 +260,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
241
260
  }[];
242
261
  layout?: {
243
262
  type: "single";
263
+ iframe?: boolean;
244
264
  } | {
245
265
  type: "grid";
246
266
  width?: string | number;
@@ -261,6 +281,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
261
281
  icon?: string;
262
282
  iconColor?: string;
263
283
  initState?: () => any;
284
+ setupApp?: (payload: any) => unknown;
264
285
  slots?: () => Readonly<any>;
265
286
  state?: any;
266
287
  source?: string;
@@ -268,6 +289,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
268
289
  configReady?: boolean;
269
290
  previewReady?: boolean;
270
291
  };
292
+ slots?: () => Readonly<any>;
271
293
  }[]>;
272
294
  setStories: (value: Story[]) => void;
273
295
  currentStory: import("vue").ComputedRef<{
@@ -280,6 +302,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
280
302
  icon?: string;
281
303
  iconColor?: string;
282
304
  initState?: () => any;
305
+ setupApp?: (payload: any) => unknown;
283
306
  slots?: () => Readonly<any>;
284
307
  state?: any;
285
308
  source?: string;
@@ -289,6 +312,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
289
312
  }[];
290
313
  layout?: {
291
314
  type: "single";
315
+ iframe?: boolean;
292
316
  } | {
293
317
  type: "grid";
294
318
  width?: string | number;
@@ -309,6 +333,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
309
333
  icon?: string;
310
334
  iconColor?: string;
311
335
  initState?: () => any;
336
+ setupApp?: (payload: any) => unknown;
312
337
  slots?: () => Readonly<any>;
313
338
  state?: any;
314
339
  source?: string;
@@ -316,6 +341,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
316
341
  configReady?: boolean;
317
342
  previewReady?: boolean;
318
343
  };
344
+ slots?: () => Readonly<any>;
319
345
  }>;
320
346
  currentVariant: import("vue").ComputedRef<{
321
347
  id: string;
@@ -323,6 +349,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
323
349
  icon?: string;
324
350
  iconColor?: string;
325
351
  initState?: () => any;
352
+ setupApp?: (payload: any) => unknown;
326
353
  slots?: () => Readonly<any>;
327
354
  state?: any;
328
355
  source?: string;
@@ -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 {
@@ -13,6 +13,7 @@ export interface Story {
13
13
  variants: Variant[];
14
14
  layout?: {
15
15
  type: 'single';
16
+ iframe?: boolean;
16
17
  } | {
17
18
  type: 'grid';
18
19
  width?: number | string;
@@ -22,6 +23,7 @@ export interface Story {
22
23
  docsOnly?: boolean;
23
24
  file?: StoryFile;
24
25
  lastSelectedVariant?: Variant;
26
+ slots?: () => Readonly<any>;
25
27
  }
26
28
  export interface Variant {
27
29
  id: string;
@@ -29,6 +31,7 @@ export interface Variant {
29
31
  icon?: string;
30
32
  iconColor?: string;
31
33
  initState?: () => any;
34
+ setupApp?: (payload: any) => unknown;
32
35
  slots?: () => Readonly<any>;
33
36
  state?: any;
34
37
  source?: string;
@@ -1 +1 @@
1
- export declare function hstEvent(name: string, argument: any): void;
1
+ export declare function hstEvent(name: string, argument: any): Promise<void>;
@@ -1,6 +1,5 @@
1
- import { useEventsStore } from '../stores/events.js';
2
1
  import { EVENT_SEND } from './const';
3
- export function hstEvent(name, argument) {
2
+ export async function hstEvent(name, argument) {
4
3
  console.log('[histoire] Event fired', { name, argument });
5
4
  const event = {
6
5
  name,
@@ -13,6 +12,7 @@ export function hstEvent(name, argument) {
13
12
  });
14
13
  }
15
14
  else {
15
+ const { useEventsStore } = await import('../stores/events.js');
16
16
  useEventsStore().addEvent(event);
17
17
  }
18
18
  }
@@ -8,6 +8,7 @@ export function mapFile(file, existingFile) {
8
8
  title: file.story.title,
9
9
  file: markRaw(file),
10
10
  variants: file.story.variants.map(v => mapVariant(v)),
11
+ slots: () => ({}),
11
12
  },
12
13
  };
13
14
  if (existingFile) {
@@ -37,6 +38,7 @@ export function mapVariant(variant) {
37
38
  ...variant,
38
39
  state: null,
39
40
  initState: null,
41
+ setupApp: null,
40
42
  slots: () => ({}),
41
43
  previewReady: false,
42
44
  };
@@ -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
  export declare type Vue3StorySetupHandler = (payload: {
5
5
  app: App;
6
6
  story?: Story;
@@ -1,4 +1,4 @@
1
- export { hstEvent } from './app/util/events';
1
+ export * from './app/api.js';
2
2
  export function defineSetupVue3(handler) {
3
3
  return handler;
4
4
  }
@@ -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: {
@@ -28,5 +28,13 @@ export async function run({ file, storyData, el }) {
28
28
  app.component('Variant', Variant);
29
29
  registerVueComponents(app);
30
30
  app.mount(el);
31
+ if (Comp.doc) {
32
+ const el = document.createElement('div');
33
+ el.innerHTML = Comp.doc;
34
+ const text = el.textContent;
35
+ storyData.forEach(s => {
36
+ s.docsText = text;
37
+ });
38
+ }
31
39
  app.unmount();
32
40
  }
@@ -2,5 +2,5 @@ import { dirname, join } from 'pathe';
2
2
  import { fileURLToPath } from 'url';
3
3
  const __dirname = dirname(fileURLToPath(import.meta.url));
4
4
  export const DIST_PATH = join(__dirname, '../');
5
- export const APP_PATH = join(DIST_PATH, 'client', 'app');
5
+ export const APP_PATH = join(DIST_PATH, 'client');
6
6
  export const TEMP_PATH = join(process.cwd(), 'node_modules', '.histoire');
@@ -57,8 +57,8 @@ export async function build(ctx) {
57
57
  build: {
58
58
  rollupOptions: {
59
59
  input: [
60
- join(APP_PATH, 'index.js'),
61
- join(APP_PATH, 'sandbox.js'),
60
+ join(APP_PATH, 'bundle-main.js'),
61
+ join(APP_PATH, 'bundle-sandbox.js'),
62
62
  ],
63
63
  output: {
64
64
  manualChunks(id) {
@@ -86,13 +86,13 @@ export async function build(ctx) {
86
86
  const prefetchOutputs = result.output.filter(o => PREFETCHED_MODULES.includes(o.name) && o.type === 'chunk');
87
87
  const prefetchHtml = generateScriptLinks(prefetchOutputs.map(o => o.fileName), 'prefetch', ctx, resolvedViteConfig);
88
88
  // Index
89
- const indexOutput = result.output.find(o => o.name === 'index' && o.type === 'chunk');
89
+ const indexOutput = result.output.find(o => o.name === 'bundle-main' && o.type === 'chunk');
90
90
  const indexHtml = generateEntryHtml(indexOutput.fileName, styleOutput.fileName, {
91
91
  HEAD: `${preloadHtml}${prefetchHtml}`,
92
92
  }, ctx, resolvedViteConfig);
93
93
  await writeFile('index.html', indexHtml, ctx);
94
94
  // Sandbox
95
- const sandboxOutput = result.output.find(o => o.name === 'sandbox' && o.type === 'chunk');
95
+ const sandboxOutput = result.output.find(o => o.name === 'bundle-sandbox' && o.type === 'chunk');
96
96
  const sandboxHtml = generateEntryHtml(sandboxOutput.fileName, styleOutput.fileName, {}, ctx, resolvedViteConfig);
97
97
  await writeFile('__sandbox.html', sandboxHtml, ctx);
98
98
  const duration = performance.now() - startTime;
@@ -83,7 +83,7 @@ defineExpose({
83
83
  })
84
84
  </script>
85
85
  <template>
86
- <Story id="tailwind" title="Tailwind" group="design-system" icon="mdi:tailwind" responsiveDisabled>
86
+ <Story id="tailwind" title="Tailwind" group="design-system" icon="mdi:tailwind" responsiveDisabled :layout="{ type: 'single', iframe: false }">
87
87
  <Variant id="background-color" title="Background Color" icon="carbon:color-palette">
88
88
  <HstColorShades
89
89
  v-for="(shades, key) of config.theme.backgroundColor"
@@ -1,2 +1,16 @@
1
1
  import { Context } from './context.js';
2
- export declare function generateSearchData(ctx: Context): Promise<unknown>;
2
+ export declare function generateTitleSearchData(ctx: Context): Promise<{
3
+ index: unknown;
4
+ idMap: Record<number, {
5
+ id: string;
6
+ kind: string;
7
+ }>;
8
+ }>;
9
+ export declare function generateDocSearchData(ctx: Context): Promise<{
10
+ index: unknown;
11
+ idMap: Record<number, {
12
+ id: string;
13
+ kind: string;
14
+ }>;
15
+ }>;
16
+ export declare function getSearchDataJS(data: any): string;
@@ -1,54 +1,80 @@
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 { loadModule } from './load.js';
5
6
  const require = createRequire(import.meta.url);
6
- export async function generateSearchData(ctx) {
7
+ export async function generateTitleSearchData(ctx) {
8
+ const searchIndex = await createIndex();
9
+ const { idMap, addToIdMap } = createIdMap();
10
+ for (const storyFile of ctx.storyFiles) {
11
+ if (storyFile.story) {
12
+ searchIndex.add({
13
+ id: addToIdMap(storyFile.story.id, 'story'),
14
+ text: convertTitleToSentence(storyFile.story.title),
15
+ });
16
+ for (const variant of storyFile.story.variants) {
17
+ searchIndex.add({
18
+ id: addToIdMap(`${storyFile.story.id}:${variant.id}`, 'variant'),
19
+ text: convertTitleToSentence(`${storyFile.story.title} ${variant.title}`),
20
+ });
21
+ }
22
+ }
23
+ }
24
+ return {
25
+ index: await exportSearchIndex(searchIndex),
26
+ idMap,
27
+ };
28
+ }
29
+ export async function generateDocSearchData(ctx) {
30
+ const searchIndex = await createIndex();
31
+ const { idMap, addToIdMap } = createIdMap();
32
+ for (const storyFile of ctx.storyFiles) {
33
+ if (storyFile.story && storyFile.story.docsText) {
34
+ searchIndex.add({
35
+ id: addToIdMap(storyFile.story.id, 'story'),
36
+ text: storyFile.story.docsText,
37
+ });
38
+ }
39
+ }
40
+ return {
41
+ index: await exportSearchIndex(searchIndex),
42
+ idMap,
43
+ };
44
+ }
45
+ async function createIndex() {
7
46
  const flexsearchRoot = path.dirname(require.resolve('flexsearch/package.json'));
8
- const searchIndex = new flexsearch.Document({
47
+ return new flexsearch.Document({
9
48
  preset: 'match',
10
49
  document: {
11
50
  id: 'id',
12
51
  index: [
13
- 'title',
14
- 'docs',
15
- ],
16
- store: [
17
- 'kind',
52
+ 'text',
18
53
  ],
19
54
  },
20
55
  charset: await loadModule(`${flexsearchRoot}/dist/module/lang/latin/advanced.js`),
21
56
  language: await loadModule(`${flexsearchRoot}/dist/module/lang/en.js`),
22
- tokenize: 'full',
57
+ tokenize: 'forward',
23
58
  });
24
- for (const storyFile of ctx.storyFiles) {
25
- if (storyFile.story) {
26
- searchIndex.add({
27
- id: storyFile.story.id,
28
- kind: 'story',
29
- title: storyFile.story.title,
30
- docs: '', // @TODO
31
- });
32
- for (const variant of storyFile.story.variants) {
33
- searchIndex.add({
34
- id: `${storyFile.story.id}:${variant.id}`,
35
- kind: 'variant',
36
- title: `${storyFile.story.title} ${variant.title}`,
37
- docs: '', // @TODO
38
- });
39
- }
40
- }
59
+ }
60
+ function createIdMap() {
61
+ let uid = 0;
62
+ const idMap = {};
63
+ function addToIdMap(id, kind) {
64
+ const n = uid++;
65
+ idMap[n] = { id, kind };
66
+ return n;
41
67
  }
42
- return exportSearchIndex(searchIndex);
68
+ return {
69
+ idMap,
70
+ addToIdMap,
71
+ };
43
72
  }
44
73
  const exportKeys = new Set([
45
74
  'reg',
46
- 'title.cfg',
47
- 'title.map',
48
- 'title.ctx',
49
- 'docs.cfg',
50
- 'docs.map',
51
- 'docs.ctx',
75
+ 'text.cfg',
76
+ 'text.map',
77
+ 'text.ctx',
52
78
  'tag',
53
79
  'store',
54
80
  ]);
@@ -66,3 +92,23 @@ async function exportSearchIndex(index) {
66
92
  });
67
93
  });
68
94
  }
95
+ function convertTitleToSentence(text) {
96
+ return text.split(' ').map(str => Case.lower(str)).join(' ');
97
+ }
98
+ // @TODO clear handlers when SearchPane unmounts
99
+ export function getSearchDataJS(data) {
100
+ return `export let searchData = ${JSON.stringify(data)}
101
+ const handlers = []
102
+ export function onUpdate (cb) {
103
+ handlers.push(cb)
104
+ }
105
+ if (import.meta.hot) {
106
+ import.meta.hot.accept(newModule => {
107
+ searchData = newModule.searchData
108
+ handlers.forEach(h => {
109
+ h(newModule.searchData)
110
+ newModule.onUpdate(h)
111
+ })
112
+ })
113
+ }`;
114
+ }
@@ -1,5 +1,5 @@
1
1
  import { createServer as createViteServer } from 'vite';
2
- import { createVitePlugins, RESOLVED_SEARCH_DATA_ID, RESOLVED_STORIES_ID } from './vite.js';
2
+ import { createVitePlugins, RESOLVED_SEARCH_TITLE_DATA_ID, RESOLVED_STORIES_ID } from './vite.js';
3
3
  import { notifyStoryChange, onStoryChange, watchStories } from './stories.js';
4
4
  import { useCollectStories } from './collect/index.js';
5
5
  import { DevPluginApi } from './plugin.js';
@@ -94,7 +94,7 @@ export async function createServer(ctx, port) {
94
94
  });
95
95
  }
96
96
  invalidateModule(RESOLVED_STORIES_ID);
97
- invalidateModule(RESOLVED_SEARCH_DATA_ID);
97
+ invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
98
98
  });
99
99
  async function close() {
100
100
  for (const cb of pluginOnCleanups) {
@@ -40,6 +40,7 @@ export interface Story {
40
40
  icon?: string;
41
41
  iconColor?: string;
42
42
  docsOnly?: boolean;
43
+ docsText?: string;
43
44
  }
44
45
  export interface Variant {
45
46
  id: string;
@@ -8,6 +8,8 @@ export declare const CONFIG_ID = "$histoire-config";
8
8
  export declare const RESOLVED_CONFIG_ID: string;
9
9
  export declare const THEME_ID = "$histoire-theme";
10
10
  export declare const RESOLVED_THEME_ID: string;
11
- export declare const SEARCH_DATA_ID = "$histoire-search-data";
12
- export declare const RESOLVED_SEARCH_DATA_ID: string;
11
+ export declare const SEARCH_TITLE_DATA_ID = "$histoire-search-title-data";
12
+ export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
13
+ export declare const SEARCH_DOCS_DATA_ID = "$histoire-search-docs-data";
14
+ export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
13
15
  export declare function createVitePlugins(ctx: Context): Promise<VitePlugin[]>;