histoire 0.2.0 → 0.2.3
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/client/app/App.vue +1 -1
- package/dist/client/app/codegen/vue3.js +11 -1
- package/dist/client/app/codegen/vue3.ts +9 -1
- package/dist/client/app/components/app/AppHeader.vue +1 -1
- package/dist/client/app/components/exposed/Story.vue +25 -14
- package/dist/client/app/components/exposed/Variant.vue +7 -0
- package/dist/client/app/components/sandbox/lib.d.ts +2 -0
- package/dist/client/app/components/sandbox/lib.js +6 -0
- package/dist/client/app/components/sandbox/lib.ts +8 -0
- package/dist/client/app/components/story/StoryResponsivePreview.vue +74 -81
- package/dist/client/app/components/story/StorySidePanel.vue +1 -1
- package/dist/client/app/components/story/StorySourceCode.vue +3 -17
- package/dist/client/app/components/story/StoryVariantGrid.vue +112 -0
- package/dist/client/app/components/story/StoryVariantGridItem.vue +36 -6
- package/dist/client/app/components/story/StoryVariantSingleView.vue +20 -161
- package/dist/client/app/components/story/StoryViewer.vue +7 -42
- package/dist/client/app/components/story/toolbar/StoryVariantBackground.vue +67 -0
- package/dist/client/app/components/story/toolbar/StoryVariantNewTab.vue +29 -0
- package/dist/client/app/components/story/toolbar/StoryVariantResponsiveSize.vue +82 -0
- package/dist/client/app/components/story/toolbar/StoryVariantTitle.vue +21 -0
- package/dist/client/app/stores/preview-settings.d.ts +8 -0
- package/dist/client/app/stores/preview-settings.js +14 -0
- package/dist/client/app/stores/preview-settings.ts +17 -0
- package/dist/client/app/stores/story.d.ts +45 -15
- package/dist/client/app/style/main.pcss +4 -0
- package/dist/client/app/types.d.ts +10 -1
- package/dist/client/app/types.ts +11 -1
- package/dist/client/app/util/mapping.js +10 -9
- package/dist/client/app/util/mapping.ts +10 -5
- package/dist/client/app/util/preview-settings.d.ts +1 -8
- package/dist/client/app/util/preview-settings.js +0 -10
- package/dist/client/app/util/preview-settings.ts +1 -19
- package/dist/client/app/util/scroll.d.ts +3 -1
- package/dist/client/app/util/scroll.js +3 -0
- package/dist/client/app/util/scroll.ts +4 -0
- package/dist/node/config.d.ts +2 -2
- package/dist/node/plugin.js +14 -6
- package/dist/node/tree.js +24 -4
- package/dist/style.css +70 -4
- package/package.json +21 -21
- package/src/client/app/App.vue +1 -1
- package/src/client/app/codegen/vue3.ts +9 -1
- package/src/client/app/components/app/AppHeader.vue +1 -1
- package/src/client/app/components/exposed/Story.vue +25 -14
- package/src/client/app/components/exposed/Variant.vue +7 -0
- package/src/client/app/components/sandbox/lib.ts +8 -0
- package/src/client/app/components/story/StoryResponsivePreview.vue +74 -81
- package/src/client/app/components/story/StorySidePanel.vue +1 -1
- package/src/client/app/components/story/StorySourceCode.vue +3 -17
- package/src/client/app/components/story/StoryVariantGrid.vue +112 -0
- package/src/client/app/components/story/StoryVariantGridItem.vue +36 -6
- package/src/client/app/components/story/StoryVariantSingleView.vue +20 -161
- package/src/client/app/components/story/StoryViewer.vue +7 -42
- package/src/client/app/components/story/toolbar/StoryVariantBackground.vue +67 -0
- package/src/client/app/components/story/toolbar/StoryVariantNewTab.vue +29 -0
- package/src/client/app/components/story/toolbar/StoryVariantResponsiveSize.vue +82 -0
- package/src/client/app/components/story/toolbar/StoryVariantTitle.vue +21 -0
- package/src/client/app/stores/preview-settings.ts +17 -0
- package/src/client/app/style/main.pcss +4 -0
- package/src/client/app/types.ts +11 -1
- package/src/client/app/util/mapping.ts +10 -5
- package/src/client/app/util/preview-settings.ts +1 -19
- package/src/client/app/util/scroll.ts +4 -0
- package/src/node/config.ts +2 -2
- package/src/node/plugin.ts +15 -6
- package/src/node/tree.spec.ts +61 -0
- package/src/node/tree.ts +29 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "A fast story book powered by Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -33,38 +33,38 @@
|
|
|
33
33
|
"histoire": "./bin.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@vitejs/plugin-vue": "^2.
|
|
39
|
-
"@vueuse/core": "^8.
|
|
40
|
-
"birpc": "^0.1.
|
|
36
|
+
"@histoire/controls": "^0.2.3",
|
|
37
|
+
"@iconify/vue": "^3.2.1",
|
|
38
|
+
"@vitejs/plugin-vue": "^2.3.1",
|
|
39
|
+
"@vueuse/core": "^8.2.5",
|
|
40
|
+
"birpc": "^0.1.1",
|
|
41
41
|
"case": "^1.6.3",
|
|
42
42
|
"chokidar": "^3.5.3",
|
|
43
43
|
"connect": "^3.7.0",
|
|
44
44
|
"defu": "^5.0.1",
|
|
45
45
|
"diacritics": "^1.3.0",
|
|
46
|
-
"floating-vue": "^2.0.0-beta.
|
|
47
|
-
"fs-extra": "^10.0.
|
|
46
|
+
"floating-vue": "^2.0.0-beta.14",
|
|
47
|
+
"fs-extra": "^10.0.1",
|
|
48
48
|
"globby": "^13.1.1",
|
|
49
|
-
"happy-dom": "^2.
|
|
49
|
+
"happy-dom": "^2.55.0",
|
|
50
50
|
"markdown-it": "^12.3.2",
|
|
51
|
-
"markdown-it-anchor": "^8.
|
|
51
|
+
"markdown-it-anchor": "^8.6.2",
|
|
52
52
|
"markdown-it-attrs": "^4.1.3",
|
|
53
53
|
"markdown-it-emoji": "^2.0.0",
|
|
54
54
|
"mrmime": "^1.0.0",
|
|
55
55
|
"pathe": "^0.2.0",
|
|
56
56
|
"picocolors": "^1.0.0",
|
|
57
|
-
"pinia": "^2.0.
|
|
57
|
+
"pinia": "^2.0.13",
|
|
58
58
|
"sade": "^1.8.1",
|
|
59
59
|
"scroll-into-view-if-needed": "^2.2.29",
|
|
60
60
|
"shiki": "^0.10.1",
|
|
61
61
|
"sirv": "^2.0.2",
|
|
62
62
|
"tinypool": "^0.1.2",
|
|
63
|
-
"vite-node": "
|
|
64
|
-
"vue-router": "^4.0.
|
|
63
|
+
"vite-node": "0.7.6",
|
|
64
|
+
"vue-router": "^4.0.14"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"vite": "^2.
|
|
67
|
+
"vite": "^2.9.0",
|
|
68
68
|
"vue": "^3.2.31"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
@@ -72,14 +72,14 @@
|
|
|
72
72
|
"@tailwindcss/typography": "^0.5.2",
|
|
73
73
|
"@types/fs-extra": "^9.0.13",
|
|
74
74
|
"@types/markdown-it": "^12.2.3",
|
|
75
|
-
"@types/node": "^17.0.
|
|
76
|
-
"autoprefixer": "^10.4.
|
|
77
|
-
"concurrently": "^7.
|
|
78
|
-
"postcss": "^8.4.
|
|
79
|
-
"postcss-import": "^14.0
|
|
75
|
+
"@types/node": "^17.0.23",
|
|
76
|
+
"autoprefixer": "^10.4.4",
|
|
77
|
+
"concurrently": "^7.1.0",
|
|
78
|
+
"postcss": "^8.4.12",
|
|
79
|
+
"postcss-import": "^14.1.0",
|
|
80
80
|
"tailwindcss": "^3.0.23",
|
|
81
|
-
"typescript": "^4.
|
|
82
|
-
"vite": "^2.
|
|
81
|
+
"typescript": "^4.6.3",
|
|
82
|
+
"vite": "^2.9.1",
|
|
83
83
|
"vue": "^3.2.31"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
package/src/client/app/App.vue
CHANGED
|
@@ -102,7 +102,7 @@ onKeyboardShortcut(['ctrl+k', 'meta+k'], (event) => {
|
|
|
102
102
|
class="htw-h-full"
|
|
103
103
|
>
|
|
104
104
|
<template #first>
|
|
105
|
-
<div class="htw-flex htw-flex-col htw-h-full
|
|
105
|
+
<div class="htw-flex htw-flex-col htw-h-full">
|
|
106
106
|
<AppHeader
|
|
107
107
|
class="htw-flex-none"
|
|
108
108
|
@search="isSearchOpen = true"
|
|
@@ -33,7 +33,9 @@ async function printVNode (vnode: VNode): Promise<string[]> {
|
|
|
33
33
|
|
|
34
34
|
const attrs: string[][] = []
|
|
35
35
|
let multilineAttrs = false
|
|
36
|
-
const skipProps: string[] = [
|
|
36
|
+
const skipProps: string[] = [
|
|
37
|
+
'key',
|
|
38
|
+
]
|
|
37
39
|
|
|
38
40
|
// Directives
|
|
39
41
|
function genDirective (dirName: string, dir, valueCode: string = null) {
|
|
@@ -138,6 +140,8 @@ async function printVNode (vnode: VNode): Promise<string[]> {
|
|
|
138
140
|
if (typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}')) {
|
|
139
141
|
// It was formatted from auto building object (slot props)
|
|
140
142
|
serialized = [value.substring(2, value.length - 2).trim()]
|
|
143
|
+
} else if (typeof value === 'function') {
|
|
144
|
+
serialized = [value.toString()]
|
|
141
145
|
} else {
|
|
142
146
|
serialized = serializeAndCleanJs(value)
|
|
143
147
|
}
|
|
@@ -230,6 +234,10 @@ async function printVNode (vnode: VNode): Promise<string[]> {
|
|
|
230
234
|
} else {
|
|
231
235
|
lines.push(`${tag[0]} />`)
|
|
232
236
|
}
|
|
237
|
+
} else if (vnode?.shapeFlag & 1 << 4) {
|
|
238
|
+
for (const child of vnode.children) {
|
|
239
|
+
lines.push(...await printVNode(child))
|
|
240
|
+
}
|
|
233
241
|
}
|
|
234
242
|
|
|
235
243
|
return lines
|
|
@@ -29,7 +29,7 @@ onKeyboardShortcut(['ctrl+shift+d', 'meta+shift+d'], (event) => {
|
|
|
29
29
|
<a
|
|
30
30
|
:href="histoireConfig.theme?.logoHref"
|
|
31
31
|
target="_blank"
|
|
32
|
-
class="htw-
|
|
32
|
+
class="htw-w-full htw-h-full htw-flex htw-items-center"
|
|
33
33
|
>
|
|
34
34
|
<AppLogo
|
|
35
35
|
class="htw-max-w-full htw-max-h-full"
|
|
@@ -40,22 +40,33 @@ export default defineComponent({
|
|
|
40
40
|
}, this.$slots)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
const vnodes: VNode[]
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
let index = 0
|
|
44
|
+
const applyAttrs = (vnodes: VNode[]) => {
|
|
45
|
+
for (const vnode of vnodes) {
|
|
46
|
+
// @ts-expect-error custom option
|
|
47
|
+
if (vnode.type?.__histoireType === 'variant') {
|
|
48
|
+
if (!vnode.props) {
|
|
49
|
+
vnode.props = {}
|
|
50
|
+
}
|
|
51
|
+
vnode.props.variant = this.story.variants[index]
|
|
52
|
+
if (!vnode.props.initState && !vnode.props['init-state']) {
|
|
53
|
+
vnode.props.initState = this.initState
|
|
54
|
+
}
|
|
55
|
+
for (const attr in this.$attrs) {
|
|
56
|
+
if (typeof vnode.props[attr] === 'undefined') {
|
|
57
|
+
vnode.props[attr] = this.$attrs[attr]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
index++
|
|
61
|
+
} else if (vnode.children?.length) {
|
|
62
|
+
applyAttrs(vnode.children as VNode[])
|
|
63
|
+
}
|
|
57
64
|
}
|
|
58
65
|
}
|
|
66
|
+
|
|
67
|
+
// Apply variant as attribute to each child vnode (should be `<Variant>` components)
|
|
68
|
+
const vnodes: VNode[] = this.$slots.default()
|
|
69
|
+
applyAttrs(vnodes)
|
|
59
70
|
return vnodes
|
|
60
71
|
},
|
|
61
72
|
})
|
|
@@ -17,6 +17,11 @@ export default defineComponent({
|
|
|
17
17
|
type: String,
|
|
18
18
|
default: null,
|
|
19
19
|
},
|
|
20
|
+
|
|
21
|
+
responsiveDisabled: {
|
|
22
|
+
type: Boolean,
|
|
23
|
+
default: false,
|
|
24
|
+
},
|
|
20
25
|
},
|
|
21
26
|
|
|
22
27
|
setup (props) {
|
|
@@ -35,6 +40,8 @@ export default defineComponent({
|
|
|
35
40
|
},
|
|
36
41
|
slots: () => vm.proxy.$slots,
|
|
37
42
|
source: props.source,
|
|
43
|
+
responsiveDisabled: props.responsiveDisabled,
|
|
44
|
+
configReady: true,
|
|
38
45
|
})
|
|
39
46
|
}
|
|
40
47
|
updateVariant()
|
|
@@ -3,29 +3,26 @@ import { computed, onUnmounted, Ref, ref, toRaw, watch } from 'vue'
|
|
|
3
3
|
import { useEventListener } from '@vueuse/core'
|
|
4
4
|
import { Icon } from '@iconify/vue'
|
|
5
5
|
import { STATE_SYNC, PREVIEW_SETTINGS_SYNC, SANDBOX_READY } from '../../util/const'
|
|
6
|
-
import { PreviewSettings } from '../../util/preview-settings'
|
|
7
6
|
import type { Story, Variant } from '../../types'
|
|
8
7
|
import HatchedPattern from '../misc/HatchedPattern.vue'
|
|
9
8
|
import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
|
|
10
9
|
import { toRawDeep } from '../../util/reactivity'
|
|
11
|
-
import {
|
|
10
|
+
import { getSandboxUrl } from '../sandbox/lib'
|
|
11
|
+
import { usePreviewSettingsStore } from '../../stores/preview-settings'
|
|
12
12
|
|
|
13
13
|
const props = defineProps<{
|
|
14
14
|
story: Story
|
|
15
15
|
variant: Variant
|
|
16
|
-
settings: PreviewSettings
|
|
17
16
|
}>()
|
|
18
17
|
|
|
19
|
-
const
|
|
20
|
-
'update:settings': (settings: PreviewSettings) => true,
|
|
21
|
-
})
|
|
18
|
+
const settings = usePreviewSettingsStore().currentSettings
|
|
22
19
|
|
|
23
20
|
// Iframe
|
|
24
21
|
|
|
25
22
|
const iframe = ref<HTMLIFrameElement>()
|
|
26
23
|
|
|
27
24
|
function syncState () {
|
|
28
|
-
if (iframe.value && props.variant.
|
|
25
|
+
if (iframe.value && props.variant.previewReady) {
|
|
29
26
|
iframe.value.contentWindow.postMessage({
|
|
30
27
|
type: STATE_SYNC,
|
|
31
28
|
state: toRawDeep(props.variant.state),
|
|
@@ -47,7 +44,7 @@ watch(() => props.variant.state, () => {
|
|
|
47
44
|
})
|
|
48
45
|
|
|
49
46
|
Object.assign(props.variant, {
|
|
50
|
-
|
|
47
|
+
previewReady: false,
|
|
51
48
|
})
|
|
52
49
|
useEventListener(window, 'message', (event) => {
|
|
53
50
|
if (event.data.type === STATE_SYNC) {
|
|
@@ -55,16 +52,13 @@ useEventListener(window, 'message', (event) => {
|
|
|
55
52
|
Object.assign(props.variant.state, event.data.state)
|
|
56
53
|
} else if (event.data.type === SANDBOX_READY) {
|
|
57
54
|
Object.assign(props.variant, {
|
|
58
|
-
|
|
55
|
+
previewReady: true,
|
|
59
56
|
})
|
|
60
57
|
}
|
|
61
58
|
})
|
|
62
59
|
|
|
63
60
|
const sandboxUrl = computed(() => {
|
|
64
|
-
|
|
65
|
-
url.append('storyId', props.story.id)
|
|
66
|
-
url.append('variantId', props.variant.id)
|
|
67
|
-
return '/__sandbox?' + url.toString()
|
|
61
|
+
return getSandboxUrl(props.story, props.variant)
|
|
68
62
|
})
|
|
69
63
|
|
|
70
64
|
const isIframeLoaded = ref(false)
|
|
@@ -79,12 +73,12 @@ function syncSettings () {
|
|
|
79
73
|
if (iframe.value) {
|
|
80
74
|
iframe.value.contentWindow.postMessage({
|
|
81
75
|
type: PREVIEW_SETTINGS_SYNC,
|
|
82
|
-
settings: toRaw(
|
|
76
|
+
settings: toRaw(settings),
|
|
83
77
|
})
|
|
84
78
|
}
|
|
85
79
|
}
|
|
86
80
|
|
|
87
|
-
watch(() =>
|
|
81
|
+
watch(() => settings, () => {
|
|
88
82
|
syncSettings()
|
|
89
83
|
}, {
|
|
90
84
|
deep: true,
|
|
@@ -132,8 +126,13 @@ function useDragger (el: Ref<HTMLDivElement>, value: Ref<number>, min: number, m
|
|
|
132
126
|
]
|
|
133
127
|
|
|
134
128
|
function onMouseMove (event: MouseEvent) {
|
|
129
|
+
const snapTarget = (axis === 'x' ? previewWrapper.value.clientWidth : previewWrapper.value.clientHeight)
|
|
135
130
|
const delta = (axis === 'x' ? event.clientX : event.clientY) - start
|
|
136
131
|
value.value = Math.max(min, Math.min(max, startValue + delta))
|
|
132
|
+
|
|
133
|
+
if (Math.abs(value.value - (snapTarget - 67)) < 16) {
|
|
134
|
+
value.value = null
|
|
135
|
+
}
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
function onMouseUp () {
|
|
@@ -169,74 +168,56 @@ function useDragger (el: Ref<HTMLDivElement>, value: Ref<number>, min: number, m
|
|
|
169
168
|
useEventListener(el, 'touchstart', onTouchStart)
|
|
170
169
|
}
|
|
171
170
|
|
|
172
|
-
// Optimize by batching settings updates to the next frame
|
|
173
|
-
// Prevents sync issues with `useStorage`
|
|
174
|
-
let settingsUpdate: Partial<Settings> = {}
|
|
175
|
-
let settingsUpdateQueued = false
|
|
176
|
-
|
|
177
|
-
function updateSettings (settings: Partial<PreviewSettings>) {
|
|
178
|
-
Object.assign(settingsUpdate, settings)
|
|
179
|
-
|
|
180
|
-
if (!settingsUpdateQueued) {
|
|
181
|
-
settingsUpdateQueued = true
|
|
182
|
-
requestAnimationFrame(() => {
|
|
183
|
-
emit('update:settings', {
|
|
184
|
-
...props.settings,
|
|
185
|
-
...settingsUpdate,
|
|
186
|
-
})
|
|
187
|
-
settingsUpdate = {}
|
|
188
|
-
settingsUpdateQueued = false
|
|
189
|
-
})
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
171
|
const responsiveWidth = computed({
|
|
194
|
-
get: () =>
|
|
195
|
-
set: (value) => {
|
|
196
|
-
updateSettings({
|
|
197
|
-
[props.settings.rotate ? 'responsiveHeight' : 'responsiveWidth']: value,
|
|
198
|
-
})
|
|
199
|
-
},
|
|
172
|
+
get: () => settings[settings.rotate ? 'responsiveHeight' : 'responsiveWidth'],
|
|
173
|
+
set: (value) => { settings[settings.rotate ? 'responsiveHeight' : 'responsiveWidth'] = value },
|
|
200
174
|
})
|
|
201
175
|
const responsiveHeight = computed({
|
|
202
|
-
get: () =>
|
|
203
|
-
set: (value) => {
|
|
204
|
-
updateSettings({
|
|
205
|
-
[props.settings.rotate ? 'responsiveWidth' : 'responsiveHeight']: value,
|
|
206
|
-
})
|
|
207
|
-
},
|
|
176
|
+
get: () => settings[settings.rotate ? 'responsiveWidth' : 'responsiveHeight'],
|
|
177
|
+
set: (value) => { settings[settings.rotate ? 'responsiveWidth' : 'responsiveHeight'] = value },
|
|
208
178
|
})
|
|
209
179
|
|
|
210
180
|
const horizontalDragger = ref<HTMLDivElement>()
|
|
211
181
|
const verticalDragger = ref<HTMLDivElement>()
|
|
212
182
|
const cornerDragger = ref<HTMLDivElement>()
|
|
183
|
+
const previewWrapper = ref<HTMLDivElement>()
|
|
213
184
|
|
|
214
|
-
useDragger(horizontalDragger, responsiveWidth,
|
|
215
|
-
useDragger(verticalDragger, responsiveHeight,
|
|
216
|
-
useDragger(cornerDragger, responsiveWidth,
|
|
217
|
-
useDragger(cornerDragger, responsiveHeight,
|
|
185
|
+
useDragger(horizontalDragger, responsiveWidth, 32, 20000, 'x')
|
|
186
|
+
useDragger(verticalDragger, responsiveHeight, 32, 20000, 'y')
|
|
187
|
+
useDragger(cornerDragger, responsiveWidth, 32, 20000, 'x')
|
|
188
|
+
useDragger(cornerDragger, responsiveHeight, 32, 20000, 'y')
|
|
218
189
|
|
|
219
190
|
// Handle rotate
|
|
220
191
|
|
|
221
|
-
const finalWidth = computed(() =>
|
|
222
|
-
const finalHeight = computed(() =>
|
|
192
|
+
const finalWidth = computed(() => settings.rotate ? settings.responsiveHeight : settings.responsiveWidth)
|
|
193
|
+
const finalHeight = computed(() => settings.rotate ? settings.responsiveWidth : settings.responsiveHeight)
|
|
194
|
+
|
|
195
|
+
// Disabled responsive
|
|
196
|
+
|
|
197
|
+
const isResponsiveEnabled = computed(() => !props.variant.responsiveDisabled)
|
|
223
198
|
</script>
|
|
224
199
|
|
|
225
200
|
<template>
|
|
226
201
|
<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">
|
|
227
|
-
<div
|
|
202
|
+
<div
|
|
203
|
+
v-if="isResponsiveEnabled"
|
|
204
|
+
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"
|
|
205
|
+
>
|
|
228
206
|
<HatchedPattern
|
|
229
207
|
class="htw-w-full htw-h-full htw-text-black/[2%] dark:htw-text-white/[2%]"
|
|
230
208
|
/>
|
|
231
209
|
</div>
|
|
232
210
|
|
|
233
|
-
<div
|
|
211
|
+
<div
|
|
212
|
+
ref="previewWrapper"
|
|
213
|
+
class="htw-h-full htw-overflow-auto htw-relative"
|
|
214
|
+
>
|
|
234
215
|
<div
|
|
235
216
|
class="htw-h-full htw-p-4 htw-overflow-hidden htw-bg-white dark:htw-bg-gray-700 htw-rounded-lg htw-relative"
|
|
236
|
-
:
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}"
|
|
217
|
+
:class="isResponsiveEnabled ? {
|
|
218
|
+
'htw-w-fit': !!finalWidth,
|
|
219
|
+
'htw-h-fit': !!finalHeight
|
|
220
|
+
} : undefined"
|
|
240
221
|
>
|
|
241
222
|
<div class="htw-p-4 htw-h-full htw-relative">
|
|
242
223
|
<div class="htw-w-full htw-h-full htw-border htw-border-gray-100 dark:htw-border-gray-800 htw-rounded-sm htw-relative">
|
|
@@ -255,6 +236,10 @@ const finalHeight = computed(() => props.settings.rotate ? props.settings.respon
|
|
|
255
236
|
'htw-invisible': !isIframeLoaded,
|
|
256
237
|
'htw-pointer-events-none': resizing,
|
|
257
238
|
}"
|
|
239
|
+
:style="isResponsiveEnabled ? {
|
|
240
|
+
width: finalWidth ? `${finalWidth}px` : null,
|
|
241
|
+
height: finalHeight ? `${finalHeight}px` : null,
|
|
242
|
+
} : undefined"
|
|
258
243
|
data-test-id="preview-iframe"
|
|
259
244
|
@load="onIframeLoad()"
|
|
260
245
|
/>
|
|
@@ -272,29 +257,37 @@ const finalHeight = computed(() => props.settings.rotate ? props.settings.respon
|
|
|
272
257
|
</div>
|
|
273
258
|
|
|
274
259
|
<!-- Resize Dragger -->
|
|
275
|
-
<
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
260
|
+
<template v-if="isResponsiveEnabled">
|
|
261
|
+
<div
|
|
262
|
+
ref="horizontalDragger"
|
|
263
|
+
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"
|
|
264
|
+
>
|
|
265
|
+
<Icon
|
|
266
|
+
icon="mdi:drag-vertical-variant"
|
|
267
|
+
class="htw-w-4 htw-h-4 htw-opacity-20 group-hover:htw-opacity-90"
|
|
268
|
+
/>
|
|
269
|
+
</div>
|
|
270
|
+
<div
|
|
271
|
+
ref="verticalDragger"
|
|
272
|
+
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"
|
|
273
|
+
>
|
|
274
|
+
<Icon
|
|
275
|
+
icon="mdi:drag-horizontal-variant"
|
|
276
|
+
class="htw-w-4 htw-h-4 htw-opacity-20 group-hover:htw-opacity-90"
|
|
277
|
+
/>
|
|
278
|
+
</div>
|
|
279
|
+
<div
|
|
280
|
+
ref="cornerDragger"
|
|
281
|
+
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"
|
|
291
282
|
/>
|
|
292
|
-
</
|
|
293
|
-
<div
|
|
294
|
-
ref="cornerDragger"
|
|
295
|
-
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"
|
|
296
|
-
/>
|
|
283
|
+
</template>
|
|
297
284
|
</div>
|
|
298
285
|
</div>
|
|
299
286
|
</div>
|
|
300
287
|
</template>
|
|
288
|
+
|
|
289
|
+
<style scoped>
|
|
290
|
+
.bind-preview-bg {
|
|
291
|
+
background-color: v-bind('settings.backgroundColor');
|
|
292
|
+
}
|
|
293
|
+
</style>
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computed, onMounted, PropType, ref, shallowRef, watch } from 'vue'
|
|
3
3
|
import { getHighlighter, Highlighter, setCDN } from 'shiki'
|
|
4
|
-
import {
|
|
4
|
+
import { HstCopyIcon } from '@histoire/controls'
|
|
5
5
|
import { generateSourceCode } from '../../codegen/vue3'
|
|
6
6
|
import type { Variant } from '../../types'
|
|
7
7
|
import { isDark } from '../../util/dark'
|
|
8
8
|
import { unindent } from '../../codegen/util'
|
|
9
|
-
import { useClipboard } from '@vueuse/core'
|
|
10
9
|
|
|
11
10
|
const props = defineProps({
|
|
12
11
|
variant: {
|
|
@@ -59,11 +58,6 @@ const sourceHtml = computed(() => highlighter.value?.codeToHtml(sourceCode.value
|
|
|
59
58
|
lang: 'html',
|
|
60
59
|
theme: isDark.value ? 'github-dark' : 'github-light',
|
|
61
60
|
}))
|
|
62
|
-
|
|
63
|
-
// Copy
|
|
64
|
-
const { copy, copied } = useClipboard()
|
|
65
|
-
|
|
66
|
-
const copySourceCode = () => copy(sourceCode.value)
|
|
67
61
|
</script>
|
|
68
62
|
|
|
69
63
|
<template>
|
|
@@ -97,16 +91,8 @@ const copySourceCode = () => copy(sourceCode.value)
|
|
|
97
91
|
v-if="!error"
|
|
98
92
|
class="htw-absolute htw-top-2 htw-right-6 htw-p-1 htw-bg-gray-100 dark:htw-bg-gray-800"
|
|
99
93
|
>
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
content: 'Copied!',
|
|
103
|
-
triggers: [],
|
|
104
|
-
shown: copied,
|
|
105
|
-
distance: 12,
|
|
106
|
-
}"
|
|
107
|
-
icon="cil:copy"
|
|
108
|
-
class="htw-w-4 htw-h-4 hover:htw-text-primary-500 dark:hover:htw-text-primary-400 htw-cursor-pointer"
|
|
109
|
-
@click="copySourceCode()"
|
|
94
|
+
<HstCopyIcon
|
|
95
|
+
:content="sourceCode"
|
|
110
96
|
/>
|
|
111
97
|
</div>
|
|
112
98
|
</div>
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { useResizeObserver } from '@vueuse/core'
|
|
3
|
+
import { computed, ref, watch } from 'vue'
|
|
4
|
+
import { useStoryStore } from '../../stores/story'
|
|
5
|
+
import StoryVariantGridItem from './StoryVariantGridItem.vue'
|
|
6
|
+
|
|
7
|
+
const storyStore = useStoryStore()
|
|
8
|
+
|
|
9
|
+
const gridTemplateWidth = computed(() => {
|
|
10
|
+
if (storyStore.currentStory.layout.type !== 'grid') {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const layoutWidth = storyStore.currentStory.layout.width
|
|
15
|
+
|
|
16
|
+
if (!layoutWidth) {
|
|
17
|
+
return '200px'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof layoutWidth === 'number') {
|
|
21
|
+
return layoutWidth + 'px'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return layoutWidth
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const margin = 16
|
|
28
|
+
const gap = 16
|
|
29
|
+
|
|
30
|
+
const itemWidth = ref(16)
|
|
31
|
+
const maxItemHeight = ref(0)
|
|
32
|
+
const maxCount = ref(10)
|
|
33
|
+
const countPerRow = ref(0)
|
|
34
|
+
const visibleRows = ref(0)
|
|
35
|
+
|
|
36
|
+
const el = ref<HTMLDivElement>(null)
|
|
37
|
+
|
|
38
|
+
useResizeObserver(el, () => {
|
|
39
|
+
updateMaxCount()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
function updateMaxCount () {
|
|
43
|
+
if (!maxItemHeight.value) return
|
|
44
|
+
|
|
45
|
+
const width = el.value!.clientWidth - margin * 2
|
|
46
|
+
const height = el.value!.clientHeight
|
|
47
|
+
const scrollTop = el.value!.scrollTop
|
|
48
|
+
|
|
49
|
+
// width = (countPerRow - 1) * gap + countPerRow * itemWidth.value
|
|
50
|
+
|
|
51
|
+
// W = (C - 1) * G + C * I
|
|
52
|
+
// W = C * G - G + C * I
|
|
53
|
+
// W + G = C * G + C * I
|
|
54
|
+
// W + G = C * (G + I)
|
|
55
|
+
// (W + G) / (G + I) = C
|
|
56
|
+
|
|
57
|
+
countPerRow.value = Math.floor((width + gap) / (itemWidth.value + gap))
|
|
58
|
+
visibleRows.value = Math.ceil((height + scrollTop + gap) / (maxItemHeight.value + gap))
|
|
59
|
+
const newMaxCount = countPerRow.value * visibleRows.value
|
|
60
|
+
if (maxCount.value < newMaxCount) {
|
|
61
|
+
maxCount.value = newMaxCount
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (storyStore.currentVariant) {
|
|
65
|
+
const index = storyStore.currentStory.variants.indexOf(storyStore.currentVariant)
|
|
66
|
+
if (index + 1 > maxCount.value) {
|
|
67
|
+
maxCount.value = index + 1
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function onItemResize (w: number, h: number) {
|
|
73
|
+
itemWidth.value = w
|
|
74
|
+
if (maxItemHeight.value < h) {
|
|
75
|
+
maxItemHeight.value = h
|
|
76
|
+
updateMaxCount()
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
watch(() => storyStore.currentVariant, () => {
|
|
81
|
+
updateMaxCount()
|
|
82
|
+
})
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<template>
|
|
86
|
+
<div
|
|
87
|
+
ref="el"
|
|
88
|
+
class="htw-h-full htw-overflow-y-auto"
|
|
89
|
+
@scroll="updateMaxCount()"
|
|
90
|
+
>
|
|
91
|
+
<div
|
|
92
|
+
:style="{
|
|
93
|
+
minHeight: `${(storyStore.currentStory.variants.length / countPerRow) * (maxItemHeight + gap) - gap}px`,
|
|
94
|
+
}"
|
|
95
|
+
>
|
|
96
|
+
<div
|
|
97
|
+
class="htw-grid htw-gap-4 htw-m-4"
|
|
98
|
+
:style="{
|
|
99
|
+
gridTemplateColumns: `repeat(auto-fill, ${gridTemplateWidth})`,
|
|
100
|
+
}"
|
|
101
|
+
>
|
|
102
|
+
<StoryVariantGridItem
|
|
103
|
+
v-for="(variant, index) of storyStore.currentStory.variants.slice(0, maxCount)"
|
|
104
|
+
:key="index"
|
|
105
|
+
:variant="variant"
|
|
106
|
+
:story="storyStore.currentStory"
|
|
107
|
+
@resize="onItemResize"
|
|
108
|
+
/>
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
</template>
|