histoire 0.0.2 → 0.0.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/README.md +11 -0
- package/dist/client/app/App.vue +8 -8
- package/dist/client/app/codegen/vue3.js +28 -4
- 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/dist/client/app/components/{StoryControls.vue → 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/{src/client/app/components → dist/client/app/components/story}/StoryListFolder.vue +5 -5
- package/{src/client/app/components → dist/client/app/components/story}/StoryListItem.vue +11 -6
- package/dist/client/app/components/story/StoryResponsivePreview.vue +214 -0
- package/dist/client/app/components/{StorySourceCode.vue → 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 -0
- package/dist/client/app/global-components.ts +3 -0
- package/dist/client/app/index.js +10 -0
- package/dist/client/app/index.ts +10 -0
- package/dist/client/app/router.js +1 -1
- package/dist/client/app/router.ts +1 -1
- package/dist/client/app/sandbox.js +37 -3
- package/dist/client/app/sandbox.ts +37 -3
- package/dist/client/app/stores/story.d.ts +15 -0
- 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.ts +1 -0
- package/dist/client/app/util/const.d.ts +2 -0
- package/dist/client/app/util/const.js +2 -0
- package/dist/client/app/util/const.ts +2 -0
- package/dist/client/app/util/mapping.js +6 -0
- 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/{composable → util}/variant.d.ts +0 -0
- package/dist/client/app/{composable → util}/variant.js +0 -0
- package/dist/client/app/{composable → util}/variant.ts +0 -0
- package/dist/client/server/Story.server.vue +25 -2
- package/dist/client/server/index.js +2 -0
- package/dist/client/server/index.ts +3 -0
- package/dist/controls.d.ts +1 -0
- package/dist/controls.js +1 -0
- package/dist/node/build.js +36 -11
- package/dist/node/collect.js +12 -3
- package/dist/node/commands/dev.js +43 -5
- package/dist/node/config.d.ts +35 -0
- package/dist/node/config.js +75 -1
- package/dist/node/markdown.d.ts +2 -0
- package/dist/node/markdown.js +48 -0
- package/dist/node/plugin.js +35 -0
- package/dist/node/util/slugify.d.ts +1 -0
- package/dist/node/util/slugify.js +22 -0
- package/dist/style.css +869 -159
- package/package.json +15 -6
- 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/src/client/app/components/{StoryControls.vue → 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/{dist/client/app/components → src/client/app/components/story}/StoryListFolder.vue +5 -5
- package/{dist/client/app/components → src/client/app/components/story}/StoryListItem.vue +11 -6
- package/src/client/app/components/story/StoryResponsivePreview.vue +214 -0
- package/src/client/app/components/{StorySourceCode.vue → 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/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 +43 -11
- package/src/node/collect.ts +12 -3
- 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/util/slugify.ts +26 -0
- package/tailwind.config.cjs +79 -4
- package/dist/client/app/components/StoryVariantSingleView.vue +0 -145
- package/src/client/app/components/StoryVariantSingleView.vue +0 -145
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed, Ref, ref, toRaw, toRefs, watch } from 'vue'
|
|
3
|
+
import { useEventListener } from '@vueuse/core'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
import { STATE_SYNC, PREVIEW_SETTINGS_SYNC, SANDBOX_READY } from '../../util/const'
|
|
6
|
+
import { PreviewSettings } from '../../util/preview-settings'
|
|
7
|
+
import type { Story, Variant } from '../../types'
|
|
8
|
+
import HatchedPattern from '../misc/HatchedPattern.vue'
|
|
9
|
+
import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
|
|
10
|
+
import { toRawDeep } from '../../util/reactivity'
|
|
11
|
+
|
|
12
|
+
const props = defineProps<{
|
|
13
|
+
story: Story
|
|
14
|
+
variant: Variant
|
|
15
|
+
settings: PreviewSettings
|
|
16
|
+
}>()
|
|
17
|
+
|
|
18
|
+
// Iframe
|
|
19
|
+
|
|
20
|
+
const iframe = ref<HTMLIFrameElement>()
|
|
21
|
+
|
|
22
|
+
function syncState () {
|
|
23
|
+
if (iframe.value && props.variant.ready) {
|
|
24
|
+
iframe.value.contentWindow.postMessage({
|
|
25
|
+
type: STATE_SYNC,
|
|
26
|
+
state: toRawDeep(props.variant.state),
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let synced = false
|
|
32
|
+
|
|
33
|
+
watch(() => props.variant.state, () => {
|
|
34
|
+
if (synced) {
|
|
35
|
+
synced = false
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
syncState()
|
|
39
|
+
}, {
|
|
40
|
+
deep: true,
|
|
41
|
+
immediate: true,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
Object.assign(props.variant, {
|
|
45
|
+
ready: false,
|
|
46
|
+
})
|
|
47
|
+
useEventListener(window, 'message', (event) => {
|
|
48
|
+
if (event.data.type === STATE_SYNC) {
|
|
49
|
+
synced = true
|
|
50
|
+
Object.assign(props.variant.state, event.data.state)
|
|
51
|
+
} else if (event.data.type === SANDBOX_READY) {
|
|
52
|
+
Object.assign(props.variant, {
|
|
53
|
+
ready: true,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const sandboxUrl = computed(() => {
|
|
59
|
+
const url = new URLSearchParams()
|
|
60
|
+
url.append('storyId', props.story.id)
|
|
61
|
+
url.append('variantId', props.variant.id)
|
|
62
|
+
return '/__sandbox?' + url.toString()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const isIframeLoaded = ref(false)
|
|
66
|
+
|
|
67
|
+
watch(sandboxUrl, () => {
|
|
68
|
+
isIframeLoaded.value = false
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
// Settings
|
|
72
|
+
|
|
73
|
+
function syncSettings () {
|
|
74
|
+
if (iframe.value) {
|
|
75
|
+
iframe.value.contentWindow.postMessage({
|
|
76
|
+
type: PREVIEW_SETTINGS_SYNC,
|
|
77
|
+
settings: toRaw(props.settings),
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
watch(() => props.settings, value => {
|
|
83
|
+
syncSettings()
|
|
84
|
+
}, {
|
|
85
|
+
deep: true,
|
|
86
|
+
immediate: true,
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// Iframe load
|
|
90
|
+
|
|
91
|
+
function onIframeLoad () {
|
|
92
|
+
isIframeLoaded.value = true
|
|
93
|
+
syncState()
|
|
94
|
+
syncSettings()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Resize
|
|
98
|
+
|
|
99
|
+
const resizing = ref(false)
|
|
100
|
+
|
|
101
|
+
function useDragger (el: Ref<HTMLDivElement>, value: Ref<number>, min: number, max: number, axis: 'x' | 'y') {
|
|
102
|
+
const onMouseDown = (event: MouseEvent) => {
|
|
103
|
+
event.preventDefault()
|
|
104
|
+
event.stopPropagation()
|
|
105
|
+
const start = axis === 'x' ? event.clientX : event.clientY
|
|
106
|
+
const startValue = value.value || (axis === 'x' ? iframe.value.offsetWidth : iframe.value.offsetHeight)
|
|
107
|
+
resizing.value = true
|
|
108
|
+
const onMouseMove = (event: MouseEvent) => {
|
|
109
|
+
const delta = (axis === 'x' ? event.clientX : event.clientY) - start
|
|
110
|
+
value.value = Math.max(min, Math.min(max, startValue + delta))
|
|
111
|
+
}
|
|
112
|
+
const onMouseUp = () => {
|
|
113
|
+
window.removeEventListener('mousemove', onMouseMove)
|
|
114
|
+
window.removeEventListener('mouseup', onMouseUp)
|
|
115
|
+
resizing.value = false
|
|
116
|
+
}
|
|
117
|
+
window.addEventListener('mousemove', onMouseMove)
|
|
118
|
+
window.addEventListener('mouseup', onMouseUp)
|
|
119
|
+
}
|
|
120
|
+
useEventListener(el, 'mousedown', onMouseDown)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const { responsiveWidth, responsiveHeight } = toRefs(props.settings)
|
|
124
|
+
|
|
125
|
+
const horizontalDragger = ref<HTMLDivElement>()
|
|
126
|
+
const verticalDragger = ref<HTMLDivElement>()
|
|
127
|
+
const cornerDragger = ref<HTMLDivElement>()
|
|
128
|
+
|
|
129
|
+
useDragger(horizontalDragger, responsiveWidth, 10, 20000, 'x')
|
|
130
|
+
useDragger(verticalDragger, responsiveHeight, 10, 20000, 'y')
|
|
131
|
+
useDragger(cornerDragger, responsiveWidth, 10, 20000, 'x')
|
|
132
|
+
useDragger(cornerDragger, responsiveHeight, 10, 20000, 'y')
|
|
133
|
+
|
|
134
|
+
// Handle rotate
|
|
135
|
+
|
|
136
|
+
const finalWidth = computed(() => props.settings.rotate ? props.settings.responsiveHeight : props.settings.responsiveWidth)
|
|
137
|
+
const finalHeight = computed(() => props.settings.rotate ? props.settings.responsiveWidth : props.settings.responsiveHeight)
|
|
138
|
+
</script>
|
|
139
|
+
|
|
140
|
+
<template>
|
|
141
|
+
<div class="htw-w-full htw-h-full htw-flex-1 htw-border htw-border-gray-100 dark:htw-border-gray-800 htw-rounded-lg htw-relative htw-overflow-hidden">
|
|
142
|
+
<div class="htw-absolute htw-inset-0 htw-w-full htw-h-full htw-bg-gray-200 dark:htw-bg-gray-850 htw-rounded-r-lg htw-border-l-2 htw-border-gray-500/10 dark:htw-border-gray-700/30 htw-overflow-hidden">
|
|
143
|
+
<HatchedPattern
|
|
144
|
+
class="htw-w-full htw-h-full htw-text-black/[2%] dark:htw-text-white/[2%]"
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
<div class="htw-h-full htw-overflow-auto htw-relative">
|
|
149
|
+
<div
|
|
150
|
+
class="htw-h-full htw-p-4 htw-overflow-hidden htw-bg-white dark:htw-bg-gray-700 htw-rounded-lg htw-relative"
|
|
151
|
+
:style="{
|
|
152
|
+
width: finalWidth ? `${finalWidth + 44}px` : null,
|
|
153
|
+
height: finalHeight ? `${finalHeight + 44}px` : null,
|
|
154
|
+
}"
|
|
155
|
+
>
|
|
156
|
+
<div class="htw-p-4 htw-h-full htw-relative">
|
|
157
|
+
<div class="htw-w-full htw-h-full htw-border htw-border-gray-100 dark:htw-border-gray-800 htw-rounded-sm htw-relative">
|
|
158
|
+
<div class="bind-preview-bg htw-absolute htw-inset-0" />
|
|
159
|
+
|
|
160
|
+
<CheckerboardPattern
|
|
161
|
+
v-if="settings.checkerboard"
|
|
162
|
+
class="htw-absolute htw-inset-0 htw-w-full htw-h-full htw-text-gray-500/20"
|
|
163
|
+
/>
|
|
164
|
+
|
|
165
|
+
<iframe
|
|
166
|
+
ref="iframe"
|
|
167
|
+
:src="sandboxUrl"
|
|
168
|
+
class="htw-w-full htw-h-full htw-relative"
|
|
169
|
+
:class="{
|
|
170
|
+
'htw-invisible': !isIframeLoaded,
|
|
171
|
+
'htw-pointer-events-none': resizing,
|
|
172
|
+
}"
|
|
173
|
+
@load="onIframeLoad()"
|
|
174
|
+
/>
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
<!-- Markers -->
|
|
178
|
+
<div class="htw-absolute htw-top-1 htw-left-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
|
|
179
|
+
<div class="htw-absolute htw-top-1 htw-right-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
|
|
180
|
+
<div class="htw-absolute htw-bottom-1 htw-left-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
|
|
181
|
+
<div class="htw-absolute htw-bottom-1 htw-right-4 htw-h-2 htw-w-px htw-bg-gray-200 dark:htw-bg-gray-800" />
|
|
182
|
+
<div class="htw-absolute htw-left-1 htw-top-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
|
|
183
|
+
<div class="htw-absolute htw-left-1 htw-bottom-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
|
|
184
|
+
<div class="htw-absolute htw-right-1 htw-top-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
|
|
185
|
+
<div class="htw-absolute htw-right-1 htw-bottom-4 htw-w-2 htw-h-px htw-bg-gray-200 dark:htw-bg-gray-800" />
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
<!-- Resize Dragger -->
|
|
189
|
+
<div
|
|
190
|
+
ref="horizontalDragger"
|
|
191
|
+
class="htw-absolute htw-w-4 htw-top-0 htw-bottom-4 htw-right-0 hover:htw-bg-primary-100 dark:hover:htw-bg-primary-800 htw-flex htw-items-center htw-justify-center htw-cursor-ew-resize htw-group hover:htw-text-primary-500"
|
|
192
|
+
>
|
|
193
|
+
<Icon
|
|
194
|
+
icon="mdi:drag-vertical-variant"
|
|
195
|
+
class="htw-w-4 htw-h-4 htw-opacity-20 group-hover:htw-opacity-90"
|
|
196
|
+
/>
|
|
197
|
+
</div>
|
|
198
|
+
<div
|
|
199
|
+
ref="verticalDragger"
|
|
200
|
+
class="htw-absolute htw-h-4 htw-left-0 htw-right-4 htw-bottom-0 hover:htw-bg-primary-100 dark:hover:htw-bg-primary-800 htw-flex htw-items-center htw-justify-center htw-cursor-ns-resize htw-group hover:htw-text-primary-500"
|
|
201
|
+
>
|
|
202
|
+
<Icon
|
|
203
|
+
icon="mdi:drag-horizontal-variant"
|
|
204
|
+
class="htw-w-4 htw-h-4 htw-opacity-20 group-hover:htw-opacity-90"
|
|
205
|
+
/>
|
|
206
|
+
</div>
|
|
207
|
+
<div
|
|
208
|
+
ref="cornerDragger"
|
|
209
|
+
class="htw-absolute htw-w-4 htw-h-4 htw-right-0 htw-bottom-0 hover:htw-bg-primary-100 dark:hover:htw-bg-primary-800 htw-flex htw-items-center htw-justify-center htw-cursor-nwse-resize htw-group hover:htw-text-primary-500"
|
|
210
|
+
/>
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
</template>
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { computed, onMounted, PropType, ref, shallowRef, watch } from 'vue'
|
|
3
3
|
import { getHighlighter, Highlighter, setCDN } from 'shiki'
|
|
4
4
|
import { Icon } from '@iconify/vue'
|
|
5
|
-
import { generateSourceCode } from '
|
|
6
|
-
import { Variant } from '
|
|
7
|
-
import { isDark } from '
|
|
8
|
-
import { unindent } from '
|
|
5
|
+
import { generateSourceCode } from '../../codegen/vue3'
|
|
6
|
+
import type { Variant } from '../../types'
|
|
7
|
+
import { isDark } from '../../util/dark'
|
|
8
|
+
import { unindent } from '../../codegen/util'
|
|
9
9
|
import { useClipboard } from '@vueuse/core'
|
|
10
10
|
|
|
11
11
|
const props = defineProps({
|
|
@@ -114,8 +114,4 @@ const copySourceCode = () => copy(sourceCode.value)
|
|
|
114
114
|
color: inherit;
|
|
115
115
|
font-size: inherit;
|
|
116
116
|
}
|
|
117
|
-
|
|
118
|
-
.__histoire-code:deep(.shiki) {
|
|
119
|
-
background: transparent !important;
|
|
120
|
-
}
|
|
121
117
|
</style>
|
package/{dist/client/app/components → src/client/app/components/story}/StoryVariantGridItem.vue
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import {
|
|
3
|
-
import { useCurrentVariantRoute } from '
|
|
4
|
-
import { Story, Variant } from '
|
|
5
|
-
import SandboxVue3 from '
|
|
2
|
+
import { PropType, toRefs } from 'vue'
|
|
3
|
+
import { useCurrentVariantRoute } from '../../util/variant'
|
|
4
|
+
import type { Story, Variant } from '../../types'
|
|
5
|
+
import SandboxVue3 from '../sandbox/SandboxVue3.vue'
|
|
6
6
|
import { Icon } from '@iconify/vue'
|
|
7
7
|
|
|
8
8
|
const props = defineProps({
|
|
@@ -20,7 +20,14 @@ const props = defineProps({
|
|
|
20
20
|
const { variant } = toRefs(props)
|
|
21
21
|
const { isActive, targetRoute } = useCurrentVariantRoute(variant)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Object.assign(props.variant, {
|
|
24
|
+
ready: false,
|
|
25
|
+
})
|
|
26
|
+
function onReady () {
|
|
27
|
+
Object.assign(props.variant, {
|
|
28
|
+
ready: true,
|
|
29
|
+
})
|
|
30
|
+
}
|
|
24
31
|
</script>
|
|
25
32
|
|
|
26
33
|
<template>
|
|
@@ -59,6 +66,7 @@ const iconColor = computed(() => props.variant.iconColor)
|
|
|
59
66
|
<SandboxVue3
|
|
60
67
|
:variant="variant"
|
|
61
68
|
:story="story"
|
|
69
|
+
@ready="onReady"
|
|
62
70
|
/>
|
|
63
71
|
</div>
|
|
64
72
|
</div>
|
|
@@ -66,6 +74,6 @@ const iconColor = computed(() => props.variant.iconColor)
|
|
|
66
74
|
|
|
67
75
|
<style scoped>
|
|
68
76
|
.bind-icon-color {
|
|
69
|
-
color: v-bind(iconColor);
|
|
77
|
+
color: v-bind('variant.iconColor');
|
|
70
78
|
}
|
|
71
79
|
</style>
|
package/src/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue}
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import {
|
|
3
|
-
import { useCurrentVariantRoute } from '
|
|
4
|
-
import { Variant } from '
|
|
5
|
-
import BaseListItemLink from '
|
|
2
|
+
import { PropType, ref, toRefs } from 'vue'
|
|
3
|
+
import { useCurrentVariantRoute } from '../../util/variant'
|
|
4
|
+
import type { Variant } from '../../types'
|
|
5
|
+
import BaseListItemLink from '../base/BaseListItemLink.vue'
|
|
6
6
|
import { Icon } from '@iconify/vue'
|
|
7
|
+
import { useScrollOnActive } from '../../util/scroll.js'
|
|
7
8
|
|
|
8
9
|
const props = defineProps({
|
|
9
10
|
variant: {
|
|
@@ -14,12 +15,12 @@ const props = defineProps({
|
|
|
14
15
|
|
|
15
16
|
const { variant } = toRefs(props)
|
|
16
17
|
const { isActive, targetRoute } = useCurrentVariantRoute(variant)
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const el = ref<HTMLDivElement>()
|
|
19
|
+
useScrollOnActive(isActive, el)
|
|
19
20
|
</script>
|
|
20
21
|
|
|
21
22
|
<template>
|
|
22
|
-
<div>
|
|
23
|
+
<div ref="el">
|
|
23
24
|
<BaseListItemLink
|
|
24
25
|
v-slot="{ active }"
|
|
25
26
|
:to="targetRoute"
|
|
@@ -41,6 +42,6 @@ const iconColor = computed(() => props.variant.iconColor)
|
|
|
41
42
|
|
|
42
43
|
<style scoped>
|
|
43
44
|
.bind-icon-color {
|
|
44
|
-
color: v-bind(iconColor);
|
|
45
|
+
color: v-bind('variant.iconColor');
|
|
45
46
|
}
|
|
46
47
|
</style>
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { PropType, ref } from 'vue'
|
|
3
|
+
import { Icon } from '@iconify/vue'
|
|
4
|
+
import type { Story, Variant } from '../../types'
|
|
5
|
+
import { histoireConfig } from '../../util/config'
|
|
6
|
+
import { usePreviewSettings } from '../../util/preview-settings'
|
|
7
|
+
import StoryResponsivePreview from './StoryResponsivePreview.vue'
|
|
8
|
+
|
|
9
|
+
defineProps({
|
|
10
|
+
variant: {
|
|
11
|
+
type: Object as PropType<Variant>,
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
story: {
|
|
16
|
+
type: Object as PropType<Story>,
|
|
17
|
+
required: true,
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const settings = usePreviewSettings()
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<div class="htw-h-full htw-flex htw-flex-col">
|
|
26
|
+
<!-- Toolbar -->
|
|
27
|
+
<div class="htw-flex-none htw-flex htw-items-center htw-h-8 -htw-mt-1">
|
|
28
|
+
<!-- Variant title -->
|
|
29
|
+
<div class="htw-flex htw-items-center htw-gap-1 htw-text-gray-500 htw-flex-1 htw-truncate htw-min-w-0">
|
|
30
|
+
<Icon
|
|
31
|
+
:icon="variant.icon ?? 'carbon:cube'"
|
|
32
|
+
class="base-list-item-link-icon htw-w-4 htw-h-4 htw-opacity-50"
|
|
33
|
+
:class="[
|
|
34
|
+
variant.iconColor ? 'bind-icon-color' : 'htw-text-gray-500',
|
|
35
|
+
]"
|
|
36
|
+
/>
|
|
37
|
+
<span>{{ variant.title }}</span>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<!-- Responsive size -->
|
|
41
|
+
<VDropdown
|
|
42
|
+
placement="bottom-end"
|
|
43
|
+
:skidding="6"
|
|
44
|
+
:disabled="!histoireConfig.responsivePresets?.length"
|
|
45
|
+
class="htw-h-full htw-flex-none"
|
|
46
|
+
>
|
|
47
|
+
<div
|
|
48
|
+
v-tooltip="'Responsive sizes'"
|
|
49
|
+
class="htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2"
|
|
50
|
+
:class="{
|
|
51
|
+
'htw-cursor-pointer hover:htw-text-primary-500': histoireConfig.responsivePresets?.length,
|
|
52
|
+
}"
|
|
53
|
+
>
|
|
54
|
+
<Icon
|
|
55
|
+
icon="ic:baseline-phone-android"
|
|
56
|
+
class="htw-w-4 htw-h-4 htw-opacity-50"
|
|
57
|
+
/>
|
|
58
|
+
<Icon
|
|
59
|
+
icon="carbon:caret-down"
|
|
60
|
+
class="htw-w-4 htw-h-4 htw-opacity-50"
|
|
61
|
+
/>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<template #popper="{ hide }">
|
|
65
|
+
<div class="htw-flex htw-flex-col htw-items-stretch">
|
|
66
|
+
<HstCheckbox
|
|
67
|
+
v-model="settings.rotate"
|
|
68
|
+
>
|
|
69
|
+
Rotate
|
|
70
|
+
</HstCheckbox>
|
|
71
|
+
|
|
72
|
+
<div class="htw-flex htw-gap-2 htw-px-4 htw-py-3">
|
|
73
|
+
<input
|
|
74
|
+
v-model.number="settings.responsiveWidth"
|
|
75
|
+
v-tooltip="'Responsive width (px)'"
|
|
76
|
+
type="number"
|
|
77
|
+
class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-20 htw-opacity-50 focus:htw-opacity-100 htw-flex-1 htw-min-w-0"
|
|
78
|
+
step="16"
|
|
79
|
+
placeholder="Auto"
|
|
80
|
+
>
|
|
81
|
+
<span class="htw-opacity-50">x</span>
|
|
82
|
+
<input
|
|
83
|
+
v-model.number="settings.responsiveHeight"
|
|
84
|
+
v-tooltip="'Responsive height (px)'"
|
|
85
|
+
type="number"
|
|
86
|
+
class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-20 htw-opacity-50 focus:htw-opacity-100 htw-flex-1 htw-min-w-0"
|
|
87
|
+
step="16"
|
|
88
|
+
placeholder="Auto"
|
|
89
|
+
>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<button
|
|
93
|
+
v-for="(preset, index) in histoireConfig.responsivePresets"
|
|
94
|
+
:key="index"
|
|
95
|
+
class="htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-4"
|
|
96
|
+
:class="[
|
|
97
|
+
settings.responsiveWidth === preset.width && settings.responsiveHeight === preset.height
|
|
98
|
+
? 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
|
|
99
|
+
: 'htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700',
|
|
100
|
+
]"
|
|
101
|
+
@click="settings.responsiveWidth = preset.width;settings.responsiveHeight = preset.height;hide()"
|
|
102
|
+
>
|
|
103
|
+
{{ preset.label }}
|
|
104
|
+
<span class="htw-ml-auto htw-opacity-70 htw-flex htw-gap-1">
|
|
105
|
+
<span v-if="preset.width">{{ preset.width }}<span v-if="!preset.height">px</span></span>
|
|
106
|
+
<span v-if="preset.width && preset.height">x</span>
|
|
107
|
+
<span v-if="preset.height">{{ preset.height }}<span v-if="!preset.width">px</span></span>
|
|
108
|
+
</span>
|
|
109
|
+
</button>
|
|
110
|
+
</div>
|
|
111
|
+
</template>
|
|
112
|
+
</VDropdown>
|
|
113
|
+
|
|
114
|
+
<!-- Background -->
|
|
115
|
+
<VDropdown
|
|
116
|
+
v-if="histoireConfig.backgroundPresets.length"
|
|
117
|
+
placement="bottom-end"
|
|
118
|
+
:skidding="6"
|
|
119
|
+
class="htw-h-full htw-flex-none"
|
|
120
|
+
>
|
|
121
|
+
<div
|
|
122
|
+
v-tooltip="'Background color'"
|
|
123
|
+
class="htw-cursor-pointer hover:htw-text-primary-500 htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2"
|
|
124
|
+
>
|
|
125
|
+
<div
|
|
126
|
+
class="bind-preview-bg htw-w-4 htw-h-4 htw-rounded-full htw-border htw-border-black/20 dark:htw-border-white/20"
|
|
127
|
+
/>
|
|
128
|
+
<Icon
|
|
129
|
+
icon="carbon:caret-down"
|
|
130
|
+
class="htw-w-4 htw-h-4 htw-opacity-50"
|
|
131
|
+
/>
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<template #popper="{ hide }">
|
|
135
|
+
<div class="htw-flex htw-flex-col htw-items-stretch">
|
|
136
|
+
<HstCheckbox
|
|
137
|
+
v-model="settings.checkerboard"
|
|
138
|
+
>
|
|
139
|
+
Checkerboard
|
|
140
|
+
</HstCheckbox>
|
|
141
|
+
|
|
142
|
+
<button
|
|
143
|
+
v-for="(option, index) in histoireConfig.backgroundPresets"
|
|
144
|
+
:key="index"
|
|
145
|
+
class="htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-4"
|
|
146
|
+
:class="[
|
|
147
|
+
settings.backgroundColor === option.color
|
|
148
|
+
? 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
|
|
149
|
+
: 'htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700',
|
|
150
|
+
]"
|
|
151
|
+
@click="settings.backgroundColor = option.color;hide()"
|
|
152
|
+
>
|
|
153
|
+
<span class="htw-mr-auto">{{ option.label }}</span>
|
|
154
|
+
<template v-if="option.color !== '$checkerboard'">
|
|
155
|
+
<span class="htw-ml-auto htw-opacity-70">{{ option.color }}</span>
|
|
156
|
+
<div
|
|
157
|
+
class="htw-w-4 htw-h-4 htw-rounded-full htw-border htw-border-black/20 dark:htw-border-white/20"
|
|
158
|
+
:style="{
|
|
159
|
+
backgroundColor: option.color,
|
|
160
|
+
}"
|
|
161
|
+
/>
|
|
162
|
+
</template>
|
|
163
|
+
</button>
|
|
164
|
+
</div>
|
|
165
|
+
</template>
|
|
166
|
+
</VDropdown>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<!-- Preview -->
|
|
170
|
+
<StoryResponsivePreview
|
|
171
|
+
:story="story"
|
|
172
|
+
:variant="variant"
|
|
173
|
+
:settings="settings"
|
|
174
|
+
/>
|
|
175
|
+
</div>
|
|
176
|
+
</template>
|
|
177
|
+
|
|
178
|
+
<style scoped>
|
|
179
|
+
.bind-preview-bg {
|
|
180
|
+
background-color: v-bind('settings.backgroundColor');
|
|
181
|
+
}
|
|
182
|
+
</style>
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import { useStoryStore } from '../stores/story'
|
|
3
|
-
import BaseSplitPane from './base/BaseSplitPane.vue'
|
|
4
|
-
import StoryVariantListItem from './StoryVariantListItem.vue'
|
|
5
|
-
import StoryVariantGridItem from './StoryVariantGridItem.vue'
|
|
6
2
|
import { computed, watch } from 'vue'
|
|
7
3
|
import { useRoute, useRouter } from 'vue-router'
|
|
4
|
+
import { useStoryStore } from '../../stores/story'
|
|
5
|
+
|
|
6
|
+
import BaseSplitPane from '../base/BaseSplitPane.vue'
|
|
7
|
+
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
8
|
+
import BaseTab from '../base/BaseTab.vue'
|
|
9
|
+
import StoryVariantListItem from './StoryVariantListItem.vue'
|
|
10
|
+
import StoryVariantGridItem from './StoryVariantGridItem.vue'
|
|
8
11
|
import StoryVariantSingleView from './StoryVariantSingleView.vue'
|
|
9
|
-
import BaseEmpty from './base/BaseEmpty.vue'
|
|
10
12
|
import StoryControls from './StoryControls.vue'
|
|
13
|
+
import StoryDocs from './StoryDocs.vue'
|
|
11
14
|
import StorySourceCode from './StorySourceCode.vue'
|
|
12
15
|
|
|
13
16
|
const storyStore = useStoryStore()
|
|
@@ -139,6 +142,10 @@ function setVariant (variantId: string) {
|
|
|
139
142
|
<span>Select a variant</span>
|
|
140
143
|
</BaseEmpty>
|
|
141
144
|
|
|
145
|
+
<BaseEmpty v-else-if="!storyStore.currentVariant.ready">
|
|
146
|
+
<span>Loading...</span>
|
|
147
|
+
</BaseEmpty>
|
|
148
|
+
|
|
142
149
|
<BaseSplitPane
|
|
143
150
|
v-else
|
|
144
151
|
save-id="story-sidepane"
|
|
@@ -146,11 +153,31 @@ function setVariant (variantId: string) {
|
|
|
146
153
|
class="htw-h-full"
|
|
147
154
|
>
|
|
148
155
|
<template #first>
|
|
149
|
-
<
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
156
|
+
<div class="htw-flex htw-flex-col htw-h-full">
|
|
157
|
+
<nav class="htw-h-10 htw-flex-none htw-border-b htw-border-gray-100 dark:htw-border-gray-750">
|
|
158
|
+
<BaseTab
|
|
159
|
+
:to="{ ...$route, query: { ...$route.query, tab: '' } }"
|
|
160
|
+
:matched="!$route.query.tab"
|
|
161
|
+
>
|
|
162
|
+
Controls
|
|
163
|
+
</BaseTab>
|
|
164
|
+
<BaseTab
|
|
165
|
+
:to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
|
|
166
|
+
:matched="$route.query.tab === 'docs'"
|
|
167
|
+
>
|
|
168
|
+
Docs
|
|
169
|
+
</BaseTab>
|
|
170
|
+
</nav>
|
|
171
|
+
|
|
172
|
+
<component
|
|
173
|
+
:is="$route.query.tab === 'docs'
|
|
174
|
+
? StoryDocs
|
|
175
|
+
: StoryControls"
|
|
176
|
+
:story="storyStore.currentStory"
|
|
177
|
+
:variant="storyStore.currentVariant"
|
|
178
|
+
class="htw-h-full htw-overflow-auto"
|
|
179
|
+
/>
|
|
180
|
+
</div>
|
|
154
181
|
</template>
|
|
155
182
|
|
|
156
183
|
<template #last>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { App } from 'vue'
|
|
2
|
+
import { registerVueComponents } from '@histoire/controls'
|
|
2
3
|
import Story from './components/exposed/Story.vue'
|
|
3
4
|
import Variant from './components/exposed/Variant.vue'
|
|
4
5
|
|
|
@@ -7,4 +8,6 @@ export function registerGlobalComponents (app: App) {
|
|
|
7
8
|
app.component('Story', Story)
|
|
8
9
|
// eslint-disable-next-line vue/multi-word-component-names
|
|
9
10
|
app.component('Variant', Variant)
|
|
11
|
+
|
|
12
|
+
registerVueComponents(app)
|
|
10
13
|
}
|
package/src/client/app/index.ts
CHANGED
|
@@ -12,6 +12,16 @@ const app = createApp(App)
|
|
|
12
12
|
app.use(createPinia())
|
|
13
13
|
app.use(FloatingVue, {
|
|
14
14
|
overflowPadding: 4,
|
|
15
|
+
arrowPadding: 8,
|
|
16
|
+
themes: {
|
|
17
|
+
tooltip: {
|
|
18
|
+
distance: 8,
|
|
19
|
+
},
|
|
20
|
+
dropdown: {
|
|
21
|
+
computeTransformOrigin: true,
|
|
22
|
+
distance: 8,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
15
25
|
})
|
|
16
26
|
app.use(router)
|
|
17
27
|
registerGlobalComponents(app)
|
package/src/client/app/router.ts
CHANGED