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.
- package/LICENSE +21 -0
- package/client.d.ts +2 -0
- package/dist/client/app/App.vue +84 -21
- package/dist/client/app/assets/histoire-text-dark.svg +89 -0
- package/dist/client/app/assets/histoire-text.svg +89 -0
- package/dist/client/app/assets/histoire.svg +51 -0
- package/dist/client/app/codegen/serialize-js.d.ts +1 -0
- package/dist/client/app/codegen/serialize-js.js +113 -0
- package/dist/client/app/codegen/serialize-js.ts +119 -0
- package/dist/client/app/codegen/util.d.ts +10 -0
- package/dist/client/app/codegen/util.js +70 -0
- package/dist/client/app/codegen/util.ts +79 -0
- package/dist/client/app/codegen/vue3.d.ts +2 -0
- package/dist/client/app/codegen/vue3.js +238 -0
- package/dist/client/app/codegen/vue3.ts +240 -0
- package/dist/client/app/components/HomeView.vue +15 -1
- package/dist/client/app/components/StoryControls.vue +7 -2
- package/dist/client/app/components/StoryList.vue +20 -13
- package/dist/client/app/components/StoryListFolder.vue +87 -0
- package/dist/client/app/components/StoryListItem.vue +38 -12
- package/dist/client/app/components/StorySourceCode.vue +121 -0
- package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
- package/dist/client/app/components/StoryVariantListItem.vue +46 -0
- package/dist/client/app/components/StoryVariantSingleView.vue +145 -15
- package/dist/client/app/components/StoryView.vue +88 -54
- package/dist/client/app/components/app/AppHeader.vue +56 -0
- package/dist/client/app/components/app/AppLogo.vue +24 -0
- package/dist/client/app/components/base/BaseEmpty.vue +1 -1
- package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
- package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
- package/dist/client/app/components/exposed/Story.vue +23 -58
- package/dist/client/app/components/exposed/Variant.vue +24 -47
- package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
- package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
- package/dist/client/app/components/search/SearchItem.vue +110 -0
- package/dist/client/app/components/search/SearchModal.vue +179 -0
- package/dist/client/app/composable/variant.js +0 -1
- package/dist/client/app/composable/variant.ts +20 -0
- package/dist/client/app/global-components.js +0 -1
- package/dist/client/app/global-components.ts +10 -0
- package/dist/client/app/index.d.ts +1 -0
- package/dist/client/app/index.js +10 -2
- package/dist/client/app/index.ts +24 -0
- package/dist/client/app/router.js +0 -1
- package/dist/client/app/router.ts +17 -0
- package/dist/client/app/sandbox.d.ts +1 -0
- package/dist/client/app/sandbox.js +53 -0
- package/dist/client/app/sandbox.ts +60 -0
- package/dist/client/app/stores/story.d.ts +167 -50
- package/dist/client/app/stores/story.js +33 -16
- package/dist/client/app/stores/story.ts +58 -0
- package/dist/client/app/style/floating-vue.css +31 -0
- package/dist/client/app/style/main.css +17 -2
- package/dist/client/app/style/sandbox.css +14 -0
- package/dist/client/app/types.d.ts +36 -4
- package/dist/client/app/types.js +0 -1
- package/dist/client/app/types.ts +59 -0
- package/dist/client/app/util/config.d.ts +3 -0
- package/dist/client/app/util/config.js +4 -0
- package/dist/client/app/util/config.ts +6 -0
- package/dist/client/app/util/const.d.ts +1 -0
- package/dist/client/app/util/const.js +1 -0
- package/dist/client/app/util/const.ts +1 -0
- package/dist/client/app/util/dark.d.ts +2 -0
- package/dist/client/app/util/dark.js +3 -0
- package/dist/client/app/util/dark.ts +4 -0
- package/dist/client/app/util/env.d.ts +1 -0
- package/dist/client/app/util/env.js +1 -0
- package/dist/client/app/util/env.ts +1 -0
- package/dist/client/app/util/keyboard.d.ts +8 -0
- package/dist/client/app/util/keyboard.js +82 -0
- package/dist/client/app/util/keyboard.ts +99 -0
- package/dist/client/app/util/mapping.d.ts +3 -0
- package/dist/client/app/util/mapping.js +39 -0
- package/dist/client/app/util/mapping.ts +41 -0
- package/dist/client/app/util/tooltip.d.ts +6 -0
- package/dist/client/app/util/tooltip.js +11 -0
- package/dist/client/app/util/tooltip.ts +13 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.ts +12 -0
- package/dist/client/server/Story.server.vue +65 -0
- package/dist/client/server/Variant.server.vue +50 -0
- package/dist/client/server/index.d.ts +2 -0
- package/dist/client/server/index.js +25 -0
- package/dist/client/server/index.ts +29 -0
- package/dist/client/shim.d.ts +5 -0
- package/dist/node/alias.js +0 -1
- package/dist/node/bin.js +8 -3
- package/dist/node/build.d.ts +2 -0
- package/dist/node/build.js +71 -0
- package/dist/node/collect.d.ts +12 -0
- package/dist/node/collect.js +65 -0
- package/dist/node/colors.d.ts +286 -0
- package/dist/node/colors.js +324 -0
- package/dist/node/commands/build.d.ts +1 -0
- package/dist/node/commands/build.js +10 -0
- package/dist/node/commands/dev.d.ts +1 -1
- package/dist/node/commands/dev.js +45 -13
- package/dist/node/config.d.ts +112 -1
- package/dist/node/config.js +124 -2
- package/dist/node/context.d.ts +13 -0
- package/dist/node/context.js +12 -2
- package/dist/node/dom/dom-keys.d.ts +4 -0
- package/dist/node/dom/dom-keys.js +223 -0
- package/dist/node/dom/env.d.ts +5 -0
- package/dist/node/dom/env.js +22 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +2 -2
- package/dist/node/plugin.d.ts +8 -2
- package/dist/node/plugin.js +150 -22
- package/dist/node/server.d.ts +4 -1
- package/dist/node/server.js +80 -21
- package/dist/node/stories.d.ts +8 -9
- package/dist/node/stories.js +42 -23
- package/dist/node/tree.d.ts +19 -0
- package/dist/node/tree.js +54 -0
- package/dist/node/types.d.ts +38 -0
- package/dist/node/types.js +1 -0
- package/dist/style.css +610 -53
- package/package.json +45 -25
- package/scripts/copy.mjs +11 -0
- package/src/client/app/App.vue +84 -21
- package/src/client/app/assets/histoire-text-dark.svg +89 -0
- package/src/client/app/assets/histoire-text.svg +89 -0
- package/src/client/app/assets/histoire.svg +51 -0
- package/src/client/app/codegen/serialize-js.ts +119 -0
- package/src/client/app/codegen/util.ts +79 -0
- package/src/client/app/codegen/vue3.ts +240 -0
- package/src/client/app/components/HomeView.vue +15 -1
- package/src/client/app/components/StoryControls.vue +7 -2
- package/src/client/app/components/StoryList.vue +20 -13
- package/src/client/app/components/StoryListFolder.vue +87 -0
- package/src/client/app/components/StoryListItem.vue +38 -12
- package/src/client/app/components/StorySourceCode.vue +121 -0
- package/src/client/app/components/StoryVariantGridItem.vue +32 -17
- package/src/client/app/components/StoryVariantListItem.vue +46 -0
- package/src/client/app/components/StoryVariantSingleView.vue +145 -15
- package/src/client/app/components/StoryView.vue +88 -54
- package/src/client/app/components/app/AppHeader.vue +56 -0
- package/src/client/app/components/app/AppLogo.vue +24 -0
- package/src/client/app/components/base/BaseEmpty.vue +1 -1
- package/src/client/app/components/base/BaseListItemLink.vue +55 -0
- package/src/client/app/components/base/BaseSplitPane.vue +57 -21
- package/src/client/app/components/exposed/Story.vue +23 -58
- package/src/client/app/components/exposed/Variant.vue +24 -47
- package/src/client/app/components/misc/HatchedPattern.vue +25 -0
- package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
- package/src/client/app/components/search/SearchItem.vue +110 -0
- package/src/client/app/components/search/SearchModal.vue +179 -0
- package/src/client/app/index.ts +10 -1
- package/src/client/app/sandbox.ts +60 -0
- package/src/client/app/stores/story.ts +39 -15
- package/src/client/app/style/floating-vue.css +31 -0
- package/src/client/app/style/main.css +17 -2
- package/src/client/app/style/sandbox.css +14 -0
- package/src/client/app/types.ts +42 -4
- package/src/client/app/util/config.ts +6 -0
- package/src/client/app/util/const.ts +1 -0
- package/src/client/app/util/dark.ts +4 -0
- package/src/client/app/util/env.ts +1 -0
- package/src/client/app/util/keyboard.ts +99 -0
- package/src/client/app/util/mapping.ts +41 -0
- package/src/client/app/util/tooltip.ts +13 -0
- package/src/client/index.ts +12 -0
- package/src/client/server/Story.server.vue +65 -0
- package/src/client/server/Variant.server.vue +50 -0
- package/src/client/server/index.ts +29 -0
- package/src/node/bin.ts +9 -2
- package/src/node/build.ts +80 -0
- package/src/node/collect.ts +78 -0
- package/src/node/colors.ts +340 -0
- package/src/node/commands/build.ts +12 -0
- package/src/node/commands/dev.ts +49 -12
- package/src/node/config.ts +240 -1
- package/src/node/context.ts +21 -1
- package/src/node/dom/dom-keys.ts +227 -0
- package/src/node/dom/env.ts +26 -0
- package/src/node/index.ts +2 -0
- package/src/node/plugin.ts +155 -22
- package/src/node/server.ts +95 -20
- package/src/node/stories.ts +53 -31
- package/src/node/tree.spec.ts +28 -0
- package/src/node/tree.ts +88 -0
- package/src/node/types.ts +40 -0
- package/tailwind.config.cjs +41 -1
- package/tsconfig.json +2 -1
- package/dist/client/app/components/StoryVariantItem.vue +0 -29
- package/dist/client/app/composable/variant.js.map +0 -1
- package/dist/client/app/global-components.js.map +0 -1
- package/dist/client/app/index.js.map +0 -1
- package/dist/client/app/router.js.map +0 -1
- package/dist/client/app/stores/story.js.map +0 -1
- package/dist/client/app/types.js.map +0 -1
- package/dist/node/alias.js.map +0 -1
- package/dist/node/bin.js.map +0 -1
- package/dist/node/commands/dev.js.map +0 -1
- package/dist/node/config.js.map +0 -1
- package/dist/node/context.js.map +0 -1
- package/dist/node/index.js.map +0 -1
- package/dist/node/plugin.js.map +0 -1
- package/dist/node/server.js.map +0 -1
- package/dist/node/stories.js.map +0 -1
- 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,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
|
+
}
|
package/dist/node/index.d.ts
CHANGED
package/dist/node/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export * from './config.js';
|
|
2
|
+
export { defaultColors } from './colors.js';
|
package/dist/node/plugin.d.ts
CHANGED
|
@@ -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
|
|
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[]>;
|
package/dist/node/plugin.js
CHANGED
|
@@ -1,38 +1,88 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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
|
|
8
|
-
const
|
|
9
|
-
const
|
|
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
|
-
|
|
34
|
+
return {
|
|
13
35
|
optimizeDeps: {
|
|
14
36
|
// force include vue to avoid duplicated copies when linked + optimized
|
|
15
|
-
include: [
|
|
37
|
+
include: [
|
|
38
|
+
'vue',
|
|
39
|
+
'@vue/runtime-core',
|
|
40
|
+
],
|
|
16
41
|
},
|
|
17
42
|
server: {
|
|
18
43
|
fs: {
|
|
19
|
-
allow: [DIST_CLIENT_PATH,
|
|
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
|
-
|
|
35
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
package/dist/node/server.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { Context } from './context.js';
|
|
2
|
-
export declare function createServer(ctx: Context): Promise<
|
|
2
|
+
export declare function createServer(ctx: Context, port: number): Promise<{
|
|
3
|
+
server: import("vite").ViteDevServer;
|
|
4
|
+
close: () => Promise<void>;
|
|
5
|
+
}>;
|
package/dist/node/server.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
91
|
+
return {
|
|
92
|
+
server,
|
|
93
|
+
close,
|
|
94
|
+
};
|
|
35
95
|
}
|
|
36
|
-
//# sourceMappingURL=server.js.map
|
package/dist/node/stories.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Context } from './context.js';
|
|
2
1
|
import chokidar from 'chokidar';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export
|
|
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 {};
|