histoire 0.7.2 → 0.7.5
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/client.d.ts +1 -1
- package/dist/bundled/StoryView.js +22 -19
- package/dist/bundled/dark.js +4 -0
- package/dist/bundled/index.js +0 -1
- package/dist/bundled/index2.js +6 -6
- package/dist/bundled/mapping.js +78 -0
- package/dist/bundled/sandbox.js +7 -6
- package/dist/bundled/state.js +13 -44
- package/dist/bundled/style.css +3 -3
- package/dist/client/app/App.vue +2 -2
- package/dist/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
- package/dist/client/app/components/panel/ControlsComponentProps.vue +2 -1
- package/dist/client/app/components/panel/StatePresets.vue +2 -1
- package/dist/client/app/components/panel/StoryControls.vue +1 -1
- package/dist/client/app/components/panel/StorySourceCode.vue +2 -2
- package/dist/client/app/components/story/StoryVariantGridItem.vue +1 -1
- package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
- package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
- package/dist/client/app/components/story/StoryVariantSingleView.vue +1 -1
- package/dist/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
- package/dist/client/app/components/tree/StoryGroup.vue +1 -1
- package/dist/client/app/index.js +0 -2
- package/dist/client/app/sandbox.js +4 -5
- package/dist/client/app/types.d.ts +1 -52
- package/dist/client/app/util/mapping.d.ts +1 -1
- package/dist/client/app/util/mapping.js +50 -36
- package/dist/client/app/{components/sandbox/lib.d.ts → util/sandbox.d.ts} +1 -1
- package/dist/client/app/{components/sandbox/lib.js → util/sandbox.js} +1 -1
- package/dist/client/app/util/state.d.ts +1 -5
- package/dist/client/app/util/state.js +12 -44
- package/dist/node/collect/index.d.ts +2 -2
- package/dist/node/collect/index.js +3 -0
- package/dist/node/collect/run.d.ts +2 -0
- package/dist/{client/server/index.js → node/collect/run.js} +1 -1
- package/dist/node/collect/worker.d.ts +3 -3
- package/dist/node/collect/worker.js +4 -1
- package/dist/node/config.d.ts +3 -3
- package/dist/node/context.d.ts +2 -2
- package/dist/node/plugin.d.ts +3 -3
- package/dist/node/stories.d.ts +4 -4
- package/dist/node/tree.d.ts +3 -22
- package/dist/node/vite.js +1 -0
- package/dist/style.css +76 -0
- package/package.json +4 -2
- package/src/client/app/App.vue +2 -2
- package/src/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
- package/src/client/app/components/panel/ControlsComponentProps.vue +2 -1
- package/src/client/app/components/panel/StatePresets.vue +2 -1
- package/src/client/app/components/panel/StoryControls.vue +1 -1
- package/src/client/app/components/panel/StorySourceCode.vue +2 -2
- package/src/client/app/components/story/StoryVariantGridItem.vue +1 -1
- package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
- package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
- package/src/client/app/components/story/StoryVariantSingleView.vue +1 -1
- package/src/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
- package/src/client/app/components/tree/StoryGroup.vue +1 -1
- package/src/client/app/index.ts +0 -2
- package/src/client/app/sandbox.ts +4 -5
- package/src/client/app/types.ts +6 -57
- package/src/client/app/util/mapping.ts +47 -34
- package/src/client/app/{components/sandbox/lib.ts → util/sandbox.ts} +2 -2
- package/src/client/app/util/state.ts +15 -44
- package/src/node/collect/index.ts +5 -2
- package/src/node/collect/run.ts +13 -0
- package/src/node/collect/worker.ts +8 -6
- package/src/node/config.ts +3 -3
- package/src/node/context.ts +2 -2
- package/src/node/plugin.ts +2 -2
- package/src/node/server.ts +2 -2
- package/src/node/stories.ts +4 -4
- package/src/node/tree.ts +7 -31
- package/src/node/vite.ts +1 -0
- package/vite.config.ts +12 -7
- package/dist/bundled/SandboxVue3.js +0 -706
- package/dist/bundled/global-components.js +0 -213
- package/dist/client/app/codegen/const.d.ts +0 -1
- package/dist/client/app/codegen/const.js +0 -3
- package/dist/client/app/codegen/serialize-js.d.ts +0 -1
- package/dist/client/app/codegen/serialize-js.js +0 -113
- package/dist/client/app/codegen/util.d.ts +0 -10
- package/dist/client/app/codegen/util.js +0 -70
- package/dist/client/app/codegen/vue3.d.ts +0 -4
- package/dist/client/app/codegen/vue3.js +0 -357
- package/dist/client/app/components/exposed/Story.vue +0 -106
- package/dist/client/app/components/exposed/Variant.vue +0 -78
- package/dist/client/app/components/sandbox/RouterLinkStub.d.ts +0 -21
- package/dist/client/app/components/sandbox/RouterLinkStub.js +0 -43
- package/dist/client/app/components/sandbox/SandboxVue3.vue +0 -185
- package/dist/client/app/global-components.d.ts +0 -2
- package/dist/client/app/global-components.js +0 -10
- package/dist/client/server/index.d.ts +0 -7
- package/dist/client/server/vue3/Story.vue +0 -120
- package/dist/client/server/vue3/Variant.vue +0 -52
- package/dist/client/server/vue3/run.d.ts +0 -2
- package/dist/client/server/vue3/run.js +0 -45
- package/dist/node/types.d.ts +0 -50
- package/dist/node/types.js +0 -1
- package/src/client/app/codegen/const.ts +0 -3
- package/src/client/app/codegen/serialize-js.ts +0 -119
- package/src/client/app/codegen/util.ts +0 -79
- package/src/client/app/codegen/vue3.ts +0 -361
- package/src/client/app/components/exposed/Story.vue +0 -106
- package/src/client/app/components/exposed/Variant.vue +0 -78
- package/src/client/app/components/sandbox/RouterLinkStub.ts +0 -49
- package/src/client/app/components/sandbox/SandboxVue3.vue +0 -185
- package/src/client/app/global-components.ts +0 -13
- package/src/client/server/index.ts +0 -19
- package/src/client/server/vue3/Story.vue +0 -120
- package/src/client/server/vue3/Variant.vue +0 -52
- package/src/client/server/vue3/run.ts +0 -55
- package/src/components.d.ts +0 -143
- package/src/node/types.ts +0 -53
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { App, createApp, onMounted, onUnmounted, PropType, ref, watch } from 'vue'
|
|
3
|
-
import { Story, Variant, PropDefinition, AutoPropComponentDefinition } from '../../types'
|
|
4
|
-
import { getTagName } from '../../codegen/vue3'
|
|
5
|
-
import { applyStateToVariant } from '../../util/state'
|
|
6
|
-
import { RouterLinkStub } from './RouterLinkStub'
|
|
7
|
-
// @ts-expect-error virtual module id
|
|
8
|
-
import * as setup from '$histoire-setup'
|
|
9
|
-
// @ts-expect-error virtual module id
|
|
10
|
-
import * as generatedSetup from '$histoire-generated-global-setup'
|
|
11
|
-
|
|
12
|
-
const props = defineProps({
|
|
13
|
-
variant: {
|
|
14
|
-
type: Object as PropType<Variant>,
|
|
15
|
-
required: true,
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
story: {
|
|
19
|
-
type: Object as PropType<Story>,
|
|
20
|
-
required: true,
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
slotName: {
|
|
24
|
-
type: String,
|
|
25
|
-
default: 'default',
|
|
26
|
-
},
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
const emit = defineEmits({
|
|
30
|
-
ready: () => true,
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const sandbox = ref<HTMLDivElement>()
|
|
34
|
-
let app: App
|
|
35
|
-
let mounting = false
|
|
36
|
-
|
|
37
|
-
async function mountVariant () {
|
|
38
|
-
mounting = true
|
|
39
|
-
|
|
40
|
-
await props.variant.initState()
|
|
41
|
-
|
|
42
|
-
let lastPropsTypesSnapshot: string
|
|
43
|
-
|
|
44
|
-
app = createApp({
|
|
45
|
-
name: 'SandboxVue3',
|
|
46
|
-
|
|
47
|
-
render: () => {
|
|
48
|
-
const vnodes = props.variant.slots()?.[props.slotName]?.({
|
|
49
|
-
state: props.variant.state ?? {},
|
|
50
|
-
}) ?? props.story.slots()?.[props.slotName]?.({
|
|
51
|
-
state: props.variant.state ?? {},
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
// Auto detect props
|
|
55
|
-
if (props.slotName === 'default') {
|
|
56
|
-
const propsTypes: AutoPropComponentDefinition[] = vnodes.filter(vnode => typeof vnode.type === 'object').map((vnode, index) => {
|
|
57
|
-
const propDefs: PropDefinition[] = []
|
|
58
|
-
for (const key in vnode.type.props) {
|
|
59
|
-
const prop = vnode.type.props[key]
|
|
60
|
-
let types
|
|
61
|
-
let defaultValue
|
|
62
|
-
if (prop) {
|
|
63
|
-
const rawTypes = Array.isArray(prop.type) ? prop.type : [prop.type]
|
|
64
|
-
types = rawTypes.map(t => {
|
|
65
|
-
switch (t) {
|
|
66
|
-
case String:
|
|
67
|
-
return 'string'
|
|
68
|
-
case Number:
|
|
69
|
-
return 'number'
|
|
70
|
-
case Boolean:
|
|
71
|
-
return 'boolean'
|
|
72
|
-
case Object:
|
|
73
|
-
return 'object'
|
|
74
|
-
case Array:
|
|
75
|
-
return 'array'
|
|
76
|
-
default:
|
|
77
|
-
return 'unknown'
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
defaultValue = typeof prop.default === 'function' ? prop.default.toString() : prop.default
|
|
81
|
-
}
|
|
82
|
-
propDefs.push({
|
|
83
|
-
name: key,
|
|
84
|
-
types,
|
|
85
|
-
required: prop?.required,
|
|
86
|
-
default: defaultValue,
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
// Props overrides
|
|
90
|
-
if (props.variant.state?._hPropState?.[index]?.[key]) {
|
|
91
|
-
if (!vnode.props) {
|
|
92
|
-
vnode.props = {}
|
|
93
|
-
}
|
|
94
|
-
vnode.props[key] = props.variant.state._hPropState[index][key]
|
|
95
|
-
if (!vnode.dynamicProps) {
|
|
96
|
-
vnode.dynamicProps = []
|
|
97
|
-
}
|
|
98
|
-
if (!vnode.dynamicProps.includes(key)) {
|
|
99
|
-
vnode.dynamicProps.push(key)
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
name: getTagName(vnode),
|
|
106
|
-
index,
|
|
107
|
-
props: propDefs,
|
|
108
|
-
} as AutoPropComponentDefinition
|
|
109
|
-
}).filter(def => def.props.length)
|
|
110
|
-
|
|
111
|
-
const snapshot = JSON.stringify(propsTypes)
|
|
112
|
-
if (!lastPropsTypesSnapshot || lastPropsTypesSnapshot !== snapshot) {
|
|
113
|
-
applyStateToVariant(props.variant, {
|
|
114
|
-
_hPropDefs: propsTypes,
|
|
115
|
-
})
|
|
116
|
-
if (!props.variant.state._hPropState) {
|
|
117
|
-
applyStateToVariant(props.variant, {
|
|
118
|
-
_hPropState: {},
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
lastPropsTypesSnapshot = snapshot
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return vnodes
|
|
126
|
-
},
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
// Stubs
|
|
130
|
-
app.component('RouterLink', RouterLinkStub)
|
|
131
|
-
|
|
132
|
-
if (typeof generatedSetup?.setupVue3 === 'function') {
|
|
133
|
-
await generatedSetup.setupVue3({
|
|
134
|
-
app,
|
|
135
|
-
story: props.story,
|
|
136
|
-
variant: props.variant,
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (typeof setup?.setupVue3 === 'function') {
|
|
141
|
-
await setup.setupVue3({
|
|
142
|
-
app,
|
|
143
|
-
story: props.story,
|
|
144
|
-
variant: props.variant,
|
|
145
|
-
})
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (typeof props.variant.setupApp === 'function') {
|
|
149
|
-
await props.variant.setupApp({
|
|
150
|
-
app,
|
|
151
|
-
story: props.story,
|
|
152
|
-
variant: props.variant,
|
|
153
|
-
})
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const target = document.createElement('div')
|
|
157
|
-
sandbox.value.appendChild(target)
|
|
158
|
-
app.mount(target)
|
|
159
|
-
|
|
160
|
-
emit('ready')
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
onMounted(async () => {
|
|
164
|
-
if (props.variant.initState) {
|
|
165
|
-
await mountVariant()
|
|
166
|
-
}
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
watch(() => props.variant.initState, value => {
|
|
170
|
-
if (value && !mounting) {
|
|
171
|
-
mountVariant()
|
|
172
|
-
}
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
onUnmounted(() => {
|
|
176
|
-
app?.unmount()
|
|
177
|
-
})
|
|
178
|
-
</script>
|
|
179
|
-
|
|
180
|
-
<template>
|
|
181
|
-
<div
|
|
182
|
-
ref="sandbox"
|
|
183
|
-
class="__histoire-sandbox htw-overflow-auto"
|
|
184
|
-
/>
|
|
185
|
-
</template>
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { registerVueComponents } from '@histoire/controls';
|
|
2
|
-
import Story from './components/exposed/Story.vue';
|
|
3
|
-
import Variant from './components/exposed/Variant.vue';
|
|
4
|
-
export function registerGlobalComponents(app) {
|
|
5
|
-
// eslint-disable-next-line vue/multi-word-component-names
|
|
6
|
-
app.component('Story', Story);
|
|
7
|
-
// eslint-disable-next-line vue/multi-word-component-names
|
|
8
|
-
app.component('Variant', Variant);
|
|
9
|
-
registerVueComponents(app);
|
|
10
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { defineComponent, inject, onMounted, PropType, provide, useAttrs } from 'vue'
|
|
3
|
-
import type { StoryFile, Story, Variant } from '../../../node/types'
|
|
4
|
-
|
|
5
|
-
const stub = { name: 'StubbedComponent', render: () => null }
|
|
6
|
-
|
|
7
|
-
export default defineComponent({
|
|
8
|
-
name: 'HistoireStory',
|
|
9
|
-
|
|
10
|
-
inheritAttrs: false,
|
|
11
|
-
|
|
12
|
-
props: {
|
|
13
|
-
title: {
|
|
14
|
-
type: String,
|
|
15
|
-
default: null,
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
id: {
|
|
19
|
-
type: String,
|
|
20
|
-
default: null,
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
group: {
|
|
24
|
-
type: String,
|
|
25
|
-
default: null,
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
layout: {
|
|
29
|
-
type: Object as PropType<Story['layout']>,
|
|
30
|
-
default: () => ({ type: 'single', iframe: true }),
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
icon: {
|
|
34
|
-
type: String,
|
|
35
|
-
default: null,
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
iconColor: {
|
|
39
|
-
type: String,
|
|
40
|
-
default: null,
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
docsOnly: {
|
|
44
|
-
type: Boolean,
|
|
45
|
-
default: false,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
setup (props) {
|
|
50
|
-
const attrs = useAttrs() as {
|
|
51
|
-
data: StoryFile
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Story
|
|
55
|
-
|
|
56
|
-
const story: Story = {
|
|
57
|
-
id: props.id ?? attrs.data.id,
|
|
58
|
-
title: props.title ?? attrs.data.fileName,
|
|
59
|
-
group: props.group,
|
|
60
|
-
layout: props.layout,
|
|
61
|
-
icon: props.icon,
|
|
62
|
-
iconColor: props.iconColor,
|
|
63
|
-
docsOnly: props.docsOnly,
|
|
64
|
-
variants: [],
|
|
65
|
-
}
|
|
66
|
-
const addStory = inject('addStory', null)
|
|
67
|
-
addStory?.(story)
|
|
68
|
-
|
|
69
|
-
// Variants
|
|
70
|
-
|
|
71
|
-
provide('story', story)
|
|
72
|
-
|
|
73
|
-
provide('addVariant', (variant: Variant) => {
|
|
74
|
-
story.variants.push(variant)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
onMounted(() => {
|
|
78
|
-
if (!story.variants.length) {
|
|
79
|
-
story.variants.push({
|
|
80
|
-
id: '_default',
|
|
81
|
-
title: 'default',
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
story,
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
render () {
|
|
92
|
-
let suppressError = false
|
|
93
|
-
try {
|
|
94
|
-
const vnodes = this.$slots.default?.({
|
|
95
|
-
get state () {
|
|
96
|
-
// No variant tags
|
|
97
|
-
suppressError = true
|
|
98
|
-
return {}
|
|
99
|
-
},
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
// Auto stub components
|
|
103
|
-
if (Array.isArray(vnodes)) {
|
|
104
|
-
for (const vnode of vnodes) {
|
|
105
|
-
if (typeof vnode.type === 'object' && (vnode.type as any).name !== 'HistoireVariant') {
|
|
106
|
-
vnode.type = stub
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return vnodes
|
|
112
|
-
} catch (e) {
|
|
113
|
-
if (!suppressError) {
|
|
114
|
-
console.error(e)
|
|
115
|
-
}
|
|
116
|
-
return null
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
})
|
|
120
|
-
</script>
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { defineComponent, inject } from 'vue'
|
|
3
|
-
import type { Story, Variant } from '../../../node/types'
|
|
4
|
-
|
|
5
|
-
export default defineComponent({
|
|
6
|
-
name: 'HistoireVariant',
|
|
7
|
-
|
|
8
|
-
props: {
|
|
9
|
-
title: {
|
|
10
|
-
type: String,
|
|
11
|
-
default: 'untitled',
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
id: {
|
|
15
|
-
type: String,
|
|
16
|
-
default: null,
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
icon: {
|
|
20
|
-
type: String,
|
|
21
|
-
default: null,
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
iconColor: {
|
|
25
|
-
type: String,
|
|
26
|
-
default: null,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
setup (props) {
|
|
31
|
-
const story = inject<Story>('story')
|
|
32
|
-
|
|
33
|
-
function generateId () {
|
|
34
|
-
return `${story.id}-${story.variants.length}`
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const variant: Variant = {
|
|
38
|
-
id: props.id ?? generateId(),
|
|
39
|
-
title: props.title,
|
|
40
|
-
icon: props.icon,
|
|
41
|
-
iconColor: props.iconColor,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const addVariant = inject('addVariant') as (variant: Variant) => void
|
|
45
|
-
addVariant(variant)
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
render () {
|
|
49
|
-
return null
|
|
50
|
-
},
|
|
51
|
-
})
|
|
52
|
-
</script>
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { createApp, h } from 'vue';
|
|
2
|
-
import { registerVueComponents } from '@histoire/controls';
|
|
3
|
-
import Story from './Story.vue';
|
|
4
|
-
import Variant from './Variant.vue';
|
|
5
|
-
// @ts-expect-error virtual module id
|
|
6
|
-
import * as setup from '$histoire-setup';
|
|
7
|
-
// @ts-expect-error virtual module id
|
|
8
|
-
import * as generatedSetup from '$histoire-generated-global-setup';
|
|
9
|
-
export async function run({ file, storyData, el }) {
|
|
10
|
-
const { default: Comp } = await import(file.moduleId);
|
|
11
|
-
const app = createApp({
|
|
12
|
-
provide: {
|
|
13
|
-
addStory(data) {
|
|
14
|
-
storyData.push(data);
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
render() {
|
|
18
|
-
return h(Comp, {
|
|
19
|
-
ref: 'comp',
|
|
20
|
-
data: file,
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
if (typeof generatedSetup?.setupVue3 === 'function') {
|
|
25
|
-
await generatedSetup.setupVue3({ app });
|
|
26
|
-
}
|
|
27
|
-
if (typeof setup?.setupVue3 === 'function') {
|
|
28
|
-
await setup.setupVue3({ app });
|
|
29
|
-
}
|
|
30
|
-
// eslint-disable-next-line vue/multi-word-component-names
|
|
31
|
-
app.component('Story', Story);
|
|
32
|
-
// eslint-disable-next-line vue/multi-word-component-names
|
|
33
|
-
app.component('Variant', Variant);
|
|
34
|
-
registerVueComponents(app);
|
|
35
|
-
app.mount(el);
|
|
36
|
-
if (Comp.doc) {
|
|
37
|
-
const el = document.createElement('div');
|
|
38
|
-
el.innerHTML = Comp.doc;
|
|
39
|
-
const text = el.textContent;
|
|
40
|
-
storyData.forEach(s => {
|
|
41
|
-
s.docsText = text;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
app.unmount();
|
|
45
|
-
}
|
package/dist/node/types.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { TreeFile } from './tree.js';
|
|
2
|
-
export interface StoryFile {
|
|
3
|
-
id: string;
|
|
4
|
-
/**
|
|
5
|
-
* Absolute path
|
|
6
|
-
*/
|
|
7
|
-
path: string;
|
|
8
|
-
/**
|
|
9
|
-
* File name without extension
|
|
10
|
-
*/
|
|
11
|
-
fileName: string;
|
|
12
|
-
/**
|
|
13
|
-
* Generated path for tree UI
|
|
14
|
-
*/
|
|
15
|
-
treePath?: string[];
|
|
16
|
-
/**
|
|
17
|
-
* Use the module id in imports to allow HMR
|
|
18
|
-
*/
|
|
19
|
-
moduleId: string;
|
|
20
|
-
/**
|
|
21
|
-
* Resolved story data from story file execution
|
|
22
|
-
*/
|
|
23
|
-
story?: Story;
|
|
24
|
-
/**
|
|
25
|
-
* Data sent to user tree config functions
|
|
26
|
-
*/
|
|
27
|
-
treeFile?: TreeFile;
|
|
28
|
-
}
|
|
29
|
-
export interface Story {
|
|
30
|
-
id: string;
|
|
31
|
-
title: string;
|
|
32
|
-
group?: string;
|
|
33
|
-
variants: Variant[];
|
|
34
|
-
layout?: {
|
|
35
|
-
type: 'single';
|
|
36
|
-
} | {
|
|
37
|
-
type: 'grid';
|
|
38
|
-
width?: number | string;
|
|
39
|
-
};
|
|
40
|
-
icon?: string;
|
|
41
|
-
iconColor?: string;
|
|
42
|
-
docsOnly?: boolean;
|
|
43
|
-
docsText?: string;
|
|
44
|
-
}
|
|
45
|
-
export interface Variant {
|
|
46
|
-
id: string;
|
|
47
|
-
title: string;
|
|
48
|
-
icon?: string;
|
|
49
|
-
iconColor?: string;
|
|
50
|
-
}
|
package/dist/node/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
const KEY_ESCAPE_REG = /[\s-.:|#@$£*%]/
|
|
2
|
-
const MAX_SINGLE_LINE_ARRAY_LENGTH = 3
|
|
3
|
-
|
|
4
|
-
interface Line {
|
|
5
|
-
spaces: number
|
|
6
|
-
line: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function serializeJs (value: any): string {
|
|
10
|
-
if (value === undefined) {
|
|
11
|
-
return 'undefined'
|
|
12
|
-
}
|
|
13
|
-
if (value === null) {
|
|
14
|
-
return 'null'
|
|
15
|
-
}
|
|
16
|
-
if (typeof value === 'string') {
|
|
17
|
-
return `'${value}'`
|
|
18
|
-
}
|
|
19
|
-
if (typeof value === 'boolean') {
|
|
20
|
-
return value ? 'true' : 'false'
|
|
21
|
-
}
|
|
22
|
-
if (Array.isArray(value)) {
|
|
23
|
-
return printLines(arrayToSourceLines(value))
|
|
24
|
-
}
|
|
25
|
-
if (typeof value === 'object') {
|
|
26
|
-
return printLines(objectToSourceLines(value))
|
|
27
|
-
}
|
|
28
|
-
if (value?.__autoBuildingObject) {
|
|
29
|
-
return value
|
|
30
|
-
}
|
|
31
|
-
if (typeof value === 'function' && value.name) {
|
|
32
|
-
return value.name
|
|
33
|
-
}
|
|
34
|
-
return value.toString()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function printLines (lines: Line[]) {
|
|
38
|
-
return lines.map(line => ' '.repeat(line.spaces) + line.line).join('\n')
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function objectToSourceLines (object, indentCount = 0) {
|
|
42
|
-
return createLines(indentCount, lines => {
|
|
43
|
-
lines.push('{')
|
|
44
|
-
lines.push(...createLines(1, lines => {
|
|
45
|
-
for (const key in object) {
|
|
46
|
-
const value = object[key]
|
|
47
|
-
|
|
48
|
-
let printedKey = key
|
|
49
|
-
if (KEY_ESCAPE_REG.test(key)) {
|
|
50
|
-
printedKey = `'${printedKey}'`
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
addLinesFromValue(lines, value, `${printedKey}: `, ',')
|
|
54
|
-
}
|
|
55
|
-
}))
|
|
56
|
-
lines.push('}')
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function arrayToSourceLines (array: any[], indentCount = 0) {
|
|
61
|
-
return createLines(indentCount, lines => {
|
|
62
|
-
const contentLines = createLines(1, lines => {
|
|
63
|
-
for (const value of array) {
|
|
64
|
-
addLinesFromValue(lines, value, '', ',')
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
if (contentLines.length === 0) {
|
|
68
|
-
lines.push('[]')
|
|
69
|
-
} else if (contentLines.length <= MAX_SINGLE_LINE_ARRAY_LENGTH && !contentLines.some(line => line.spaces > 1)) {
|
|
70
|
-
const [first] = contentLines
|
|
71
|
-
first.line = contentLines.map(({ line }) => line.substring(0, line.length - 1)).join(', ')
|
|
72
|
-
first.line = `[${first.line}]`
|
|
73
|
-
first.spaces--
|
|
74
|
-
lines.push(first)
|
|
75
|
-
} else {
|
|
76
|
-
lines.push('[', ...contentLines, ']')
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function createLines (indentCount: number, handler: (lines: any[]) => unknown) {
|
|
82
|
-
const lines: any[] = []
|
|
83
|
-
handler(lines)
|
|
84
|
-
return lines.map(line => {
|
|
85
|
-
if (line.spaces != null) {
|
|
86
|
-
line.spaces += indentCount
|
|
87
|
-
return line
|
|
88
|
-
}
|
|
89
|
-
return { spaces: indentCount, line }
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function addLinesFromValue (lines: Line[], value, before, after) {
|
|
94
|
-
let result
|
|
95
|
-
if (Array.isArray(value)) {
|
|
96
|
-
lines.push(...wrap(arrayToSourceLines(value), before, after))
|
|
97
|
-
return
|
|
98
|
-
} else if (value && typeof value === 'object') {
|
|
99
|
-
lines.push(...wrap(objectToSourceLines(value), before, after))
|
|
100
|
-
return
|
|
101
|
-
} else if (typeof value === 'string') {
|
|
102
|
-
result = value.includes('\'') ? `\`${value}\`` : `'${value}'`
|
|
103
|
-
} else if (typeof value === 'undefined') {
|
|
104
|
-
result = 'undefined'
|
|
105
|
-
} else if (value === null) {
|
|
106
|
-
result = 'null'
|
|
107
|
-
} else if (typeof value === 'boolean') {
|
|
108
|
-
result = value ? 'true' : 'false'
|
|
109
|
-
} else {
|
|
110
|
-
result = value
|
|
111
|
-
}
|
|
112
|
-
lines.push(before + result + after)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function wrap (lines: Line[], before: string, after: string) {
|
|
116
|
-
lines[0].line = before + lines[0].line
|
|
117
|
-
lines[lines.length - 1].line += after
|
|
118
|
-
return lines
|
|
119
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
-
|
|
3
|
-
export function indent (lines: string[], count = 1) {
|
|
4
|
-
return lines.map(line => `${' '.repeat(count)}${line}`)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function unindent (code: string) {
|
|
8
|
-
const lines = code.split('\n')
|
|
9
|
-
let indentLevel = -1
|
|
10
|
-
let indentText: string
|
|
11
|
-
const linesToAnalyze = lines.filter(line => line.trim().length > 0)
|
|
12
|
-
for (const line of linesToAnalyze) {
|
|
13
|
-
const match = /^\s*/.exec(line)
|
|
14
|
-
if (match && (indentLevel === -1 || indentLevel > match[0].length)) {
|
|
15
|
-
indentLevel = match[0].length
|
|
16
|
-
indentText = match[0]
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const result: string[] = []
|
|
20
|
-
for (const line of lines) {
|
|
21
|
-
result.push(line.replace(indentText, ''))
|
|
22
|
-
}
|
|
23
|
-
return result.join('\n').trim()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface AutoBuildingOject {
|
|
27
|
-
key: string
|
|
28
|
-
cache: Record<string | symbol, AutoBuildingOject>
|
|
29
|
-
target: any
|
|
30
|
-
proxy: any
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function createAutoBuildingObject (format?: (key: string) => string, specialKeysHandler?: (target: any, p: string | symbol) => (() => unknown) | null, key = '', depth = 0): AutoBuildingOject {
|
|
34
|
-
const cache: Record<string | symbol, AutoBuildingOject> = {}
|
|
35
|
-
if (depth > 32) return { key, cache, target: {}, proxy: () => key }
|
|
36
|
-
const target: any = () => {
|
|
37
|
-
const k = key + '()'
|
|
38
|
-
return format ? format(k) : k
|
|
39
|
-
}
|
|
40
|
-
const proxy = new Proxy(target, {
|
|
41
|
-
get (_, p) {
|
|
42
|
-
if (p === '__autoBuildingObject') {
|
|
43
|
-
return true
|
|
44
|
-
}
|
|
45
|
-
if (p === '__autoBuildingObjectGetKey') {
|
|
46
|
-
return key
|
|
47
|
-
}
|
|
48
|
-
if (specialKeysHandler) {
|
|
49
|
-
const fn = specialKeysHandler(target, p)
|
|
50
|
-
if (fn) {
|
|
51
|
-
return fn()
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (p === 'toString') {
|
|
55
|
-
const k = key + '.toString()'
|
|
56
|
-
return () => format ? format(k) : k
|
|
57
|
-
}
|
|
58
|
-
if (p === Symbol.toPrimitive) {
|
|
59
|
-
return () => format ? format(key) : key
|
|
60
|
-
}
|
|
61
|
-
if (!cache[p]) {
|
|
62
|
-
const childKey = key ? `${key}.${p.toString()}` : p.toString()
|
|
63
|
-
const child = createAutoBuildingObject(format, specialKeysHandler, childKey, depth + 1)
|
|
64
|
-
cache[p] = { key: childKey, ...child }
|
|
65
|
-
}
|
|
66
|
-
return cache[p].proxy
|
|
67
|
-
},
|
|
68
|
-
apply (_, thisArg, args) {
|
|
69
|
-
const k = `${key}(${args.join(', ')})`
|
|
70
|
-
return format ? format(k) : k
|
|
71
|
-
},
|
|
72
|
-
})
|
|
73
|
-
return {
|
|
74
|
-
key,
|
|
75
|
-
cache,
|
|
76
|
-
target,
|
|
77
|
-
proxy,
|
|
78
|
-
}
|
|
79
|
-
}
|