histoire 0.0.0 → 0.0.3

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 (204) hide show
  1. package/LICENSE +21 -0
  2. package/client.d.ts +2 -0
  3. package/dist/client/app/App.vue +84 -21
  4. package/dist/client/app/assets/histoire-text-dark.svg +89 -0
  5. package/dist/client/app/assets/histoire-text.svg +89 -0
  6. package/dist/client/app/assets/histoire.svg +51 -0
  7. package/dist/client/app/codegen/serialize-js.d.ts +1 -0
  8. package/dist/client/app/codegen/serialize-js.js +113 -0
  9. package/dist/client/app/codegen/serialize-js.ts +119 -0
  10. package/dist/client/app/codegen/util.d.ts +10 -0
  11. package/dist/client/app/codegen/util.js +70 -0
  12. package/dist/client/app/codegen/util.ts +79 -0
  13. package/dist/client/app/codegen/vue3.d.ts +2 -0
  14. package/dist/client/app/codegen/vue3.js +238 -0
  15. package/dist/client/app/codegen/vue3.ts +240 -0
  16. package/dist/client/app/components/HomeView.vue +15 -1
  17. package/dist/client/app/components/StoryControls.vue +7 -2
  18. package/dist/client/app/components/StoryList.vue +20 -13
  19. package/dist/client/app/components/StoryListFolder.vue +87 -0
  20. package/dist/client/app/components/StoryListItem.vue +38 -12
  21. package/dist/client/app/components/StorySourceCode.vue +121 -0
  22. package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
  23. package/dist/client/app/components/StoryVariantListItem.vue +46 -0
  24. package/dist/client/app/components/StoryVariantSingleView.vue +145 -15
  25. package/dist/client/app/components/StoryView.vue +88 -54
  26. package/dist/client/app/components/app/AppHeader.vue +56 -0
  27. package/dist/client/app/components/app/AppLogo.vue +24 -0
  28. package/dist/client/app/components/base/BaseEmpty.vue +1 -1
  29. package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
  30. package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
  31. package/dist/client/app/components/exposed/Story.vue +23 -58
  32. package/dist/client/app/components/exposed/Variant.vue +24 -47
  33. package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
  34. package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  35. package/dist/client/app/components/search/SearchItem.vue +110 -0
  36. package/dist/client/app/components/search/SearchModal.vue +179 -0
  37. package/dist/client/app/composable/variant.js +0 -1
  38. package/dist/client/app/composable/variant.ts +20 -0
  39. package/dist/client/app/global-components.js +0 -1
  40. package/dist/client/app/global-components.ts +10 -0
  41. package/dist/client/app/index.d.ts +1 -0
  42. package/dist/client/app/index.js +10 -2
  43. package/dist/client/app/index.ts +24 -0
  44. package/dist/client/app/router.js +0 -1
  45. package/dist/client/app/router.ts +17 -0
  46. package/dist/client/app/sandbox.d.ts +1 -0
  47. package/dist/client/app/sandbox.js +53 -0
  48. package/dist/client/app/sandbox.ts +60 -0
  49. package/dist/client/app/stores/story.d.ts +167 -50
  50. package/dist/client/app/stores/story.js +33 -16
  51. package/dist/client/app/stores/story.ts +58 -0
  52. package/dist/client/app/style/floating-vue.css +31 -0
  53. package/dist/client/app/style/main.css +17 -2
  54. package/dist/client/app/style/sandbox.css +14 -0
  55. package/dist/client/app/types.d.ts +36 -4
  56. package/dist/client/app/types.js +0 -1
  57. package/dist/client/app/types.ts +59 -0
  58. package/dist/client/app/util/config.d.ts +3 -0
  59. package/dist/client/app/util/config.js +4 -0
  60. package/dist/client/app/util/config.ts +6 -0
  61. package/dist/client/app/util/const.d.ts +1 -0
  62. package/dist/client/app/util/const.js +1 -0
  63. package/dist/client/app/util/const.ts +1 -0
  64. package/dist/client/app/util/dark.d.ts +2 -0
  65. package/dist/client/app/util/dark.js +3 -0
  66. package/dist/client/app/util/dark.ts +4 -0
  67. package/dist/client/app/util/env.d.ts +1 -0
  68. package/dist/client/app/util/env.js +1 -0
  69. package/dist/client/app/util/env.ts +1 -0
  70. package/dist/client/app/util/keyboard.d.ts +8 -0
  71. package/dist/client/app/util/keyboard.js +82 -0
  72. package/dist/client/app/util/keyboard.ts +99 -0
  73. package/dist/client/app/util/mapping.d.ts +3 -0
  74. package/dist/client/app/util/mapping.js +39 -0
  75. package/dist/client/app/util/mapping.ts +41 -0
  76. package/dist/client/app/util/tooltip.d.ts +6 -0
  77. package/dist/client/app/util/tooltip.js +11 -0
  78. package/dist/client/app/util/tooltip.ts +13 -0
  79. package/dist/client/index.d.ts +8 -0
  80. package/dist/client/index.js +3 -0
  81. package/dist/client/index.ts +12 -0
  82. package/dist/client/server/Story.server.vue +65 -0
  83. package/dist/client/server/Variant.server.vue +50 -0
  84. package/dist/client/server/index.d.ts +2 -0
  85. package/dist/client/server/index.js +25 -0
  86. package/dist/client/server/index.ts +29 -0
  87. package/dist/client/shim.d.ts +5 -0
  88. package/dist/node/alias.js +0 -1
  89. package/dist/node/bin.js +8 -3
  90. package/dist/node/build.d.ts +2 -0
  91. package/dist/node/build.js +71 -0
  92. package/dist/node/collect.d.ts +12 -0
  93. package/dist/node/collect.js +65 -0
  94. package/dist/node/colors.d.ts +286 -0
  95. package/dist/node/colors.js +324 -0
  96. package/dist/node/commands/build.d.ts +1 -0
  97. package/dist/node/commands/build.js +10 -0
  98. package/dist/node/commands/dev.d.ts +1 -1
  99. package/dist/node/commands/dev.js +45 -13
  100. package/dist/node/config.d.ts +112 -1
  101. package/dist/node/config.js +124 -2
  102. package/dist/node/context.d.ts +13 -0
  103. package/dist/node/context.js +12 -2
  104. package/dist/node/dom/dom-keys.d.ts +4 -0
  105. package/dist/node/dom/dom-keys.js +223 -0
  106. package/dist/node/dom/env.d.ts +5 -0
  107. package/dist/node/dom/env.js +22 -0
  108. package/dist/node/index.d.ts +2 -0
  109. package/dist/node/index.js +2 -2
  110. package/dist/node/plugin.d.ts +8 -2
  111. package/dist/node/plugin.js +150 -22
  112. package/dist/node/server.d.ts +4 -1
  113. package/dist/node/server.js +80 -21
  114. package/dist/node/stories.d.ts +8 -9
  115. package/dist/node/stories.js +42 -23
  116. package/dist/node/tree.d.ts +19 -0
  117. package/dist/node/tree.js +54 -0
  118. package/dist/node/types.d.ts +38 -0
  119. package/dist/node/types.js +1 -0
  120. package/dist/style.css +610 -53
  121. package/package.json +45 -25
  122. package/scripts/copy.mjs +11 -0
  123. package/src/client/app/App.vue +84 -21
  124. package/src/client/app/assets/histoire-text-dark.svg +89 -0
  125. package/src/client/app/assets/histoire-text.svg +89 -0
  126. package/src/client/app/assets/histoire.svg +51 -0
  127. package/src/client/app/codegen/serialize-js.ts +119 -0
  128. package/src/client/app/codegen/util.ts +79 -0
  129. package/src/client/app/codegen/vue3.ts +240 -0
  130. package/src/client/app/components/HomeView.vue +15 -1
  131. package/src/client/app/components/StoryControls.vue +7 -2
  132. package/src/client/app/components/StoryList.vue +20 -13
  133. package/src/client/app/components/StoryListFolder.vue +87 -0
  134. package/src/client/app/components/StoryListItem.vue +38 -12
  135. package/src/client/app/components/StorySourceCode.vue +121 -0
  136. package/src/client/app/components/StoryVariantGridItem.vue +32 -17
  137. package/src/client/app/components/StoryVariantListItem.vue +46 -0
  138. package/src/client/app/components/StoryVariantSingleView.vue +145 -15
  139. package/src/client/app/components/StoryView.vue +88 -54
  140. package/src/client/app/components/app/AppHeader.vue +56 -0
  141. package/src/client/app/components/app/AppLogo.vue +24 -0
  142. package/src/client/app/components/base/BaseEmpty.vue +1 -1
  143. package/src/client/app/components/base/BaseListItemLink.vue +55 -0
  144. package/src/client/app/components/base/BaseSplitPane.vue +57 -21
  145. package/src/client/app/components/exposed/Story.vue +23 -58
  146. package/src/client/app/components/exposed/Variant.vue +24 -47
  147. package/src/client/app/components/misc/HatchedPattern.vue +25 -0
  148. package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  149. package/src/client/app/components/search/SearchItem.vue +110 -0
  150. package/src/client/app/components/search/SearchModal.vue +179 -0
  151. package/src/client/app/index.ts +10 -1
  152. package/src/client/app/sandbox.ts +60 -0
  153. package/src/client/app/stores/story.ts +39 -15
  154. package/src/client/app/style/floating-vue.css +31 -0
  155. package/src/client/app/style/main.css +17 -2
  156. package/src/client/app/style/sandbox.css +14 -0
  157. package/src/client/app/types.ts +42 -4
  158. package/src/client/app/util/config.ts +6 -0
  159. package/src/client/app/util/const.ts +1 -0
  160. package/src/client/app/util/dark.ts +4 -0
  161. package/src/client/app/util/env.ts +1 -0
  162. package/src/client/app/util/keyboard.ts +99 -0
  163. package/src/client/app/util/mapping.ts +41 -0
  164. package/src/client/app/util/tooltip.ts +13 -0
  165. package/src/client/index.ts +12 -0
  166. package/src/client/server/Story.server.vue +65 -0
  167. package/src/client/server/Variant.server.vue +50 -0
  168. package/src/client/server/index.ts +29 -0
  169. package/src/node/bin.ts +9 -2
  170. package/src/node/build.ts +80 -0
  171. package/src/node/collect.ts +78 -0
  172. package/src/node/colors.ts +340 -0
  173. package/src/node/commands/build.ts +12 -0
  174. package/src/node/commands/dev.ts +49 -12
  175. package/src/node/config.ts +240 -1
  176. package/src/node/context.ts +21 -1
  177. package/src/node/dom/dom-keys.ts +227 -0
  178. package/src/node/dom/env.ts +26 -0
  179. package/src/node/index.ts +2 -0
  180. package/src/node/plugin.ts +155 -22
  181. package/src/node/server.ts +95 -20
  182. package/src/node/stories.ts +53 -31
  183. package/src/node/tree.spec.ts +28 -0
  184. package/src/node/tree.ts +88 -0
  185. package/src/node/types.ts +40 -0
  186. package/tailwind.config.cjs +41 -1
  187. package/tsconfig.json +2 -1
  188. package/dist/client/app/components/StoryVariantItem.vue +0 -29
  189. package/dist/client/app/composable/variant.js.map +0 -1
  190. package/dist/client/app/global-components.js.map +0 -1
  191. package/dist/client/app/index.js.map +0 -1
  192. package/dist/client/app/router.js.map +0 -1
  193. package/dist/client/app/stores/story.js.map +0 -1
  194. package/dist/client/app/types.js.map +0 -1
  195. package/dist/node/alias.js.map +0 -1
  196. package/dist/node/bin.js.map +0 -1
  197. package/dist/node/commands/dev.js.map +0 -1
  198. package/dist/node/config.js.map +0 -1
  199. package/dist/node/context.js.map +0 -1
  200. package/dist/node/index.js.map +0 -1
  201. package/dist/node/plugin.js.map +0 -1
  202. package/dist/node/server.js.map +0 -1
  203. package/dist/node/stories.js.map +0 -1
  204. package/src/client/app/components/StoryVariantItem.vue +0 -29
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Code from vitest https://github.com/antfu-sponsors/vitest/blob/6066fdbf3b1d17021aac20591b5ef3603056fa5f/src/integrations/dom/keys.ts by @antfu and @patak
3
+ */
4
+ // SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
5
+ const LIVING_KEYS = [
6
+ 'DOMException',
7
+ 'URL',
8
+ 'URLSearchParams',
9
+ 'EventTarget',
10
+ 'NamedNodeMap',
11
+ 'Node',
12
+ 'Attr',
13
+ 'Element',
14
+ 'DocumentFragment',
15
+ 'DOMImplementation',
16
+ 'Document',
17
+ 'XMLDocument',
18
+ 'CharacterData',
19
+ 'Text',
20
+ 'CDATASection',
21
+ 'ProcessingInstruction',
22
+ 'Comment',
23
+ 'DocumentType',
24
+ 'NodeList',
25
+ 'HTMLCollection',
26
+ 'HTMLOptionsCollection',
27
+ 'DOMStringMap',
28
+ 'DOMTokenList',
29
+ 'StyleSheetList',
30
+ 'HTMLElement',
31
+ 'HTMLHeadElement',
32
+ 'HTMLTitleElement',
33
+ 'HTMLBaseElement',
34
+ 'HTMLLinkElement',
35
+ 'HTMLMetaElement',
36
+ 'HTMLStyleElement',
37
+ 'HTMLBodyElement',
38
+ 'HTMLHeadingElement',
39
+ 'HTMLParagraphElement',
40
+ 'HTMLHRElement',
41
+ 'HTMLPreElement',
42
+ 'HTMLUListElement',
43
+ 'HTMLOListElement',
44
+ 'HTMLLIElement',
45
+ 'HTMLMenuElement',
46
+ 'HTMLDListElement',
47
+ 'HTMLDivElement',
48
+ 'HTMLAnchorElement',
49
+ 'HTMLAreaElement',
50
+ 'HTMLBRElement',
51
+ 'HTMLButtonElement',
52
+ 'HTMLCanvasElement',
53
+ 'HTMLDataElement',
54
+ 'HTMLDataListElement',
55
+ 'HTMLDetailsElement',
56
+ 'HTMLDialogElement',
57
+ 'HTMLDirectoryElement',
58
+ 'HTMLFieldSetElement',
59
+ 'HTMLFontElement',
60
+ 'HTMLFormElement',
61
+ 'HTMLHtmlElement',
62
+ 'HTMLImageElement',
63
+ 'HTMLInputElement',
64
+ 'HTMLLabelElement',
65
+ 'HTMLLegendElement',
66
+ 'HTMLMapElement',
67
+ 'HTMLMarqueeElement',
68
+ 'HTMLMediaElement',
69
+ 'HTMLMeterElement',
70
+ 'HTMLModElement',
71
+ 'HTMLOptGroupElement',
72
+ 'HTMLOptionElement',
73
+ 'HTMLOutputElement',
74
+ 'HTMLPictureElement',
75
+ 'HTMLProgressElement',
76
+ 'HTMLQuoteElement',
77
+ 'HTMLScriptElement',
78
+ 'HTMLSelectElement',
79
+ 'HTMLSlotElement',
80
+ 'HTMLSourceElement',
81
+ 'HTMLSpanElement',
82
+ 'HTMLTableCaptionElement',
83
+ 'HTMLTableCellElement',
84
+ 'HTMLTableColElement',
85
+ 'HTMLTableElement',
86
+ 'HTMLTimeElement',
87
+ 'HTMLTableRowElement',
88
+ 'HTMLTableSectionElement',
89
+ 'HTMLTemplateElement',
90
+ 'HTMLTextAreaElement',
91
+ 'HTMLUnknownElement',
92
+ 'HTMLFrameElement',
93
+ 'HTMLFrameSetElement',
94
+ 'HTMLIFrameElement',
95
+ 'HTMLEmbedElement',
96
+ 'HTMLObjectElement',
97
+ 'HTMLParamElement',
98
+ 'HTMLVideoElement',
99
+ 'HTMLAudioElement',
100
+ 'HTMLTrackElement',
101
+ 'SVGElement',
102
+ 'SVGGraphicsElement',
103
+ 'SVGSVGElement',
104
+ 'SVGTitleElement',
105
+ 'SVGAnimatedString',
106
+ 'SVGNumber',
107
+ 'SVGStringList',
108
+ 'Event',
109
+ 'CloseEvent',
110
+ 'CustomEvent',
111
+ 'MessageEvent',
112
+ 'ErrorEvent',
113
+ 'HashChangeEvent',
114
+ 'PopStateEvent',
115
+ 'StorageEvent',
116
+ 'ProgressEvent',
117
+ 'PageTransitionEvent',
118
+ 'UIEvent',
119
+ 'FocusEvent',
120
+ 'InputEvent',
121
+ 'MouseEvent',
122
+ 'KeyboardEvent',
123
+ 'TouchEvent',
124
+ 'CompositionEvent',
125
+ 'WheelEvent',
126
+ 'BarProp',
127
+ 'External',
128
+ 'Location',
129
+ 'History',
130
+ 'Screen',
131
+ 'Performance',
132
+ 'Navigator',
133
+ 'PluginArray',
134
+ 'MimeTypeArray',
135
+ 'Plugin',
136
+ 'MimeType',
137
+ 'FileReader',
138
+ 'Blob',
139
+ 'File',
140
+ 'FileList',
141
+ 'ValidityState',
142
+ 'DOMParser',
143
+ 'XMLSerializer',
144
+ 'FormData',
145
+ 'XMLHttpRequestEventTarget',
146
+ 'XMLHttpRequestUpload',
147
+ 'XMLHttpRequest',
148
+ 'WebSocket',
149
+ 'NodeFilter',
150
+ 'NodeIterator',
151
+ 'TreeWalker',
152
+ 'AbstractRange',
153
+ 'Range',
154
+ 'StaticRange',
155
+ 'Selection',
156
+ 'Storage',
157
+ 'CustomElementRegistry',
158
+ 'ShadowRoot',
159
+ 'MutationObserver',
160
+ 'MutationRecord',
161
+ 'Headers',
162
+ 'AbortController',
163
+ 'AbortSignal',
164
+ ];
165
+ const OTHER_KEYS = [
166
+ 'addEventListener',
167
+ 'alert',
168
+ 'atob',
169
+ 'blur',
170
+ 'btoa',
171
+ /* 'clearInterval', */
172
+ /* 'clearTimeout', */
173
+ 'close',
174
+ 'confirm',
175
+ /* 'console', */
176
+ 'createPopup',
177
+ 'dispatchEvent',
178
+ 'document',
179
+ 'focus',
180
+ 'frames',
181
+ 'getComputedStyle',
182
+ 'history',
183
+ 'innerHeight',
184
+ 'innerWidth',
185
+ 'length',
186
+ 'location',
187
+ 'moveBy',
188
+ 'moveTo',
189
+ 'name',
190
+ 'navigator',
191
+ 'open',
192
+ 'outerHeight',
193
+ 'outerWidth',
194
+ 'pageXOffset',
195
+ 'pageYOffset',
196
+ 'parent',
197
+ 'postMessage',
198
+ 'print',
199
+ 'prompt',
200
+ 'removeEventListener',
201
+ 'resizeBy',
202
+ 'resizeTo',
203
+ 'screen',
204
+ 'screenLeft',
205
+ 'screenTop',
206
+ 'screenX',
207
+ 'screenY',
208
+ 'scroll',
209
+ 'scrollBy',
210
+ 'scrollLeft',
211
+ 'scrollTo',
212
+ 'scrollTop',
213
+ 'scrollX',
214
+ 'scrollY',
215
+ 'self',
216
+ /* 'setInterval', */
217
+ /* 'setTimeout', */
218
+ 'stop',
219
+ /* 'toString', */
220
+ 'top',
221
+ 'window',
222
+ ];
223
+ export const KEYS = LIVING_KEYS.concat(OTHER_KEYS);
@@ -0,0 +1,5 @@
1
+ import { Window } from 'happy-dom';
2
+ export declare function createDomEnv(): {
3
+ window: Window;
4
+ destroy: () => void;
5
+ };
@@ -0,0 +1,22 @@
1
+ import { Window } from 'happy-dom';
2
+ import { KEYS } from './dom-keys.js';
3
+ export function createDomEnv() {
4
+ // @ts-ignore
5
+ const window = global.window = new Window();
6
+ const globalKeys = KEYS.concat(Object.getOwnPropertyNames(window))
7
+ .filter(k => !k.startsWith('_'))
8
+ .filter(k => !(k in global));
9
+ for (const key of globalKeys) {
10
+ global[key] = window[key];
11
+ }
12
+ function destroy() {
13
+ globalKeys.forEach(key => delete global[key]);
14
+ globalKeys.length = 0;
15
+ window.happyDOM.cancelAsync();
16
+ delete global.window;
17
+ }
18
+ return {
19
+ window,
20
+ destroy,
21
+ };
22
+ }
@@ -0,0 +1,2 @@
1
+ export * from './config.js';
2
+ export { defaultColors } from './colors.js';
@@ -1,2 +1,2 @@
1
- "use strict";
2
- //# sourceMappingURL=index.js.map
1
+ export * from './config.js';
2
+ export { defaultColors } from './colors.js';
@@ -1,5 +1,11 @@
1
- import { Plugin } from 'vite';
1
+ import { Plugin as VitePlugin } from 'vite';
2
2
  import { Context } from './context.js';
3
3
  export declare const STORIES_ID = "$histoire-stories";
4
4
  export declare const RESOLVED_STORIES_ID: string;
5
- export declare function createVitePlugins(ctx: Context): Promise<Plugin[]>;
5
+ export declare const SETUP_ID = "$histoire-setup";
6
+ export declare const NOOP_ID = "/$histoire-noop";
7
+ export declare const CONFIG_ID = "$histoire-config";
8
+ export declare const RESOLVED_CONFIG_ID: string;
9
+ export declare const THEME_ID = "$histoire-theme";
10
+ export declare const RESOLVED_THEME_ID: string;
11
+ export declare function createVitePlugins(ctx: Context): Promise<VitePlugin[]>;
@@ -1,38 +1,88 @@
1
- import { defineConfig, mergeConfig } from 'vite';
1
+ import { relative } from 'pathe';
2
+ import { resolveConfig as resolveViteConfig } from 'vite';
3
+ import { lookup as lookupMime } from 'mrmime';
2
4
  import { APP_PATH, DIST_CLIENT_PATH } from './alias.js';
3
- import { stories } from './stories.js';
5
+ import { notifyStoryChange } from './stories.js';
6
+ import { makeTree } from './tree.js';
7
+ import { parseColor } from './colors.js';
4
8
  export const STORIES_ID = '$histoire-stories';
5
9
  export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`;
10
+ export const SETUP_ID = '$histoire-setup';
11
+ export const NOOP_ID = '/$histoire-noop';
12
+ export const CONFIG_ID = '$histoire-config';
13
+ export const RESOLVED_CONFIG_ID = `/${CONFIG_ID}-resolved`;
14
+ export const THEME_ID = '$histoire-theme';
15
+ export const RESOLVED_THEME_ID = `/${THEME_ID}-resolved.css`;
6
16
  export async function createVitePlugins(ctx) {
7
- const userViteConfig = {}; // @TODO
8
- const vuePlugin = (await import('@vitejs/plugin-vue')).default();
9
- const vitePlugin = {
17
+ const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
18
+ const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue');
19
+ const plugins = [];
20
+ if (!hasVuePlugin) {
21
+ plugins.push((await import('@vitejs/plugin-vue')).default());
22
+ }
23
+ if (ctx.config.vite) {
24
+ plugins.push({
25
+ name: 'histoire-vite-config-override',
26
+ config() {
27
+ return ctx.config.vite;
28
+ },
29
+ });
30
+ }
31
+ plugins.push({
10
32
  name: 'histoire-vite-plugin',
11
33
  config() {
12
- const baseConfig = defineConfig({
34
+ return {
13
35
  optimizeDeps: {
14
36
  // force include vue to avoid duplicated copies when linked + optimized
15
- include: ['vue'],
37
+ include: [
38
+ 'vue',
39
+ '@vue/runtime-core',
40
+ ],
16
41
  },
17
42
  server: {
18
43
  fs: {
19
- allow: [DIST_CLIENT_PATH, ctx.config.sourceDir, process.cwd()],
44
+ allow: [DIST_CLIENT_PATH, viteConfig.root, process.cwd()],
20
45
  },
21
46
  },
22
- });
23
- return userViteConfig
24
- ? mergeConfig(userViteConfig, baseConfig)
25
- : baseConfig;
47
+ };
26
48
  },
27
- resolveId(id) {
49
+ async resolveId(id, importer) {
28
50
  if (id.startsWith(STORIES_ID)) {
29
51
  return RESOLVED_STORIES_ID;
30
52
  }
53
+ if (id.startsWith(SETUP_ID)) {
54
+ if (ctx.config.setupFile) {
55
+ return this.resolve(ctx.config.setupFile, importer, {
56
+ skipSelf: true,
57
+ });
58
+ }
59
+ else {
60
+ return NOOP_ID;
61
+ }
62
+ }
63
+ if (id.startsWith(CONFIG_ID)) {
64
+ return RESOLVED_CONFIG_ID;
65
+ }
66
+ if (id.startsWith(THEME_ID)) {
67
+ return RESOLVED_THEME_ID;
68
+ }
31
69
  },
32
70
  load(id) {
33
71
  if (id === RESOLVED_STORIES_ID) {
34
- return `${stories.map((story, index) => `import Comp${index} from '/${story.file}'`).join('\n')}
35
- export let files = [${stories.map((story, index) => `{ id: '${story.id}', file: '/${story.file}', component: Comp${index} }`).join(',\n')}]
72
+ const resolvedStories = ctx.storyFiles.filter(s => !!s.story);
73
+ const files = resolvedStories.map((file, index) => {
74
+ return {
75
+ id: file.id,
76
+ path: file.treePath,
77
+ story: file.story,
78
+ framework: 'vue3',
79
+ index,
80
+ };
81
+ });
82
+ return `import { defineAsyncComponent } from 'vue'
83
+ ${resolvedStories.map((file, index) => `const Comp${index} = defineAsyncComponent(() => import('${file.path}'))`).join('\n')}
84
+ export let files = [${files.map((file) => `{${JSON.stringify(file).slice(1, -1)}, component: Comp${file.index}}`).join(',\n')}]
85
+ export let tree = ${JSON.stringify(makeTree(ctx.config, files))}
36
86
  const handlers = []
37
87
  export function onUpdate (cb) {
38
88
  handlers.push(cb)
@@ -40,15 +90,76 @@ export function onUpdate (cb) {
40
90
  if (import.meta.hot) {
41
91
  import.meta.hot.accept(newModule => {
42
92
  files = newModule.files
93
+ tree = newModule.tree
43
94
  handlers.forEach(h => {
44
- h(newModule.files)
95
+ h(newModule.files, newModule.tree)
45
96
  newModule.onUpdate(h)
46
97
  })
47
98
  })
48
99
  }`;
49
100
  }
101
+ if (id === NOOP_ID) {
102
+ return `export default () => {}`;
103
+ }
104
+ if (id === RESOLVED_CONFIG_ID) {
105
+ let js = `export const config = ${JSON.stringify(ctx.config)}\n`;
106
+ if (ctx.config.theme?.logo) {
107
+ for (const key in ctx.config.theme.logo) {
108
+ js += `import Logo_${key} from '${ctx.config.theme.logo[key]}'\n`;
109
+ }
110
+ }
111
+ js += `export const logos = {${Object.keys(ctx.config.theme?.logo ?? {}).map(key => `${key}: Logo_${key}`).join(', ')}}\n`;
112
+ return js;
113
+ }
114
+ if (id === RESOLVED_THEME_ID) {
115
+ let css = '*, ::before, ::after {';
116
+ // Colors
117
+ for (const color in ctx.config.theme?.colors ?? {}) {
118
+ for (const key in ctx.config.theme.colors[color]) {
119
+ css += `--_histoire-color-${color}-${key}: ${parseColor(ctx.config.theme.colors[color][key]).color.join(' ')};`;
120
+ }
121
+ }
122
+ css += '}';
123
+ return css;
124
+ }
125
+ },
126
+ handleHotUpdate(updateContext) {
127
+ const story = ctx.storyFiles.find(file => file.path === updateContext.file);
128
+ if (story) {
129
+ notifyStoryChange(story);
130
+ }
50
131
  },
51
132
  configureServer(server) {
133
+ server.middlewares.use((req, res, next) => {
134
+ if (req.url.startsWith('/__sandbox')) {
135
+ res.statusCode = 200;
136
+ res.end(`
137
+ <!DOCTYPE html>
138
+ <html>
139
+ <head>
140
+ <title></title>
141
+ <meta charset="utf-8">
142
+ <meta name="viewport" content="width=device-width,initial-scale=1">
143
+ <meta name="description" content="">
144
+ </head>
145
+ <body>
146
+ <div id="app"></div>
147
+ <script>
148
+ // Hide spammy vite messages
149
+ const origConsoleLog = console.log
150
+ console.log = (...args) => {
151
+ if (typeof args[0] !== 'string' || !args[0].startsWith('[vite] connect')) {
152
+ origConsoleLog(...args)
153
+ }
154
+ }
155
+ </script>
156
+ <script type="module" src="/@fs/${APP_PATH}/sandbox.js"></script>
157
+ </body>
158
+ </html>`);
159
+ return;
160
+ }
161
+ next();
162
+ });
52
163
  // serve our index.html after vite history fallback
53
164
  return () => {
54
165
  server.middlewares.use((req, res, next) => {
@@ -59,9 +170,11 @@ if (import.meta.hot) {
59
170
  <html>
60
171
  <head>
61
172
  <title></title>
173
+ <link rel="icon" href=""/>
62
174
  <meta charset="utf-8">
63
175
  <meta name="viewport" content="width=device-width,initial-scale=1">
64
176
  <meta name="description" content="">
177
+ ${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${ctx.config.theme.favicon}"/>` : ''}
65
178
  </head>
66
179
  <body>
67
180
  <div id="app"></div>
@@ -74,10 +187,25 @@ if (import.meta.hot) {
74
187
  });
75
188
  };
76
189
  },
77
- };
78
- return [
79
- vitePlugin,
80
- vuePlugin,
81
- ];
190
+ });
191
+ if (ctx.mode === 'build') {
192
+ // Add file name in build mode to have components names instead of <Anonymous>
193
+ const include = [/\.vue$/];
194
+ const exclude = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/];
195
+ plugins.push({
196
+ name: 'histoire-file-name-plugin',
197
+ enforce: 'post',
198
+ transform(code, id) {
199
+ if (exclude.some(r => r.test(id)))
200
+ return;
201
+ if (include.some(r => r.test(id))) {
202
+ const file = relative(viteConfig.root, id);
203
+ const index = code.indexOf('export default');
204
+ const result = `${code.substring(0, index)}_sfc_main.__file = '${file}'\n${code.substring(index)}`;
205
+ return result;
206
+ }
207
+ },
208
+ });
209
+ }
210
+ return plugins;
82
211
  }
83
- //# sourceMappingURL=plugin.js.map
@@ -1,2 +1,5 @@
1
1
  import { Context } from './context.js';
2
- export declare function createServer(ctx: Context): Promise<import("vite").ViteDevServer>;
2
+ export declare function createServer(ctx: Context, port: number): Promise<{
3
+ server: import("vite").ViteDevServer;
4
+ close: () => Promise<void>;
5
+ }>;
@@ -1,10 +1,10 @@
1
1
  import { createServer as createViteServer } from 'vite';
2
2
  import { createVitePlugins, RESOLVED_STORIES_ID } from './plugin.js';
3
- import { onStoryChange, watchStories } from './stories.js';
4
- export async function createServer(ctx) {
3
+ import { notifyStoryChange, onStoryChange, watchStories } from './stories.js';
4
+ import { useCollectStories } from './collect.js';
5
+ export async function createServer(ctx, port) {
5
6
  await watchStories(ctx);
6
7
  const server = await createViteServer({
7
- root: ctx.config.sourceDir,
8
8
  plugins: await createVitePlugins(ctx),
9
9
  server: {
10
10
  watch: {
@@ -12,25 +12,84 @@ export async function createServer(ctx) {
12
12
  },
13
13
  },
14
14
  });
15
- onStoryChange(() => {
15
+ await server.pluginContainer.buildStart({});
16
+ // Wait for pre-bundling (in `listen()`)
17
+ await server.listen(port);
18
+ const { clearCache, executeStoryFile, destroy: destroyCollectStories, } = useCollectStories({
19
+ server,
20
+ }, ctx);
21
+ // onStoryChange debouncing
22
+ let queue;
23
+ let queueResolve;
24
+ let queued = false;
25
+ let queuedFiles = [];
26
+ onStoryChange(async (changedFile) => {
27
+ if (queue) {
28
+ if (queued && changedFile) {
29
+ queuedFiles.push(changedFile);
30
+ return;
31
+ }
32
+ else {
33
+ queued = true;
34
+ // Next call
35
+ await queue;
36
+ }
37
+ }
38
+ queued = false;
39
+ queue = new Promise(resolve => {
40
+ queueResolve = resolve;
41
+ });
42
+ clearCache();
43
+ if (changedFile) {
44
+ // Granular update
45
+ await executeStoryFile(changedFile);
46
+ }
47
+ else {
48
+ // Full update
49
+ for (const storyFile of ctx.storyFiles) {
50
+ await executeStoryFile(storyFile);
51
+ }
52
+ }
53
+ // Queued updates
54
+ for (const storyFile of queuedFiles) {
55
+ await executeStoryFile(storyFile);
56
+ }
57
+ queuedFiles = [];
58
+ queueResolve();
59
+ // Invalidate stories data module
16
60
  const mod = server.moduleGraph.getModuleById(RESOLVED_STORIES_ID);
17
- if (mod) {
18
- server.moduleGraph.invalidateModule(mod);
19
- const timestamp = Date.now();
20
- mod.lastHMRTimestamp = timestamp;
21
- server.ws.send({
22
- type: 'update',
23
- updates: [
24
- {
25
- type: 'js-update',
26
- acceptedPath: mod.url,
27
- path: mod.url,
28
- timestamp: timestamp,
29
- },
30
- ],
31
- });
61
+ if (!mod) {
62
+ return;
63
+ }
64
+ server.moduleGraph.invalidateModule(mod);
65
+ // Send stories data HMR update
66
+ const timestamp = Date.now();
67
+ mod.lastHMRTimestamp = timestamp;
68
+ server.ws.send({
69
+ type: 'update',
70
+ updates: [
71
+ {
72
+ type: 'js-update',
73
+ acceptedPath: mod.url,
74
+ path: mod.url,
75
+ timestamp: timestamp,
76
+ },
77
+ ],
78
+ });
79
+ });
80
+ async function close() {
81
+ await server.close();
82
+ await destroyCollectStories();
83
+ }
84
+ // On page refresh, refresh stories
85
+ // Useful when vite optimizes new dependencies
86
+ server.ws.on('connection', (socket) => {
87
+ if (socket.protocol === 'vite-hmr') {
88
+ notifyStoryChange();
32
89
  }
33
90
  });
34
- return server;
91
+ return {
92
+ server,
93
+ close,
94
+ };
35
95
  }
36
- //# sourceMappingURL=server.js.map
@@ -1,10 +1,9 @@
1
- import { Context } from './context.js';
2
1
  import chokidar from 'chokidar';
3
- export interface Story {
4
- id: string;
5
- file: string;
6
- }
7
- export declare const stories: Story[];
8
- export declare function onStoryChange(handler: () => unknown): void;
9
- export declare function watchStories(ctx: Context): Promise<chokidar.FSWatcher>;
10
- export declare function findStories(ctx: Context): Promise<void>;
2
+ import { Context } from './context.js';
3
+ import type { StoryFile } from './types.js';
4
+ declare type StoryChangeHandler = (file?: StoryFile) => unknown;
5
+ export declare function onStoryChange(handler: StoryChangeHandler): void;
6
+ export declare function watchStories(newContext: Context): Promise<chokidar.FSWatcher>;
7
+ export declare function notifyStoryChange(file?: StoryFile): void;
8
+ export declare function findAllStories(newContext: Context): Promise<void>;
9
+ export {};