histoire 0.2.5 → 0.3.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 (156) hide show
  1. package/dist/client/app/App.vue +8 -3
  2. package/dist/client/app/codegen/const.d.ts +1 -0
  3. package/dist/client/app/codegen/const.js +3 -0
  4. package/dist/client/app/codegen/vue3.js +82 -21
  5. package/dist/client/app/components/base/BaseEmpty.vue +17 -1
  6. package/dist/client/app/components/exposed/Story.vue +22 -1
  7. package/dist/client/app/components/exposed/Variant.vue +13 -1
  8. package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -4
  9. package/dist/client/app/components/sandbox/lib.js +2 -1
  10. package/dist/client/app/components/search/SearchLoading.vue +16 -0
  11. package/dist/client/app/components/search/SearchModal.vue +12 -149
  12. package/dist/client/app/components/search/SearchPane.vue +210 -0
  13. package/dist/client/app/components/search/search-data.d.ts +2 -0
  14. package/dist/client/app/components/search/search-data.js +7 -0
  15. package/dist/client/app/components/story/StoryControls.vue +5 -0
  16. package/dist/client/app/components/story/StoryDocs.vue +18 -11
  17. package/dist/client/app/components/story/StoryEvent.vue +53 -0
  18. package/dist/client/app/components/story/StoryEvents.vue +45 -0
  19. package/dist/client/app/components/story/StoryResponsivePreview.vue +41 -8
  20. package/dist/client/app/components/story/StorySidePanel.vue +28 -3
  21. package/dist/client/app/components/story/StorySourceCode.vue +24 -14
  22. package/dist/client/app/components/story/StoryView.vue +16 -2
  23. package/dist/client/app/components/tree/StoryGroup.vue +4 -4
  24. package/dist/client/app/components/tree/StoryListFolder.vue +4 -4
  25. package/dist/client/app/components/tree/StoryListItem.vue +4 -1
  26. package/dist/client/app/router.d.ts +1 -0
  27. package/dist/client/app/router.js +3 -1
  28. package/dist/client/app/sandbox.js +11 -1
  29. package/dist/client/app/stores/events.d.ts +29 -0
  30. package/dist/client/app/stores/events.js +25 -0
  31. package/dist/client/app/stores/folder.d.ts +10 -0
  32. package/dist/client/app/stores/folder.js +47 -0
  33. package/dist/client/app/stores/story.d.ts +14 -8
  34. package/dist/client/app/stores/story.js +20 -33
  35. package/dist/client/app/style/main.pcss +5 -0
  36. package/dist/client/app/style/sandbox.css +2 -0
  37. package/dist/client/app/types.d.ts +1 -0
  38. package/dist/client/app/util/const.d.ts +1 -0
  39. package/dist/client/app/util/const.js +1 -0
  40. package/dist/client/app/util/events.d.ts +1 -0
  41. package/dist/client/app/util/events.js +31 -0
  42. package/dist/client/app/util/mapping.js +2 -2
  43. package/dist/client/index.d.ts +2 -1
  44. package/dist/client/index.js +2 -1
  45. package/dist/client/server/Story.server.vue +13 -2
  46. package/dist/node/alias.d.ts +2 -1
  47. package/dist/node/alias.js +3 -2
  48. package/dist/node/build.js +74 -21
  49. package/dist/node/builtin-plugins/tailwind-tokens.d.ts +5 -0
  50. package/dist/node/builtin-plugins/tailwind-tokens.js +510 -0
  51. package/dist/node/collect/index.js +3 -1
  52. package/dist/node/commands/preview.js +4 -25
  53. package/dist/node/config.d.ts +103 -3
  54. package/dist/node/config.js +40 -23
  55. package/dist/node/context.d.ts +3 -3
  56. package/dist/node/context.js +1 -1
  57. package/dist/node/index.d.ts +1 -0
  58. package/dist/node/index.js +1 -0
  59. package/dist/node/load.d.ts +12 -0
  60. package/dist/node/load.js +42 -0
  61. package/dist/node/plugin.d.ts +67 -11
  62. package/dist/node/plugin.js +42 -245
  63. package/dist/node/preview.d.ts +8 -0
  64. package/dist/node/preview.js +41 -0
  65. package/dist/node/search.d.ts +2 -0
  66. package/dist/node/search.js +68 -0
  67. package/dist/node/server.js +43 -21
  68. package/dist/node/stories.d.ts +2 -0
  69. package/dist/node/stories.js +4 -4
  70. package/dist/node/types.d.ts +1 -0
  71. package/dist/node/util/find-up.d.ts +1 -0
  72. package/dist/node/util/find-up.js +20 -0
  73. package/dist/node/vite.d.ts +13 -0
  74. package/dist/node/vite.js +278 -0
  75. package/dist/style.css +111 -47
  76. package/package.json +5 -3
  77. package/scripts/copy.mjs +2 -1
  78. package/src/client/app/App.vue +8 -3
  79. package/src/client/app/codegen/const.ts +3 -0
  80. package/src/client/app/codegen/vue3.ts +80 -22
  81. package/src/client/app/components/base/BaseEmpty.vue +17 -1
  82. package/src/client/app/components/exposed/Story.vue +22 -1
  83. package/src/client/app/components/exposed/Variant.vue +13 -1
  84. package/src/client/app/components/sandbox/SandboxVue3.vue +6 -4
  85. package/src/client/app/components/sandbox/lib.ts +3 -1
  86. package/src/client/app/components/search/SearchLoading.vue +16 -0
  87. package/src/client/app/components/search/SearchModal.vue +12 -149
  88. package/src/client/app/components/search/SearchPane.vue +210 -0
  89. package/src/client/app/components/search/search-data.ts +9 -0
  90. package/src/client/app/components/story/StoryControls.vue +5 -0
  91. package/src/client/app/components/story/StoryDocs.vue +18 -11
  92. package/src/client/app/components/story/StoryEvent.vue +53 -0
  93. package/src/client/app/components/story/StoryEvents.vue +45 -0
  94. package/src/client/app/components/story/StoryResponsivePreview.vue +41 -8
  95. package/src/client/app/components/story/StorySidePanel.vue +28 -3
  96. package/src/client/app/components/story/StorySourceCode.vue +24 -14
  97. package/src/client/app/components/story/StoryView.vue +16 -2
  98. package/src/client/app/components/tree/StoryGroup.vue +4 -4
  99. package/src/client/app/components/tree/StoryListFolder.vue +4 -4
  100. package/src/client/app/components/tree/StoryListItem.vue +4 -1
  101. package/src/client/app/router.ts +4 -1
  102. package/src/client/app/sandbox.ts +12 -2
  103. package/src/client/app/stores/events.ts +36 -0
  104. package/{dist/client/app/stores/story.ts → src/client/app/stores/folder.ts} +16 -23
  105. package/src/client/app/stores/story.ts +21 -40
  106. package/src/client/app/style/main.pcss +5 -0
  107. package/src/client/app/style/sandbox.css +2 -0
  108. package/src/client/app/types.ts +1 -0
  109. package/src/client/app/util/const.ts +1 -0
  110. package/src/client/app/util/events.ts +30 -0
  111. package/src/client/app/util/mapping.ts +2 -2
  112. package/src/client/index.ts +2 -1
  113. package/src/client/server/Story.server.vue +13 -2
  114. package/src/node/alias.ts +4 -2
  115. package/src/node/build.ts +86 -21
  116. package/src/node/builtin-plugins/tailwind-tokens.ts +521 -0
  117. package/src/node/collect/index.ts +3 -1
  118. package/src/node/commands/preview.ts +4 -33
  119. package/src/node/config.ts +53 -27
  120. package/src/node/context.ts +3 -3
  121. package/src/node/index.ts +1 -0
  122. package/src/node/load.ts +63 -0
  123. package/src/node/plugin.ts +75 -252
  124. package/src/node/preview.ts +56 -0
  125. package/src/node/search.ts +75 -0
  126. package/src/node/server.ts +49 -23
  127. package/src/node/stories.ts +4 -4
  128. package/src/node/types.ts +1 -0
  129. package/src/node/util/find-up.ts +24 -0
  130. package/src/node/vite.ts +296 -0
  131. package/tailwind.config.cjs +1 -0
  132. package/dist/client/app/codegen/serialize-js.ts +0 -119
  133. package/dist/client/app/codegen/util.ts +0 -79
  134. package/dist/client/app/codegen/vue3.ts +0 -276
  135. package/dist/client/app/components/sandbox/lib.ts +0 -8
  136. package/dist/client/app/global-components.ts +0 -13
  137. package/dist/client/app/index.ts +0 -28
  138. package/dist/client/app/router.ts +0 -17
  139. package/dist/client/app/sandbox.ts +0 -94
  140. package/dist/client/app/stores/preview-settings.ts +0 -17
  141. package/dist/client/app/types.ts +0 -78
  142. package/dist/client/app/util/config.ts +0 -6
  143. package/dist/client/app/util/const.ts +0 -3
  144. package/dist/client/app/util/dark.ts +0 -4
  145. package/dist/client/app/util/env.ts +0 -1
  146. package/dist/client/app/util/keyboard.ts +0 -99
  147. package/dist/client/app/util/mapping.ts +0 -48
  148. package/dist/client/app/util/preview-settings.ts +0 -8
  149. package/dist/client/app/util/reactivity.ts +0 -22
  150. package/dist/client/app/util/responsive.ts +0 -3
  151. package/dist/client/app/util/scroll.ts +0 -31
  152. package/dist/client/app/util/tooltip.ts +0 -13
  153. package/dist/client/app/util/variant.ts +0 -20
  154. package/dist/client/index.ts +0 -12
  155. package/dist/client/server/index.ts +0 -32
  156. package/dist/client/shim.d.ts +0 -5
@@ -0,0 +1,510 @@
1
+ import { findUp } from '../util/find-up.js';
2
+ export function tailwindTokens(options = {}) {
3
+ const tailwindConfigFile = options.configFile ?? findUp(process.cwd(), [
4
+ 'tailwind.config.js',
5
+ 'tailwind.config.cjs',
6
+ 'tailwind.config.mjs',
7
+ 'tailwind.config.ts',
8
+ 'tailwind-config.js',
9
+ 'tailwind-config.cjs',
10
+ 'tailwind-config.mjs',
11
+ 'tailwind-config.ts',
12
+ ]);
13
+ async function generate(api) {
14
+ try {
15
+ await api.fs.ensureDir(api.pluginTempDir);
16
+ await api.fs.emptyDir(api.pluginTempDir);
17
+ api.moduleLoader.clearCache();
18
+ const tailwindConfig = await api.moduleLoader.loadModule(tailwindConfigFile);
19
+ const { default: resolveConfig } = await import('tailwindcss/resolveConfig.js');
20
+ const resolvedTailwindConfig = resolveConfig(tailwindConfig);
21
+ const storyFile = api.path.resolve(api.pluginTempDir, 'Tailwind.story.vue');
22
+ await api.fs.writeFile(storyFile, storyTemplate(resolvedTailwindConfig));
23
+ api.addStoryFile(storyFile);
24
+ }
25
+ catch (e) {
26
+ api.error(e.stack ?? e.message);
27
+ }
28
+ }
29
+ return {
30
+ name: 'tailwind-tokens',
31
+ config(config) {
32
+ if (tailwindConfigFile) {
33
+ // Add 'design-system' group
34
+ if (!config.tree) {
35
+ config.tree = {};
36
+ }
37
+ if (!config.tree.groups) {
38
+ config.tree.groups = [];
39
+ }
40
+ if (!config.tree.groups.some(g => g.id === 'design-system')) {
41
+ let index = 0;
42
+ // After 'top' group
43
+ const topIndex = config.tree.groups.findIndex(g => g.id === 'top');
44
+ if (topIndex > -1) {
45
+ index = topIndex + 1;
46
+ }
47
+ // Insert group
48
+ config.tree.groups.splice(index, 0, {
49
+ id: 'design-system',
50
+ title: 'Design System',
51
+ });
52
+ }
53
+ }
54
+ },
55
+ onDev(api, onCleanup) {
56
+ if (tailwindConfigFile) {
57
+ const watcher = api.watcher.watch(tailwindConfigFile)
58
+ .on('change', () => generate(api))
59
+ .on('add', () => generate(api));
60
+ onCleanup(() => {
61
+ watcher.close();
62
+ });
63
+ }
64
+ },
65
+ async onBuild(api) {
66
+ if (tailwindConfigFile) {
67
+ await generate(api);
68
+ }
69
+ },
70
+ };
71
+ }
72
+ const storyTemplate = (tailwindConfig) => `<script setup>
73
+ import 'histoire/dist/style.css'
74
+ import { ref } from 'vue'
75
+ const config = ${JSON.stringify(tailwindConfig, null, 2)}
76
+ const search = ref('')
77
+ const sampleText = ref('Cat sit like bread eat prawns daintily with a claw then lick paws clean wash down prawns with a lap of carnation milk then retire to the warmest spot on the couch to claw at the fabric before taking a catnap mrow cat cat moo moo lick ears lick paws')
78
+ const fontSize = ref(16)
79
+ defineExpose({
80
+ search,
81
+ sampleText,
82
+ fontSize,
83
+ })
84
+ </script>
85
+ <template>
86
+ <Story id="tailwind" title="Tailwind" group="design-system" icon="mdi:tailwind" responsiveDisabled>
87
+ <Variant id="background-color" title="Background Color" icon="carbon:color-palette">
88
+ <HstColorShades
89
+ v-for="(shades, key) of config.theme.backgroundColor"
90
+ :key="key"
91
+ :shades="typeof shades === 'object' ? shades : { DEFAULT: shades }"
92
+ :get-name="shade => (config.prefix ?? '') + (shade === 'DEFAULT' ? \`bg-\${key}\` : \`bg-\${key}-\${shade}\`)"
93
+ :search="search"
94
+ >
95
+ <template #default="{ color }">
96
+ <div
97
+ class="shade"
98
+ :style="{
99
+ backgroundColor: color,
100
+ }"
101
+ />
102
+ </template>
103
+ </HstColorShades>
104
+ <template #controls>
105
+ <HstText
106
+ v-model="search"
107
+ title="Filter..."
108
+ />
109
+ </template>
110
+ </Variant>
111
+ <Variant id="text-color" title="Text Color" icon="carbon:text-color">
112
+ <HstColorShades
113
+ v-for="(shades, key) of config.theme.textColor"
114
+ :key="key"
115
+ :shades="typeof shades === 'object' ? shades : { DEFAULT: shades }"
116
+ :get-name="shade => (config.prefix ?? '') + (shade === 'DEFAULT' ? \`text-\${key}\` : \`text-\${key}-\${shade}\`)"
117
+ :search="search"
118
+ >
119
+ <template #default="{ color }">
120
+ <div
121
+ class="shade text"
122
+ :style="{
123
+ color: color,
124
+ }"
125
+ >
126
+ Aa
127
+ </div>
128
+ </template>
129
+ </HstColorShades>
130
+ <template #controls>
131
+ <HstText
132
+ v-model="search"
133
+ title="Filter..."
134
+ />
135
+ </template>
136
+ </Variant>
137
+ <Variant id="border-color" title="Border Color" icon="carbon:color-palette">
138
+ <HstColorShades
139
+ v-for="(shades, key) of config.theme.borderColor"
140
+ :key="key"
141
+ :shades="typeof shades === 'object' ? shades : { DEFAULT: shades }"
142
+ :get-name="shade => (config.prefix ?? '') + (shade === 'DEFAULT' ? \`border-\${key}\` : \`border-\${key}-\${shade}\`)"
143
+ :search="search"
144
+ >
145
+ <template #default="{ color }">
146
+ <div
147
+ class="shade border"
148
+ :style="{
149
+ borderColor: color,
150
+ }"
151
+ />
152
+ </template>
153
+ </HstColorShades>
154
+ <template #controls>
155
+ <HstText
156
+ v-model="search"
157
+ title="Filter..."
158
+ />
159
+ </template>
160
+ </Variant>
161
+ <Variant id="padding" title="Padding" icon="carbon:area">
162
+ <HstTokenList
163
+ :tokens="config.theme.padding"
164
+ :get-name="key => \`\${config.prefix ?? ''}p-\${key}\`"
165
+ >
166
+ <template #default="{ token }">
167
+ <div class="padding"
168
+ :style="{
169
+ padding: token.value,
170
+ }"
171
+ >
172
+ <div
173
+ class="padding-box"
174
+ />
175
+ </div>
176
+ </template>
177
+ </HstTokenList>
178
+ </Variant>
179
+ <Variant id="margin" title="Margin" icon="carbon:area">
180
+ <HstTokenList
181
+ :tokens="config.theme.margin"
182
+ :get-name="key => \`\${config.prefix ?? ''}m-\${key}\`"
183
+ >
184
+ <template #default="{ token }">
185
+ <div class="margin"
186
+ :style="{
187
+ padding: token.value,
188
+ }"
189
+ >
190
+ <div
191
+ class="margin-box"
192
+ />
193
+ </div>
194
+ </template>
195
+ </HstTokenList>
196
+ </Variant>
197
+ <Variant id="font-size" title="Font Size" icon="carbon:text-font">
198
+ <HstTokenList
199
+ :tokens="config.theme.fontSize"
200
+ :get-name="key => \`\${config.prefix ?? ''}text-\${key}\`"
201
+ >
202
+ <template #default="{ token }">
203
+ <div
204
+ class="truncate"
205
+ :style="{
206
+ fontSize: token.value[0],
207
+ ...token.value[1],
208
+ }"
209
+ >
210
+ {{ sampleText }}
211
+ </div>
212
+ </template>
213
+ </HstTokenList>
214
+ <template #controls>
215
+ <HstTextarea
216
+ v-model="sampleText"
217
+ title="Sample text"
218
+ rows="5"
219
+ />
220
+ </template>
221
+ </Variant>
222
+ <Variant id="font-weight" title="Font Weight" icon="carbon:text-font">
223
+ <HstTokenList
224
+ :tokens="config.theme.fontWeight"
225
+ :get-name="key => \`\${config.prefix ?? ''}font-\${key}\`"
226
+ >
227
+ <template #default="{ token }">
228
+ <div
229
+ class="truncate"
230
+ :style="{
231
+ fontWeight: token.value,
232
+ fontSize: \`\${fontSize}px\`,
233
+ }"
234
+ >
235
+ {{ sampleText }}
236
+ </div>
237
+ </template>
238
+ </HstTokenList>
239
+ <template #controls>
240
+ <HstTextarea
241
+ v-model="sampleText"
242
+ title="Sample text"
243
+ rows="5"
244
+ />
245
+ <HstNumber
246
+ v-model="fontSize"
247
+ title="Font size"
248
+ min="1"
249
+ />
250
+ </template>
251
+ </Variant>
252
+ <Variant id="font-family" title="Font Family" icon="carbon:text-font">
253
+ <HstTokenList
254
+ :tokens="config.theme.fontFamily"
255
+ :get-name="key => \`\${config.prefix ?? ''}font-\${key}\`"
256
+ >
257
+ <template #default="{ token }">
258
+ <div
259
+ class="truncate"
260
+ :style="{
261
+ fontFamily: token.value,
262
+ fontSize: \`\${fontSize}px\`,
263
+ }"
264
+ >
265
+ {{ sampleText }}
266
+ </div>
267
+ </template>
268
+ </HstTokenList>
269
+ <template #controls>
270
+ <HstTextarea
271
+ v-model="sampleText"
272
+ title="Sample text"
273
+ rows="5"
274
+ />
275
+ <HstNumber
276
+ v-model="fontSize"
277
+ title="Font size"
278
+ min="1"
279
+ />
280
+ </template>
281
+ </Variant>
282
+ <Variant id="letter-spacing" title="Letter Spacing" icon="carbon:text-font">
283
+ <HstTokenList
284
+ :tokens="config.theme.letterSpacing"
285
+ :get-name="key => \`\${config.prefix ?? ''}tracking-\${key}\`"
286
+ >
287
+ <template #default="{ token }">
288
+ <div
289
+ class="truncate"
290
+ :style="{
291
+ letterSpacing: token.value,
292
+ fontSize: \`\${fontSize}px\`,
293
+ }"
294
+ >
295
+ {{ sampleText }}
296
+ </div>
297
+ </template>
298
+ </HstTokenList>
299
+ <template #controls>
300
+ <HstTextarea
301
+ v-model="sampleText"
302
+ title="Sample text"
303
+ rows="5"
304
+ />
305
+ <HstNumber
306
+ v-model="fontSize"
307
+ title="Font size"
308
+ min="1"
309
+ />
310
+ </template>
311
+ </Variant>
312
+ <Variant id="line-height" title="Line Height" icon="carbon:text-font">
313
+ <HstTokenList
314
+ :tokens="config.theme.lineHeight"
315
+ :get-name="key => \`\${config.prefix ?? ''}leading-\${key}\`"
316
+ >
317
+ <template #default="{ token }">
318
+ <div
319
+ :style="{
320
+ lineHeight: token.value,
321
+ fontSize: \`\${fontSize}px\`,
322
+ }"
323
+ >
324
+ {{ sampleText }}
325
+ </div>
326
+ </template>
327
+ </HstTokenList>
328
+ <template #controls>
329
+ <HstTextarea
330
+ v-model="sampleText"
331
+ title="Sample text"
332
+ rows="5"
333
+ />
334
+ <HstNumber
335
+ v-model="fontSize"
336
+ title="Font size"
337
+ min="1"
338
+ />
339
+ </template>
340
+ </Variant>
341
+ <Variant id="drop-shadow" title="Drop Shadow" icon="carbon:shape-except">
342
+ <HstTokenGrid
343
+ :tokens="config.theme.dropShadow"
344
+ :get-name="key => (config.prefix ?? '') + (key === 'DEFAULT' ? 'drop-shadow' : \`drop-shadow-\${key}\`)"
345
+ :col-size="180"
346
+ >
347
+ <template #default="{ token }">
348
+ <div
349
+ class="drop-shadow"
350
+ :style="{
351
+ filter: \`\${(Array.isArray(token.value) ? token.value : [token.value]).map(v => \`drop-shadow(\${v})\`).join(' ')}\`,
352
+ }"
353
+ />
354
+ </template>
355
+ </HstTokenGrid>
356
+ </Variant>
357
+ <Variant id="border-radius" title="Border Radius" icon="carbon:condition-wait-point">
358
+ <HstTokenGrid
359
+ :tokens="config.theme.borderRadius"
360
+ :get-name="key => (config.prefix ?? '') + (key === 'DEFAULT' ? 'rounded' : \`rounded-\${key}\`)"
361
+ :col-size="180"
362
+ >
363
+ <template #default="{ token }">
364
+ <div
365
+ class="border-radius"
366
+ :style="{
367
+ borderRadius: token.value,
368
+ }"
369
+ />
370
+ </template>
371
+ </HstTokenGrid>
372
+ </Variant>
373
+ <Variant id="border-width" title="Border Width" icon="carbon:checkbox">
374
+ <HstTokenGrid
375
+ :tokens="config.theme.borderWidth"
376
+ :get-name="key => (config.prefix ?? '') + (key === 'DEFAULT' ? 'border' : \`border-\${key}\`)"
377
+ :col-size="180"
378
+ >
379
+ <template #default="{ token }">
380
+ <div
381
+ class="border-width"
382
+ :style="{
383
+ borderWidth: token.value,
384
+ }"
385
+ />
386
+ </template>
387
+ </HstTokenGrid>
388
+ </Variant>
389
+ <Variant id="width" title="Width" icon="carbon:pan-horizontal">
390
+ <HstTokenList
391
+ :tokens="config.theme.width"
392
+ :get-name="key => (config.prefix ?? '') + (key === 'DEFAULT' ? 'w' : \`w-\${key}\`)"
393
+ >
394
+ <template #default="{ token }">
395
+ <div class="width">
396
+ <div
397
+ class="width-box"
398
+ :style="{
399
+ width: token.value,
400
+ }"
401
+ />
402
+ </div>
403
+ </template>
404
+ </HstTokenList>
405
+ </Variant>
406
+ <Variant id="height" title="Height" icon="carbon:pan-vertical">
407
+ <HstTokenList
408
+ :tokens="config.theme.height"
409
+ :get-name="key => (config.prefix ?? '') + (key === 'DEFAULT' ? 'h' : \`h-\${key}\`)"
410
+ >
411
+ <template #default="{ token }">
412
+ <div
413
+ class="height"
414
+ :style="{
415
+ height: token.value,
416
+ }"
417
+ />
418
+ </template>
419
+ </HstTokenList>
420
+ </Variant>
421
+ <Variant id="full-config" title="Full Config" icon="carbon:code">
422
+ <pre>{{ config }}</pre>
423
+ </Variant>
424
+ </Story>
425
+ </template>
426
+ <style scoped>
427
+ .shade {
428
+ height: 80px;
429
+ border-radius: 4px;
430
+ }
431
+
432
+ .text {
433
+ font-size: 4rem;
434
+ display: flex;
435
+ align-items: flex-end;
436
+ }
437
+
438
+ .border {
439
+ border-style: solid;
440
+ border-width: 2px;
441
+ }
442
+
443
+ .padding {
444
+ background-color: rgb(113 113 122 / 0.1);
445
+ width: min-content;
446
+ }
447
+
448
+ .margin {
449
+ border: dashed 1px rgb(113 113 122 / 0.5);
450
+ width: min-content;
451
+ }
452
+
453
+ .padding-box,
454
+ .margin-box {
455
+ width: 5rem;
456
+ height: 5rem;
457
+ background-color: rgb(113 113 122 / 0.5);
458
+ }
459
+
460
+ .padding,
461
+ .padding-box,
462
+ .margin,
463
+ .margin-box,
464
+ .drop-shadow {
465
+ border-radius: 4px;
466
+ }
467
+
468
+ .truncate {
469
+ overflow: hidden;
470
+ text-overflow: ellipsis;
471
+ white-space: nowrap;
472
+ }
473
+
474
+ .drop-shadow {
475
+ width: 8rem;
476
+ height: 8rem;
477
+ background: white;
478
+ margin-bottom: 0.5rem;
479
+ }
480
+
481
+ .dark .drop-shadow {
482
+ background: #4e4e57;
483
+ }
484
+
485
+ .border-radius {
486
+ width: 8rem;
487
+ height: 8rem;
488
+ background-color: rgb(113 113 122 / 0.5);
489
+ }
490
+
491
+ .border-width {
492
+ width: 8rem;
493
+ height: 8rem;
494
+ border-color: rgb(113 113 122 / 0.5);
495
+ background-color: rgb(113 113 122 / 0.1);
496
+ }
497
+
498
+ .width {
499
+ background-color: rgb(113 113 122 / 0.1);
500
+ }
501
+
502
+ .width-box,
503
+ .height {
504
+ background-color: rgb(113 113 122 / 0.5);
505
+ }
506
+
507
+ .width-box {
508
+ height: 5rem;
509
+ }
510
+ </style>`;
@@ -17,9 +17,10 @@ export function useCollectStories(options, ctx) {
17
17
  const threadPool = new Tinypool({
18
18
  filename: new URL('./worker.js', import.meta.url).href,
19
19
  // WebContainer compatibility (Stackblitz)
20
- useAtomics: false,
20
+ useAtomics: typeof process.versions.webcontainer !== 'string',
21
21
  });
22
22
  function clearCache() {
23
+ server.moduleGraph.invalidateAll();
23
24
  node.fetchCache.clear();
24
25
  }
25
26
  function createChannel() {
@@ -58,6 +59,7 @@ export function useCollectStories(options, ctx) {
58
59
  else if (storyData.length > 1) {
59
60
  console.warn(pc.yellow(`⚠️ Multiple stories not supported: ${storyFile.path}`));
60
61
  }
62
+ storyFile.id = storyData[0].id;
61
63
  storyFile.story = storyData[0];
62
64
  storyFile.treeFile = {
63
65
  title: storyData[0].title,
@@ -1,10 +1,8 @@
1
- import http from 'http';
2
1
  import { resolveConfig as resolveViteConfig } from 'vite';
3
- import connect from 'connect';
4
- import sirv from 'sirv';
5
2
  import pc from 'picocolors';
6
3
  import { createContext } from '../context.js';
7
- import { createVitePlugins } from '../plugin.js';
4
+ import { createVitePlugins } from '../vite.js';
5
+ import { startPreview } from '../preview.js';
8
6
  export async function previewCommand(options) {
9
7
  const ctx = await createContext({
10
8
  mode: 'build',
@@ -12,25 +10,6 @@ export async function previewCommand(options) {
12
10
  const viteConfig = await resolveViteConfig({
13
11
  plugins: await createVitePlugins(ctx),
14
12
  }, 'build');
15
- const app = connect();
16
- app.use(viteConfig.base, sirv(ctx.config.outDir, {
17
- dev: true,
18
- etag: true,
19
- single: true,
20
- }));
21
- let port = options.port ?? 3000;
22
- const httpServer = http.createServer(app);
23
- function onError(e) {
24
- if (e.code === 'EADDRINUSE') {
25
- httpServer.listen(++port);
26
- }
27
- else {
28
- throw e;
29
- }
30
- }
31
- httpServer.on('error', onError);
32
- httpServer.listen(port, () => {
33
- httpServer.off('error', onError);
34
- console.log(`Preview server listening on ${pc.cyan(`http://localhost:${port}`)}`);
35
- });
13
+ const { baseUrl } = await startPreview(viteConfig, options.port, ctx);
14
+ console.log(`Preview server listening on ${pc.cyan(baseUrl)}`);
36
15
  }