histoire 0.1.5 → 0.2.2
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/codegen/vue3.js +1 -0
- package/dist/client/app/codegen/vue3.js.map +1 -0
- package/dist/client/app/components/app/AppHeader.vue +2 -1
- package/dist/client/app/components/base/BaseCheckbox.vue +76 -0
- package/dist/client/app/components/exposed/Story.vue +20 -14
- 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/search/SearchItem.vue +4 -1
- package/dist/client/app/components/search/SearchModal.vue +4 -4
- package/dist/client/app/components/story/StoryControls.vue +1 -1
- package/dist/client/app/components/story/StoryDocs.vue +1 -0
- package/dist/client/app/components/story/StoryListFolder.vue +1 -1
- package/dist/client/app/components/story/StoryListItem.vue +4 -1
- package/dist/client/app/components/story/StoryResponsivePreview.vue +3 -4
- package/dist/client/app/components/story/StorySidePanel.vue +1 -0
- package/dist/client/app/components/story/StorySourceCode.vue +4 -1
- package/dist/client/app/components/story/StoryVariantGrid.vue +112 -0
- package/dist/client/app/components/story/StoryVariantGridItem.vue +34 -4
- package/dist/client/app/components/story/StoryVariantListItem.vue +4 -1
- package/dist/client/app/components/story/StoryVariantSingleView.vue +20 -160
- package/dist/client/app/components/story/StoryViewer.vue +6 -25
- package/dist/client/app/components/story/variant/StoryVariantBackground.vue +67 -0
- package/dist/client/app/components/story/variant/StoryVariantNewTab.vue +29 -0
- package/dist/client/app/components/story/variant/StoryVariantResponsiveSize.vue +82 -0
- package/dist/client/app/components/story/variant/StoryVariantTitle.vue +21 -0
- package/dist/client/app/global-components.js +1 -0
- package/dist/client/app/global-components.js.map +1 -0
- package/dist/client/app/index.js +1 -0
- package/dist/client/app/index.js.map +1 -0
- package/dist/client/app/sandbox.js +1 -0
- package/dist/client/app/sandbox.js.map +1 -0
- package/dist/client/app/stores/story.d.ts +6 -6
- package/dist/client/app/stores/story.js +1 -0
- package/dist/client/app/stores/story.js.map +1 -0
- package/dist/client/app/style/main.pcss +9 -5
- package/dist/client/app/types.d.ts +1 -1
- package/dist/client/app/types.ts +1 -1
- package/dist/client/app/util/keyboard.js +1 -0
- package/dist/client/app/util/keyboard.js.map +1 -0
- package/dist/client/app/util/mapping.js +1 -0
- package/dist/client/app/util/mapping.js.map +1 -0
- package/dist/client/app/util/preview-settings.js +1 -0
- package/dist/client/app/util/preview-settings.js.map +1 -0
- package/dist/client/app/util/reactivity.js +1 -0
- package/dist/client/app/util/reactivity.js.map +1 -0
- package/dist/client/app/util/scroll.d.ts +3 -1
- package/dist/client/app/util/scroll.js +4 -0
- package/dist/client/app/util/scroll.js.map +1 -0
- package/dist/client/app/util/scroll.ts +4 -0
- package/dist/client/app/util/variant.js +1 -0
- package/dist/client/app/util/variant.js.map +1 -0
- package/dist/client/index.js +1 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/server/index.js +1 -0
- package/dist/client/server/index.js.map +1 -0
- package/dist/controls.js +1 -0
- package/dist/controls.js.map +1 -0
- package/dist/node/bin.js +7 -0
- package/dist/node/build.js +1 -1
- package/dist/node/{collect.d.ts → collect/index.d.ts} +2 -2
- package/dist/node/{collect.js → collect/index.js} +37 -27
- package/dist/node/collect/worker.d.ts +14 -0
- package/dist/node/collect/worker.js +36 -0
- package/dist/node/commands/preview.d.ts +4 -0
- package/dist/node/commands/preview.js +36 -0
- package/dist/node/config.d.ts +2 -2
- package/dist/node/server.js +1 -1
- package/dist/node/tree.js +24 -4
- package/dist/node/types.d.ts +1 -1
- package/dist/style.css +98 -50
- package/package.json +10 -6
- package/src/client/app/components/app/AppHeader.vue +2 -1
- package/src/client/app/components/base/BaseCheckbox.vue +76 -0
- package/src/client/app/components/exposed/Story.vue +20 -14
- package/src/client/app/components/sandbox/lib.ts +8 -0
- package/src/client/app/components/search/SearchItem.vue +4 -1
- package/src/client/app/components/search/SearchModal.vue +4 -4
- package/src/client/app/components/story/StoryControls.vue +1 -1
- package/src/client/app/components/story/StoryDocs.vue +1 -0
- package/src/client/app/components/story/StoryListFolder.vue +1 -1
- package/src/client/app/components/story/StoryListItem.vue +4 -1
- package/src/client/app/components/story/StoryResponsivePreview.vue +3 -4
- package/src/client/app/components/story/StorySidePanel.vue +1 -0
- package/src/client/app/components/story/StorySourceCode.vue +4 -1
- package/src/client/app/components/story/StoryVariantGrid.vue +112 -0
- package/src/client/app/components/story/StoryVariantGridItem.vue +34 -4
- package/src/client/app/components/story/StoryVariantListItem.vue +4 -1
- package/src/client/app/components/story/StoryVariantSingleView.vue +20 -160
- package/src/client/app/components/story/StoryViewer.vue +6 -25
- package/src/client/app/components/story/variant/StoryVariantBackground.vue +67 -0
- package/src/client/app/components/story/variant/StoryVariantNewTab.vue +29 -0
- package/src/client/app/components/story/variant/StoryVariantResponsiveSize.vue +82 -0
- package/src/client/app/components/story/variant/StoryVariantTitle.vue +21 -0
- package/src/client/app/style/main.pcss +9 -5
- package/src/client/app/types.ts +1 -1
- package/src/client/app/util/scroll.ts +4 -0
- package/src/node/bin.ts +8 -0
- package/src/node/build.ts +1 -1
- package/src/node/{collect.ts → collect/index.ts} +48 -30
- package/src/node/collect/worker.ts +61 -0
- package/src/node/commands/preview.ts +50 -0
- package/src/node/config.ts +2 -2
- package/src/node/server.ts +1 -1
- package/src/node/tree.spec.ts +61 -0
- package/src/node/tree.ts +29 -5
- package/src/node/types.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A fast story book powered by Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -34,11 +34,13 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@iconify/vue": "^3.1.3",
|
|
37
|
-
"@histoire/controls": "^0.
|
|
38
|
-
"@vitejs/plugin-vue": "^2.
|
|
37
|
+
"@histoire/controls": "^0.2.2",
|
|
38
|
+
"@vitejs/plugin-vue": "^2.3.1",
|
|
39
39
|
"@vueuse/core": "^8.1.1",
|
|
40
|
+
"birpc": "^0.1.0",
|
|
40
41
|
"case": "^1.6.3",
|
|
41
42
|
"chokidar": "^3.5.3",
|
|
43
|
+
"connect": "^3.7.0",
|
|
42
44
|
"defu": "^5.0.1",
|
|
43
45
|
"diacritics": "^1.3.0",
|
|
44
46
|
"floating-vue": "^2.0.0-beta.6",
|
|
@@ -56,11 +58,13 @@
|
|
|
56
58
|
"sade": "^1.8.1",
|
|
57
59
|
"scroll-into-view-if-needed": "^2.2.29",
|
|
58
60
|
"shiki": "^0.10.1",
|
|
59
|
-
"
|
|
61
|
+
"sirv": "^2.0.2",
|
|
62
|
+
"tinypool": "^0.1.2",
|
|
63
|
+
"vite-node": "=0.7.6",
|
|
60
64
|
"vue-router": "^4.0.12"
|
|
61
65
|
},
|
|
62
66
|
"peerDependencies": {
|
|
63
|
-
"vite": "^2.
|
|
67
|
+
"vite": "^2.9.0",
|
|
64
68
|
"vue": "^3.2.31"
|
|
65
69
|
},
|
|
66
70
|
"devDependencies": {
|
|
@@ -75,7 +79,7 @@
|
|
|
75
79
|
"postcss-import": "^14.0.2",
|
|
76
80
|
"tailwindcss": "^3.0.23",
|
|
77
81
|
"typescript": "^4.5.5",
|
|
78
|
-
"vite": "^2.
|
|
82
|
+
"vite": "^2.9.0",
|
|
79
83
|
"vue": "^3.2.31"
|
|
80
84
|
},
|
|
81
85
|
"scripts": {
|
|
@@ -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,6 +40,7 @@ onKeyboardShortcut(['ctrl+shift+d', 'meta+shift+d'], (event) => {
|
|
|
40
40
|
<a
|
|
41
41
|
v-tooltip="makeTooltip('Search', ({ isMac }) => isMac ? 'meta+k' : 'ctrl+k')"
|
|
42
42
|
class="htw-p-2 sm:htw-p-1 hover:htw-text-primary-500 dark:hover:htw-text-primary-400 htw-cursor-pointer"
|
|
43
|
+
data-test-id="search-btn"
|
|
43
44
|
@click="$emit('search')"
|
|
44
45
|
>
|
|
45
46
|
<Icon
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed, ref, watch } from 'vue'
|
|
3
|
+
|
|
4
|
+
const props = defineProps({
|
|
5
|
+
modelValue: {
|
|
6
|
+
type: Boolean,
|
|
7
|
+
default: false,
|
|
8
|
+
},
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const emit = defineEmits({
|
|
12
|
+
'update:modelValue': (newValue: boolean) => true,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
function toggle () {
|
|
16
|
+
emit('update:modelValue', !props.modelValue)
|
|
17
|
+
animationEnabled.value = true
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// SVG check
|
|
21
|
+
|
|
22
|
+
const path = ref<SVGPathElement>()
|
|
23
|
+
const dasharray = ref(0)
|
|
24
|
+
const progress = computed(() => props.modelValue ? 1 : 0)
|
|
25
|
+
const dashoffset = computed(() => (1 - progress.value) * dasharray.value)
|
|
26
|
+
const animationEnabled = ref(false)
|
|
27
|
+
|
|
28
|
+
watch(path, value => {
|
|
29
|
+
dasharray.value = path.value.getTotalLength?.() ?? 21.21
|
|
30
|
+
})
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<template>
|
|
34
|
+
<div
|
|
35
|
+
role="checkbox"
|
|
36
|
+
tabindex="0"
|
|
37
|
+
class="htw-flex htw-items-center htw-gap-2 htw-select-none htw-px-4 htw-py-3 htw-cursor-pointer hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700"
|
|
38
|
+
@click="toggle()"
|
|
39
|
+
@keydown.enter.prevent="toggle()"
|
|
40
|
+
@keydown.space.prevent="toggle()"
|
|
41
|
+
>
|
|
42
|
+
<div class="htw-text-white htw-w-[16px] htw-h-[16px] htw-relative">
|
|
43
|
+
<div
|
|
44
|
+
class="htw-border group-active:htw-bg-gray-500/20 htw-rounded-sm htw-box-border htw-absolute htw-inset-0 htw-transition-border htw-duration-150 htw-ease-out"
|
|
45
|
+
:class="[
|
|
46
|
+
modelValue
|
|
47
|
+
? 'htw-border-primary-500 htw-border-8'
|
|
48
|
+
: 'htw-border-black/25 dark:htw-border-white/25 htw-delay-150',
|
|
49
|
+
]"
|
|
50
|
+
/>
|
|
51
|
+
<svg
|
|
52
|
+
width="16"
|
|
53
|
+
height="16"
|
|
54
|
+
viewBox="0 0 24 24"
|
|
55
|
+
class="htw-relative htw-z-10"
|
|
56
|
+
>
|
|
57
|
+
<path
|
|
58
|
+
ref="path"
|
|
59
|
+
d="m 4 12 l 5 5 l 10 -10"
|
|
60
|
+
fill="none"
|
|
61
|
+
class="htw-stroke-white htw-stroke-2 htw-duration-200 htw-ease-in-out"
|
|
62
|
+
:class="[
|
|
63
|
+
animationEnabled ? 'htw-transition-all' : 'htw-transition-none',
|
|
64
|
+
{
|
|
65
|
+
'htw-delay-150': modelValue,
|
|
66
|
+
},
|
|
67
|
+
]"
|
|
68
|
+
:stroke-dasharray="dasharray"
|
|
69
|
+
:stroke-dashoffset="dashoffset"
|
|
70
|
+
/>
|
|
71
|
+
</svg>
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
<slot />
|
|
75
|
+
</div>
|
|
76
|
+
</template>
|
|
@@ -40,22 +40,28 @@ 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
|
-
vnode.
|
|
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
|
+
index++
|
|
56
|
+
} else if (vnode.children?.length) {
|
|
57
|
+
applyAttrs(vnode.children as VNode[])
|
|
58
|
+
}
|
|
57
59
|
}
|
|
58
60
|
}
|
|
61
|
+
|
|
62
|
+
// Apply variant as attribute to each child vnode (should be `<Variant>` components)
|
|
63
|
+
const vnodes: VNode[] = this.$slots.default()
|
|
64
|
+
applyAttrs(vnodes)
|
|
59
65
|
return vnodes
|
|
60
66
|
},
|
|
61
67
|
})
|
|
@@ -25,8 +25,7 @@ function close () {
|
|
|
25
25
|
// Autofocus
|
|
26
26
|
|
|
27
27
|
const input = ref<HTMLInputElement>()
|
|
28
|
-
const { focused } = useFocus({
|
|
29
|
-
target: input,
|
|
28
|
+
const { focused } = useFocus(input, {
|
|
30
29
|
initialValue: true,
|
|
31
30
|
})
|
|
32
31
|
|
|
@@ -132,6 +131,7 @@ function selectPrevious () {
|
|
|
132
131
|
<div
|
|
133
132
|
v-show="shown"
|
|
134
133
|
class="htw-fixed htw-inset-0 htw-bg-white/80 dark:htw-bg-gray-700/80 htw-z-20"
|
|
134
|
+
data-test-id="search-modal"
|
|
135
135
|
>
|
|
136
136
|
<div
|
|
137
137
|
class="htw-absolute htw-inset-0"
|
|
@@ -152,8 +152,8 @@ function selectPrevious () {
|
|
|
152
152
|
v-model="search"
|
|
153
153
|
placeholder="Search for stories, variants..."
|
|
154
154
|
class="htw-bg-transparent htw-w-full htw-flex-1 htw-pl-0 htw-pr-6 htw-py-4 htw-outline-none"
|
|
155
|
-
@keydown.down="selectNext()"
|
|
156
|
-
@keydown.up="selectPrevious()"
|
|
155
|
+
@keydown.down.prevent="selectNext()"
|
|
156
|
+
@keydown.up.prevent="selectPrevious()"
|
|
157
157
|
@keydown.escape="close()"
|
|
158
158
|
>
|
|
159
159
|
</div>
|
|
@@ -9,6 +9,7 @@ import HatchedPattern from '../misc/HatchedPattern.vue'
|
|
|
9
9
|
import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
|
|
10
10
|
import { toRawDeep } from '../../util/reactivity'
|
|
11
11
|
import { Settings } from 'http2'
|
|
12
|
+
import { getSandboxUrl } from '../sandbox/lib'
|
|
12
13
|
|
|
13
14
|
const props = defineProps<{
|
|
14
15
|
story: Story
|
|
@@ -61,10 +62,7 @@ useEventListener(window, 'message', (event) => {
|
|
|
61
62
|
})
|
|
62
63
|
|
|
63
64
|
const sandboxUrl = computed(() => {
|
|
64
|
-
|
|
65
|
-
url.append('storyId', props.story.id)
|
|
66
|
-
url.append('variantId', props.variant.id)
|
|
67
|
-
return '/__sandbox?' + url.toString()
|
|
65
|
+
return getSandboxUrl(props.story, props.variant)
|
|
68
66
|
})
|
|
69
67
|
|
|
70
68
|
const isIframeLoaded = ref(false)
|
|
@@ -255,6 +253,7 @@ const finalHeight = computed(() => props.settings.rotate ? props.settings.respon
|
|
|
255
253
|
'htw-invisible': !isIframeLoaded,
|
|
256
254
|
'htw-pointer-events-none': resizing,
|
|
257
255
|
}"
|
|
256
|
+
data-test-id="preview-iframe"
|
|
258
257
|
@load="onIframeLoad()"
|
|
259
258
|
/>
|
|
260
259
|
</div>
|
|
@@ -67,7 +67,10 @@ const copySourceCode = () => copy(sourceCode.value)
|
|
|
67
67
|
</script>
|
|
68
68
|
|
|
69
69
|
<template>
|
|
70
|
-
<div
|
|
70
|
+
<div
|
|
71
|
+
class="htw-bg-gray-100 dark:htw-bg-gray-800 htw-h-full htw-overflow-hidden htw-relative"
|
|
72
|
+
data-test-id="story-source-code"
|
|
73
|
+
>
|
|
71
74
|
<div
|
|
72
75
|
v-if="error"
|
|
73
76
|
class="htw-text-red-500 htw-h-full htw-p-2 htw-overflow-auto htw-font-mono htw-text-sm"
|
|
@@ -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>
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import { PropType, toRefs } from 'vue'
|
|
2
|
+
import { PropType, ref, toRefs } from 'vue'
|
|
3
|
+
import { Icon } from '@iconify/vue'
|
|
4
|
+
import { useRouter } from 'vue-router'
|
|
5
|
+
import { useResizeObserver } from '@vueuse/core'
|
|
3
6
|
import { useCurrentVariantRoute } from '../../util/variant'
|
|
4
7
|
import type { Story, Variant } from '../../types'
|
|
5
8
|
import SandboxVue3 from '../sandbox/SandboxVue3.vue'
|
|
6
|
-
import {
|
|
9
|
+
import { useScrollOnActive } from '../../util/scroll.js'
|
|
7
10
|
|
|
8
11
|
const props = defineProps({
|
|
9
12
|
variant: {
|
|
@@ -17,6 +20,10 @@ const props = defineProps({
|
|
|
17
20
|
},
|
|
18
21
|
})
|
|
19
22
|
|
|
23
|
+
const emit = defineEmits({
|
|
24
|
+
resize: (width: number, height: number) => true,
|
|
25
|
+
})
|
|
26
|
+
|
|
20
27
|
const { variant } = toRefs(props)
|
|
21
28
|
const { isActive, targetRoute } = useCurrentVariantRoute(variant)
|
|
22
29
|
|
|
@@ -28,10 +35,32 @@ function onReady () {
|
|
|
28
35
|
ready: true,
|
|
29
36
|
})
|
|
30
37
|
}
|
|
38
|
+
|
|
39
|
+
const router = useRouter()
|
|
40
|
+
|
|
41
|
+
function selectVariant () {
|
|
42
|
+
router.push(targetRoute.value)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const el = ref<HTMLDivElement>()
|
|
46
|
+
|
|
47
|
+
const { autoScroll } = useScrollOnActive(isActive, el)
|
|
48
|
+
|
|
49
|
+
useResizeObserver(el, () => {
|
|
50
|
+
if (props.variant.ready) {
|
|
51
|
+
emit('resize', el.value!.clientWidth, el.value!.clientHeight)
|
|
52
|
+
if (isActive.value) {
|
|
53
|
+
autoScroll()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
})
|
|
31
57
|
</script>
|
|
32
58
|
|
|
33
59
|
<template>
|
|
34
|
-
<div
|
|
60
|
+
<div
|
|
61
|
+
ref="el"
|
|
62
|
+
class="htw-cursor-default htw-flex htw-flex-col htw-gap-y-1"
|
|
63
|
+
>
|
|
35
64
|
<!-- Header -->
|
|
36
65
|
<div class="htw-flex-none htw-flex htw-items-center">
|
|
37
66
|
<RouterLink
|
|
@@ -61,7 +90,8 @@ function onReady () {
|
|
|
61
90
|
'htw-border-gray-100 dark:htw-border-gray-800': !isActive,
|
|
62
91
|
'htw-border-primary-200 dark:htw-border-primary-900': isActive,
|
|
63
92
|
}"
|
|
64
|
-
@click.stop.prevent
|
|
93
|
+
@click.stop.prevent="selectVariant()"
|
|
94
|
+
@keyup="selectVariant()"
|
|
65
95
|
>
|
|
66
96
|
<SandboxVue3
|
|
67
97
|
:variant="variant"
|