histoire 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/client/app/App.vue +1 -1
- 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 +4 -0
- package/dist/client/app/index.ts +4 -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/main.css +15 -0
- 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 +3 -0
- package/dist/client/app/util/mapping.ts +2 -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 +13 -8
- package/dist/node/collect.js +12 -3
- package/dist/node/config.d.ts +24 -2
- package/dist/node/config.js +44 -4
- package/dist/node/markdown.d.ts +2 -0
- package/dist/node/markdown.js +48 -0
- package/dist/node/plugin.js +29 -2
- package/dist/node/util/slugify.d.ts +1 -0
- package/dist/node/util/slugify.js +22 -0
- package/dist/style.css +826 -171
- package/package.json +14 -4
- package/src/client/app/App.vue +1 -1
- 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 +4 -0
- package/src/client/app/router.ts +1 -1
- package/src/client/app/sandbox.ts +37 -3
- package/src/client/app/style/main.css +15 -0
- 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 +2 -0
- package/src/client/app/util/preview-settings.ts +26 -0
- package/src/client/app/util/reactivity.ts +22 -0
- package/src/client/app/util/scroll.ts +27 -0
- package/src/client/app/{composable → util}/variant.ts +0 -0
- package/src/client/server/Story.server.vue +25 -2
- package/src/client/server/index.ts +3 -0
- package/src/controls.ts +1 -0
- package/src/node/build.ts +15 -8
- package/src/node/collect.ts +12 -3
- package/src/node/config.ts +69 -6
- package/src/node/markdown.ts +56 -0
- package/src/node/plugin.ts +31 -2
- package/src/node/util/slugify.ts +26 -0
- package/tailwind.config.cjs +79 -4
- package/dist/client/app/components/StoryVariantSingleView.vue +0 -173
- package/src/client/app/components/StoryVariantSingleView.vue +0 -173
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// From vitepress
|
|
2
|
+
|
|
3
|
+
// string.js slugify drops non ascii chars so we have to
|
|
4
|
+
// use a custom implementation here
|
|
5
|
+
import { remove as removeDiacritics } from 'diacritics'
|
|
6
|
+
// eslint-disable-next-line no-control-regex
|
|
7
|
+
const rControl = /[\u0000-\u001f]/g
|
|
8
|
+
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g
|
|
9
|
+
|
|
10
|
+
export const slugify = (str: string): string => {
|
|
11
|
+
return (
|
|
12
|
+
removeDiacritics(str)
|
|
13
|
+
// Remove control characters
|
|
14
|
+
.replace(rControl, '')
|
|
15
|
+
// Replace special characters
|
|
16
|
+
.replace(rSpecial, '-')
|
|
17
|
+
// Remove continuous separators
|
|
18
|
+
.replace(/-{2,}/g, '-')
|
|
19
|
+
// Remove prefixing and trailing separators
|
|
20
|
+
.replace(/^-+|-+$/g, '')
|
|
21
|
+
// ensure it doesn't start with a number (#121)
|
|
22
|
+
.replace(/^(\d)/, '_$1')
|
|
23
|
+
// lowercase
|
|
24
|
+
.toLowerCase()
|
|
25
|
+
)
|
|
26
|
+
}
|
package/tailwind.config.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
const inheritedConfig = require('../../tailwind.config.cjs')
|
|
3
3
|
const defaultColors = require('tailwindcss/colors')
|
|
4
|
+
const path = require('pathe')
|
|
4
5
|
|
|
5
6
|
// Colors
|
|
6
7
|
|
|
@@ -23,11 +24,30 @@ const themedColors = ['primary', 'gray'].reduce((acc, color) => {
|
|
|
23
24
|
return acc
|
|
24
25
|
}, {})
|
|
25
26
|
|
|
27
|
+
const excludedDefaultColors = [
|
|
28
|
+
// Grays
|
|
29
|
+
'slate',
|
|
30
|
+
'gray',
|
|
31
|
+
'zinc',
|
|
32
|
+
'neutral',
|
|
33
|
+
'stone',
|
|
34
|
+
// Deprecated colors
|
|
35
|
+
'lightBlue',
|
|
36
|
+
'warmGray',
|
|
37
|
+
'trueGray',
|
|
38
|
+
'coolGray',
|
|
39
|
+
'blueGray',
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const includedDefaultColors = {}
|
|
43
|
+
for (const key in defaultColors) {
|
|
44
|
+
if (!excludedDefaultColors.includes(key)) {
|
|
45
|
+
includedDefaultColors[key] = defaultColors[key]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
26
49
|
const colors = {
|
|
27
|
-
...
|
|
28
|
-
...defaultColors,
|
|
29
|
-
gray: undefined,
|
|
30
|
-
},
|
|
50
|
+
...includedDefaultColors,
|
|
31
51
|
white: '#fff',
|
|
32
52
|
black: '#000',
|
|
33
53
|
transparent: 'transparent',
|
|
@@ -38,6 +58,8 @@ module.exports = {
|
|
|
38
58
|
...inheritedConfig,
|
|
39
59
|
content: [
|
|
40
60
|
'./src/**/*.{vue,js,ts,jsx,tsx,md}',
|
|
61
|
+
// Include controls CSS directly
|
|
62
|
+
path.resolve(__dirname, '../histoire-controls/src/**/*.{vue,js,ts,jsx,tsx,md}'),
|
|
41
63
|
],
|
|
42
64
|
corePlugins: {
|
|
43
65
|
preflight: false,
|
|
@@ -47,3 +69,56 @@ module.exports = {
|
|
|
47
69
|
delete module.exports.theme.extend.colors.primary
|
|
48
70
|
delete module.exports.theme.extend.colors.gray
|
|
49
71
|
module.exports.theme.colors = colors
|
|
72
|
+
|
|
73
|
+
module.exports.plugins.push(require('@tailwindcss/typography'))
|
|
74
|
+
// prose-a:htw-text-primary-500 prose-headings:htw-mb-2 prose-headings:htw-mt-4 first:prose-headings:htw-mt-0 prose-blockquote:htw-ml-0
|
|
75
|
+
module.exports.theme.extend.typography = (theme) => ({
|
|
76
|
+
DEFAULT: {
|
|
77
|
+
css: {
|
|
78
|
+
a: {
|
|
79
|
+
color: theme('colors.primary-500'),
|
|
80
|
+
textDecoration: 'none',
|
|
81
|
+
|
|
82
|
+
'&:hover': {
|
|
83
|
+
textDecoration: 'underline',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
'h1, h2, h3, h4, th': {
|
|
88
|
+
marginBottom: '0.75rem',
|
|
89
|
+
|
|
90
|
+
'&:not(:first-child)': {
|
|
91
|
+
marginTop: '1.25rem',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
'--tw-prose-invert-quote-borders': theme('colors.gray-800'),
|
|
96
|
+
|
|
97
|
+
blockquote: {
|
|
98
|
+
marginLeft: 0,
|
|
99
|
+
marginRight: 0,
|
|
100
|
+
backgroundColor: theme('colors.gray-100'),
|
|
101
|
+
padding: '4px 6px',
|
|
102
|
+
|
|
103
|
+
'& p:first-child': {
|
|
104
|
+
marginTop: 0,
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
'& p:last-child': {
|
|
108
|
+
marginBottom: 0,
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
'.dark &': {
|
|
112
|
+
backgroundColor: theme('colors.gray-750'),
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
'--tw-prose-invert-bullets': theme('colors.gray-500'),
|
|
117
|
+
|
|
118
|
+
li: {
|
|
119
|
+
marginTop: '0.1rem',
|
|
120
|
+
marginBottom: '0.1rem',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
})
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { useEventListener } from '@vueuse/core'
|
|
3
|
-
import { PropType, ref, watch, toRaw, computed } from 'vue'
|
|
4
|
-
import { Icon } from '@iconify/vue'
|
|
5
|
-
import { Story, Variant } from '../types'
|
|
6
|
-
import { STATE_SYNC } from '../util/const.js'
|
|
7
|
-
import { histoireConfig } from '../util/config.js'
|
|
8
|
-
import BaseSplitPane from './base/BaseSplitPane.vue'
|
|
9
|
-
import HatchedPattern from './misc/HatchedPattern.vue'
|
|
10
|
-
|
|
11
|
-
const props = defineProps({
|
|
12
|
-
variant: {
|
|
13
|
-
type: Object as PropType<Variant>,
|
|
14
|
-
required: true,
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
story: {
|
|
18
|
-
type: Object as PropType<Story>,
|
|
19
|
-
required: true,
|
|
20
|
-
},
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
// Iframe
|
|
24
|
-
|
|
25
|
-
const iframe = ref<HTMLIFrameElement>()
|
|
26
|
-
|
|
27
|
-
function syncState () {
|
|
28
|
-
if (iframe.value) {
|
|
29
|
-
iframe.value.contentWindow.postMessage({
|
|
30
|
-
type: STATE_SYNC,
|
|
31
|
-
state: toRaw(props.variant.state),
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
watch(() => props.variant.state, () => {
|
|
37
|
-
syncState()
|
|
38
|
-
}, {
|
|
39
|
-
deep: true,
|
|
40
|
-
immediate: true,
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
useEventListener(window, 'message', (event) => {
|
|
44
|
-
if (event.data.type === STATE_SYNC) {
|
|
45
|
-
Object.assign(props.variant.state, event.data.state)
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const sandboxUrl = computed(() => {
|
|
50
|
-
const url = new URLSearchParams()
|
|
51
|
-
url.append('storyId', props.story.id)
|
|
52
|
-
url.append('variantId', props.variant.id)
|
|
53
|
-
return '/__sandbox?' + url.toString()
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
const isIframeLoaded = ref(false)
|
|
57
|
-
|
|
58
|
-
watch(sandboxUrl, () => {
|
|
59
|
-
isIframeLoaded.value = false
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
function onIframeLoad () {
|
|
63
|
-
isIframeLoaded.value = true
|
|
64
|
-
syncState()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Responsive
|
|
68
|
-
|
|
69
|
-
const responsiveWidth = ref<number>(undefined)
|
|
70
|
-
</script>
|
|
71
|
-
|
|
72
|
-
<template>
|
|
73
|
-
<div class="htw-h-full htw-flex htw-flex-col htw-gap-2">
|
|
74
|
-
<div class="htw-flex-none htw-flex htw-items-center htw-gap-2">
|
|
75
|
-
<!-- Variant title -->
|
|
76
|
-
<div class="htw-flex htw-items-center htw-gap-1 htw-text-gray-500 htw-flex-1 htw-truncate htw-min-w-0">
|
|
77
|
-
<Icon
|
|
78
|
-
:icon="variant.icon ?? 'carbon:cube'"
|
|
79
|
-
class="base-list-item-link-icon htw-w-4 htw-h-4 htw-opacity-50"
|
|
80
|
-
:class="[
|
|
81
|
-
variant.iconColor ? 'bind-icon-color' : 'htw-text-gray-500',
|
|
82
|
-
]"
|
|
83
|
-
/>
|
|
84
|
-
<span>{{ variant.title }}</span>
|
|
85
|
-
</div>
|
|
86
|
-
|
|
87
|
-
<!-- Responsive size -->
|
|
88
|
-
<div class="htw-flex-none htw-flex htw-gap-1 htw-items-center">
|
|
89
|
-
<VDropdown
|
|
90
|
-
placement="bottom-end"
|
|
91
|
-
:distance="10"
|
|
92
|
-
:skidding="6"
|
|
93
|
-
:disabled="!histoireConfig.responsivePresets?.length"
|
|
94
|
-
>
|
|
95
|
-
<Icon
|
|
96
|
-
icon="ic:baseline-phone-android"
|
|
97
|
-
class="htw-w-4 htw-h-4 htw-opacity-50"
|
|
98
|
-
:class="{
|
|
99
|
-
'htw-cursor-pointer hover:htw-text-primary-500': histoireConfig.responsivePresets?.length,
|
|
100
|
-
}"
|
|
101
|
-
/>
|
|
102
|
-
|
|
103
|
-
<template #popper="{ hide }">
|
|
104
|
-
<div class="htw-flex htw-flex-col htw-items-stretch">
|
|
105
|
-
<button
|
|
106
|
-
v-for="(preset, index) in histoireConfig.responsivePresets"
|
|
107
|
-
:key="index"
|
|
108
|
-
class="htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700 htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-2"
|
|
109
|
-
:class="{
|
|
110
|
-
'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black': responsiveWidth === preset.width,
|
|
111
|
-
}"
|
|
112
|
-
@click="responsiveWidth = preset.width;hide()"
|
|
113
|
-
>
|
|
114
|
-
{{ preset.label }}
|
|
115
|
-
<span class="htw-ml-auto htw-opacity-70">{{ preset.width }}px</span>
|
|
116
|
-
</button>
|
|
117
|
-
</div>
|
|
118
|
-
</template>
|
|
119
|
-
</VDropdown>
|
|
120
|
-
|
|
121
|
-
<input
|
|
122
|
-
v-model.number="responsiveWidth"
|
|
123
|
-
v-tooltip="'Responsive width (px)'"
|
|
124
|
-
type="number"
|
|
125
|
-
class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-16 htw-opacity-50 focus:htw-opacity-100"
|
|
126
|
-
step="16"
|
|
127
|
-
>
|
|
128
|
-
</div>
|
|
129
|
-
</div>
|
|
130
|
-
|
|
131
|
-
<BaseSplitPane
|
|
132
|
-
v-model:split="responsiveWidth"
|
|
133
|
-
save-id="story-single-responsive"
|
|
134
|
-
:min="30"
|
|
135
|
-
:max="6000"
|
|
136
|
-
:default-split="720"
|
|
137
|
-
fixed
|
|
138
|
-
class="htw-w-full htw-h-full htw-flex-1 htw-border htw-border-gray-100 dark:htw-border-gray-800 htw-rounded-lg"
|
|
139
|
-
>
|
|
140
|
-
<template #first>
|
|
141
|
-
<div class="htw-p-4 htw-h-full htw-overflow-hidden htw-bg-white dark:htw-bg-gray-700 htw-rounded-l-lg htw-relative">
|
|
142
|
-
<div class="htw-w-full htw-h-full htw-border htw-border-gray-100 dark:htw-border-gray-800 htw-bg-white htw-rounded-sm">
|
|
143
|
-
<iframe
|
|
144
|
-
ref="iframe"
|
|
145
|
-
:src="sandboxUrl"
|
|
146
|
-
class="htw-w-full htw-h-full"
|
|
147
|
-
:class="{'htw-invisible': !isIframeLoaded}"
|
|
148
|
-
@load="onIframeLoad()"
|
|
149
|
-
/>
|
|
150
|
-
</div>
|
|
151
|
-
<!-- Markers -->
|
|
152
|
-
<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" />
|
|
153
|
-
<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" />
|
|
154
|
-
<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" />
|
|
155
|
-
<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" />
|
|
156
|
-
<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" />
|
|
157
|
-
<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" />
|
|
158
|
-
<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" />
|
|
159
|
-
<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" />
|
|
160
|
-
</div>
|
|
161
|
-
</template>
|
|
162
|
-
<template #last>
|
|
163
|
-
<div
|
|
164
|
-
class="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"
|
|
165
|
-
>
|
|
166
|
-
<HatchedPattern
|
|
167
|
-
class="htw-w-full htw-h-full htw-text-black/[2%] dark:htw-text-white/[2%]"
|
|
168
|
-
/>
|
|
169
|
-
</div>
|
|
170
|
-
</template>
|
|
171
|
-
</BaseSplitPane>
|
|
172
|
-
</div>
|
|
173
|
-
</template>
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { useEventListener } from '@vueuse/core'
|
|
3
|
-
import { PropType, ref, watch, toRaw, computed } from 'vue'
|
|
4
|
-
import { Icon } from '@iconify/vue'
|
|
5
|
-
import { Story, Variant } from '../types'
|
|
6
|
-
import { STATE_SYNC } from '../util/const.js'
|
|
7
|
-
import { histoireConfig } from '../util/config.js'
|
|
8
|
-
import BaseSplitPane from './base/BaseSplitPane.vue'
|
|
9
|
-
import HatchedPattern from './misc/HatchedPattern.vue'
|
|
10
|
-
|
|
11
|
-
const props = defineProps({
|
|
12
|
-
variant: {
|
|
13
|
-
type: Object as PropType<Variant>,
|
|
14
|
-
required: true,
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
story: {
|
|
18
|
-
type: Object as PropType<Story>,
|
|
19
|
-
required: true,
|
|
20
|
-
},
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
// Iframe
|
|
24
|
-
|
|
25
|
-
const iframe = ref<HTMLIFrameElement>()
|
|
26
|
-
|
|
27
|
-
function syncState () {
|
|
28
|
-
if (iframe.value) {
|
|
29
|
-
iframe.value.contentWindow.postMessage({
|
|
30
|
-
type: STATE_SYNC,
|
|
31
|
-
state: toRaw(props.variant.state),
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
watch(() => props.variant.state, () => {
|
|
37
|
-
syncState()
|
|
38
|
-
}, {
|
|
39
|
-
deep: true,
|
|
40
|
-
immediate: true,
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
useEventListener(window, 'message', (event) => {
|
|
44
|
-
if (event.data.type === STATE_SYNC) {
|
|
45
|
-
Object.assign(props.variant.state, event.data.state)
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const sandboxUrl = computed(() => {
|
|
50
|
-
const url = new URLSearchParams()
|
|
51
|
-
url.append('storyId', props.story.id)
|
|
52
|
-
url.append('variantId', props.variant.id)
|
|
53
|
-
return '/__sandbox?' + url.toString()
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
const isIframeLoaded = ref(false)
|
|
57
|
-
|
|
58
|
-
watch(sandboxUrl, () => {
|
|
59
|
-
isIframeLoaded.value = false
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
function onIframeLoad () {
|
|
63
|
-
isIframeLoaded.value = true
|
|
64
|
-
syncState()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Responsive
|
|
68
|
-
|
|
69
|
-
const responsiveWidth = ref<number>(undefined)
|
|
70
|
-
</script>
|
|
71
|
-
|
|
72
|
-
<template>
|
|
73
|
-
<div class="htw-h-full htw-flex htw-flex-col htw-gap-2">
|
|
74
|
-
<div class="htw-flex-none htw-flex htw-items-center htw-gap-2">
|
|
75
|
-
<!-- Variant title -->
|
|
76
|
-
<div class="htw-flex htw-items-center htw-gap-1 htw-text-gray-500 htw-flex-1 htw-truncate htw-min-w-0">
|
|
77
|
-
<Icon
|
|
78
|
-
:icon="variant.icon ?? 'carbon:cube'"
|
|
79
|
-
class="base-list-item-link-icon htw-w-4 htw-h-4 htw-opacity-50"
|
|
80
|
-
:class="[
|
|
81
|
-
variant.iconColor ? 'bind-icon-color' : 'htw-text-gray-500',
|
|
82
|
-
]"
|
|
83
|
-
/>
|
|
84
|
-
<span>{{ variant.title }}</span>
|
|
85
|
-
</div>
|
|
86
|
-
|
|
87
|
-
<!-- Responsive size -->
|
|
88
|
-
<div class="htw-flex-none htw-flex htw-gap-1 htw-items-center">
|
|
89
|
-
<VDropdown
|
|
90
|
-
placement="bottom-end"
|
|
91
|
-
:distance="10"
|
|
92
|
-
:skidding="6"
|
|
93
|
-
:disabled="!histoireConfig.responsivePresets?.length"
|
|
94
|
-
>
|
|
95
|
-
<Icon
|
|
96
|
-
icon="ic:baseline-phone-android"
|
|
97
|
-
class="htw-w-4 htw-h-4 htw-opacity-50"
|
|
98
|
-
:class="{
|
|
99
|
-
'htw-cursor-pointer hover:htw-text-primary-500': histoireConfig.responsivePresets?.length,
|
|
100
|
-
}"
|
|
101
|
-
/>
|
|
102
|
-
|
|
103
|
-
<template #popper="{ hide }">
|
|
104
|
-
<div class="htw-flex htw-flex-col htw-items-stretch">
|
|
105
|
-
<button
|
|
106
|
-
v-for="(preset, index) in histoireConfig.responsivePresets"
|
|
107
|
-
:key="index"
|
|
108
|
-
class="htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700 htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-2"
|
|
109
|
-
:class="{
|
|
110
|
-
'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black': responsiveWidth === preset.width,
|
|
111
|
-
}"
|
|
112
|
-
@click="responsiveWidth = preset.width;hide()"
|
|
113
|
-
>
|
|
114
|
-
{{ preset.label }}
|
|
115
|
-
<span class="htw-ml-auto htw-opacity-70">{{ preset.width }}px</span>
|
|
116
|
-
</button>
|
|
117
|
-
</div>
|
|
118
|
-
</template>
|
|
119
|
-
</VDropdown>
|
|
120
|
-
|
|
121
|
-
<input
|
|
122
|
-
v-model.number="responsiveWidth"
|
|
123
|
-
v-tooltip="'Responsive width (px)'"
|
|
124
|
-
type="number"
|
|
125
|
-
class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-16 htw-opacity-50 focus:htw-opacity-100"
|
|
126
|
-
step="16"
|
|
127
|
-
>
|
|
128
|
-
</div>
|
|
129
|
-
</div>
|
|
130
|
-
|
|
131
|
-
<BaseSplitPane
|
|
132
|
-
v-model:split="responsiveWidth"
|
|
133
|
-
save-id="story-single-responsive"
|
|
134
|
-
:min="30"
|
|
135
|
-
:max="6000"
|
|
136
|
-
:default-split="720"
|
|
137
|
-
fixed
|
|
138
|
-
class="htw-w-full htw-h-full htw-flex-1 htw-border htw-border-gray-100 dark:htw-border-gray-800 htw-rounded-lg"
|
|
139
|
-
>
|
|
140
|
-
<template #first>
|
|
141
|
-
<div class="htw-p-4 htw-h-full htw-overflow-hidden htw-bg-white dark:htw-bg-gray-700 htw-rounded-l-lg htw-relative">
|
|
142
|
-
<div class="htw-w-full htw-h-full htw-border htw-border-gray-100 dark:htw-border-gray-800 htw-bg-white htw-rounded-sm">
|
|
143
|
-
<iframe
|
|
144
|
-
ref="iframe"
|
|
145
|
-
:src="sandboxUrl"
|
|
146
|
-
class="htw-w-full htw-h-full"
|
|
147
|
-
:class="{'htw-invisible': !isIframeLoaded}"
|
|
148
|
-
@load="onIframeLoad()"
|
|
149
|
-
/>
|
|
150
|
-
</div>
|
|
151
|
-
<!-- Markers -->
|
|
152
|
-
<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" />
|
|
153
|
-
<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" />
|
|
154
|
-
<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" />
|
|
155
|
-
<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" />
|
|
156
|
-
<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" />
|
|
157
|
-
<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" />
|
|
158
|
-
<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" />
|
|
159
|
-
<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" />
|
|
160
|
-
</div>
|
|
161
|
-
</template>
|
|
162
|
-
<template #last>
|
|
163
|
-
<div
|
|
164
|
-
class="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"
|
|
165
|
-
>
|
|
166
|
-
<HatchedPattern
|
|
167
|
-
class="htw-w-full htw-h-full htw-text-black/[2%] dark:htw-text-white/[2%]"
|
|
168
|
-
/>
|
|
169
|
-
</div>
|
|
170
|
-
</template>
|
|
171
|
-
</BaseSplitPane>
|
|
172
|
-
</div>
|
|
173
|
-
</template>
|