histoire 0.12.4 → 0.13.1
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/dist/node/build.js +17 -11
- package/dist/node/builtin-plugins/pinceau-tokens.d.ts +6 -0
- package/dist/node/builtin-plugins/pinceau-tokens.js +505 -0
- package/dist/node/collect/index.js +1 -0
- package/dist/node/index.d.ts +7 -0
- package/dist/node/server.js +7 -6
- package/dist/node/util/vendors.d.ts +1 -0
- package/dist/node/util/vendors.js +7 -2
- package/dist/node/virtual/index.d.ts +34 -0
- package/dist/node/virtual/index.js +46 -0
- package/dist/node/virtual/markdown.d.ts +2 -0
- package/dist/node/virtual/markdown.js +19 -0
- package/dist/node/virtual/noop.d.ts +1 -0
- package/dist/node/virtual/noop.js +1 -0
- package/dist/node/virtual/resolved-config.d.ts +2 -0
- package/dist/node/virtual/resolved-config.js +10 -0
- package/dist/node/virtual/resolved-generated-global-setup.d.ts +2 -0
- package/dist/node/virtual/resolved-generated-global-setup.js +23 -0
- package/dist/node/virtual/resolved-generated-setup-code.d.ts +2 -0
- package/dist/node/virtual/resolved-generated-setup-code.js +5 -0
- package/dist/node/virtual/resolved-markdown-files.d.ts +2 -0
- package/dist/node/virtual/resolved-markdown-files.js +17 -0
- package/dist/node/virtual/resolved-stories.d.ts +2 -0
- package/dist/node/virtual/resolved-stories.js +41 -0
- package/dist/node/virtual/resolved-support-plugins-client.d.ts +2 -0
- package/dist/node/virtual/resolved-support-plugins-client.js +11 -0
- package/dist/node/virtual/resolved-support-plugins-collect.d.ts +2 -0
- package/dist/node/virtual/resolved-support-plugins-collect.js +11 -0
- package/dist/node/virtual/resolved-theme.d.ts +2 -0
- package/dist/node/virtual/resolved-theme.js +12 -0
- package/dist/node/virtual/story-source.d.ts +2 -0
- package/dist/node/virtual/story-source.js +16 -0
- package/dist/node/virtual/story.d.ts +2 -0
- package/dist/node/virtual/story.js +7 -0
- package/dist/node/virtual/util.d.ts +2 -0
- package/dist/node/virtual/util.js +4 -0
- package/dist/node/virtual/vite-plugin.d.ts +3 -0
- package/dist/node/virtual/vite-plugin.js +118 -0
- package/dist/node/vite.d.ts +0 -22
- package/dist/node/vite.js +27 -281
- package/package.json +9 -9
- package/src/node/build.ts +19 -11
- package/src/node/builtin-plugins/pinceau-tokens.ts +521 -0
- package/src/node/collect/index.ts +1 -0
- package/src/node/index.ts +8 -0
- package/src/node/server.ts +7 -6
- package/src/node/util/vendors.ts +9 -2
- package/src/node/virtual/index.ts +47 -0
- package/src/node/virtual/markdown.ts +21 -0
- package/src/node/virtual/noop.ts +1 -0
- package/src/node/virtual/resolved-config.ts +12 -0
- package/src/node/virtual/resolved-generated-global-setup.ts +24 -0
- package/src/node/virtual/resolved-generated-setup-code.ts +7 -0
- package/src/node/virtual/resolved-markdown-files.ts +19 -0
- package/src/node/virtual/resolved-stories.ts +43 -0
- package/src/node/virtual/resolved-support-plugins-client.ts +14 -0
- package/src/node/virtual/resolved-support-plugins-collect.ts +14 -0
- package/src/node/virtual/resolved-theme.ts +14 -0
- package/src/node/virtual/story-source.ts +17 -0
- package/src/node/virtual/story.ts +9 -0
- package/src/node/virtual/util.ts +5 -0
- package/src/node/virtual/vite-plugin.ts +135 -0
- package/src/node/vite.ts +28 -294
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import type { Plugin, PluginApiBase } from '@histoire/shared'
|
|
2
|
+
import { getInjectedImport } from '../util/vendors.js'
|
|
3
|
+
import { findUp } from '../util/find-up.js'
|
|
4
|
+
import { join } from 'pathe'
|
|
5
|
+
|
|
6
|
+
export interface PinceauTokensOptions {
|
|
7
|
+
configOrPaths?: string | string[]
|
|
8
|
+
configFileName?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function pinceauTokens (options: PinceauTokensOptions = {}): Plugin {
|
|
12
|
+
const themePath = join(process.cwd(), 'node_modules/.vite/pinceau/index.js')
|
|
13
|
+
|
|
14
|
+
async function generate (api: PluginApiBase) {
|
|
15
|
+
try {
|
|
16
|
+
await api.fs.ensureDir(api.pluginTempDir)
|
|
17
|
+
await api.fs.emptyDir(api.pluginTempDir)
|
|
18
|
+
api.moduleLoader.clearCache()
|
|
19
|
+
await api.fs.writeFile(api.path.resolve(api.pluginTempDir, 'style.css'), css)
|
|
20
|
+
const theme = await api.moduleLoader.loadModule(themePath)
|
|
21
|
+
const storyFile = api.path.resolve(api.pluginTempDir, 'Pinceau.story.js')
|
|
22
|
+
await api.fs.writeFile(storyFile, storyTemplate(theme))
|
|
23
|
+
api.addStoryFile(storyFile)
|
|
24
|
+
} catch (e) {
|
|
25
|
+
api.error(e.stack ?? e.message)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
name: 'builtin:pinceau-tokens',
|
|
31
|
+
|
|
32
|
+
config (config) {
|
|
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
|
+
const watcher = api.watcher.watch(themePath)
|
|
57
|
+
.on('change', () => generate(api))
|
|
58
|
+
.on('add', () => generate(api))
|
|
59
|
+
|
|
60
|
+
onCleanup(() => {
|
|
61
|
+
watcher.close()
|
|
62
|
+
})
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
async onBuild (api) {
|
|
66
|
+
await generate(api)
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const storyTemplate = (pinceauConfig: any) => {
|
|
72
|
+
pinceauConfig = pinceauConfig?.theme || pinceauConfig?.default?.theme || {}
|
|
73
|
+
|
|
74
|
+
return `import 'histoire-style'
|
|
75
|
+
import './style.css'
|
|
76
|
+
import { createApp, h, markRaw, ref } from ${getInjectedImport('@histoire/vendors/vue')}
|
|
77
|
+
import {
|
|
78
|
+
HstColorShades,
|
|
79
|
+
HstTokenList,
|
|
80
|
+
HstTokenGrid,
|
|
81
|
+
HstText,
|
|
82
|
+
HstTextarea,
|
|
83
|
+
HstNumber,
|
|
84
|
+
} from ${getInjectedImport('@histoire/controls')}
|
|
85
|
+
|
|
86
|
+
const config = markRaw(${JSON.stringify(pinceauConfig, null, 2)})
|
|
87
|
+
const search = ref('')
|
|
88
|
+
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')
|
|
89
|
+
const fontSize = ref(16)
|
|
90
|
+
const flattenTokens = (data, transformValue = (value) => (value?.value || value)) => {
|
|
91
|
+
const output = {}
|
|
92
|
+
function step(obj, prev) {
|
|
93
|
+
Object.keys(obj).forEach((key) => {
|
|
94
|
+
const value = obj[key]
|
|
95
|
+
const isarray = Array.isArray(value)
|
|
96
|
+
const type = Object.prototype.toString.call(value)
|
|
97
|
+
const isobject
|
|
98
|
+
= type === '[object Object]'
|
|
99
|
+
|| type === '[object Array]'
|
|
100
|
+
|
|
101
|
+
const newKey = prev ? prev + '.' + key : key
|
|
102
|
+
|
|
103
|
+
if (value.value && !output[newKey]) {
|
|
104
|
+
output[newKey] = transformValue(value)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!isarray && isobject && Object.keys(value).length) { return step(value, newKey) }
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
step(data)
|
|
111
|
+
return output
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function mountApp ({ el, state, onUnmount }, render) {
|
|
115
|
+
Object.assign(state, {
|
|
116
|
+
search,
|
|
117
|
+
sampleText,
|
|
118
|
+
fontSize,
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
const app = createApp({
|
|
122
|
+
render,
|
|
123
|
+
})
|
|
124
|
+
app.mount(el)
|
|
125
|
+
|
|
126
|
+
onUnmount(() => {
|
|
127
|
+
app.unmount()
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
media?: PinceauTokens
|
|
133
|
+
colors?: ScaleTokens
|
|
134
|
+
fonts?: PinceauTokens
|
|
135
|
+
fontWeights?: FontWeightTokens
|
|
136
|
+
fontSizes?: BreakpointsTokens
|
|
137
|
+
size?: BreakpointsTokens
|
|
138
|
+
space?: BreakpointsTokens
|
|
139
|
+
radii?: BreakpointsTokens
|
|
140
|
+
borders?: BreakpointsTokens
|
|
141
|
+
borderWidths?: BreakpointsTokens
|
|
142
|
+
borderStyles?: BreakpointsTokens
|
|
143
|
+
shadows?: BreakpointsTokens
|
|
144
|
+
opacity?: BreakpointsTokens
|
|
145
|
+
leads?: BreakpointsTokens
|
|
146
|
+
letterSpacings?: BreakpointsTokens
|
|
147
|
+
transitions?: PinceauTokens
|
|
148
|
+
zIndices?: PinceauTokens
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
export default {
|
|
152
|
+
id: 'pinceau',
|
|
153
|
+
title: 'Pinceau',
|
|
154
|
+
group: 'design-system',
|
|
155
|
+
icon: 'noto:paintbrush',
|
|
156
|
+
responsiveDisabled: true,
|
|
157
|
+
layout: { type: 'single', iframe: false },
|
|
158
|
+
variants: [
|
|
159
|
+
{
|
|
160
|
+
id: 'media-queries',
|
|
161
|
+
title: 'Media Queries',
|
|
162
|
+
icon: 'carbon:screen',
|
|
163
|
+
onMount: (api) => mountApp(api, () => h(HstTokenGrid, {
|
|
164
|
+
tokens: flattenTokens(config.media),
|
|
165
|
+
getName: key => '@mq.' + key,
|
|
166
|
+
colSize: 180,
|
|
167
|
+
}, ({ token }) => h('div', {
|
|
168
|
+
class: '__hst-drop-shadow',
|
|
169
|
+
}))),
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
id: 'colors',
|
|
173
|
+
title: 'Colors',
|
|
174
|
+
icon: 'carbon:color-palette',
|
|
175
|
+
onMount: (api) => mountApp(api, () => Object.entries(config.colors).map(([key, shades]) => h(HstColorShades, {
|
|
176
|
+
key,
|
|
177
|
+
shades: shades.value ? { DEFAULT: shades.value } : flattenTokens(shades),
|
|
178
|
+
getName: shade => '{colors.' + key + '.' + shade + '}',
|
|
179
|
+
search: search.value,
|
|
180
|
+
}, ({ color}) => h('div', {
|
|
181
|
+
class: '__hst-shade',
|
|
182
|
+
style: {
|
|
183
|
+
backgroundColor: color,
|
|
184
|
+
},
|
|
185
|
+
})))),
|
|
186
|
+
onMountControls: (api) => mountApp(api, () => [
|
|
187
|
+
h(HstText, {
|
|
188
|
+
title: 'Filter...',
|
|
189
|
+
modelValue: search.value,
|
|
190
|
+
'onUpdate:modelValue': value => { search.value = value },
|
|
191
|
+
}),
|
|
192
|
+
]),
|
|
193
|
+
},
|
|
194
|
+
// SPACES
|
|
195
|
+
{
|
|
196
|
+
id: 'Spaces',
|
|
197
|
+
title: 'Spaces',
|
|
198
|
+
icon: 'carbon:area',
|
|
199
|
+
onMount: (api) => mountApp(api, () => h(HstTokenList, {
|
|
200
|
+
tokens: flattenTokens(config.space),
|
|
201
|
+
getName: key => '{space.' + key + '}',
|
|
202
|
+
}, ({ token }) => h('div', {
|
|
203
|
+
class: '__hst-spaces',
|
|
204
|
+
style: {
|
|
205
|
+
padding: token.value,
|
|
206
|
+
},
|
|
207
|
+
}, [
|
|
208
|
+
h('div', {
|
|
209
|
+
class: '__hst-spaces-box',
|
|
210
|
+
}),
|
|
211
|
+
]))),
|
|
212
|
+
},
|
|
213
|
+
// SIZES
|
|
214
|
+
{
|
|
215
|
+
id: 'sizes',
|
|
216
|
+
title: 'Sizes',
|
|
217
|
+
icon: 'carbon:pan-horizontal',
|
|
218
|
+
onMount: (api) => mountApp(api, () => h(HstTokenList, {
|
|
219
|
+
tokens: flattenTokens(config.size),
|
|
220
|
+
getName: key => '{size.' + key + '}',
|
|
221
|
+
}, ({ token }) => h('div', {
|
|
222
|
+
class: '__hst-width',
|
|
223
|
+
}, [
|
|
224
|
+
h('div', {
|
|
225
|
+
class: '__hst-width-box',
|
|
226
|
+
style: {
|
|
227
|
+
width: token.value,
|
|
228
|
+
},
|
|
229
|
+
}),
|
|
230
|
+
]))),
|
|
231
|
+
},
|
|
232
|
+
// FONTSIZES
|
|
233
|
+
{
|
|
234
|
+
id: 'font-size',
|
|
235
|
+
title: 'Font Size',
|
|
236
|
+
icon: 'carbon:text-font',
|
|
237
|
+
onMount: (api) => mountApp(api, () => h(HstTokenList, {
|
|
238
|
+
tokens: flattenTokens(config.fontSizes),
|
|
239
|
+
getName: key => '{fontSizes.' + key + '}',
|
|
240
|
+
}, ({ token }) => h('div', {
|
|
241
|
+
class: '__hst-truncate',
|
|
242
|
+
style: {
|
|
243
|
+
fontSize: token.value,
|
|
244
|
+
},
|
|
245
|
+
}, sampleText.value))),
|
|
246
|
+
onMountControls: (api) => mountApp(api, () => [
|
|
247
|
+
h(HstTextarea, {
|
|
248
|
+
title: 'Sample text',
|
|
249
|
+
modelValue: sampleText.value,
|
|
250
|
+
'onUpdate:modelValue': value => { sampleText.value = value },
|
|
251
|
+
rows: 5,
|
|
252
|
+
}),
|
|
253
|
+
]),
|
|
254
|
+
},
|
|
255
|
+
// FONTWEIGHTS
|
|
256
|
+
{
|
|
257
|
+
id: 'font-weight',
|
|
258
|
+
title: 'Font Weight',
|
|
259
|
+
icon: 'carbon:text-font',
|
|
260
|
+
onMount: (api) => mountApp(api, () => h(HstTokenList, {
|
|
261
|
+
tokens: flattenTokens(config.fontWeights),
|
|
262
|
+
getName: key => '{fontWeights.' + key + '}',
|
|
263
|
+
}, ({ token }) => h('div', {
|
|
264
|
+
class: '__hst-truncate',
|
|
265
|
+
style: {
|
|
266
|
+
fontWeight: token.value,
|
|
267
|
+
fontSize: \`\${fontSize.value}px\`,
|
|
268
|
+
},
|
|
269
|
+
}, sampleText.value))),
|
|
270
|
+
onMountControls: (api) => mountApp(api, () => [
|
|
271
|
+
h(HstTextarea, {
|
|
272
|
+
title: 'Sample text',
|
|
273
|
+
modelValue: sampleText.value,
|
|
274
|
+
'onUpdate:modelValue': value => { sampleText.value = value },
|
|
275
|
+
rows: 5,
|
|
276
|
+
}),
|
|
277
|
+
h(HstNumber, {
|
|
278
|
+
title: 'Font size',
|
|
279
|
+
modelValue: fontSize.value,
|
|
280
|
+
'onUpdate:modelValue': value => { fontSize.value = value },
|
|
281
|
+
min: 1,
|
|
282
|
+
}),
|
|
283
|
+
]),
|
|
284
|
+
},
|
|
285
|
+
// FONTS
|
|
286
|
+
{
|
|
287
|
+
id: 'fonts',
|
|
288
|
+
title: 'Fonts',
|
|
289
|
+
icon: 'carbon:text-font',
|
|
290
|
+
onMount: (api) => mountApp(api, () => h(HstTokenList, {
|
|
291
|
+
tokens: flattenTokens(config.fonts),
|
|
292
|
+
getName: key => '{fonts.' + key + '}',
|
|
293
|
+
}, ({ token }) => h('div', {
|
|
294
|
+
class: '__hst-truncate',
|
|
295
|
+
style: {
|
|
296
|
+
fontFamily: token.value,
|
|
297
|
+
fontSize: \`\${fontSize.value}px\`,
|
|
298
|
+
},
|
|
299
|
+
}, sampleText.value))),
|
|
300
|
+
onMountControls: (api) => mountApp(api, () => [
|
|
301
|
+
h(HstTextarea, {
|
|
302
|
+
title: 'Sample text',
|
|
303
|
+
modelValue: sampleText.value,
|
|
304
|
+
'onUpdate:modelValue': value => { sampleText.value = value },
|
|
305
|
+
rows: 5,
|
|
306
|
+
}),
|
|
307
|
+
h(HstNumber, {
|
|
308
|
+
title: 'Font size',
|
|
309
|
+
modelValue: fontSize.value,
|
|
310
|
+
'onUpdate:modelValue': value => { fontSize.value = value },
|
|
311
|
+
min: 1,
|
|
312
|
+
}),
|
|
313
|
+
]),
|
|
314
|
+
},
|
|
315
|
+
// LETTERSPACINGS
|
|
316
|
+
{
|
|
317
|
+
id: 'letter-spacing',
|
|
318
|
+
title: 'Letter Spacing',
|
|
319
|
+
icon: 'carbon:text-font',
|
|
320
|
+
onMount: (api) => mountApp(api, () => h(HstTokenList, {
|
|
321
|
+
tokens: flattenTokens(config.letterSpacings),
|
|
322
|
+
getName: key => '{letterSpacings.' + key + '}',
|
|
323
|
+
}, ({ token }) => h('div', {
|
|
324
|
+
class: '__hst-truncate',
|
|
325
|
+
style: {
|
|
326
|
+
letterSpacing: token.value,
|
|
327
|
+
fontSize: \`\${fontSize.value}px\`,
|
|
328
|
+
},
|
|
329
|
+
}, sampleText.value))),
|
|
330
|
+
onMountControls: (api) => mountApp(api, () => [
|
|
331
|
+
h(HstTextarea, {
|
|
332
|
+
title: 'Sample text',
|
|
333
|
+
modelValue: sampleText.value,
|
|
334
|
+
'onUpdate:modelValue': value => { sampleText.value = value },
|
|
335
|
+
rows: 5,
|
|
336
|
+
}),
|
|
337
|
+
h(HstNumber, {
|
|
338
|
+
title: 'Font size',
|
|
339
|
+
modelValue: fontSize.value,
|
|
340
|
+
'onUpdate:modelValue': value => { fontSize.value = value },
|
|
341
|
+
min: 1,
|
|
342
|
+
}),
|
|
343
|
+
]),
|
|
344
|
+
},
|
|
345
|
+
// LEADS
|
|
346
|
+
{
|
|
347
|
+
id: 'leads',
|
|
348
|
+
title: 'Leads',
|
|
349
|
+
icon: 'carbon:text-font',
|
|
350
|
+
onMount: (api) => mountApp(api, () => h(HstTokenList, {
|
|
351
|
+
tokens: flattenTokens(config.leads),
|
|
352
|
+
getName: key => '{leads.' + key + '}',
|
|
353
|
+
}, ({ token }) => h('div', {
|
|
354
|
+
style: {
|
|
355
|
+
lineHeight: token.value,
|
|
356
|
+
},
|
|
357
|
+
}, sampleText.value))),
|
|
358
|
+
onMountControls: (api) => mountApp(api, () => [
|
|
359
|
+
h(HstTextarea, {
|
|
360
|
+
title: 'Sample text',
|
|
361
|
+
modelValue: sampleText.value,
|
|
362
|
+
'onUpdate:modelValue': value => { sampleText.value = value },
|
|
363
|
+
rows: 5,
|
|
364
|
+
}),
|
|
365
|
+
// @TODO select font size
|
|
366
|
+
]),
|
|
367
|
+
},
|
|
368
|
+
// SHADOWS
|
|
369
|
+
{
|
|
370
|
+
id: 'shadows',
|
|
371
|
+
title: 'Shadows',
|
|
372
|
+
icon: 'carbon:shape-except',
|
|
373
|
+
onMount: (api) => mountApp(api, () => h(HstTokenGrid, {
|
|
374
|
+
tokens: flattenTokens(config.shadows),
|
|
375
|
+
getName: key => '{shadows.' + key + '}',
|
|
376
|
+
colSize: 180,
|
|
377
|
+
}, ({ token }) => h('div', {
|
|
378
|
+
class: '__hst-drop-shadow',
|
|
379
|
+
style: 'box-shadow:' + token.value,
|
|
380
|
+
}))),
|
|
381
|
+
},
|
|
382
|
+
// OPACITIES
|
|
383
|
+
{
|
|
384
|
+
id: 'opacities',
|
|
385
|
+
title: 'Opacities',
|
|
386
|
+
icon: 'carbon:bring-forward',
|
|
387
|
+
onMount: (api) => mountApp(api, () => h(HstTokenGrid, {
|
|
388
|
+
tokens: flattenTokens(config.opacity),
|
|
389
|
+
getName: key => '{opacity.' + key + '}',
|
|
390
|
+
colSize: 180,
|
|
391
|
+
}, ({ token }) => h('div', {
|
|
392
|
+
class: '__hst-drop-shadow',
|
|
393
|
+
style: 'opacity:' + token.value,
|
|
394
|
+
}))),
|
|
395
|
+
},
|
|
396
|
+
// RADII
|
|
397
|
+
{
|
|
398
|
+
id: 'border-radius',
|
|
399
|
+
title: 'Border Radius',
|
|
400
|
+
icon: 'carbon:condition-wait-point',
|
|
401
|
+
onMount: (api) => mountApp(api, () => h(HstTokenGrid, {
|
|
402
|
+
tokens: flattenTokens(config.radii),
|
|
403
|
+
getName: key => '{radii.' + key + '}',
|
|
404
|
+
colSize: 180,
|
|
405
|
+
}, ({ token }) => h('div', {
|
|
406
|
+
class: '__hst-border-radius',
|
|
407
|
+
style: {
|
|
408
|
+
borderRadius: token.value,
|
|
409
|
+
},
|
|
410
|
+
}))),
|
|
411
|
+
},
|
|
412
|
+
// BORDERWIDTHS
|
|
413
|
+
{
|
|
414
|
+
id: 'border-width',
|
|
415
|
+
title: 'Border Width',
|
|
416
|
+
icon: 'carbon:checkbox',
|
|
417
|
+
onMount: (api) => mountApp(api, () => h(HstTokenGrid, {
|
|
418
|
+
tokens: flattenTokens(config.borderWidths),
|
|
419
|
+
getName: key => '{borderWidths.' + key + '}',
|
|
420
|
+
colSize: 180,
|
|
421
|
+
}, ({ token }) => h('div', {
|
|
422
|
+
class: '__hst-border-width',
|
|
423
|
+
style: {
|
|
424
|
+
borderWidth: token.value,
|
|
425
|
+
},
|
|
426
|
+
}))),
|
|
427
|
+
},
|
|
428
|
+
// FULL CONFIG
|
|
429
|
+
{
|
|
430
|
+
id: 'full-config',
|
|
431
|
+
title: 'Full Config',
|
|
432
|
+
icon: 'carbon:code',
|
|
433
|
+
onMount: (api) => mountApp(api, () => h('pre', JSON.stringify(config, null, 2))),
|
|
434
|
+
},
|
|
435
|
+
],
|
|
436
|
+
}`
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const css = `.__hst-shade {
|
|
440
|
+
height: 80px;
|
|
441
|
+
border-radius: 4px;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
.__hst-text {
|
|
445
|
+
font-size: 4rem;
|
|
446
|
+
display: flex;
|
|
447
|
+
align-items: flex-end;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.__hst-border {
|
|
451
|
+
border-style: solid;
|
|
452
|
+
border-width: 2px;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
.__hst-spaces {
|
|
456
|
+
background-color: rgb(113 113 122 / 0.1);
|
|
457
|
+
width: min-content;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
.__hst-margin {
|
|
461
|
+
border: dashed 1px rgb(113 113 122 / 0.5);
|
|
462
|
+
width: min-content;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.__hst-spaces-box,
|
|
466
|
+
.__hst-margin-box {
|
|
467
|
+
width: 5rem;
|
|
468
|
+
height: 5rem;
|
|
469
|
+
background-color: rgb(113 113 122 / 0.5);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
.__hst-spaces,
|
|
473
|
+
.__hst-spaces-box,
|
|
474
|
+
.__hst-margin,
|
|
475
|
+
.__hst-margin-box,
|
|
476
|
+
.__hst-drop-shadow {
|
|
477
|
+
border-radius: 4px;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
.__hst-truncate {
|
|
481
|
+
overflow: hidden;
|
|
482
|
+
text-overflow: ellipsis;
|
|
483
|
+
white-space: nowrap;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
.__hst-drop-shadow {
|
|
487
|
+
width: 8rem;
|
|
488
|
+
height: 8rem;
|
|
489
|
+
background: white;
|
|
490
|
+
margin-bottom: 0.5rem;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
.__hst-drop-shadow {
|
|
494
|
+
background: #4e4e57;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
.__hst-border-radius {
|
|
498
|
+
width: 8rem;
|
|
499
|
+
height: 8rem;
|
|
500
|
+
background-color: rgb(113 113 122 / 0.5);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
.__hst-border-width {
|
|
504
|
+
width: 8rem;
|
|
505
|
+
height: 8rem;
|
|
506
|
+
border-color: rgb(113 113 122 / 0.5);
|
|
507
|
+
background-color: rgb(113 113 122 / 0.1);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
.__hst-width {
|
|
511
|
+
background-color: rgb(113 113 122 / 0.1);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
.__hst-width-box,
|
|
515
|
+
.__hst-height {
|
|
516
|
+
background-color: rgb(113 113 122 / 0.5);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.__hst-width-box {
|
|
520
|
+
height: 5rem;
|
|
521
|
+
}`
|
package/src/node/index.ts
CHANGED
package/src/node/server.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { createServer as createViteServer } from 'vite'
|
|
|
3
3
|
import pc from 'picocolors'
|
|
4
4
|
import type { ServerStoryFile } from '@histoire/shared'
|
|
5
5
|
import { Context } from './context.js'
|
|
6
|
-
import { getViteConfigWithPlugins
|
|
6
|
+
import { getViteConfigWithPlugins } from './vite.js'
|
|
7
|
+
import * as VirtualFiles from './virtual/index.js'
|
|
7
8
|
import { onStoryChange, onStoryListChange, watchStories } from './stories.js'
|
|
8
9
|
import { useCollectStories } from './collect/index.js'
|
|
9
10
|
import { DevPluginApi } from './plugin.js'
|
|
@@ -170,8 +171,8 @@ export async function createServer (ctx: Context, options: CreateServerOptions =
|
|
|
170
171
|
|
|
171
172
|
clearInvalidates()
|
|
172
173
|
|
|
173
|
-
invalidateModule(RESOLVED_STORIES_ID)
|
|
174
|
-
invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID)
|
|
174
|
+
invalidateModule(VirtualFiles.RESOLVED_STORIES_ID)
|
|
175
|
+
invalidateModule(VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID)
|
|
175
176
|
|
|
176
177
|
collecting = false
|
|
177
178
|
|
|
@@ -181,12 +182,12 @@ export async function createServer (ctx: Context, options: CreateServerOptions =
|
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
onStoryListChange(() => {
|
|
184
|
-
invalidateModule(RESOLVED_STORIES_ID)
|
|
185
|
-
invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID)
|
|
185
|
+
invalidateModule(VirtualFiles.RESOLVED_STORIES_ID)
|
|
186
|
+
invalidateModule(VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID)
|
|
186
187
|
})
|
|
187
188
|
|
|
188
189
|
onMarkdownListChange(() => {
|
|
189
|
-
invalidateModule(RESOLVED_MARKDOWN_FILES)
|
|
190
|
+
invalidateModule(VirtualFiles.RESOLVED_MARKDOWN_FILES)
|
|
190
191
|
})
|
|
191
192
|
|
|
192
193
|
async function close () {
|
package/src/node/util/vendors.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
|
|
4
|
+
// Resolve an absolute path to e.g. node_modules/.pnpm/histoire@0.11.7_vite@3.2.4/node_modules/histoire/dist/node/vendors/controls.js
|
|
5
|
+
// https://github.com/histoire-dev/histoire/issues/282
|
|
6
|
+
export const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
|
|
1
8
|
// https://github.com/vitejs/vite/issues/9661
|
|
2
9
|
const alias = {
|
|
3
|
-
'@histoire/vendors/vue': '
|
|
4
|
-
'@histoire/controls': '
|
|
10
|
+
'@histoire/vendors/vue': path.resolve(__dirname, '../vendors/vue.js'),
|
|
11
|
+
'@histoire/controls': path.resolve(__dirname, '../vendors/controls.js'),
|
|
5
12
|
}
|
|
6
13
|
|
|
7
14
|
export function getInjectedImport (request: string) {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// @TODO wait for virtual modules HMR to work in vite to use `virtual:` and `\0` prefix
|
|
2
|
+
// https://github.com/vitejs/vite/pull/10313
|
|
3
|
+
export const STORIES_ID = 'virtual:$histoire-stories'
|
|
4
|
+
export const RESOLVED_STORIES_ID = `/__resolved__${STORIES_ID}`
|
|
5
|
+
// export const RESOLVED_STORIES_ID = `\0${STORIES_ID}`
|
|
6
|
+
export const SETUP_ID = 'virtual:$histoire-setup'
|
|
7
|
+
export const NOOP_ID = 'virtual:$histoire-noop'
|
|
8
|
+
export const CONFIG_ID = 'virtual:$histoire-config'
|
|
9
|
+
export const RESOLVED_CONFIG_ID = `/__resolved__${CONFIG_ID}`
|
|
10
|
+
// export const RESOLVED_CONFIG_ID = `\0${CONFIG_ID}`
|
|
11
|
+
export const THEME_ID = 'virtual:$histoire-theme'
|
|
12
|
+
export const RESOLVED_THEME_ID = `/__resolved__${THEME_ID}.css`
|
|
13
|
+
// export const RESOLVED_THEME_ID = `\0${THEME_ID}.css`
|
|
14
|
+
export const SEARCH_TITLE_DATA_ID = 'virtual:$histoire-search-title-data'
|
|
15
|
+
export const RESOLVED_SEARCH_TITLE_DATA_ID = `/__resolved__${SEARCH_TITLE_DATA_ID}`
|
|
16
|
+
// export const RESOLVED_SEARCH_TITLE_DATA_ID = `\0${SEARCH_TITLE_DATA_ID}`
|
|
17
|
+
export const SEARCH_DOCS_DATA_ID = 'virtual:$histoire-search-docs-data'
|
|
18
|
+
export const RESOLVED_SEARCH_DOCS_DATA_ID = `/__resolved__${SEARCH_DOCS_DATA_ID}`
|
|
19
|
+
// export const RESOLVED_SEARCH_DOCS_DATA_ID = `\0${SEARCH_DOCS_DATA_ID}`
|
|
20
|
+
export const GENERATED_GLOBAL_SETUP = 'virtual:$histoire-generated-global-setup'
|
|
21
|
+
export const RESOLVED_GENERATED_GLOBAL_SETUP = `/__resolved__${GENERATED_GLOBAL_SETUP}`
|
|
22
|
+
// export const RESOLVED_GENERATED_GLOBAL_SETUP = `\0${GENERATED_GLOBAL_SETUP}`
|
|
23
|
+
export const GENERATED_SETUP_CODE = 'virtual:$histoire-generated-setup-code'
|
|
24
|
+
export const RESOLVED_GENERATED_SETUP_CODE = `/__resolved__${GENERATED_SETUP_CODE}`
|
|
25
|
+
// export const RESOLVED_GENERATED_SETUP_CODE = `\0${GENERATED_SETUP_CODE}`
|
|
26
|
+
export const SUPPORT_PLUGINS_CLIENT = 'virtual:$histoire-support-plugins-client'
|
|
27
|
+
export const RESOLVED_SUPPORT_PLUGINS_CLIENT = `/__resolved__${SUPPORT_PLUGINS_CLIENT}`
|
|
28
|
+
// export const RESOLVED_SUPPORT_PLUGINS_CLIENT = `\0${SUPPORT_PLUGINS_CLIENT}`
|
|
29
|
+
export const SUPPORT_PLUGINS_COLLECT = 'virtual:$histoire-support-plugins-collect'
|
|
30
|
+
export const RESOLVED_SUPPORT_PLUGINS_COLLECT = `/__resolved__${SUPPORT_PLUGINS_COLLECT}`
|
|
31
|
+
// export const RESOLVED_SUPPORT_PLUGINS_COLLECT = `\0${SUPPORT_PLUGINS_COLLECT}`
|
|
32
|
+
export const MARKDOWN_FILES = 'virtual:$histoire-markdown-files'
|
|
33
|
+
export const RESOLVED_MARKDOWN_FILES = `/__resolved__${MARKDOWN_FILES}`
|
|
34
|
+
// export const RESOLVED_MARKDOWN_FILES = `\0${MARKDOWN_FILES}`
|
|
35
|
+
|
|
36
|
+
export * from './markdown.js'
|
|
37
|
+
export * from './noop.js'
|
|
38
|
+
export * from './resolved-config.js'
|
|
39
|
+
export * from './resolved-generated-global-setup.js'
|
|
40
|
+
export * from './resolved-generated-setup-code.js'
|
|
41
|
+
export * from './resolved-markdown-files.js'
|
|
42
|
+
export * from './resolved-stories.js'
|
|
43
|
+
export * from './resolved-support-plugins-client.js'
|
|
44
|
+
export * from './resolved-support-plugins-collect.js'
|
|
45
|
+
export * from './resolved-theme.js'
|
|
46
|
+
export * from './story.js'
|
|
47
|
+
export * from './story-source.js'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
|
|
3
|
+
export const markdown = (ctx: Context, id: string) => {
|
|
4
|
+
const fileId = id.slice('/__resolved__virtual:md:'.length)
|
|
5
|
+
const file = ctx.markdownFiles.find(f => f.id === fileId)
|
|
6
|
+
if (!file) {
|
|
7
|
+
throw new Error(`Markdown file not found: ${fileId}`)
|
|
8
|
+
}
|
|
9
|
+
const { html, frontmatter, relativePath } = file
|
|
10
|
+
return `export const html = ${JSON.stringify(html)}
|
|
11
|
+
export const frontmatter = ${JSON.stringify(frontmatter)}
|
|
12
|
+
export const relativePath = ${JSON.stringify(relativePath)}
|
|
13
|
+
|
|
14
|
+
if (import.meta.hot) {
|
|
15
|
+
import.meta.hot.accept(newModule => {
|
|
16
|
+
if (newModule) {
|
|
17
|
+
window.__hst_md_hmr(newModule)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
}`
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const noop = () => `export default () => {}`
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
|
|
3
|
+
export const resolvedConfig = (ctx: Context) => {
|
|
4
|
+
let js = `export const config = ${JSON.stringify(ctx.config)}\n`
|
|
5
|
+
if (ctx.config.theme?.logo) {
|
|
6
|
+
for (const key in ctx.config.theme.logo) {
|
|
7
|
+
js += `import Logo_${key} from '${ctx.config.theme.logo[key]}'\n`
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
js += `export const logos = {${Object.keys(ctx.config.theme?.logo ?? {}).map(key => `${key}: Logo_${key}`).join(', ')}}\n`
|
|
11
|
+
return js
|
|
12
|
+
}
|