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
|
@@ -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,21 +20,47 @@ 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
|
|
|
23
30
|
Object.assign(props.variant, {
|
|
24
|
-
|
|
31
|
+
previewReady: false,
|
|
25
32
|
})
|
|
26
33
|
function onReady () {
|
|
27
34
|
Object.assign(props.variant, {
|
|
28
|
-
|
|
35
|
+
previewReady: 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.previewReady) {
|
|
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"
|
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import { PropType, ref } from 'vue'
|
|
3
|
-
import { Icon } from '@iconify/vue'
|
|
4
2
|
import type { Story, Variant } from '../../types'
|
|
5
|
-
import { histoireConfig } from '../../util/config'
|
|
6
|
-
import { usePreviewSettings } from '../../util/preview-settings'
|
|
7
3
|
import StoryResponsivePreview from './StoryResponsivePreview.vue'
|
|
8
|
-
import BaseCheckbox from '../base/BaseCheckbox.vue'
|
|
9
4
|
import { isMobile } from '../../util/responsive'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
story:
|
|
18
|
-
|
|
19
|
-
required: true,
|
|
20
|
-
},
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const settings = usePreviewSettings()
|
|
5
|
+
import StoryVariantTitle from './toolbar/StoryVariantTitle.vue'
|
|
6
|
+
import StoryVariantResponsiveSize from './toolbar/StoryVariantResponsiveSize.vue'
|
|
7
|
+
import StoryVariantBackground from './toolbar/StoryVariantBackground.vue'
|
|
8
|
+
import StoryVariantNewTab from './toolbar/StoryVariantNewTab.vue'
|
|
9
|
+
|
|
10
|
+
defineProps<{
|
|
11
|
+
variant: Variant
|
|
12
|
+
story: Story
|
|
13
|
+
}>()
|
|
24
14
|
</script>
|
|
25
15
|
|
|
26
16
|
<template>
|
|
@@ -33,154 +23,23 @@ const settings = usePreviewSettings()
|
|
|
33
23
|
v-if="!isMobile"
|
|
34
24
|
class="htw-flex-none htw-flex htw-items-center htw-h-8 -htw-mt-1"
|
|
35
25
|
>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<!-- Responsive size -->
|
|
49
|
-
<VDropdown
|
|
50
|
-
placement="bottom-end"
|
|
51
|
-
:skidding="6"
|
|
52
|
-
:disabled="!histoireConfig.responsivePresets?.length"
|
|
53
|
-
class="htw-h-full htw-flex-none"
|
|
54
|
-
>
|
|
55
|
-
<div
|
|
56
|
-
v-tooltip="'Responsive sizes'"
|
|
57
|
-
class="htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2"
|
|
58
|
-
:class="{
|
|
59
|
-
'htw-cursor-pointer hover:htw-text-primary-500': histoireConfig.responsivePresets?.length,
|
|
60
|
-
}"
|
|
61
|
-
>
|
|
62
|
-
<Icon
|
|
63
|
-
icon="ic:baseline-phone-android"
|
|
64
|
-
class="htw-w-4 htw-h-4 htw-opacity-50"
|
|
65
|
-
/>
|
|
66
|
-
<Icon
|
|
67
|
-
icon="carbon:caret-down"
|
|
68
|
-
class="htw-w-4 htw-h-4 htw-opacity-50"
|
|
69
|
-
/>
|
|
70
|
-
</div>
|
|
71
|
-
|
|
72
|
-
<template #popper="{ hide }">
|
|
73
|
-
<div class="htw-flex htw-flex-col htw-items-stretch">
|
|
74
|
-
<BaseCheckbox v-model="settings.rotate">
|
|
75
|
-
Rotate
|
|
76
|
-
</BaseCheckbox>
|
|
77
|
-
|
|
78
|
-
<div class="htw-flex htw-gap-2 htw-px-4 htw-py-3">
|
|
79
|
-
<input
|
|
80
|
-
v-model.number="settings.responsiveWidth"
|
|
81
|
-
v-tooltip="'Responsive width (px)'"
|
|
82
|
-
type="number"
|
|
83
|
-
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"
|
|
84
|
-
step="16"
|
|
85
|
-
placeholder="Auto"
|
|
86
|
-
>
|
|
87
|
-
<span class="htw-opacity-50">x</span>
|
|
88
|
-
<input
|
|
89
|
-
v-model.number="settings.responsiveHeight"
|
|
90
|
-
v-tooltip="'Responsive height (px)'"
|
|
91
|
-
type="number"
|
|
92
|
-
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"
|
|
93
|
-
step="16"
|
|
94
|
-
placeholder="Auto"
|
|
95
|
-
>
|
|
96
|
-
</div>
|
|
97
|
-
|
|
98
|
-
<button
|
|
99
|
-
v-for="(preset, index) in histoireConfig.responsivePresets"
|
|
100
|
-
:key="index"
|
|
101
|
-
class="htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-4"
|
|
102
|
-
:class="[
|
|
103
|
-
settings.responsiveWidth === preset.width && settings.responsiveHeight === preset.height
|
|
104
|
-
? 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
|
|
105
|
-
: 'htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700',
|
|
106
|
-
]"
|
|
107
|
-
@click="settings.responsiveWidth = preset.width;settings.responsiveHeight = preset.height;hide()"
|
|
108
|
-
>
|
|
109
|
-
{{ preset.label }}
|
|
110
|
-
<span class="htw-ml-auto htw-opacity-70 htw-flex htw-gap-1">
|
|
111
|
-
<span v-if="preset.width">{{ preset.width }}<span v-if="!preset.height">px</span></span>
|
|
112
|
-
<span v-if="preset.width && preset.height">x</span>
|
|
113
|
-
<span v-if="preset.height">{{ preset.height }}<span v-if="!preset.width">px</span></span>
|
|
114
|
-
</span>
|
|
115
|
-
</button>
|
|
116
|
-
</div>
|
|
117
|
-
</template>
|
|
118
|
-
</VDropdown>
|
|
119
|
-
|
|
120
|
-
<!-- Background -->
|
|
121
|
-
<VDropdown
|
|
122
|
-
v-if="histoireConfig.backgroundPresets.length"
|
|
123
|
-
placement="bottom-end"
|
|
124
|
-
:skidding="6"
|
|
125
|
-
class="htw-h-full htw-flex-none"
|
|
126
|
-
>
|
|
127
|
-
<div
|
|
128
|
-
v-tooltip="'Background color'"
|
|
129
|
-
class="htw-cursor-pointer hover:htw-text-primary-500 htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2"
|
|
130
|
-
>
|
|
131
|
-
<div
|
|
132
|
-
class="bind-preview-bg htw-w-4 htw-h-4 htw-rounded-full htw-border htw-border-black/20 dark:htw-border-white/20"
|
|
133
|
-
/>
|
|
134
|
-
<Icon
|
|
135
|
-
icon="carbon:caret-down"
|
|
136
|
-
class="htw-w-4 htw-h-4 htw-opacity-50"
|
|
137
|
-
/>
|
|
138
|
-
</div>
|
|
139
|
-
|
|
140
|
-
<template #popper="{ hide }">
|
|
141
|
-
<div class="htw-flex htw-flex-col htw-items-stretch">
|
|
142
|
-
<BaseCheckbox v-model="settings.checkerboard">
|
|
143
|
-
Checkerboard
|
|
144
|
-
</BaseCheckbox>
|
|
145
|
-
|
|
146
|
-
<button
|
|
147
|
-
v-for="(option, index) in histoireConfig.backgroundPresets"
|
|
148
|
-
:key="index"
|
|
149
|
-
class="htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-4"
|
|
150
|
-
:class="[
|
|
151
|
-
settings.backgroundColor === option.color
|
|
152
|
-
? 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
|
|
153
|
-
: 'htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700',
|
|
154
|
-
]"
|
|
155
|
-
@click="settings.backgroundColor = option.color;hide()"
|
|
156
|
-
>
|
|
157
|
-
<span class="htw-mr-auto">{{ option.label }}</span>
|
|
158
|
-
<template v-if="option.color !== '$checkerboard'">
|
|
159
|
-
<span class="htw-ml-auto htw-opacity-70">{{ option.color }}</span>
|
|
160
|
-
<div
|
|
161
|
-
class="htw-w-4 htw-h-4 htw-rounded-full htw-border htw-border-black/20 dark:htw-border-white/20"
|
|
162
|
-
:style="{
|
|
163
|
-
backgroundColor: option.color,
|
|
164
|
-
}"
|
|
165
|
-
/>
|
|
166
|
-
</template>
|
|
167
|
-
</button>
|
|
168
|
-
</div>
|
|
169
|
-
</template>
|
|
170
|
-
</VDropdown>
|
|
26
|
+
<StoryVariantTitle
|
|
27
|
+
:variant="variant"
|
|
28
|
+
/>
|
|
29
|
+
<StoryVariantResponsiveSize
|
|
30
|
+
v-if="!variant.responsiveDisabled"
|
|
31
|
+
/>
|
|
32
|
+
<StoryVariantBackground />
|
|
33
|
+
<StoryVariantNewTab
|
|
34
|
+
:variant="variant"
|
|
35
|
+
:story="story"
|
|
36
|
+
/>
|
|
171
37
|
</div>
|
|
172
38
|
|
|
173
39
|
<!-- Preview -->
|
|
174
40
|
<StoryResponsivePreview
|
|
175
|
-
v-model:settings="settings"
|
|
176
41
|
:story="story"
|
|
177
42
|
:variant="variant"
|
|
178
43
|
/>
|
|
179
44
|
</div>
|
|
180
45
|
</template>
|
|
181
|
-
|
|
182
|
-
<style scoped>
|
|
183
|
-
.bind-preview-bg {
|
|
184
|
-
background-color: v-bind('settings.backgroundColor');
|
|
185
|
-
}
|
|
186
|
-
</style>
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computed, ref, watch } from 'vue'
|
|
3
|
-
import { useRoute, useRouter } from 'vue-router'
|
|
4
3
|
import { useStoryStore } from '../../stores/story'
|
|
5
|
-
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
import { isMobile } from '../../util/responsive'
|
|
6
6
|
import BaseSplitPane from '../base/BaseSplitPane.vue'
|
|
7
7
|
import StoryVariantListItem from './StoryVariantListItem.vue'
|
|
8
|
-
import StoryVariantGridItem from './StoryVariantGridItem.vue'
|
|
9
8
|
import StoryVariantSingleView from './StoryVariantSingleView.vue'
|
|
10
|
-
import { isMobile } from '../../util/responsive'
|
|
11
|
-
import { Icon } from '@iconify/vue'
|
|
12
9
|
import MobileOverlay from '../app/MobileOverlay.vue'
|
|
10
|
+
import StoryVariantGrid from './StoryVariantGrid.vue'
|
|
13
11
|
|
|
14
12
|
const storyStore = useStoryStore()
|
|
15
13
|
|
|
16
|
-
const router = useRouter()
|
|
17
|
-
const route = useRoute()
|
|
18
|
-
|
|
19
14
|
const hasSingleVariant = computed(() => (storyStore.currentStory?.variants.length === 1))
|
|
20
15
|
|
|
21
16
|
const variant = computed(() => storyStore.currentVariant)
|
|
@@ -34,45 +29,13 @@ watch(variant, () => {
|
|
|
34
29
|
isMenuOpened.value = false
|
|
35
30
|
})
|
|
36
31
|
|
|
37
|
-
const templateWidth = computed(() => {
|
|
38
|
-
if (storyStore.currentStory.layout.type !== 'grid') {
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const layoutWidth = storyStore.currentStory.layout.width
|
|
43
|
-
|
|
44
|
-
if (!layoutWidth) {
|
|
45
|
-
return '200px'
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (typeof layoutWidth === 'number') {
|
|
49
|
-
return layoutWidth + 'px'
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return layoutWidth
|
|
53
|
-
})
|
|
54
32
|
</script>
|
|
55
33
|
|
|
56
34
|
<template>
|
|
57
35
|
<div class="htw-bg-gray-50 htw-h-full dark:htw-bg-gray-750">
|
|
58
|
-
<
|
|
36
|
+
<StoryVariantGrid
|
|
59
37
|
v-if="storyStore.currentStory.layout.type === 'grid'"
|
|
60
|
-
|
|
61
|
-
>
|
|
62
|
-
<div
|
|
63
|
-
class="htw-grid htw-gap-4 htw-m-4"
|
|
64
|
-
:style="{
|
|
65
|
-
gridTemplateColumns: `repeat(auto-fill, ${templateWidth})`,
|
|
66
|
-
}"
|
|
67
|
-
>
|
|
68
|
-
<StoryVariantGridItem
|
|
69
|
-
v-for="(variant, index) of storyStore.currentStory.variants"
|
|
70
|
-
:key="index"
|
|
71
|
-
:variant="variant"
|
|
72
|
-
:story="storyStore.currentStory"
|
|
73
|
-
/>
|
|
74
|
-
</div>
|
|
75
|
-
</div>
|
|
38
|
+
/>
|
|
76
39
|
|
|
77
40
|
<template v-else-if="storyStore.currentStory.layout.type === 'single'">
|
|
78
41
|
<div
|
|
@@ -80,6 +43,7 @@ const templateWidth = computed(() => {
|
|
|
80
43
|
class="htw-p-2 htw-h-full"
|
|
81
44
|
>
|
|
82
45
|
<StoryVariantSingleView
|
|
46
|
+
v-if="storyStore.currentVariant.configReady"
|
|
83
47
|
:variant="storyStore.currentVariant"
|
|
84
48
|
:story="storyStore.currentStory"
|
|
85
49
|
/>
|
|
@@ -118,6 +82,7 @@ const templateWidth = computed(() => {
|
|
|
118
82
|
class="htw-p-2 htw-h-full"
|
|
119
83
|
>
|
|
120
84
|
<StoryVariantSingleView
|
|
85
|
+
v-if="storyStore.currentVariant.configReady"
|
|
121
86
|
:variant="storyStore.currentVariant"
|
|
122
87
|
:story="storyStore.currentStory"
|
|
123
88
|
/>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { Icon } from '@iconify/vue'
|
|
3
|
+
import { usePreviewSettingsStore } from '../../../stores/preview-settings'
|
|
4
|
+
import { histoireConfig } from '../../../util/config'
|
|
5
|
+
import BaseCheckbox from '../../base/BaseCheckbox.vue'
|
|
6
|
+
|
|
7
|
+
const settings = usePreviewSettingsStore().currentSettings
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<VDropdown
|
|
12
|
+
v-if="histoireConfig.backgroundPresets.length"
|
|
13
|
+
placement="bottom-end"
|
|
14
|
+
:skidding="6"
|
|
15
|
+
class="htw-h-full htw-flex-none"
|
|
16
|
+
>
|
|
17
|
+
<div
|
|
18
|
+
v-tooltip="'Background color'"
|
|
19
|
+
class="htw-cursor-pointer hover:htw-text-primary-500 htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2 htw-group"
|
|
20
|
+
>
|
|
21
|
+
<div
|
|
22
|
+
class="bind-preview-bg htw-w-4 htw-h-4 htw-rounded-full htw-border htw-border-black/50 dark:htw-border-white/50"
|
|
23
|
+
/>
|
|
24
|
+
<Icon
|
|
25
|
+
icon="carbon:caret-down"
|
|
26
|
+
class="htw-w-4 htw-h-4 htw-opacity-50 group-hover:htw-opacity-100"
|
|
27
|
+
/>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<template #popper="{ hide }">
|
|
31
|
+
<div class="htw-flex htw-flex-col htw-items-stretch">
|
|
32
|
+
<BaseCheckbox v-model="settings.checkerboard">
|
|
33
|
+
Checkerboard
|
|
34
|
+
</BaseCheckbox>
|
|
35
|
+
|
|
36
|
+
<button
|
|
37
|
+
v-for="(option, index) in histoireConfig.backgroundPresets"
|
|
38
|
+
:key="index"
|
|
39
|
+
class="htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-4"
|
|
40
|
+
:class="[
|
|
41
|
+
settings.backgroundColor === option.color
|
|
42
|
+
? 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
|
|
43
|
+
: 'htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700',
|
|
44
|
+
]"
|
|
45
|
+
@click="settings.backgroundColor = option.color;hide()"
|
|
46
|
+
>
|
|
47
|
+
<span class="htw-mr-auto">{{ option.label }}</span>
|
|
48
|
+
<template v-if="option.color !== '$checkerboard'">
|
|
49
|
+
<span class="htw-ml-auto htw-opacity-70">{{ option.color }}</span>
|
|
50
|
+
<div
|
|
51
|
+
class="htw-w-4 htw-h-4 htw-rounded-full htw-border htw-border-black/20 dark:htw-border-white/20"
|
|
52
|
+
:style="{
|
|
53
|
+
backgroundColor: option.color,
|
|
54
|
+
}"
|
|
55
|
+
/>
|
|
56
|
+
</template>
|
|
57
|
+
</button>
|
|
58
|
+
</div>
|
|
59
|
+
</template>
|
|
60
|
+
</VDropdown>
|
|
61
|
+
</template>
|
|
62
|
+
|
|
63
|
+
<style scoped>
|
|
64
|
+
.bind-preview-bg {
|
|
65
|
+
background-color: v-bind('settings.backgroundColor');
|
|
66
|
+
}
|
|
67
|
+
</style>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { Icon } from '@iconify/vue'
|
|
3
|
+
import type { Story, Variant } from '../../../types'
|
|
4
|
+
import { computed } from 'vue'
|
|
5
|
+
import { getSandboxUrl } from '../../sandbox/lib'
|
|
6
|
+
|
|
7
|
+
const props = defineProps<{
|
|
8
|
+
variant: Variant
|
|
9
|
+
story: Story
|
|
10
|
+
}>()
|
|
11
|
+
|
|
12
|
+
const sandboxUrl = computed(() => {
|
|
13
|
+
return getSandboxUrl(props.story, props.variant)
|
|
14
|
+
})
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<a
|
|
19
|
+
v-tooltip="'Open variant in new tab'"
|
|
20
|
+
:href="sandboxUrl"
|
|
21
|
+
target="_blank"
|
|
22
|
+
class="htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2 hover:htw-text-primary-500 htw-opacity-50 hover:htw-opacity-100"
|
|
23
|
+
>
|
|
24
|
+
<Icon
|
|
25
|
+
icon="carbon:launch"
|
|
26
|
+
class="base-list-item-link-icon htw-w-4 htw-h-4"
|
|
27
|
+
/>
|
|
28
|
+
</a>
|
|
29
|
+
</template>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { Icon } from '@iconify/vue'
|
|
3
|
+
import { usePreviewSettingsStore } from '../../../stores/preview-settings'
|
|
4
|
+
import { histoireConfig } from '../../../util/config'
|
|
5
|
+
import BaseCheckbox from '../../base/BaseCheckbox.vue'
|
|
6
|
+
|
|
7
|
+
const settings = usePreviewSettingsStore().currentSettings
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<!-- Responsive size -->
|
|
12
|
+
<VDropdown
|
|
13
|
+
placement="bottom-end"
|
|
14
|
+
:skidding="6"
|
|
15
|
+
:disabled="!histoireConfig.responsivePresets?.length"
|
|
16
|
+
class="htw-h-full htw-flex-none"
|
|
17
|
+
>
|
|
18
|
+
<div
|
|
19
|
+
v-tooltip="'Responsive sizes'"
|
|
20
|
+
class="htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2 htw-group"
|
|
21
|
+
:class="{
|
|
22
|
+
'htw-cursor-pointer hover:htw-text-primary-500': histoireConfig.responsivePresets?.length,
|
|
23
|
+
}"
|
|
24
|
+
>
|
|
25
|
+
<Icon
|
|
26
|
+
icon="carbon:devices"
|
|
27
|
+
class="htw-w-4 htw-h-4 htw-opacity-50 group-hover:htw-opacity-100"
|
|
28
|
+
/>
|
|
29
|
+
<Icon
|
|
30
|
+
icon="carbon:caret-down"
|
|
31
|
+
class="htw-w-4 htw-h-4 htw-opacity-50 group-hover:htw-opacity-100"
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<template #popper="{ hide }">
|
|
36
|
+
<div class="htw-flex htw-flex-col htw-items-stretch">
|
|
37
|
+
<BaseCheckbox v-model="settings.rotate">
|
|
38
|
+
Rotate
|
|
39
|
+
</BaseCheckbox>
|
|
40
|
+
|
|
41
|
+
<div class="htw-flex htw-gap-2 htw-px-4 htw-py-3">
|
|
42
|
+
<input
|
|
43
|
+
v-model.number="settings.responsiveWidth"
|
|
44
|
+
v-tooltip="'Responsive width (px)'"
|
|
45
|
+
type="number"
|
|
46
|
+
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"
|
|
47
|
+
step="16"
|
|
48
|
+
placeholder="Auto"
|
|
49
|
+
>
|
|
50
|
+
<span class="htw-opacity-50">x</span>
|
|
51
|
+
<input
|
|
52
|
+
v-model.number="settings.responsiveHeight"
|
|
53
|
+
v-tooltip="'Responsive height (px)'"
|
|
54
|
+
type="number"
|
|
55
|
+
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"
|
|
56
|
+
step="16"
|
|
57
|
+
placeholder="Auto"
|
|
58
|
+
>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<button
|
|
62
|
+
v-for="(preset, index) in histoireConfig.responsivePresets"
|
|
63
|
+
:key="index"
|
|
64
|
+
class="htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-4"
|
|
65
|
+
:class="[
|
|
66
|
+
settings.responsiveWidth === preset.width && settings.responsiveHeight === preset.height
|
|
67
|
+
? 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
|
|
68
|
+
: 'htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700',
|
|
69
|
+
]"
|
|
70
|
+
@click="settings.responsiveWidth = preset.width;settings.responsiveHeight = preset.height;hide()"
|
|
71
|
+
>
|
|
72
|
+
{{ preset.label }}
|
|
73
|
+
<span class="htw-ml-auto htw-opacity-70 htw-flex htw-gap-1">
|
|
74
|
+
<span v-if="preset.width">{{ preset.width }}<span v-if="!preset.height">px</span></span>
|
|
75
|
+
<span v-if="preset.width && preset.height">x</span>
|
|
76
|
+
<span v-if="preset.height">{{ preset.height }}<span v-if="!preset.width">px</span></span>
|
|
77
|
+
</span>
|
|
78
|
+
</button>
|
|
79
|
+
</div>
|
|
80
|
+
</template>
|
|
81
|
+
</VDropdown>
|
|
82
|
+
</template>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { Icon } from '@iconify/vue'
|
|
3
|
+
import type { Variant } from '../../../types'
|
|
4
|
+
|
|
5
|
+
defineProps<{
|
|
6
|
+
variant: Variant
|
|
7
|
+
}>()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<div class="htw-flex htw-items-center htw-gap-1 htw-text-gray-500 htw-flex-1 htw-truncate htw-min-w-0">
|
|
12
|
+
<Icon
|
|
13
|
+
:icon="variant.icon ?? 'carbon:cube'"
|
|
14
|
+
class="base-list-item-link-icon htw-w-4 htw-h-4 htw-opacity-50"
|
|
15
|
+
:class="[
|
|
16
|
+
variant.iconColor ? 'bind-icon-color' : 'htw-text-gray-500',
|
|
17
|
+
]"
|
|
18
|
+
/>
|
|
19
|
+
<span>{{ variant.title }}</span>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineStore } from 'pinia'
|
|
2
|
+
import { useStorage } from '@vueuse/core'
|
|
3
|
+
import type { PreviewSettings } from '../types'
|
|
4
|
+
|
|
5
|
+
export const usePreviewSettingsStore = defineStore('preview-settings', () => {
|
|
6
|
+
const currentSettings = useStorage<PreviewSettings>('_histoire-sandbox-settings-v2', {
|
|
7
|
+
responsiveWidth: 720,
|
|
8
|
+
responsiveHeight: null,
|
|
9
|
+
rotate: false,
|
|
10
|
+
backgroundColor: 'transparent',
|
|
11
|
+
checkerboard: false,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
currentSettings,
|
|
16
|
+
}
|
|
17
|
+
})
|
package/src/client/app/types.ts
CHANGED
|
@@ -33,7 +33,9 @@ export interface Variant {
|
|
|
33
33
|
slots?: () => Readonly<any>
|
|
34
34
|
state?: any
|
|
35
35
|
source?: string
|
|
36
|
-
|
|
36
|
+
responsiveDisabled?: boolean
|
|
37
|
+
configReady?: boolean
|
|
38
|
+
previewReady?: boolean
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
export type TreeLeaf = {
|
|
@@ -58,3 +60,11 @@ export interface SearchResult {
|
|
|
58
60
|
icon?: string
|
|
59
61
|
iconColor?: string
|
|
60
62
|
}
|
|
63
|
+
|
|
64
|
+
export interface PreviewSettings {
|
|
65
|
+
responsiveWidth: number
|
|
66
|
+
responsiveHeight: number
|
|
67
|
+
rotate: boolean
|
|
68
|
+
backgroundColor: string
|
|
69
|
+
checkerboard: boolean
|
|
70
|
+
}
|
|
@@ -18,10 +18,15 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
|
|
|
18
18
|
const variant = result.story.variants[index]
|
|
19
19
|
const existingVariant = existingFile.story.variants[index]
|
|
20
20
|
if (existingVariant) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
for (const key in existingVariant) {
|
|
22
|
+
if (typeof existingVariant[key] !== 'undefined') {
|
|
23
|
+
if (key === 'state') {
|
|
24
|
+
Object.assign(variant.state, existingVariant.state)
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
variant[key] = existingVariant[key]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
if (existingFile.story.lastSelectedVariant) {
|
|
@@ -38,6 +43,6 @@ export function mapVariant (variant: Variant): Variant {
|
|
|
38
43
|
state: {},
|
|
39
44
|
initState: null,
|
|
40
45
|
slots: () => ({}),
|
|
41
|
-
|
|
46
|
+
previewReady: false,
|
|
42
47
|
}
|
|
43
48
|
}
|
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
import { useStorage } from '@vueuse/core'
|
|
2
1
|
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
|
-
}
|
|
2
|
+
import type { PreviewSettings } from '../types'
|
|
21
3
|
|
|
22
4
|
export const receivedSettings = reactive<PreviewSettings>({} as PreviewSettings)
|
|
23
5
|
|