poveste 0.6.0 → 0.7.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.
- package/dist/controls.d.ts +0 -1
- package/dist/node/alias.d.ts +0 -1
- package/dist/node/bin.d.ts +0 -1
- package/dist/node/build-serialize.d.ts +0 -1
- package/dist/node/build.d.ts +0 -1
- package/dist/node/builtin-plugins/pinceau-tokens.d.ts +0 -1
- package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts +0 -1
- package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts +0 -1
- package/dist/node/builtin-plugins/vanilla-support/client.d.ts +0 -1
- package/dist/node/builtin-plugins/vanilla-support/collect.d.ts +0 -1
- package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts +0 -1
- package/dist/node/builtin-plugins/vanilla-support/types.d.ts +0 -1
- package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts +0 -1
- package/dist/node/collect/index.d.ts +0 -1
- package/dist/node/collect/run.d.ts +0 -1
- package/dist/node/collect/worker.d.ts +0 -1
- package/dist/node/colors.d.ts +0 -1
- package/dist/node/commands/build.d.ts +0 -1
- package/dist/node/commands/dev.d.ts +0 -1
- package/dist/node/commands/port.d.ts +0 -1
- package/dist/node/commands/preview.d.ts +0 -1
- package/dist/node/config.d.ts +0 -1
- package/dist/node/context.d.ts +0 -1
- package/dist/node/dom/dom-keys.d.ts +0 -1
- package/dist/node/dom/env.d.ts +0 -1
- package/dist/node/dom/util.d.ts +0 -1
- package/dist/node/index.d.ts +0 -1
- package/dist/node/load.d.ts +0 -1
- package/dist/node/markdown.d.ts +0 -1
- package/dist/node/plugin.d.ts +0 -1
- package/dist/node/preview.d.ts +0 -1
- package/dist/node/search.d.ts +0 -1
- package/dist/node/server.d.ts +0 -1
- package/dist/node/stories.d.ts +0 -1
- package/dist/node/style-isolation/entry-css-merger.d.ts +0 -1
- package/dist/node/style-isolation/global-styles.d.ts +0 -1
- package/dist/node/style-isolation/index.d.ts +0 -1
- package/dist/node/style-isolation/scope-chrome.d.ts +0 -1
- package/dist/node/style-isolation/selectors.d.ts +0 -1
- package/dist/node/style-isolation/transforms.d.ts +0 -1
- package/dist/node/style-isolation/vite-plugin.d.ts +0 -1
- package/dist/node/tree.d.ts +0 -1
- package/dist/node/util/find-up.d.ts +0 -1
- package/dist/node/util/fs.d.ts +0 -1
- package/dist/node/util/head.d.ts +0 -1
- package/dist/node/util/log.d.ts +0 -1
- package/dist/node/util/slugify.d.ts +0 -1
- package/dist/node/util/vendors.d.ts +0 -1
- package/dist/node/util/watch-ignore.d.ts +0 -1
- package/dist/node/vendors/controls.d.ts +0 -1
- package/dist/node/vendors/vue.d.ts +0 -1
- package/dist/node/virtual/index.d.ts +0 -1
- package/dist/node/virtual/markdown.d.ts +0 -1
- package/dist/node/virtual/noop.d.ts +0 -1
- package/dist/node/virtual/resolved-commands.d.ts +0 -1
- package/dist/node/virtual/resolved-config.d.ts +0 -1
- package/dist/node/virtual/resolved-generated-global-setup.d.ts +0 -1
- package/dist/node/virtual/resolved-generated-setup-code.d.ts +0 -1
- package/dist/node/virtual/resolved-markdown-files.d.ts +0 -1
- package/dist/node/virtual/resolved-stories.d.ts +0 -1
- package/dist/node/virtual/resolved-support-plugins-client.d.ts +0 -1
- package/dist/node/virtual/resolved-support-plugins-collect.d.ts +0 -1
- package/dist/node/virtual/resolved-theme.d.ts +0 -1
- package/dist/node/virtual/story-source.d.ts +0 -1
- package/dist/node/virtual/story.d.ts +0 -1
- package/dist/node/virtual/util.d.ts +0 -1
- package/dist/node/virtual/vite-plugin.d.ts +0 -1
- package/dist/node/vite.d.ts +0 -1
- package/package.json +36 -6
- package/dist/controls.d.ts.map +0 -1
- package/dist/node/alias.d.ts.map +0 -1
- package/dist/node/bin.d.ts.map +0 -1
- package/dist/node/build-serialize.d.ts.map +0 -1
- package/dist/node/build.d.ts.map +0 -1
- package/dist/node/builtin-plugins/pinceau-tokens.d.ts.map +0 -1
- package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts.map +0 -1
- package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts.map +0 -1
- package/dist/node/builtin-plugins/vanilla-support/client.d.ts.map +0 -1
- package/dist/node/builtin-plugins/vanilla-support/collect.d.ts.map +0 -1
- package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts.map +0 -1
- package/dist/node/builtin-plugins/vanilla-support/types.d.ts.map +0 -1
- package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts.map +0 -1
- package/dist/node/collect/index.d.ts.map +0 -1
- package/dist/node/collect/run.d.ts.map +0 -1
- package/dist/node/collect/worker.d.ts.map +0 -1
- package/dist/node/colors.d.ts.map +0 -1
- package/dist/node/commands/build.d.ts.map +0 -1
- package/dist/node/commands/dev.d.ts.map +0 -1
- package/dist/node/commands/port.d.ts.map +0 -1
- package/dist/node/commands/preview.d.ts.map +0 -1
- package/dist/node/config.d.ts.map +0 -1
- package/dist/node/context.d.ts.map +0 -1
- package/dist/node/dom/dom-keys.d.ts.map +0 -1
- package/dist/node/dom/env.d.ts.map +0 -1
- package/dist/node/dom/util.d.ts.map +0 -1
- package/dist/node/index.d.ts.map +0 -1
- package/dist/node/load.d.ts.map +0 -1
- package/dist/node/markdown.d.ts.map +0 -1
- package/dist/node/plugin.d.ts.map +0 -1
- package/dist/node/preview.d.ts.map +0 -1
- package/dist/node/search.d.ts.map +0 -1
- package/dist/node/server.d.ts.map +0 -1
- package/dist/node/stories.d.ts.map +0 -1
- package/dist/node/style-isolation/entry-css-merger.d.ts.map +0 -1
- package/dist/node/style-isolation/global-styles.d.ts.map +0 -1
- package/dist/node/style-isolation/index.d.ts.map +0 -1
- package/dist/node/style-isolation/scope-chrome.d.ts.map +0 -1
- package/dist/node/style-isolation/selectors.d.ts.map +0 -1
- package/dist/node/style-isolation/transforms.d.ts.map +0 -1
- package/dist/node/style-isolation/vite-plugin.d.ts.map +0 -1
- package/dist/node/tree.d.ts.map +0 -1
- package/dist/node/util/find-up.d.ts.map +0 -1
- package/dist/node/util/fs.d.ts.map +0 -1
- package/dist/node/util/head.d.ts.map +0 -1
- package/dist/node/util/log.d.ts.map +0 -1
- package/dist/node/util/slugify.d.ts.map +0 -1
- package/dist/node/util/vendors.d.ts.map +0 -1
- package/dist/node/util/watch-ignore.d.ts.map +0 -1
- package/dist/node/vendors/controls.d.ts.map +0 -1
- package/dist/node/vendors/vue.d.ts.map +0 -1
- package/dist/node/virtual/index.d.ts.map +0 -1
- package/dist/node/virtual/markdown.d.ts.map +0 -1
- package/dist/node/virtual/noop.d.ts.map +0 -1
- package/dist/node/virtual/resolved-commands.d.ts.map +0 -1
- package/dist/node/virtual/resolved-config.d.ts.map +0 -1
- package/dist/node/virtual/resolved-generated-global-setup.d.ts.map +0 -1
- package/dist/node/virtual/resolved-generated-setup-code.d.ts.map +0 -1
- package/dist/node/virtual/resolved-markdown-files.d.ts.map +0 -1
- package/dist/node/virtual/resolved-stories.d.ts.map +0 -1
- package/dist/node/virtual/resolved-support-plugins-client.d.ts.map +0 -1
- package/dist/node/virtual/resolved-support-plugins-collect.d.ts.map +0 -1
- package/dist/node/virtual/resolved-theme.d.ts.map +0 -1
- package/dist/node/virtual/story-source.d.ts.map +0 -1
- package/dist/node/virtual/story.d.ts.map +0 -1
- package/dist/node/virtual/util.d.ts.map +0 -1
- package/dist/node/virtual/vite-plugin.d.ts.map +0 -1
- package/dist/node/vite.d.ts.map +0 -1
- package/src/controls.ts +0 -1
- package/src/node/__tests__/config.spec.ts +0 -25
- package/src/node/__tests__/dom-env.spec.ts +0 -97
- package/src/node/__tests__/head.spec.ts +0 -32
- package/src/node/__tests__/markdown/test1.story.md +0 -7
- package/src/node/__tests__/markdown/test2.story.md +0 -5
- package/src/node/__tests__/markdown.spec.ts +0 -61
- package/src/node/__tests__/port.spec.ts +0 -65
- package/src/node/__tests__/tree.spec.ts +0 -109
- package/src/node/__tests__/virtual-setup.spec.ts +0 -61
- package/src/node/__tests__/watch-ignore.spec.ts +0 -33
- package/src/node/alias.ts +0 -8
- package/src/node/bin.ts +0 -46
- package/src/node/build-serialize.ts +0 -62
- package/src/node/build.ts +0 -339
- package/src/node/builtin-plugins/pinceau-tokens.ts +0 -523
- package/src/node/builtin-plugins/vanilla-support/MountStory.ts +0 -49
- package/src/node/builtin-plugins/vanilla-support/RenderStory.ts +0 -167
- package/src/node/builtin-plugins/vanilla-support/client.ts +0 -6
- package/src/node/builtin-plugins/vanilla-support/collect.ts +0 -43
- package/src/node/builtin-plugins/vanilla-support/plugin.ts +0 -35
- package/src/node/builtin-plugins/vanilla-support/types.ts +0 -42
- package/src/node/builtin-plugins/vanilla-support/vanilla.story.ts +0 -63
- package/src/node/collect/index.ts +0 -164
- package/src/node/collect/run.ts +0 -9
- package/src/node/collect/worker.ts +0 -103
- package/src/node/colors.ts +0 -340
- package/src/node/commands/build.ts +0 -14
- package/src/node/commands/dev.ts +0 -70
- package/src/node/commands/port.ts +0 -41
- package/src/node/commands/preview.ts +0 -30
- package/src/node/config.ts +0 -396
- package/src/node/context.ts +0 -60
- package/src/node/dom/dom-keys.ts +0 -238
- package/src/node/dom/env.ts +0 -123
- package/src/node/dom/util.ts +0 -83
- package/src/node/index.ts +0 -7
- package/src/node/load.ts +0 -59
- package/src/node/markdown.ts +0 -280
- package/src/node/plugin.ts +0 -95
- package/src/node/preview.ts +0 -45
- package/src/node/search.ts +0 -84
- package/src/node/server.ts +0 -258
- package/src/node/stories.ts +0 -145
- package/src/node/style-isolation/__tests__/entry-css-merger.spec.ts +0 -145
- package/src/node/style-isolation/__tests__/transforms.spec.ts +0 -200
- package/src/node/style-isolation/__tests__/vite-plugin.spec.ts +0 -39
- package/src/node/style-isolation/entry-css-merger.ts +0 -134
- package/src/node/style-isolation/global-styles.ts +0 -37
- package/src/node/style-isolation/index.ts +0 -5
- package/src/node/style-isolation/scope-chrome.ts +0 -42
- package/src/node/style-isolation/selectors.ts +0 -19
- package/src/node/style-isolation/transforms.ts +0 -163
- package/src/node/style-isolation/vite-plugin.ts +0 -75
- package/src/node/tree.ts +0 -158
- package/src/node/util/find-up.ts +0 -24
- package/src/node/util/fs.ts +0 -1
- package/src/node/util/head.ts +0 -12
- package/src/node/util/log.ts +0 -10
- package/src/node/util/slugify.ts +0 -26
- package/src/node/util/vendors.ts +0 -27
- package/src/node/util/watch-ignore.ts +0 -13
- package/src/node/vendors/controls.ts +0 -1
- package/src/node/vendors/vue.ts +0 -1
- package/src/node/virtual/index.ts +0 -50
- package/src/node/virtual/markdown.ts +0 -21
- package/src/node/virtual/noop.ts +0 -9
- package/src/node/virtual/resolved-commands.ts +0 -42
- package/src/node/virtual/resolved-config.ts +0 -12
- package/src/node/virtual/resolved-generated-global-setup.ts +0 -33
- package/src/node/virtual/resolved-generated-setup-code.ts +0 -7
- package/src/node/virtual/resolved-markdown-files.ts +0 -19
- package/src/node/virtual/resolved-stories.ts +0 -44
- package/src/node/virtual/resolved-support-plugins-client.ts +0 -14
- package/src/node/virtual/resolved-support-plugins-collect.ts +0 -14
- package/src/node/virtual/resolved-theme.ts +0 -14
- package/src/node/virtual/story-source.ts +0 -18
- package/src/node/virtual/story.ts +0 -9
- package/src/node/virtual/util.ts +0 -41
- package/src/node/virtual/vite-plugin.ts +0 -146
- package/src/node/vite.ts +0 -438
- package/tsconfig.json +0 -44
- package/vitest.config.ts +0 -10
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import type { Story, Variant } from '@poveste/shared'
|
|
2
|
-
import type { PropType as _PropType } from '@poveste/vendors/vue'
|
|
3
|
-
import type { VanillaStorySetupHandler as _VanillaStorySetupHandler, App, MountApi, VanillaApi } from './types'
|
|
4
|
-
import { getSetupHook as _getSetupHook } from '@poveste/shared'
|
|
5
|
-
import {
|
|
6
|
-
defineComponent as _defineComponent,
|
|
7
|
-
h as _h,
|
|
8
|
-
onBeforeUnmount as _onBeforeUnmount,
|
|
9
|
-
onMounted as _onMounted,
|
|
10
|
-
ref as _ref,
|
|
11
|
-
watch as _watch,
|
|
12
|
-
} from '@poveste/vendors/vue'
|
|
13
|
-
// @ts-expect-error virtual module id
|
|
14
|
-
import * as generatedSetup from 'virtual:$poveste-generated-global-setup'
|
|
15
|
-
// @ts-expect-error virtual module id
|
|
16
|
-
import * as setup from 'virtual:$poveste-setup'
|
|
17
|
-
|
|
18
|
-
export default _defineComponent({
|
|
19
|
-
name: 'RenderStory',
|
|
20
|
-
|
|
21
|
-
props: {
|
|
22
|
-
variant: {
|
|
23
|
-
type: Object as _PropType<Variant>,
|
|
24
|
-
required: true,
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
story: {
|
|
28
|
-
type: Object as _PropType<Story>,
|
|
29
|
-
required: true,
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
slotName: {
|
|
33
|
-
type: String,
|
|
34
|
-
default: 'default',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
emits: {
|
|
39
|
-
ready: () => true,
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
setup(props, { emit }) {
|
|
43
|
-
const sandbox = _ref<HTMLDivElement>()
|
|
44
|
-
let mounting = false
|
|
45
|
-
let app: App
|
|
46
|
-
let appHooks: Record<'onUpdate' | 'onUnmount', (() => unknown)[]>
|
|
47
|
-
|
|
48
|
-
async function unmountVariant() {
|
|
49
|
-
if (app) {
|
|
50
|
-
await app.onUnmount?.()
|
|
51
|
-
if (appHooks) {
|
|
52
|
-
for (const hook of appHooks.onUnmount) {
|
|
53
|
-
await hook()
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
app.el.parentNode.removeChild(app.el)
|
|
58
|
-
app = null
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function mountVariant() {
|
|
63
|
-
if (mounting) return
|
|
64
|
-
mounting = true
|
|
65
|
-
|
|
66
|
-
await unmountVariant()
|
|
67
|
-
|
|
68
|
-
app = {
|
|
69
|
-
el: document.createElement('div'),
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const generatedSetupVanilla = _getSetupHook<_VanillaStorySetupHandler>(generatedSetup, 'setupVanilla')
|
|
73
|
-
if (generatedSetupVanilla) {
|
|
74
|
-
await generatedSetupVanilla({
|
|
75
|
-
app,
|
|
76
|
-
story: props.story,
|
|
77
|
-
variant: props.variant,
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const setupVanilla = _getSetupHook<_VanillaStorySetupHandler>(setup, 'setupVanilla')
|
|
82
|
-
if (setupVanilla) {
|
|
83
|
-
await setupVanilla({
|
|
84
|
-
app,
|
|
85
|
-
story: props.story,
|
|
86
|
-
variant: props.variant,
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (typeof props.variant.setupApp === 'function') {
|
|
91
|
-
await props.variant.setupApp({
|
|
92
|
-
app,
|
|
93
|
-
story: props.story,
|
|
94
|
-
variant: props.variant,
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
await app.onMount?.()
|
|
99
|
-
|
|
100
|
-
appHooks = {
|
|
101
|
-
onUpdate: [],
|
|
102
|
-
onUnmount: [],
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const api: MountApi = {
|
|
106
|
-
el: app.el,
|
|
107
|
-
state: props.variant.state,
|
|
108
|
-
onUpdate: (cb) => {
|
|
109
|
-
appHooks.onUpdate.push(cb)
|
|
110
|
-
},
|
|
111
|
-
onUnmount: (cb) => {
|
|
112
|
-
appHooks.onUnmount.push(cb)
|
|
113
|
-
},
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const onMount = props.variant.slots()[props.slotName] as VanillaApi['onMount'] | VanillaApi['onMountControls']
|
|
117
|
-
await onMount(api)
|
|
118
|
-
|
|
119
|
-
sandbox.value.appendChild(app.el)
|
|
120
|
-
|
|
121
|
-
emit('ready')
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
_onMounted(async () => {
|
|
125
|
-
if (props.variant.configReady) {
|
|
126
|
-
await mountVariant()
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
_watch(() => props.variant, async (value) => {
|
|
131
|
-
if (value.configReady && !mounting) {
|
|
132
|
-
if (!app) {
|
|
133
|
-
await mountVariant()
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
// @TODO check if need to refresh here
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}, {
|
|
140
|
-
deep: true,
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
_watch(() => props.variant.state, async () => {
|
|
144
|
-
if (appHooks) {
|
|
145
|
-
for (const hook of appHooks.onUpdate) {
|
|
146
|
-
await hook()
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}, {
|
|
150
|
-
deep: true,
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
_onBeforeUnmount(() => {
|
|
154
|
-
unmountVariant()
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
sandbox,
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
|
|
162
|
-
render() {
|
|
163
|
-
return _h('div', {
|
|
164
|
-
ref: 'sandbox',
|
|
165
|
-
})
|
|
166
|
-
},
|
|
167
|
-
})
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { ServerRunPayload, ServerStory, ServerVariant } from '@poveste/shared'
|
|
2
|
-
import type { StoryOptions, VariantOptions } from './types'
|
|
3
|
-
|
|
4
|
-
export async function run({ file, storyData }: ServerRunPayload) {
|
|
5
|
-
const { default: Comp } = await import(/* @vite-ignore */ file.moduleId)
|
|
6
|
-
|
|
7
|
-
const options = Comp as StoryOptions
|
|
8
|
-
|
|
9
|
-
let rawVariants: VariantOptions[] = []
|
|
10
|
-
|
|
11
|
-
if (options.onMount) {
|
|
12
|
-
// Implicit variant
|
|
13
|
-
rawVariants = [{
|
|
14
|
-
id: '_default',
|
|
15
|
-
title: 'default',
|
|
16
|
-
}]
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
rawVariants = options.variants
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const story: ServerStory = {
|
|
23
|
-
id: options.id ?? file.id,
|
|
24
|
-
title: options.title ?? file.fileName,
|
|
25
|
-
group: options.group,
|
|
26
|
-
layout: options.layout ?? { type: 'single', iframe: true },
|
|
27
|
-
icon: options.icon,
|
|
28
|
-
iconColor: options.iconColor,
|
|
29
|
-
docsOnly: options.docsOnly ?? false,
|
|
30
|
-
variants: null,
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const variants: ServerVariant[] = rawVariants.map((v, index) => ({
|
|
34
|
-
id: v.id ?? `${story.id}-${index}`,
|
|
35
|
-
title: v.title ?? 'untitled',
|
|
36
|
-
icon: v.icon ?? options.icon,
|
|
37
|
-
iconColor: v.iconColor ?? options.iconColor,
|
|
38
|
-
}))
|
|
39
|
-
|
|
40
|
-
story.variants = variants
|
|
41
|
-
|
|
42
|
-
storyData.push(story)
|
|
43
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from '@poveste/shared'
|
|
2
|
-
import { fileURLToPath } from 'node:url'
|
|
3
|
-
import { dirname } from 'pathe'
|
|
4
|
-
|
|
5
|
-
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
6
|
-
|
|
7
|
-
export function vanillaSupport(): Plugin {
|
|
8
|
-
return {
|
|
9
|
-
name: 'builtin:vanilla-support',
|
|
10
|
-
|
|
11
|
-
defaultConfig() {
|
|
12
|
-
return {
|
|
13
|
-
supportMatch: [
|
|
14
|
-
{
|
|
15
|
-
id: 'vanilla',
|
|
16
|
-
patterns: ['**/*.js'],
|
|
17
|
-
pluginIds: ['vanilla'],
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
supportPlugin: {
|
|
24
|
-
id: 'vanilla',
|
|
25
|
-
moduleName: __dirname,
|
|
26
|
-
setupFn: 'setupVanilla',
|
|
27
|
-
importStoryComponent: (file, index) => `import Comp${index} from ${JSON.stringify(file.moduleId)}`, // @TODO code-splitting
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
// onDev (api) {
|
|
31
|
-
// // Test vanilla story
|
|
32
|
-
// api.addStoryFile(resolve(__dirname, './vanilla.story.js'))
|
|
33
|
-
// },
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { Awaitable, Story, StoryProps, Variant, VariantProps } from '@poveste/shared'
|
|
2
|
-
|
|
3
|
-
export interface App {
|
|
4
|
-
el: HTMLElement
|
|
5
|
-
onMount?: () => void
|
|
6
|
-
onUpdate?: () => void
|
|
7
|
-
onUnmount?: () => void
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface MountApi {
|
|
11
|
-
el: HTMLElement
|
|
12
|
-
state: Record<string, any>
|
|
13
|
-
onUpdate: (cb: () => unknown) => Awaitable<void>
|
|
14
|
-
onUnmount: (cb: () => unknown) => Awaitable<void>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface VanillaApi {
|
|
18
|
-
onMount?: (api: MountApi) => Awaitable<void>
|
|
19
|
-
onMountControls?: (api: MountApi) => Awaitable<void>
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type VanillaStorySetupHandler = (payload: { app: App, story: Story, variant: Variant }) => unknown
|
|
23
|
-
|
|
24
|
-
interface CommonProps {
|
|
25
|
-
setupApp?: VanillaStorySetupHandler
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type StoryOptions = Omit<StoryProps, 'setupApp'> & CommonProps & ((VanillaApi & {
|
|
29
|
-
variants?: never
|
|
30
|
-
}) | {
|
|
31
|
-
variants?: VariantOptions[]
|
|
32
|
-
onMount?: never
|
|
33
|
-
onMountControls?: never
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
export interface VariantOptions extends Omit<VariantProps, 'setupApp'>, CommonProps, VanillaApi {
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function defineStory(story: StoryOptions) {
|
|
41
|
-
return story
|
|
42
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { StoryOptions } from './types'
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
title: 'Vanilla story',
|
|
5
|
-
icon: 'ion:logo-nodejs',
|
|
6
|
-
variants: [
|
|
7
|
-
{
|
|
8
|
-
title: 'Hello',
|
|
9
|
-
onMount: ({ el, state, onUpdate }) => {
|
|
10
|
-
state.count = 0
|
|
11
|
-
|
|
12
|
-
const div = document.createElement('div')
|
|
13
|
-
div.innerHTML = '<h1>Hello World</h1>'
|
|
14
|
-
el.appendChild(div)
|
|
15
|
-
|
|
16
|
-
const counter = document.createElement('pre')
|
|
17
|
-
counter.innerHTML = `Counter: ${state.counter}`
|
|
18
|
-
div.appendChild(counter)
|
|
19
|
-
|
|
20
|
-
onUpdate(() => {
|
|
21
|
-
counter.innerHTML = `Counter: ${state.count}`
|
|
22
|
-
})
|
|
23
|
-
},
|
|
24
|
-
onMountControls: ({ el, state, onUnmount }) => {
|
|
25
|
-
const add = () => {
|
|
26
|
-
state.count++
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
Object.assign(el.style, {
|
|
30
|
-
padding: '8px',
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const btn = document.createElement('button')
|
|
34
|
-
btn.innerHTML = '+1'
|
|
35
|
-
Object.assign(btn.style, {
|
|
36
|
-
padding: '6px',
|
|
37
|
-
borderRadius: '3px',
|
|
38
|
-
backgroundColor: '#a7f3d0',
|
|
39
|
-
})
|
|
40
|
-
btn.addEventListener('click', add)
|
|
41
|
-
el.appendChild(btn)
|
|
42
|
-
|
|
43
|
-
onUnmount(() => {
|
|
44
|
-
btn.removeEventListener('click', add)
|
|
45
|
-
})
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
title: 'Meow',
|
|
50
|
-
onMount: ({ el, onUpdate, onUnmount }) => {
|
|
51
|
-
const div = document.createElement('div')
|
|
52
|
-
div.innerHTML = '<h1>Meow</h1>'
|
|
53
|
-
el.appendChild(div)
|
|
54
|
-
onUpdate(() => {
|
|
55
|
-
console.log('update')
|
|
56
|
-
})
|
|
57
|
-
onUnmount(() => {
|
|
58
|
-
el.removeChild(div)
|
|
59
|
-
})
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
} as StoryOptions
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import type { ServerStoryFile } from '@poveste/shared'
|
|
2
|
-
import type { ViteDevServer } from 'vite'
|
|
3
|
-
import type { FetchFunction, ResolveIdFunction } from 'vite-node'
|
|
4
|
-
import type { Context } from '../context.js'
|
|
5
|
-
import type { Payload, ReturnData } from './worker.js'
|
|
6
|
-
import { cpus } from 'node:os'
|
|
7
|
-
import { MessageChannel } from 'node:worker_threads'
|
|
8
|
-
import Tinypool from '@akryum/tinypool'
|
|
9
|
-
import { createBirpc } from 'birpc'
|
|
10
|
-
import path, { relative } from 'pathe'
|
|
11
|
-
import pc from 'picocolors'
|
|
12
|
-
import { ViteNodeServer } from 'vite-node/server'
|
|
13
|
-
import { TEMP_PATH } from '../alias.js'
|
|
14
|
-
import { createPath } from '../tree.js'
|
|
15
|
-
import { slash } from '../util/fs.js'
|
|
16
|
-
|
|
17
|
-
export interface UseCollectStoriesOptions {
|
|
18
|
-
server: ViteDevServer
|
|
19
|
-
mainServer?: ViteDevServer
|
|
20
|
-
throws?: boolean
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function useCollectStories(options: UseCollectStoriesOptions, ctx: Context) {
|
|
24
|
-
const { server, mainServer } = options
|
|
25
|
-
|
|
26
|
-
const node = new ViteNodeServer(server as any, {
|
|
27
|
-
deps: {
|
|
28
|
-
inline: [
|
|
29
|
-
// Published layout: `poveste` and scoped `@poveste/*` packages. These
|
|
30
|
-
// MUST be inlined so vite-node transforms them and resolves their
|
|
31
|
-
// `virtual:` imports; otherwise they're loaded via native Node ESM,
|
|
32
|
-
// which throws ERR_UNSUPPORTED_ESM_URL_SCHEME on `virtual:` and breaks
|
|
33
|
-
// story collection for any fresh npm install.
|
|
34
|
-
/\/poveste\/dist/,
|
|
35
|
-
/\/poveste\/client/,
|
|
36
|
-
/@poveste\/[\w-]+\/dist/,
|
|
37
|
-
// Workspace layout: packages/poveste-<name>/dist (dev / monorepo).
|
|
38
|
-
/poveste-[\w-]+\/dist/,
|
|
39
|
-
/@vue\/devtools-api/,
|
|
40
|
-
/vuetify/,
|
|
41
|
-
// @TODO temporary fix for https://github.com/histoire-dev/histoire/issues/409
|
|
42
|
-
/vite\w*\/dist\/client\/(client|env).mjs/,
|
|
43
|
-
...ctx.config.viteNodeInlineDeps ?? [],
|
|
44
|
-
new RegExp(path.resolve(TEMP_PATH, 'plugins')),
|
|
45
|
-
],
|
|
46
|
-
fallbackCJS: true,
|
|
47
|
-
},
|
|
48
|
-
transformMode: ctx.config.viteNodeTransformMode,
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
const maxThreads = ctx.config.collectMaxThreads ?? cpus().length
|
|
52
|
-
|
|
53
|
-
const threadsCount = ctx.mode === 'dev'
|
|
54
|
-
? Math.max(Math.min(maxThreads, Math.floor(cpus().length / 2)), 1)
|
|
55
|
-
: Math.max(Math.min(maxThreads, cpus().length - 1), 1)
|
|
56
|
-
console.log(pc.blue(`Using ${threadsCount} thread${threadsCount === 1 ? '' : 's'} for story collection`))
|
|
57
|
-
|
|
58
|
-
const threadPool = new Tinypool({
|
|
59
|
-
filename: new URL('./worker.js', import.meta.url).href,
|
|
60
|
-
// WebContainer compatibility (Stackblitz)
|
|
61
|
-
useAtomics: typeof process.versions.webcontainer !== 'string',
|
|
62
|
-
minThreads: threadsCount,
|
|
63
|
-
maxThreads: threadsCount,
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
function clearCache() {
|
|
67
|
-
server.moduleGraph.invalidateAll()
|
|
68
|
-
node.fetchCache.clear()
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function createChannel() {
|
|
72
|
-
const channel = new MessageChannel()
|
|
73
|
-
const port = channel.port2
|
|
74
|
-
const workerPort = channel.port1
|
|
75
|
-
|
|
76
|
-
createBirpc<Record<string, never>, {
|
|
77
|
-
fetchModule: FetchFunction
|
|
78
|
-
resolveId: ResolveIdFunction
|
|
79
|
-
}>({
|
|
80
|
-
fetchModule: id => node.fetchModule(id),
|
|
81
|
-
resolveId: (id, importer) => node.resolveId(id, importer),
|
|
82
|
-
}, {
|
|
83
|
-
post: data => port.postMessage(data),
|
|
84
|
-
on: data => port.on('message', data),
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
port,
|
|
89
|
-
workerPort,
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (mainServer) {
|
|
94
|
-
mainServer.watcher.on('change', (file) => {
|
|
95
|
-
file = slash(file)
|
|
96
|
-
threadPool.broadcastMessage({
|
|
97
|
-
kind: 'hst:invalidate',
|
|
98
|
-
file,
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function executeStoryFile(storyFile: ServerStoryFile) {
|
|
104
|
-
try {
|
|
105
|
-
const { workerPort } = createChannel()
|
|
106
|
-
const payload: Payload = {
|
|
107
|
-
root: server.config.root,
|
|
108
|
-
base: server.config.base,
|
|
109
|
-
storyFile,
|
|
110
|
-
port: workerPort,
|
|
111
|
-
}
|
|
112
|
-
const { storyData } = await threadPool.run(payload, {
|
|
113
|
-
transferList: [
|
|
114
|
-
workerPort,
|
|
115
|
-
],
|
|
116
|
-
}) as ReturnData
|
|
117
|
-
if (storyData.length === 0) {
|
|
118
|
-
console.warn(pc.yellow(`⚠️ No story found for ${storyFile.path}`))
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
else if (storyData.length > 1) {
|
|
122
|
-
console.warn(pc.yellow(`⚠️ Multiple stories not supported: ${storyFile.path}`))
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const finalData = storyData[0]
|
|
126
|
-
|
|
127
|
-
// Default props
|
|
128
|
-
if (ctx.config.defaultStoryProps) {
|
|
129
|
-
for (const key in ctx.config.defaultStoryProps) {
|
|
130
|
-
finalData[key] ??= ctx.config.defaultStoryProps[key]
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (!finalData.layout) {
|
|
135
|
-
finalData.layout = { type: 'single', iframe: true }
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
storyFile.id = finalData.id
|
|
139
|
-
storyFile.story = finalData
|
|
140
|
-
storyFile.treeFile = {
|
|
141
|
-
title: finalData.title,
|
|
142
|
-
path: relative(server.config.root, storyFile.path),
|
|
143
|
-
}
|
|
144
|
-
storyFile.treePath = createPath(ctx.config, storyFile.treeFile)
|
|
145
|
-
storyFile.story.title = storyFile.treePath[storyFile.treePath.length - 1]
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
console.error(pc.red(`Error while collecting story ${storyFile.path}:\n${e.frame ? `${pc.bold(e.message)}\n${e.frame}` : e.stack}`))
|
|
149
|
-
if (options.throws) {
|
|
150
|
-
throw e
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
async function destroy() {
|
|
156
|
-
await threadPool.destroy()
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
clearCache,
|
|
161
|
-
executeStoryFile,
|
|
162
|
-
destroy,
|
|
163
|
-
}
|
|
164
|
-
}
|
package/src/node/collect/run.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ServerRunPayload } from '@poveste/shared'
|
|
2
|
-
// @ts-expect-error virtual module
|
|
3
|
-
import { collectSupportPlugins } from 'virtual:$poveste-support-plugins-collect'
|
|
4
|
-
|
|
5
|
-
export async function run(payload: ServerRunPayload) {
|
|
6
|
-
const { run } = await collectSupportPlugins[payload.file.supportPluginId]()
|
|
7
|
-
const result = await run(payload)
|
|
8
|
-
return result
|
|
9
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import type { ServerRunPayload, ServerStory, ServerStoryFile } from '@poveste/shared'
|
|
2
|
-
import type { MessagePort } from 'node:worker_threads'
|
|
3
|
-
import type { FetchFunction, ResolveIdFunction } from 'vite-node'
|
|
4
|
-
import { performance } from 'node:perf_hooks'
|
|
5
|
-
import { fileURLToPath } from 'node:url'
|
|
6
|
-
import { parentPort } from 'node:worker_threads'
|
|
7
|
-
import { createBirpc } from 'birpc'
|
|
8
|
-
import { dirname, resolve } from 'pathe'
|
|
9
|
-
import pc from 'picocolors'
|
|
10
|
-
import { ModuleCacheMap, ViteNodeRunner } from 'vite-node/client'
|
|
11
|
-
import { createDomEnv, resetDomEnv } from '../dom/env.js'
|
|
12
|
-
|
|
13
|
-
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
14
|
-
|
|
15
|
-
export interface Payload {
|
|
16
|
-
root: string
|
|
17
|
-
base: string
|
|
18
|
-
port: MessagePort
|
|
19
|
-
storyFile: ServerStoryFile
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface ReturnData {
|
|
23
|
-
storyData: ServerStory[]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const _moduleCache = new ModuleCacheMap()
|
|
27
|
-
let _runner: ViteNodeRunner
|
|
28
|
-
// Worker-lifetime: externalised runtimes cache the DOM they first saw, so one
|
|
29
|
-
// per story broke re-collection.
|
|
30
|
-
let _domEnv: ReturnType<typeof createDomEnv> | undefined
|
|
31
|
-
let _rpc: ReturnType<typeof createBirpc<{
|
|
32
|
-
fetchModule: FetchFunction
|
|
33
|
-
resolveId: ResolveIdFunction
|
|
34
|
-
}>>
|
|
35
|
-
|
|
36
|
-
// Cleanup module cache
|
|
37
|
-
parentPort.on('message', (message) => {
|
|
38
|
-
if (message?.kind === 'hst:invalidate') {
|
|
39
|
-
_moduleCache.delete(message.file)
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
export default async (payload: Payload): Promise<ReturnData> => {
|
|
44
|
-
const startTime = performance.now()
|
|
45
|
-
process.env.HST_COLLECT = 'true'
|
|
46
|
-
|
|
47
|
-
_rpc = createBirpc<{
|
|
48
|
-
fetchModule: FetchFunction
|
|
49
|
-
resolveId: ResolveIdFunction
|
|
50
|
-
}>({}, {
|
|
51
|
-
post: data => payload.port.postMessage(data),
|
|
52
|
-
on: data => payload.port.on('message', data),
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
const runner = _runner ?? (_runner = new ViteNodeRunner({
|
|
56
|
-
root: payload.root,
|
|
57
|
-
base: payload.base,
|
|
58
|
-
moduleCache: _moduleCache,
|
|
59
|
-
fetchModule(id) {
|
|
60
|
-
return _rpc.fetchModule(id)
|
|
61
|
-
},
|
|
62
|
-
resolveId(id, importer) {
|
|
63
|
-
return _rpc.resolveId(id, importer)
|
|
64
|
-
},
|
|
65
|
-
}))
|
|
66
|
-
|
|
67
|
-
if (_domEnv) {
|
|
68
|
-
resetDomEnv(_domEnv)
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
_domEnv = createDomEnv()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const el = window.document.createElement('div')
|
|
75
|
-
|
|
76
|
-
const beforeExecuteTime = performance.now()
|
|
77
|
-
// Mount app to collect stories/variants
|
|
78
|
-
const { run } = (await runner.executeFile(resolve(__dirname, './run.js'))) as { run: (payload: ServerRunPayload) => Promise<any> }
|
|
79
|
-
const afterExecuteTime = performance.now()
|
|
80
|
-
const storyData: ServerStory[] = []
|
|
81
|
-
await run({
|
|
82
|
-
file: payload.storyFile,
|
|
83
|
-
storyData,
|
|
84
|
-
el,
|
|
85
|
-
})
|
|
86
|
-
const afterRunTime = performance.now()
|
|
87
|
-
|
|
88
|
-
if (payload.storyFile.markdownFile) {
|
|
89
|
-
const el = document.createElement('div')
|
|
90
|
-
el.innerHTML = payload.storyFile.markdownFile.html
|
|
91
|
-
const text = el.textContent
|
|
92
|
-
storyData.forEach((s) => {
|
|
93
|
-
s.docsText = text
|
|
94
|
-
})
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const endTime = performance.now()
|
|
98
|
-
console.log(pc.dim(`${payload.storyFile.relativePath} ${Math.round(endTime - startTime)}ms (setup:${Math.round(beforeExecuteTime - startTime)}ms, execute:${Math.round(afterExecuteTime - beforeExecuteTime)}ms, run:${Math.round(afterRunTime - afterExecuteTime)}ms)`))
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
storyData,
|
|
102
|
-
}
|
|
103
|
-
}
|