histoire 0.0.1 → 0.0.4
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/README.md +11 -0
- package/dist/client/app/App.vue +8 -8
- package/dist/client/app/codegen/serialize-js.js +0 -1
- package/dist/client/app/codegen/util.js +0 -1
- package/dist/client/app/codegen/vue3.js +28 -5
- package/dist/client/app/codegen/vue3.ts +32 -4
- package/dist/client/app/components/app/AppHeader.vue +10 -3
- package/dist/client/app/components/base/BaseTab.vue +46 -0
- package/dist/client/app/components/exposed/Story.vue +21 -1
- package/dist/client/app/components/exposed/Variant.vue +1 -0
- package/dist/client/app/components/misc/CheckerboardPattern.vue +32 -0
- package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -0
- package/dist/client/app/components/search/SearchItem.vue +5 -9
- package/{src/client/app/components → dist/client/app/components/story}/StoryControls.vue +3 -3
- package/dist/client/app/components/story/StoryDocs.vue +37 -0
- package/dist/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
- package/dist/client/app/components/{StoryListFolder.vue → story/StoryListFolder.vue} +13 -6
- package/dist/client/app/components/{StoryListItem.vue → story/StoryListItem.vue} +11 -6
- package/dist/client/app/components/story/StoryResponsivePreview.vue +214 -0
- package/{src/client/app/components → dist/client/app/components/story}/StorySourceCode.vue +4 -8
- package/{src/client/app/components → dist/client/app/components/story}/StoryVariantGridItem.vue +14 -6
- package/dist/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
- package/dist/client/app/components/story/StoryVariantSingleView.vue +182 -0
- package/dist/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
- package/dist/client/app/global-components.js +2 -1
- package/dist/client/app/global-components.ts +3 -0
- package/dist/client/app/index.js +10 -1
- package/dist/client/app/index.ts +10 -0
- package/dist/client/app/router.js +1 -2
- package/dist/client/app/router.ts +1 -1
- package/dist/client/app/sandbox.js +37 -4
- package/dist/client/app/sandbox.ts +37 -3
- package/dist/client/app/stores/story.d.ts +22 -1
- package/dist/client/app/stores/story.js +30 -2
- package/dist/client/app/stores/story.ts +37 -1
- package/dist/client/app/style/floating-vue.css +31 -0
- package/dist/client/app/style/main.css +17 -1
- package/dist/client/app/style/sandbox.css +5 -0
- package/dist/client/app/style/transitions.css +12 -0
- package/dist/client/app/types.d.ts +1 -0
- package/dist/client/app/types.js +0 -1
- package/dist/client/app/types.ts +15 -0
- package/dist/client/app/util/config.js +0 -1
- package/dist/client/app/util/const.d.ts +2 -0
- package/dist/client/app/util/const.js +2 -1
- package/dist/client/app/util/const.ts +2 -0
- package/dist/client/app/util/dark.js +0 -1
- package/dist/client/app/util/env.js +0 -1
- package/dist/client/app/util/env.ts +1 -0
- package/dist/client/app/util/keyboard.js +0 -1
- package/dist/client/app/util/keyboard.ts +99 -0
- package/dist/client/app/util/mapping.js +6 -1
- package/dist/client/app/util/mapping.ts +5 -0
- package/dist/client/app/util/preview-settings.d.ts +16 -0
- package/dist/client/app/util/preview-settings.js +15 -0
- package/dist/client/app/util/preview-settings.ts +26 -0
- package/dist/client/app/util/reactivity.d.ts +1 -0
- package/dist/client/app/util/reactivity.js +16 -0
- package/dist/client/app/util/reactivity.ts +22 -0
- package/dist/client/app/util/scroll.d.ts +2 -0
- package/dist/client/app/util/scroll.js +24 -0
- package/dist/client/app/util/scroll.ts +27 -0
- package/dist/client/app/util/tooltip.js +0 -1
- package/dist/client/app/util/tooltip.ts +13 -0
- package/dist/client/app/{composable → util}/variant.d.ts +0 -0
- package/dist/client/app/{composable → util}/variant.js +0 -1
- package/dist/client/app/{composable → util}/variant.ts +0 -0
- package/dist/client/index.js +0 -1
- package/dist/client/server/Story.server.vue +25 -2
- package/dist/client/server/index.js +2 -1
- package/dist/client/server/index.ts +3 -0
- package/dist/controls.d.ts +1 -0
- package/dist/controls.js +1 -0
- package/dist/node/alias.js +0 -1
- package/dist/node/bin.js +0 -1
- package/dist/node/build.js +13 -9
- package/dist/node/collect.js +12 -4
- package/dist/node/colors.d.ts +12 -0
- package/dist/node/colors.js +12 -1
- package/dist/node/commands/build.js +0 -1
- package/dist/node/commands/dev.js +43 -6
- package/dist/node/config.d.ts +35 -0
- package/dist/node/config.js +75 -2
- package/dist/node/context.js +0 -1
- package/dist/node/dom/dom-keys.js +0 -1
- package/dist/node/dom/env.js +0 -1
- package/dist/node/index.js +0 -1
- package/dist/node/markdown.d.ts +2 -0
- package/dist/node/markdown.js +48 -0
- package/dist/node/plugin.js +35 -1
- package/dist/node/server.js +0 -1
- package/dist/node/stories.js +0 -1
- package/dist/node/tree.js +0 -1
- package/dist/node/types.js +0 -1
- package/dist/node/util/slugify.d.ts +1 -0
- package/dist/node/util/slugify.js +22 -0
- package/dist/style.css +863 -157
- package/package.json +17 -4
- package/src/client/app/App.vue +8 -8
- package/src/client/app/codegen/vue3.ts +32 -4
- package/src/client/app/components/app/AppHeader.vue +10 -3
- package/src/client/app/components/base/BaseTab.vue +46 -0
- package/src/client/app/components/exposed/Story.vue +21 -1
- package/src/client/app/components/exposed/Variant.vue +1 -0
- package/src/client/app/components/misc/CheckerboardPattern.vue +32 -0
- package/src/client/app/components/sandbox/SandboxVue3.vue +6 -0
- package/src/client/app/components/search/SearchItem.vue +5 -9
- package/{dist/client/app/components → src/client/app/components/story}/StoryControls.vue +3 -3
- package/src/client/app/components/story/StoryDocs.vue +37 -0
- package/src/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
- package/src/client/app/components/{StoryListFolder.vue → story/StoryListFolder.vue} +13 -6
- package/src/client/app/components/{StoryListItem.vue → story/StoryListItem.vue} +11 -6
- package/src/client/app/components/story/StoryResponsivePreview.vue +214 -0
- package/{dist/client/app/components → src/client/app/components/story}/StorySourceCode.vue +4 -8
- package/{dist/client/app/components → src/client/app/components/story}/StoryVariantGridItem.vue +14 -6
- package/src/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
- package/src/client/app/components/story/StoryVariantSingleView.vue +182 -0
- package/src/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
- package/src/client/app/global-components.ts +3 -0
- package/src/client/app/index.ts +10 -0
- package/src/client/app/router.ts +1 -1
- package/src/client/app/sandbox.ts +37 -3
- package/src/client/app/stores/story.ts +37 -1
- package/src/client/app/style/floating-vue.css +31 -0
- package/src/client/app/style/main.css +17 -1
- package/src/client/app/style/sandbox.css +5 -0
- package/src/client/app/style/transitions.css +12 -0
- package/src/client/app/types.ts +1 -0
- package/src/client/app/util/const.ts +2 -0
- package/src/client/app/util/mapping.ts +5 -0
- package/src/client/app/util/preview-settings.ts +26 -0
- package/src/client/app/util/reactivity.ts +22 -0
- package/src/client/app/util/scroll.ts +27 -0
- package/src/client/app/{composable → util}/variant.ts +0 -0
- package/src/client/server/Story.server.vue +25 -2
- package/src/client/server/index.ts +3 -0
- package/src/controls.ts +1 -0
- package/src/node/build.ts +15 -8
- package/src/node/collect.ts +12 -3
- package/src/node/colors.ts +12 -0
- package/src/node/commands/dev.ts +49 -5
- package/src/node/config.ts +112 -2
- package/src/node/markdown.ts +56 -0
- package/src/node/plugin.ts +38 -0
- package/src/node/tree.spec.ts +28 -0
- package/src/node/util/slugify.ts +26 -0
- package/tailwind.config.cjs +79 -4
- package/tsconfig.json +2 -1
- package/dist/client/app/codegen/serialize-js.js.map +0 -1
- package/dist/client/app/codegen/util.js.map +0 -1
- package/dist/client/app/codegen/vue3.js.map +0 -1
- package/dist/client/app/components/StoryVariantSingleView.vue +0 -145
- package/dist/client/app/composable/variant.js.map +0 -1
- package/dist/client/app/global-components.js.map +0 -1
- package/dist/client/app/index.js.map +0 -1
- package/dist/client/app/router.js.map +0 -1
- package/dist/client/app/sandbox.js.map +0 -1
- package/dist/client/app/stores/story.js.map +0 -1
- package/dist/client/app/types.js.map +0 -1
- package/dist/client/app/util/config.js.map +0 -1
- package/dist/client/app/util/const.js.map +0 -1
- package/dist/client/app/util/dark.js.map +0 -1
- package/dist/client/app/util/env.js.map +0 -1
- package/dist/client/app/util/keyboard.js.map +0 -1
- package/dist/client/app/util/mapping.js.map +0 -1
- package/dist/client/app/util/tooltip.js.map +0 -1
- package/dist/client/index.js.map +0 -1
- package/dist/client/server/index.js.map +0 -1
- package/dist/node/alias.js.map +0 -1
- package/dist/node/bin.js.map +0 -1
- package/dist/node/build.js.map +0 -1
- package/dist/node/collect.js.map +0 -1
- package/dist/node/colors.js.map +0 -1
- package/dist/node/commands/build.js.map +0 -1
- package/dist/node/commands/dev.js.map +0 -1
- package/dist/node/config.js.map +0 -1
- package/dist/node/context.js.map +0 -1
- package/dist/node/dom/dom-keys.js.map +0 -1
- package/dist/node/dom/env.js.map +0 -1
- package/dist/node/index.js.map +0 -1
- package/dist/node/plugin.js.map +0 -1
- package/dist/node/server.js.map +0 -1
- package/dist/node/stories.js.map +0 -1
- package/dist/node/tree.js.map +0 -1
- package/dist/node/types.js.map +0 -1
- package/src/client/app/components/StoryVariantSingleView.vue +0 -145
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './style/sandbox.css'
|
|
2
2
|
import { parseQuery } from 'vue-router'
|
|
3
|
-
import { computed, createApp, h,
|
|
3
|
+
import { computed, createApp, h, onMounted, ref, watch } from 'vue'
|
|
4
4
|
import { createPinia } from 'pinia'
|
|
5
5
|
import { registerGlobalComponents } from './global-components'
|
|
6
6
|
import SandboxVue3 from './components/sandbox/SandboxVue3.vue'
|
|
@@ -8,7 +8,11 @@ import type { StoryFile } from './types'
|
|
|
8
8
|
import { mapFile } from './util/mapping'
|
|
9
9
|
// @ts-expect-error virtual module
|
|
10
10
|
import { files } from '$histoire-stories'
|
|
11
|
-
import { STATE_SYNC } from './util/const.js'
|
|
11
|
+
import { PREVIEW_SETTINGS_SYNC, STATE_SYNC, SANDBOX_READY } from './util/const.js'
|
|
12
|
+
import { applyPreviewSettings } from './util/preview-settings.js'
|
|
13
|
+
import { isDark } from './util/dark.js'
|
|
14
|
+
import { histoireConfig } from './util/config.js'
|
|
15
|
+
import { toRawDeep } from './util/reactivity'
|
|
12
16
|
|
|
13
17
|
const query = parseQuery(window.location.search)
|
|
14
18
|
const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
|
|
@@ -18,21 +22,36 @@ const app = createApp({
|
|
|
18
22
|
const story = computed(() => file.value.story)
|
|
19
23
|
const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId))
|
|
20
24
|
|
|
25
|
+
let synced = false
|
|
26
|
+
let mounted = false
|
|
27
|
+
|
|
21
28
|
window.addEventListener('message', event => {
|
|
22
29
|
if (event.data?.type === STATE_SYNC) {
|
|
30
|
+
if (!mounted) return
|
|
31
|
+
synced = true
|
|
23
32
|
Object.assign(variant.value.state, event.data.state)
|
|
33
|
+
} else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
|
|
34
|
+
applyPreviewSettings(event.data.settings)
|
|
24
35
|
}
|
|
25
36
|
})
|
|
26
37
|
|
|
27
38
|
watch(() => variant.value.state, value => {
|
|
39
|
+
if (synced && mounted) {
|
|
40
|
+
synced = false
|
|
41
|
+
return
|
|
42
|
+
}
|
|
28
43
|
window.parent?.postMessage({
|
|
29
44
|
type: STATE_SYNC,
|
|
30
|
-
state:
|
|
45
|
+
state: toRawDeep(value),
|
|
31
46
|
})
|
|
32
47
|
}, {
|
|
33
48
|
deep: true,
|
|
34
49
|
})
|
|
35
50
|
|
|
51
|
+
onMounted(() => {
|
|
52
|
+
mounted = true
|
|
53
|
+
})
|
|
54
|
+
|
|
36
55
|
return {
|
|
37
56
|
story,
|
|
38
57
|
variant,
|
|
@@ -50,6 +69,11 @@ const app = createApp({
|
|
|
50
69
|
? h(SandboxVue3, {
|
|
51
70
|
story: this.story,
|
|
52
71
|
variant: this.variant,
|
|
72
|
+
onReady: () => {
|
|
73
|
+
window.parent?.postMessage({
|
|
74
|
+
type: SANDBOX_READY,
|
|
75
|
+
})
|
|
76
|
+
},
|
|
53
77
|
})
|
|
54
78
|
: null,
|
|
55
79
|
]
|
|
@@ -58,3 +82,13 @@ const app = createApp({
|
|
|
58
82
|
app.use(createPinia())
|
|
59
83
|
registerGlobalComponents(app)
|
|
60
84
|
app.mount('#app')
|
|
85
|
+
|
|
86
|
+
watch(isDark, value => {
|
|
87
|
+
if (value) {
|
|
88
|
+
document.documentElement.classList.add(histoireConfig.sandboxDarkClass)
|
|
89
|
+
} else {
|
|
90
|
+
document.documentElement.classList.remove(histoireConfig.sandboxDarkClass)
|
|
91
|
+
}
|
|
92
|
+
}, {
|
|
93
|
+
immediate: true,
|
|
94
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineStore } from 'pinia'
|
|
2
|
-
import { computed, ref } from 'vue'
|
|
2
|
+
import { computed, reactive, ref, watch } from 'vue'
|
|
3
3
|
import { router } from '../router'
|
|
4
4
|
import { Story } from '../types'
|
|
5
5
|
|
|
@@ -13,10 +13,46 @@ export const useStoryStore = defineStore('story', () => {
|
|
|
13
13
|
|
|
14
14
|
const currentVariant = computed(() => currentStory.value?.variants.find(v => v.id === router.currentRoute.value.query.variantId))
|
|
15
15
|
|
|
16
|
+
const openedFolders = ref(new Map() as Map<string, boolean>)
|
|
17
|
+
|
|
18
|
+
function getStringPath (path: Array<string>) {
|
|
19
|
+
return path.join('␜')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function toggleFolder (path: Array<string>, force?: boolean) {
|
|
23
|
+
const stringPath = getStringPath(path)
|
|
24
|
+
|
|
25
|
+
if (force === undefined) {
|
|
26
|
+
force = !openedFolders.value.get(stringPath)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (force) {
|
|
30
|
+
openedFolders.value.set(stringPath, true)
|
|
31
|
+
} else {
|
|
32
|
+
openedFolders.value.delete(stringPath)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isFolderOpened (path: Array<string>) {
|
|
37
|
+
return openedFolders.value.get(getStringPath(path))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function openFileFolders (path: Array<string>) {
|
|
41
|
+
for (let pathLength = 1; pathLength < path.length; pathLength++) {
|
|
42
|
+
toggleFolder(path.slice(0, pathLength), true)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
watch(currentStory, () => {
|
|
47
|
+
openFileFolders(currentStory.value.file.path)
|
|
48
|
+
})
|
|
49
|
+
|
|
16
50
|
return {
|
|
17
51
|
stories,
|
|
18
52
|
setStories,
|
|
19
53
|
currentStory,
|
|
20
54
|
currentVariant,
|
|
55
|
+
isFolderOpened,
|
|
56
|
+
toggleFolder,
|
|
21
57
|
}
|
|
22
58
|
})
|
|
@@ -1 +1,32 @@
|
|
|
1
1
|
/* @TODO custom themes */
|
|
2
|
+
|
|
3
|
+
.v-popper {
|
|
4
|
+
line-height: 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.v-popper--theme-dropdown {
|
|
8
|
+
.htw-dark & {
|
|
9
|
+
.v-popper__inner {
|
|
10
|
+
@apply htw-bg-gray-700 htw-border-gray-850 htw-text-gray-100;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.v-popper__arrow-inner {
|
|
14
|
+
@apply htw-border-gray-700;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.v-popper__arrow-outer {
|
|
18
|
+
@apply htw-border-gray-850;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&.v-popper__popper--show-from .v-popper__wrapper {
|
|
23
|
+
transform: scale(.75);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
&.v-popper__popper--show-to .v-popper__wrapper {
|
|
27
|
+
transform: none;
|
|
28
|
+
transition: transform .15s cubic-bezier(0, 1, .5, 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
@import url('https://fonts.googleapis.com/css2?family=Lato&display=swap');
|
|
2
2
|
@import 'floating-vue/dist/style.css';
|
|
3
3
|
@import 'floating-vue.css';
|
|
4
|
+
@import 'transitions.css';
|
|
4
5
|
|
|
5
6
|
*,
|
|
6
7
|
::before,
|
|
@@ -12,7 +13,8 @@
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
a,
|
|
15
|
-
input
|
|
16
|
+
input,
|
|
17
|
+
button {
|
|
16
18
|
color: inherit;
|
|
17
19
|
}
|
|
18
20
|
|
|
@@ -49,3 +51,17 @@ body,
|
|
|
49
51
|
.__histoire-sandbox {
|
|
50
52
|
contain: content;
|
|
51
53
|
}
|
|
54
|
+
|
|
55
|
+
.__histoire-code .shiki {
|
|
56
|
+
background: transparent !important;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.htw-prose {
|
|
60
|
+
h1, h2, h3, h4 {
|
|
61
|
+
&:not(:hover) {
|
|
62
|
+
.header-anchor[aria-hidden="true"] {
|
|
63
|
+
visibility: hidden;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/client/app/types.ts
CHANGED
|
@@ -21,8 +21,12 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
|
|
|
21
21
|
if (existingVariant.state) Object.assign(variant.state, existingVariant.state)
|
|
22
22
|
if (existingVariant.initState) variant.initState = existingVariant.initState
|
|
23
23
|
if (existingVariant.slots) variant.slots = existingVariant.slots
|
|
24
|
+
if (existingVariant.ready) variant.ready = existingVariant.ready
|
|
24
25
|
}
|
|
25
26
|
}
|
|
27
|
+
if (existingFile.story.lastSelectedVariant) {
|
|
28
|
+
result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id)
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
return result
|
|
@@ -34,5 +38,6 @@ export function mapVariant (variant: Variant): Variant {
|
|
|
34
38
|
state: {},
|
|
35
39
|
initState: null,
|
|
36
40
|
slots: () => ({}),
|
|
41
|
+
ready: false,
|
|
37
42
|
}
|
|
38
43
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useStorage } from '@vueuse/core'
|
|
2
|
+
import { reactive } from 'vue'
|
|
3
|
+
|
|
4
|
+
export interface PreviewSettings {
|
|
5
|
+
responsiveWidth: number
|
|
6
|
+
responsiveHeight: number
|
|
7
|
+
rotate: boolean
|
|
8
|
+
backgroundColor: string
|
|
9
|
+
checkerboard: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function usePreviewSettings () {
|
|
13
|
+
return useStorage<PreviewSettings>('_histoire-sandbox-settings-v1', {
|
|
14
|
+
responsiveWidth: 720,
|
|
15
|
+
responsiveHeight: null,
|
|
16
|
+
rotate: false,
|
|
17
|
+
backgroundColor: 'transparent',
|
|
18
|
+
checkerboard: false,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const receivedSettings = reactive<PreviewSettings>({} as PreviewSettings)
|
|
23
|
+
|
|
24
|
+
export function applyPreviewSettings (settings: PreviewSettings) {
|
|
25
|
+
Object.assign(receivedSettings, settings)
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { unref, isRef } from 'vue'
|
|
2
|
+
|
|
3
|
+
const isObject = (val) => val !== null && typeof val === 'object'
|
|
4
|
+
|
|
5
|
+
export function toRawDeep (val) {
|
|
6
|
+
const unwrappedValue = isRef(val) ? unref(val) : val
|
|
7
|
+
|
|
8
|
+
if (!isObject(unwrappedValue)) {
|
|
9
|
+
return unwrappedValue
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (Array.isArray(unwrappedValue)) {
|
|
13
|
+
return unwrappedValue.map(toRawDeep)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return toRawObject(unwrappedValue)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const toRawObject = (obj: Record<any, any>) => Object.keys(obj).reduce((raw, key) => {
|
|
20
|
+
raw[key] = toRawDeep(obj[key])
|
|
21
|
+
return raw
|
|
22
|
+
}, {})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { watch, onMounted, Ref } from 'vue'
|
|
2
|
+
import scrollIntoView from 'scroll-into-view-if-needed'
|
|
3
|
+
|
|
4
|
+
export function useScrollOnActive (active: Ref<boolean>, el: Ref<HTMLElement>) {
|
|
5
|
+
watch(active, value => {
|
|
6
|
+
if (value) {
|
|
7
|
+
autoScroll()
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
function autoScroll () {
|
|
12
|
+
if (el.value) {
|
|
13
|
+
scrollIntoView(el.value, {
|
|
14
|
+
scrollMode: 'if-needed',
|
|
15
|
+
block: 'center',
|
|
16
|
+
inline: 'nearest',
|
|
17
|
+
behavior: 'smooth',
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
onMounted(() => {
|
|
23
|
+
if (active.value) {
|
|
24
|
+
autoScroll()
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
}
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { defineComponent, inject, PropType, provide, useAttrs } from 'vue'
|
|
2
|
+
import { defineComponent, inject, onMounted, PropType, provide, useAttrs } from 'vue'
|
|
3
3
|
import type { StoryFile, Story, Variant } from '../../node/types'
|
|
4
4
|
|
|
5
5
|
export default defineComponent({
|
|
@@ -53,13 +53,36 @@ export default defineComponent({
|
|
|
53
53
|
story.variants.push(variant)
|
|
54
54
|
})
|
|
55
55
|
|
|
56
|
+
onMounted(() => {
|
|
57
|
+
if (!story.variants.length) {
|
|
58
|
+
story.variants.push({
|
|
59
|
+
id: '_default',
|
|
60
|
+
title: 'default',
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
56
65
|
return {
|
|
57
66
|
story,
|
|
58
67
|
}
|
|
59
68
|
},
|
|
60
69
|
|
|
61
70
|
render () {
|
|
62
|
-
|
|
71
|
+
let suppressError = false
|
|
72
|
+
try {
|
|
73
|
+
return this.$slots.default({
|
|
74
|
+
get state () {
|
|
75
|
+
// No variant tags
|
|
76
|
+
suppressError = true
|
|
77
|
+
return {}
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
} catch (e) {
|
|
81
|
+
if (!suppressError) {
|
|
82
|
+
console.error(e)
|
|
83
|
+
}
|
|
84
|
+
return null
|
|
85
|
+
}
|
|
63
86
|
},
|
|
64
87
|
})
|
|
65
88
|
</script>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createApp, h } from 'vue'
|
|
2
|
+
import { registerVueComponents } from '@histoire/controls'
|
|
2
3
|
import type { StoryFile } from '../../node/types'
|
|
3
4
|
import Story from './Story.server.vue'
|
|
4
5
|
import Variant from './Variant.server.vue'
|
|
@@ -24,6 +25,8 @@ export async function run (file: StoryFile, storyData, el) {
|
|
|
24
25
|
// eslint-disable-next-line vue/multi-word-component-names
|
|
25
26
|
app.component('Variant', Variant)
|
|
26
27
|
|
|
28
|
+
registerVueComponents(app)
|
|
29
|
+
|
|
27
30
|
app.mount(el)
|
|
28
31
|
app.unmount()
|
|
29
32
|
}
|
package/src/controls.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@histoire/controls'
|
package/src/node/build.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { join } from 'pathe'
|
|
2
|
-
import { build as viteBuild, createServer as createViteServer
|
|
2
|
+
import { build as viteBuild, createServer as createViteServer } from 'vite'
|
|
3
3
|
import fs from 'fs-extra'
|
|
4
4
|
import { lookup as lookupMime } from 'mrmime'
|
|
5
|
+
import pc from 'picocolors'
|
|
6
|
+
import { performance } from 'perf_hooks'
|
|
5
7
|
import { APP_PATH } from './alias.js'
|
|
6
8
|
import { Context } from './context.js'
|
|
7
9
|
import { createVitePlugins } from './plugin.js'
|
|
@@ -10,17 +12,12 @@ import type { RollupOutput } from 'rollup'
|
|
|
10
12
|
import { useCollectStories } from './collect.js'
|
|
11
13
|
|
|
12
14
|
export async function build (ctx: Context) {
|
|
15
|
+
const startTime = performance.now()
|
|
13
16
|
await findAllStories(ctx)
|
|
14
17
|
|
|
15
18
|
// Collect story data
|
|
16
|
-
const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build')
|
|
17
|
-
const plugins: VitePlugin[] = []
|
|
18
|
-
const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue')
|
|
19
|
-
if (!hasVuePlugin) {
|
|
20
|
-
plugins.push((await import('@vitejs/plugin-vue')).default())
|
|
21
|
-
}
|
|
22
19
|
const server = await createViteServer({
|
|
23
|
-
plugins,
|
|
20
|
+
plugins: await createVitePlugins(ctx),
|
|
24
21
|
})
|
|
25
22
|
await server.pluginContainer.buildStart({})
|
|
26
23
|
const { executeStoryFile, destroy: destroyCollectStories } = useCollectStories({
|
|
@@ -33,6 +30,10 @@ export async function build (ctx: Context) {
|
|
|
33
30
|
await server.close()
|
|
34
31
|
await destroyCollectStories()
|
|
35
32
|
|
|
33
|
+
const storyCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ? 1 : 0), 0)
|
|
34
|
+
const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0)
|
|
35
|
+
const emptyStoryCount = ctx.storyFiles.length - storyCount
|
|
36
|
+
|
|
36
37
|
const results = await viteBuild({
|
|
37
38
|
plugins: await createVitePlugins(ctx),
|
|
38
39
|
build: {
|
|
@@ -58,6 +59,12 @@ export async function build (ctx: Context) {
|
|
|
58
59
|
// Sandbox
|
|
59
60
|
const sandboxOutput = result.output.find(o => o.name === 'sandbox' && o.type === 'chunk')
|
|
60
61
|
await writeHtml(sandboxOutput.fileName, styleOutput.fileName, '__sandbox.html', ctx)
|
|
62
|
+
|
|
63
|
+
const duration = performance.now() - startTime
|
|
64
|
+
if (emptyStoryCount) {
|
|
65
|
+
console.warn(pc.yellow(`⚠️ ${emptyStoryCount} empty story file`))
|
|
66
|
+
}
|
|
67
|
+
console.log(pc.green(`✅ Built ${storyCount} stories (${variantCount} variants) in ${Math.round(duration / 1000 * 100) / 100}s`))
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
async function writeHtml (jsEntryFile: string, cssEntryFile: string, htmlFileName: string, ctx: Context) {
|
package/src/node/collect.ts
CHANGED
|
@@ -20,7 +20,13 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
|
|
|
20
20
|
const { server } = options
|
|
21
21
|
const { destroy: destroyDomEnv } = createDomEnv()
|
|
22
22
|
|
|
23
|
-
const node = new ViteNodeServer(server
|
|
23
|
+
const node = new ViteNodeServer(server, {
|
|
24
|
+
deps: {
|
|
25
|
+
inline: [
|
|
26
|
+
/histoire\/dist/,
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
})
|
|
24
30
|
const runner = new ViteNodeRunner({
|
|
25
31
|
root: server.config.root,
|
|
26
32
|
base: server.config.base,
|
|
@@ -31,6 +37,9 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
|
|
|
31
37
|
}
|
|
32
38
|
return node.fetchModule(id)
|
|
33
39
|
},
|
|
40
|
+
resolveId (id, importer) {
|
|
41
|
+
return node.resolveId(id, importer)
|
|
42
|
+
},
|
|
34
43
|
})
|
|
35
44
|
|
|
36
45
|
function clearCache () {
|
|
@@ -46,10 +55,10 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
|
|
|
46
55
|
const storyData: Story[] = []
|
|
47
56
|
await run(storyFile, storyData, el)
|
|
48
57
|
if (storyData.length === 0) {
|
|
49
|
-
console.warn(pc.yellow(
|
|
58
|
+
console.warn(pc.yellow(`⚠️ No story found for ${storyFile.path}`))
|
|
50
59
|
return
|
|
51
60
|
} else if (storyData.length > 1) {
|
|
52
|
-
console.warn(pc.yellow(
|
|
61
|
+
console.warn(pc.yellow(`⚠️ Multiple stories not supported: ${storyFile.path}`))
|
|
53
62
|
}
|
|
54
63
|
storyFile.story = storyData[0]
|
|
55
64
|
const file: TreeFile = {
|
package/src/node/colors.ts
CHANGED
|
@@ -8,8 +8,11 @@ export const defaultColors = {
|
|
|
8
8
|
500: '#64748b',
|
|
9
9
|
600: '#475569',
|
|
10
10
|
700: '#334155',
|
|
11
|
+
750: '#283548',
|
|
11
12
|
800: '#1e293b',
|
|
13
|
+
850: '#151f32',
|
|
12
14
|
900: '#0f172a',
|
|
15
|
+
950: '#09101f',
|
|
13
16
|
},
|
|
14
17
|
gray: {
|
|
15
18
|
50: '#f9fafb',
|
|
@@ -20,8 +23,11 @@ export const defaultColors = {
|
|
|
20
23
|
500: '#6b7280',
|
|
21
24
|
600: '#4b5563',
|
|
22
25
|
700: '#374151',
|
|
26
|
+
750: '#2b3546',
|
|
23
27
|
800: '#1f2937',
|
|
28
|
+
850: '#18212f',
|
|
24
29
|
900: '#111827',
|
|
30
|
+
950: '#0c101d',
|
|
25
31
|
},
|
|
26
32
|
zinc: {
|
|
27
33
|
50: '#fafafa',
|
|
@@ -47,8 +53,11 @@ export const defaultColors = {
|
|
|
47
53
|
500: '#737373',
|
|
48
54
|
600: '#525252',
|
|
49
55
|
700: '#404040',
|
|
56
|
+
750: '#333333',
|
|
50
57
|
800: '#262626',
|
|
58
|
+
850: '#1f1f1f',
|
|
51
59
|
900: '#171717',
|
|
60
|
+
950: '#0f0f0f',
|
|
52
61
|
},
|
|
53
62
|
stone: {
|
|
54
63
|
50: '#fafaf9',
|
|
@@ -59,8 +68,11 @@ export const defaultColors = {
|
|
|
59
68
|
500: '#78716c',
|
|
60
69
|
600: '#57534e',
|
|
61
70
|
700: '#44403c',
|
|
71
|
+
750: '#363230',
|
|
62
72
|
800: '#292524',
|
|
73
|
+
850: '#211e1c',
|
|
63
74
|
900: '#1c1917',
|
|
75
|
+
950: '#171412',
|
|
64
76
|
},
|
|
65
77
|
red: {
|
|
66
78
|
50: '#fef2f2',
|
package/src/node/commands/dev.ts
CHANGED
|
@@ -1,14 +1,58 @@
|
|
|
1
|
+
import { resolveConfigFile } from '../config.js'
|
|
1
2
|
import { createContext } from '../context.js'
|
|
2
3
|
import { createServer } from '../server.js'
|
|
4
|
+
import chokidar from 'chokidar'
|
|
5
|
+
import pc from 'picocolors'
|
|
3
6
|
|
|
4
7
|
export interface DevOptions {
|
|
5
8
|
port: number
|
|
6
9
|
}
|
|
7
10
|
|
|
8
11
|
export async function devCommand (options: DevOptions) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
let stop: () => Promise<void>
|
|
13
|
+
|
|
14
|
+
async function start () {
|
|
15
|
+
const ctx = await createContext({
|
|
16
|
+
mode: 'dev',
|
|
17
|
+
})
|
|
18
|
+
const { server, close } = await createServer(ctx, options.port)
|
|
19
|
+
server.printUrls()
|
|
20
|
+
|
|
21
|
+
// Histoire config watcher
|
|
22
|
+
let watcher: chokidar.FSWatcher
|
|
23
|
+
if (server.config.configFile) {
|
|
24
|
+
watcher = chokidar.watch(server.config.configFile, {
|
|
25
|
+
ignoreInitial: true,
|
|
26
|
+
})
|
|
27
|
+
watcher.on('change', () => {
|
|
28
|
+
restart('Vite')
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return async () => {
|
|
33
|
+
await watcher?.close()
|
|
34
|
+
await close()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function restart (source: string) {
|
|
39
|
+
if (stop) {
|
|
40
|
+
console.log(pc.blue(`${source} config changed, restarting...`))
|
|
41
|
+
stop()
|
|
42
|
+
stop = null // Don't call stop again until new start() is done
|
|
43
|
+
stop = await start()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
stop = await start()
|
|
48
|
+
|
|
49
|
+
const configFile = await resolveConfigFile()
|
|
50
|
+
if (configFile) {
|
|
51
|
+
const watcher = chokidar.watch(configFile, {
|
|
52
|
+
ignoreInitial: true,
|
|
53
|
+
})
|
|
54
|
+
watcher.on('change', () => {
|
|
55
|
+
restart('Histoire')
|
|
56
|
+
})
|
|
57
|
+
}
|
|
14
58
|
}
|