histoire 0.2.5 → 0.3.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/App.vue +8 -3
- package/dist/client/app/codegen/const.d.ts +1 -0
- package/dist/client/app/codegen/const.js +3 -0
- package/dist/client/app/codegen/vue3.js +83 -21
- package/dist/client/app/codegen/vue3.js.map +1 -0
- package/dist/client/app/components/base/BaseEmpty.vue +17 -1
- package/dist/client/app/components/base/BaseOverflowMenu.vue +118 -0
- package/dist/client/app/components/base/BaseOverflowTab.vue +46 -0
- package/dist/client/app/components/exposed/Story.vue +33 -1
- package/dist/client/app/components/exposed/Variant.vue +19 -1
- package/dist/client/app/components/panel/PaneTabs.vue +64 -0
- package/dist/client/app/components/{story → panel}/StoryControls.vue +6 -1
- package/dist/client/app/components/{story → panel}/StoryDocs.vue +18 -11
- package/dist/client/app/components/panel/StoryEvent.vue +53 -0
- package/dist/client/app/components/panel/StoryEvents.vue +45 -0
- package/{src/client/app/components/story → dist/client/app/components/panel}/StorySidePanel.vue +17 -20
- package/{src/client/app/components/story → dist/client/app/components/panel}/StorySourceCode.vue +24 -14
- package/dist/client/app/components/sandbox/SandboxVue3.vue +16 -4
- package/dist/client/app/components/sandbox/lib.js +2 -1
- package/dist/client/app/components/search/SearchLoading.vue +16 -0
- package/dist/client/app/components/search/SearchModal.vue +12 -149
- package/dist/client/app/components/search/SearchPane.vue +210 -0
- package/dist/client/app/components/search/search-data.d.ts +2 -0
- package/dist/client/app/components/search/search-data.js +8 -0
- package/dist/client/app/components/search/search-data.js.map +1 -0
- package/dist/client/app/components/story/StoryResponsivePreview.vue +9 -98
- package/dist/client/app/components/story/StoryVariantSingle.vue +109 -0
- package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +39 -0
- package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
- package/dist/client/app/components/story/StoryVariantSingleView.vue +13 -6
- package/dist/client/app/components/story/StoryView.vue +17 -3
- package/dist/client/app/components/story/StoryViewer.vue +2 -92
- package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantBackground.vue +3 -3
- package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantNewTab.vue +2 -2
- package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantResponsiveSize.vue +3 -3
- package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
- package/dist/client/app/components/tree/StoryGroup.vue +4 -4
- package/dist/client/app/components/tree/StoryListFolder.vue +4 -4
- package/dist/client/app/components/tree/StoryListItem.vue +4 -1
- 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/router.d.ts +1 -0
- package/dist/client/app/router.js +3 -1
- package/dist/client/app/sandbox.js +12 -1
- package/dist/client/app/sandbox.js.map +1 -0
- package/dist/client/app/stores/events.d.ts +29 -0
- package/dist/client/app/stores/events.js +26 -0
- package/dist/client/app/stores/events.js.map +1 -0
- package/dist/client/app/stores/folder.d.ts +10 -0
- package/dist/client/app/stores/folder.js +48 -0
- package/dist/client/app/stores/folder.js.map +1 -0
- package/dist/client/app/stores/story.d.ts +41 -8
- package/dist/client/app/stores/story.js +21 -33
- package/dist/client/app/stores/story.js.map +1 -0
- package/dist/client/app/style/main.pcss +5 -0
- package/dist/client/app/style/sandbox.css +2 -0
- package/dist/client/app/style/transitions.pcss +13 -0
- package/dist/client/app/types.d.ts +4 -0
- package/dist/client/app/types.js +1 -0
- package/dist/client/app/types.js.map +1 -0
- package/dist/client/app/util/const.d.ts +1 -0
- package/dist/client/app/util/const.js +1 -0
- package/dist/client/app/util/events.d.ts +1 -0
- package/dist/client/app/util/events.js +32 -0
- package/dist/client/app/util/events.js.map +1 -0
- 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 +5 -2
- 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.js +1 -0
- package/dist/client/app/util/scroll.js.map +1 -0
- package/dist/client/app/util/variant.js +1 -0
- package/dist/client/app/util/variant.js.map +1 -0
- package/dist/client/index.d.ts +4 -3
- package/dist/client/index.js +3 -1
- package/dist/client/index.js.map +1 -0
- package/dist/client/server/index.d.ts +7 -2
- package/dist/client/server/index.js +8 -26
- package/{src/client/server/Story.server.vue → dist/client/server/vue3/Story.vue} +14 -3
- package/dist/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
- package/dist/client/server/vue3/run.d.ts +2 -0
- package/dist/client/server/vue3/run.js +33 -0
- package/dist/client/server/vue3/run.js.map +1 -0
- package/dist/controls.js +1 -0
- package/dist/controls.js.map +1 -0
- package/dist/node/alias.d.ts +2 -1
- package/dist/node/alias.js +3 -2
- package/dist/node/build.js +74 -21
- package/dist/node/builtin-plugins/tailwind-tokens.d.ts +5 -0
- package/dist/node/builtin-plugins/tailwind-tokens.js +510 -0
- package/dist/node/collect/index.js +3 -1
- package/dist/node/collect/worker.js +6 -2
- package/dist/node/commands/preview.js +4 -25
- package/dist/node/config.d.ts +103 -3
- package/dist/node/config.js +40 -23
- package/dist/node/context.d.ts +3 -3
- package/dist/node/context.js +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/load.d.ts +12 -0
- package/dist/node/load.js +42 -0
- package/dist/node/plugin.d.ts +67 -11
- package/dist/node/plugin.js +42 -245
- package/dist/node/preview.d.ts +8 -0
- package/dist/node/preview.js +41 -0
- package/dist/node/search.d.ts +2 -0
- package/dist/node/search.js +68 -0
- package/dist/node/server.js +43 -21
- package/dist/node/stories.d.ts +2 -0
- package/dist/node/stories.js +4 -4
- package/dist/node/types.d.ts +1 -0
- package/dist/node/util/find-up.d.ts +1 -0
- package/dist/node/util/find-up.js +20 -0
- package/dist/node/vite.d.ts +13 -0
- package/dist/node/vite.js +278 -0
- package/dist/style.css +174 -86
- package/package.json +7 -6
- package/scripts/copy.mjs +2 -1
- package/src/client/app/App.vue +8 -3
- package/src/client/app/codegen/const.ts +3 -0
- package/src/client/app/codegen/vue3.ts +80 -22
- package/src/client/app/components/base/BaseEmpty.vue +17 -1
- package/src/client/app/components/base/BaseOverflowMenu.vue +118 -0
- package/src/client/app/components/base/BaseOverflowTab.vue +46 -0
- package/src/client/app/components/exposed/Story.vue +33 -1
- package/src/client/app/components/exposed/Variant.vue +19 -1
- package/src/client/app/components/panel/PaneTabs.vue +64 -0
- package/src/client/app/components/{story → panel}/StoryControls.vue +6 -1
- package/src/client/app/components/{story → panel}/StoryDocs.vue +18 -11
- package/src/client/app/components/panel/StoryEvent.vue +53 -0
- package/src/client/app/components/panel/StoryEvents.vue +45 -0
- package/{dist/client/app/components/story → src/client/app/components/panel}/StorySidePanel.vue +17 -20
- package/{dist/client/app/components/story → src/client/app/components/panel}/StorySourceCode.vue +24 -14
- package/src/client/app/components/sandbox/SandboxVue3.vue +16 -4
- package/src/client/app/components/sandbox/lib.ts +3 -1
- package/src/client/app/components/search/SearchLoading.vue +16 -0
- package/src/client/app/components/search/SearchModal.vue +12 -149
- package/src/client/app/components/search/SearchPane.vue +210 -0
- package/src/client/app/components/search/search-data.ts +9 -0
- package/src/client/app/components/story/StoryResponsivePreview.vue +9 -98
- package/src/client/app/components/story/StoryVariantSingle.vue +109 -0
- package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +39 -0
- package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +153 -0
- package/src/client/app/components/story/StoryVariantSingleView.vue +13 -6
- package/src/client/app/components/story/StoryView.vue +17 -3
- package/src/client/app/components/story/StoryViewer.vue +2 -92
- package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantBackground.vue +3 -3
- package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantNewTab.vue +2 -2
- package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantResponsiveSize.vue +3 -3
- package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
- package/src/client/app/components/tree/StoryGroup.vue +4 -4
- package/src/client/app/components/tree/StoryListFolder.vue +4 -4
- package/src/client/app/components/tree/StoryListItem.vue +4 -1
- package/src/client/app/router.ts +4 -1
- package/src/client/app/sandbox.ts +11 -1
- package/src/client/app/stores/events.ts +36 -0
- package/{dist/client/app/stores/story.ts → src/client/app/stores/folder.ts} +16 -23
- package/src/client/app/stores/story.ts +21 -40
- package/src/client/app/style/main.pcss +5 -0
- package/src/client/app/style/sandbox.css +2 -0
- package/src/client/app/style/transitions.pcss +13 -0
- package/src/client/app/types.ts +5 -0
- package/src/client/app/util/const.ts +1 -0
- package/src/client/app/util/events.ts +30 -0
- package/src/client/app/util/mapping.ts +4 -2
- package/src/client/index.ts +4 -3
- package/src/client/server/index.ts +14 -27
- package/{dist/client/server/Story.server.vue → src/client/server/vue3/Story.vue} +14 -3
- package/src/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
- package/{dist/client/server/index.ts → src/client/server/vue3/run.ts} +10 -4
- package/src/node/alias.ts +4 -2
- package/src/node/build.ts +86 -21
- package/src/node/builtin-plugins/tailwind-tokens.ts +521 -0
- package/src/node/collect/index.ts +3 -1
- package/src/node/collect/worker.ts +7 -2
- package/src/node/commands/preview.ts +4 -33
- package/src/node/config.ts +53 -27
- package/src/node/context.ts +3 -3
- package/src/node/index.ts +1 -0
- package/src/node/load.ts +63 -0
- package/src/node/plugin.ts +75 -252
- package/src/node/preview.ts +56 -0
- package/src/node/search.ts +75 -0
- package/src/node/server.ts +49 -23
- package/src/node/stories.ts +4 -4
- package/src/node/types.ts +1 -0
- package/src/node/util/find-up.ts +24 -0
- package/src/node/vite.ts +296 -0
- package/tailwind.config.cjs +1 -0
- package/dist/client/app/codegen/serialize-js.ts +0 -119
- package/dist/client/app/codegen/util.ts +0 -79
- package/dist/client/app/codegen/vue3.ts +0 -276
- package/dist/client/app/components/sandbox/lib.ts +0 -8
- package/dist/client/app/global-components.ts +0 -13
- package/dist/client/app/index.ts +0 -28
- package/dist/client/app/router.ts +0 -17
- package/dist/client/app/sandbox.ts +0 -94
- package/dist/client/app/stores/preview-settings.ts +0 -17
- package/dist/client/app/types.ts +0 -78
- package/dist/client/app/util/config.ts +0 -6
- package/dist/client/app/util/const.ts +0 -3
- package/dist/client/app/util/dark.ts +0 -4
- package/dist/client/app/util/env.ts +0 -1
- package/dist/client/app/util/keyboard.ts +0 -99
- package/dist/client/app/util/mapping.ts +0 -48
- package/dist/client/app/util/preview-settings.ts +0 -8
- package/dist/client/app/util/reactivity.ts +0 -22
- package/dist/client/app/util/responsive.ts +0 -3
- package/dist/client/app/util/scroll.ts +0 -31
- package/dist/client/app/util/tooltip.ts +0 -13
- package/dist/client/app/util/variant.ts +0 -20
- package/dist/client/index.ts +0 -12
- package/dist/client/shim.d.ts +0 -5
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { useFocus, useDebounce } from '@vueuse/core'
|
|
3
|
+
import { ref, watch } from 'vue'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
import flexsearch from 'flexsearch'
|
|
6
|
+
import charset from 'flexsearch/dist/module/lang/latin/advanced.js'
|
|
7
|
+
import language from 'flexsearch/dist/module/lang/en.js'
|
|
8
|
+
import { useStoryStore } from '../../stores/story'
|
|
9
|
+
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
10
|
+
import type { SearchResult, Story, Variant } from '../../types'
|
|
11
|
+
import SearchItem from './SearchItem.vue'
|
|
12
|
+
import { searchData, onUpdate } from './search-data.js'
|
|
13
|
+
|
|
14
|
+
const props = defineProps({
|
|
15
|
+
shown: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
default: false,
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const emit = defineEmits({
|
|
22
|
+
close: () => true,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
function close () {
|
|
26
|
+
emit('close')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Autofocus
|
|
30
|
+
|
|
31
|
+
const input = ref<HTMLInputElement>()
|
|
32
|
+
const { focused } = useFocus(input, {
|
|
33
|
+
initialValue: true,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
watch(() => props.shown, value => {
|
|
37
|
+
if (value) {
|
|
38
|
+
requestAnimationFrame(() => {
|
|
39
|
+
focused.value = true
|
|
40
|
+
input.value.select()
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Search
|
|
46
|
+
|
|
47
|
+
const searchInputText = ref('')
|
|
48
|
+
const rateLimitedSearch = useDebounce(searchInputText, 50)
|
|
49
|
+
|
|
50
|
+
const storyStore = useStoryStore()
|
|
51
|
+
|
|
52
|
+
let searchIndex: flexsearch.Document<any, any>
|
|
53
|
+
|
|
54
|
+
async function loadSearchIndex (data) {
|
|
55
|
+
searchIndex = new flexsearch.Document({
|
|
56
|
+
preset: 'match',
|
|
57
|
+
document: {
|
|
58
|
+
id: 'id',
|
|
59
|
+
index: [
|
|
60
|
+
'title',
|
|
61
|
+
'docs',
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
worker: true,
|
|
65
|
+
charset,
|
|
66
|
+
language,
|
|
67
|
+
tokenize: 'full',
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
for (const key of Object.keys(data)) {
|
|
71
|
+
await searchIndex.import(key, data[key])
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
loadSearchIndex(searchData)
|
|
76
|
+
// Handle HMR
|
|
77
|
+
onUpdate(searchData => {
|
|
78
|
+
loadSearchIndex(searchData)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const results = ref<SearchResult[]>([])
|
|
82
|
+
|
|
83
|
+
watch(rateLimitedSearch, async value => {
|
|
84
|
+
const list: SearchResult[] = []
|
|
85
|
+
const raw = await searchIndex.search(value, {
|
|
86
|
+
enrich: true,
|
|
87
|
+
})
|
|
88
|
+
let rank = 0
|
|
89
|
+
for (const field of raw) {
|
|
90
|
+
for (const item of field.result as any[]) {
|
|
91
|
+
switch (item.doc.kind) {
|
|
92
|
+
case 'story': {
|
|
93
|
+
list.push(storyResultFactory(storyStore.getStoryById(item.id), rank))
|
|
94
|
+
rank++
|
|
95
|
+
break
|
|
96
|
+
}
|
|
97
|
+
case 'variant': {
|
|
98
|
+
const [storyId] = item.id.split(':')
|
|
99
|
+
const story = storyStore.getStoryById(storyId)
|
|
100
|
+
const variant = storyStore.getVariantById(item.id)
|
|
101
|
+
list.push(variantResultFactory(story, variant, rank))
|
|
102
|
+
rank++
|
|
103
|
+
break
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
results.value = list
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
function storyResultFactory (story: Story, rank: number): SearchResult {
|
|
112
|
+
return {
|
|
113
|
+
kind: 'story',
|
|
114
|
+
rank,
|
|
115
|
+
id: story.id,
|
|
116
|
+
title: story.title,
|
|
117
|
+
route: {
|
|
118
|
+
name: 'story',
|
|
119
|
+
params: {
|
|
120
|
+
storyId: story.id,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
path: story.file.path.slice(0, -1),
|
|
124
|
+
icon: story.icon,
|
|
125
|
+
iconColor: story.iconColor,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function variantResultFactory (story: Story, variant: Variant, rank: number): SearchResult {
|
|
130
|
+
return {
|
|
131
|
+
kind: 'variant',
|
|
132
|
+
rank,
|
|
133
|
+
id: variant.id,
|
|
134
|
+
title: variant.title,
|
|
135
|
+
route: {
|
|
136
|
+
name: 'story',
|
|
137
|
+
params: {
|
|
138
|
+
storyId: story.id,
|
|
139
|
+
},
|
|
140
|
+
query: {
|
|
141
|
+
variantId: variant.id,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
path: [...story.file.path ?? [], story.title],
|
|
145
|
+
icon: variant.icon,
|
|
146
|
+
iconColor: variant.iconColor,
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Selection
|
|
151
|
+
|
|
152
|
+
const selectedIndex = ref(0)
|
|
153
|
+
|
|
154
|
+
watch(results, () => {
|
|
155
|
+
selectedIndex.value = 0
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
function selectNext () {
|
|
159
|
+
selectedIndex.value++
|
|
160
|
+
if (selectedIndex.value > results.value.length - 1) {
|
|
161
|
+
selectedIndex.value = 0
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function selectPrevious () {
|
|
166
|
+
selectedIndex.value--
|
|
167
|
+
if (selectedIndex.value < 0) {
|
|
168
|
+
selectedIndex.value = results.value.length - 1
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
</script>
|
|
172
|
+
|
|
173
|
+
<template>
|
|
174
|
+
<div
|
|
175
|
+
class="htw-flex htw-items-center htw-gap-4 htw-pl-6 htw-border htw-border-transparent focus-visible:htw-border-primary-500"
|
|
176
|
+
@click="focused = true"
|
|
177
|
+
>
|
|
178
|
+
<Icon
|
|
179
|
+
icon="carbon:search"
|
|
180
|
+
class="flex-none htw-w-4 htw-h-4"
|
|
181
|
+
/>
|
|
182
|
+
|
|
183
|
+
<input
|
|
184
|
+
ref="input"
|
|
185
|
+
v-model="searchInputText"
|
|
186
|
+
placeholder="Search for stories, variants..."
|
|
187
|
+
class="htw-bg-transparent htw-w-full htw-flex-1 htw-pl-0 htw-pr-6 htw-py-4 htw-outline-none"
|
|
188
|
+
@keydown.down.prevent="selectNext()"
|
|
189
|
+
@keydown.up.prevent="selectPrevious()"
|
|
190
|
+
@keydown.escape="close()"
|
|
191
|
+
>
|
|
192
|
+
</div>
|
|
193
|
+
|
|
194
|
+
<BaseEmpty v-if="rateLimitedSearch && !results.length">
|
|
195
|
+
No results
|
|
196
|
+
</BaseEmpty>
|
|
197
|
+
|
|
198
|
+
<div
|
|
199
|
+
v-else-if="results.length"
|
|
200
|
+
class="htw-max-h-[400px] htw-overflow-y-auto htw-rounded-b-lg"
|
|
201
|
+
>
|
|
202
|
+
<SearchItem
|
|
203
|
+
v-for="(result, index) of results"
|
|
204
|
+
:key="`${result.kind}-${result.id}`"
|
|
205
|
+
:result="result"
|
|
206
|
+
:selected="index === selectedIndex"
|
|
207
|
+
@close="close()"
|
|
208
|
+
/>
|
|
209
|
+
</div>
|
|
210
|
+
</template>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { markRaw } from 'vue';
|
|
2
|
+
// @ts-expect-error virtual module
|
|
3
|
+
import { searchData as _searchData, onUpdate as _onUpdate } from '$histoire-search-data';
|
|
4
|
+
export const searchData = markRaw(_searchData);
|
|
5
|
+
export function onUpdate(cb) {
|
|
6
|
+
_onUpdate(cb);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=search-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-data.js","sourceRoot":"","sources":["../../../../../src/client/app/components/search/search-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAC7B,kCAAkC;AAClC,OAAO,EAAE,UAAU,IAAI,WAAW,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAExF,MAAM,CAAC,MAAM,UAAU,GAAwB,OAAO,CAAC,WAAW,CAAC,CAAA;AAEnE,MAAM,UAAU,QAAQ,CAAE,EAAwC;IAChE,SAAS,CAAC,EAAE,CAAC,CAAA;AACf,CAAC"}
|
|
@@ -1,98 +1,18 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import { computed, onUnmounted, Ref, ref
|
|
2
|
+
import { computed, onUnmounted, Ref, ref } from 'vue'
|
|
3
3
|
import { useEventListener } from '@vueuse/core'
|
|
4
4
|
import { Icon } from '@iconify/vue'
|
|
5
|
-
import { STATE_SYNC, PREVIEW_SETTINGS_SYNC, SANDBOX_READY } from '../../util/const'
|
|
6
|
-
import type { Story, Variant } from '../../types'
|
|
7
5
|
import HatchedPattern from '../misc/HatchedPattern.vue'
|
|
8
6
|
import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
|
|
9
|
-
import { toRawDeep } from '../../util/reactivity'
|
|
10
|
-
import { getSandboxUrl } from '../sandbox/lib'
|
|
11
7
|
import { usePreviewSettingsStore } from '../../stores/preview-settings'
|
|
8
|
+
import { Variant } from '../../types'
|
|
12
9
|
|
|
13
10
|
const props = defineProps<{
|
|
14
|
-
story: Story
|
|
15
11
|
variant: Variant
|
|
16
12
|
}>()
|
|
17
13
|
|
|
18
14
|
const settings = usePreviewSettingsStore().currentSettings
|
|
19
15
|
|
|
20
|
-
// Iframe
|
|
21
|
-
|
|
22
|
-
const iframe = ref<HTMLIFrameElement>()
|
|
23
|
-
|
|
24
|
-
function syncState () {
|
|
25
|
-
if (iframe.value && props.variant.previewReady) {
|
|
26
|
-
iframe.value.contentWindow.postMessage({
|
|
27
|
-
type: STATE_SYNC,
|
|
28
|
-
state: toRawDeep(props.variant.state),
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let synced = false
|
|
34
|
-
|
|
35
|
-
watch(() => props.variant.state, () => {
|
|
36
|
-
if (synced) {
|
|
37
|
-
synced = false
|
|
38
|
-
return
|
|
39
|
-
}
|
|
40
|
-
syncState()
|
|
41
|
-
}, {
|
|
42
|
-
deep: true,
|
|
43
|
-
immediate: true,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
Object.assign(props.variant, {
|
|
47
|
-
previewReady: false,
|
|
48
|
-
})
|
|
49
|
-
useEventListener(window, 'message', (event) => {
|
|
50
|
-
if (event.data.type === STATE_SYNC) {
|
|
51
|
-
synced = true
|
|
52
|
-
Object.assign(props.variant.state, event.data.state)
|
|
53
|
-
} else if (event.data.type === SANDBOX_READY) {
|
|
54
|
-
Object.assign(props.variant, {
|
|
55
|
-
previewReady: true,
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
const sandboxUrl = computed(() => {
|
|
61
|
-
return getSandboxUrl(props.story, props.variant)
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
const isIframeLoaded = ref(false)
|
|
65
|
-
|
|
66
|
-
watch(sandboxUrl, () => {
|
|
67
|
-
isIframeLoaded.value = false
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
// Settings
|
|
71
|
-
|
|
72
|
-
function syncSettings () {
|
|
73
|
-
if (iframe.value) {
|
|
74
|
-
iframe.value.contentWindow.postMessage({
|
|
75
|
-
type: PREVIEW_SETTINGS_SYNC,
|
|
76
|
-
settings: toRaw(settings),
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
watch(() => settings, () => {
|
|
82
|
-
syncSettings()
|
|
83
|
-
}, {
|
|
84
|
-
deep: true,
|
|
85
|
-
immediate: true,
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
// Iframe load
|
|
89
|
-
|
|
90
|
-
function onIframeLoad () {
|
|
91
|
-
isIframeLoaded.value = true
|
|
92
|
-
syncState()
|
|
93
|
-
syncSettings()
|
|
94
|
-
}
|
|
95
|
-
|
|
96
16
|
// Resize
|
|
97
17
|
|
|
98
18
|
const resizing = ref(false)
|
|
@@ -117,7 +37,7 @@ function useDragger (el: Ref<HTMLDivElement>, value: Ref<number>, min: number, m
|
|
|
117
37
|
event.preventDefault()
|
|
118
38
|
event.stopPropagation()
|
|
119
39
|
const start = axis === 'x' ? event.clientX : event.clientY
|
|
120
|
-
const startValue = value.value
|
|
40
|
+
const startValue = value.value
|
|
121
41
|
resizing.value = true
|
|
122
42
|
|
|
123
43
|
const removeListeners = [
|
|
@@ -146,7 +66,7 @@ function useDragger (el: Ref<HTMLDivElement>, value: Ref<number>, min: number, m
|
|
|
146
66
|
event.preventDefault()
|
|
147
67
|
event.stopPropagation()
|
|
148
68
|
const start = axis === 'x' ? event.touches[0].clientX : event.touches[0].clientY
|
|
149
|
-
const startValue = value.value
|
|
69
|
+
const startValue = value.value
|
|
150
70
|
resizing.value = true
|
|
151
71
|
|
|
152
72
|
const removeListeners = [
|
|
@@ -228,20 +148,11 @@ const isResponsiveEnabled = computed(() => !props.variant.responsiveDisabled)
|
|
|
228
148
|
class="htw-absolute htw-inset-0 htw-w-full htw-h-full htw-text-gray-500/20"
|
|
229
149
|
/>
|
|
230
150
|
|
|
231
|
-
<
|
|
232
|
-
|
|
233
|
-
:
|
|
234
|
-
|
|
235
|
-
:
|
|
236
|
-
'htw-invisible': !isIframeLoaded,
|
|
237
|
-
'htw-pointer-events-none': resizing,
|
|
238
|
-
}"
|
|
239
|
-
:style="isResponsiveEnabled ? {
|
|
240
|
-
width: finalWidth ? `${finalWidth}px` : null,
|
|
241
|
-
height: finalHeight ? `${finalHeight}px` : null,
|
|
242
|
-
} : undefined"
|
|
243
|
-
data-test-id="preview-iframe"
|
|
244
|
-
@load="onIframeLoad()"
|
|
151
|
+
<slot
|
|
152
|
+
:is-responsive-enabled="isResponsiveEnabled"
|
|
153
|
+
:final-width="finalWidth"
|
|
154
|
+
:final-height="finalHeight"
|
|
155
|
+
:resizing="resizing"
|
|
245
156
|
/>
|
|
246
157
|
</div>
|
|
247
158
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed, ref } from 'vue'
|
|
3
|
+
import { useStoryStore } from '../../stores/story'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
import { isMobile } from '../../util/responsive'
|
|
6
|
+
import BaseSplitPane from '../base/BaseSplitPane.vue'
|
|
7
|
+
import StoryVariantListItem from './StoryVariantListItem.vue'
|
|
8
|
+
import StoryVariantSingleView from './StoryVariantSingleView.vue'
|
|
9
|
+
|
|
10
|
+
const storyStore = useStoryStore()
|
|
11
|
+
|
|
12
|
+
const hasSingleVariant = computed(() => (storyStore.currentStory?.variants.length === 1))
|
|
13
|
+
|
|
14
|
+
const variant = computed(() => storyStore.currentVariant)
|
|
15
|
+
|
|
16
|
+
const isMenuOpened = ref(false)
|
|
17
|
+
|
|
18
|
+
function openMenu () {
|
|
19
|
+
isMenuOpened.value = true
|
|
20
|
+
}
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<template>
|
|
24
|
+
<div
|
|
25
|
+
v-if="hasSingleVariant && storyStore.currentVariant"
|
|
26
|
+
class="htw-p-2 htw-h-full"
|
|
27
|
+
>
|
|
28
|
+
<StoryVariantSingleView
|
|
29
|
+
v-if="storyStore.currentVariant.configReady"
|
|
30
|
+
:variant="storyStore.currentVariant"
|
|
31
|
+
:story="storyStore.currentStory"
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
<template v-else>
|
|
35
|
+
<div
|
|
36
|
+
v-if="isMobile"
|
|
37
|
+
class="htw-divide-y htw-divide-gray-100 dark:htw-divide-gray-800 htw-h-full htw-flex htw-flex-col"
|
|
38
|
+
>
|
|
39
|
+
<a
|
|
40
|
+
class="htw-px-6 htw-h-12 hover:htw-text-primary-500 dark:hover:htw-text-primary-400 htw-cursor-pointer htw-flex htw-gap-2 htw-flex-wrap htw-w-full htw-items-center"
|
|
41
|
+
@click="openMenu"
|
|
42
|
+
>
|
|
43
|
+
<template v-if="variant">
|
|
44
|
+
<Icon
|
|
45
|
+
:icon="variant.icon ?? 'carbon:cube'"
|
|
46
|
+
class="base-list-item-link-icon htw-w-5 htw-h-5 htw-flex-none"
|
|
47
|
+
:class="{
|
|
48
|
+
'htw-text-gray-500': !variant.iconColor,
|
|
49
|
+
'bind-icon-color': variant.iconColor,
|
|
50
|
+
}"
|
|
51
|
+
/>
|
|
52
|
+
{{ variant.title }}
|
|
53
|
+
</template>
|
|
54
|
+
<template v-else>
|
|
55
|
+
Select a variant...
|
|
56
|
+
</template>
|
|
57
|
+
|
|
58
|
+
<Icon
|
|
59
|
+
icon="carbon:chevron-sort"
|
|
60
|
+
class="htw-w-5 htw-h-5 htw-shrink-0 htw-ml-auto"
|
|
61
|
+
/>
|
|
62
|
+
</a>
|
|
63
|
+
<div
|
|
64
|
+
v-if="storyStore.currentVariant"
|
|
65
|
+
class="htw-p-2 htw-h-full"
|
|
66
|
+
>
|
|
67
|
+
<StoryVariantSingleView
|
|
68
|
+
v-if="storyStore.currentVariant.configReady"
|
|
69
|
+
:variant="storyStore.currentVariant"
|
|
70
|
+
:story="storyStore.currentStory"
|
|
71
|
+
/>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
<BaseSplitPane
|
|
75
|
+
v-else
|
|
76
|
+
save-id="story-single-main-split"
|
|
77
|
+
:min="5"
|
|
78
|
+
:max="40"
|
|
79
|
+
:default-split="17"
|
|
80
|
+
>
|
|
81
|
+
<template #first>
|
|
82
|
+
<div class="htw-h-full htw-overflow-y-auto">
|
|
83
|
+
<StoryVariantListItem
|
|
84
|
+
v-for="(variant, index) of storyStore.currentStory.variants"
|
|
85
|
+
:key="index"
|
|
86
|
+
:variant="variant"
|
|
87
|
+
/>
|
|
88
|
+
</div>
|
|
89
|
+
</template>
|
|
90
|
+
<template #last>
|
|
91
|
+
<div
|
|
92
|
+
v-if="storyStore.currentVariant"
|
|
93
|
+
class="htw-p-2 htw-h-full"
|
|
94
|
+
>
|
|
95
|
+
<StoryVariantSingleView
|
|
96
|
+
:variant="storyStore.currentVariant"
|
|
97
|
+
:story="storyStore.currentStory"
|
|
98
|
+
/>
|
|
99
|
+
</div>
|
|
100
|
+
</template>
|
|
101
|
+
</BaseSplitPane>
|
|
102
|
+
</template>
|
|
103
|
+
</template>
|
|
104
|
+
|
|
105
|
+
<style scoped>
|
|
106
|
+
.bind-icon-color {
|
|
107
|
+
color: v-bind('variant?.iconColor');
|
|
108
|
+
}
|
|
109
|
+
</style>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { Story, Variant } from '../../types'
|
|
3
|
+
import SandboxVue3 from '../sandbox/SandboxVue3.vue'
|
|
4
|
+
import StoryResponsivePreview from './StoryResponsivePreview.vue'
|
|
5
|
+
|
|
6
|
+
const props = defineProps<{
|
|
7
|
+
story: Story
|
|
8
|
+
variant: Variant
|
|
9
|
+
}>()
|
|
10
|
+
|
|
11
|
+
Object.assign(props.variant, {
|
|
12
|
+
previewReady: false,
|
|
13
|
+
})
|
|
14
|
+
function onReady () {
|
|
15
|
+
Object.assign(props.variant, {
|
|
16
|
+
previewReady: true,
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<StoryResponsivePreview
|
|
23
|
+
v-slot="{ isResponsiveEnabled, finalWidth, finalHeight }"
|
|
24
|
+
:variant="variant"
|
|
25
|
+
>
|
|
26
|
+
<div
|
|
27
|
+
:style="isResponsiveEnabled ? {
|
|
28
|
+
width: finalWidth ? `${finalWidth}px` : null,
|
|
29
|
+
height: finalHeight ? `${finalHeight}px` : null,
|
|
30
|
+
} : undefined"
|
|
31
|
+
>
|
|
32
|
+
<SandboxVue3
|
|
33
|
+
:variant="variant"
|
|
34
|
+
:story="story"
|
|
35
|
+
@ready="onReady"
|
|
36
|
+
/>
|
|
37
|
+
</div>
|
|
38
|
+
</StoryResponsivePreview>
|
|
39
|
+
</template>
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed, onUnmounted, Ref, ref, toRaw, watch } from 'vue'
|
|
3
|
+
import { useEventListener } from '@vueuse/core'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
import { STATE_SYNC, PREVIEW_SETTINGS_SYNC, SANDBOX_READY, EVENT_SEND } from '../../util/const'
|
|
6
|
+
import type { Story, Variant } from '../../types'
|
|
7
|
+
import HatchedPattern from '../misc/HatchedPattern.vue'
|
|
8
|
+
import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
|
|
9
|
+
import { toRawDeep } from '../../util/reactivity'
|
|
10
|
+
import { getSandboxUrl } from '../sandbox/lib'
|
|
11
|
+
import { usePreviewSettingsStore } from '../../stores/preview-settings'
|
|
12
|
+
import { HstEvent, useEventsStore } from '../../stores/events'
|
|
13
|
+
import StoryResponsivePreview from './StoryResponsivePreview.vue'
|
|
14
|
+
|
|
15
|
+
const props = defineProps<{
|
|
16
|
+
story: Story
|
|
17
|
+
variant: Variant
|
|
18
|
+
}>()
|
|
19
|
+
|
|
20
|
+
const settings = usePreviewSettingsStore().currentSettings
|
|
21
|
+
|
|
22
|
+
// Iframe
|
|
23
|
+
|
|
24
|
+
const iframe = ref<HTMLIFrameElement>()
|
|
25
|
+
|
|
26
|
+
function syncState () {
|
|
27
|
+
if (iframe.value && props.variant.previewReady) {
|
|
28
|
+
iframe.value.contentWindow.postMessage({
|
|
29
|
+
type: STATE_SYNC,
|
|
30
|
+
state: toRawDeep(props.variant.state),
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let synced = false
|
|
36
|
+
|
|
37
|
+
watch(() => props.variant.state, () => {
|
|
38
|
+
if (synced) {
|
|
39
|
+
synced = false
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
syncState()
|
|
43
|
+
}, {
|
|
44
|
+
deep: true,
|
|
45
|
+
immediate: true,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
Object.assign(props.variant, {
|
|
49
|
+
previewReady: false,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
useEventListener(window, 'message', (event) => {
|
|
53
|
+
switch (event.data.type) {
|
|
54
|
+
case STATE_SYNC:
|
|
55
|
+
updateVariantState(event.data.state)
|
|
56
|
+
break
|
|
57
|
+
case EVENT_SEND:
|
|
58
|
+
logEvent(event.data.event)
|
|
59
|
+
break
|
|
60
|
+
case SANDBOX_READY:
|
|
61
|
+
setPreviewReady()
|
|
62
|
+
break
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
function updateVariantState (state: any) {
|
|
67
|
+
synced = true
|
|
68
|
+
if (props.variant.state) {
|
|
69
|
+
for (const key in state) {
|
|
70
|
+
if (typeof props.variant.state[key] === 'object') {
|
|
71
|
+
Object.assign(props.variant.state[key], state[key])
|
|
72
|
+
} else {
|
|
73
|
+
// eslint-disable-next-line vue/no-mutating-props
|
|
74
|
+
props.variant.state[key] = state[key]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
// eslint-disable-next-line vue/no-mutating-props
|
|
79
|
+
props.variant.state = state
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function logEvent (event: HstEvent) {
|
|
84
|
+
const eventsStore = useEventsStore()
|
|
85
|
+
eventsStore.addEvent(event)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function setPreviewReady () {
|
|
89
|
+
Object.assign(props.variant, {
|
|
90
|
+
previewReady: true,
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const sandboxUrl = computed(() => {
|
|
95
|
+
return getSandboxUrl(props.story, props.variant)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
const isIframeLoaded = ref(false)
|
|
99
|
+
|
|
100
|
+
watch(sandboxUrl, () => {
|
|
101
|
+
isIframeLoaded.value = false
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
// Settings
|
|
105
|
+
|
|
106
|
+
function syncSettings () {
|
|
107
|
+
if (iframe.value) {
|
|
108
|
+
iframe.value.contentWindow.postMessage({
|
|
109
|
+
type: PREVIEW_SETTINGS_SYNC,
|
|
110
|
+
settings: toRaw(settings),
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
watch(() => settings, () => {
|
|
116
|
+
syncSettings()
|
|
117
|
+
}, {
|
|
118
|
+
deep: true,
|
|
119
|
+
immediate: true,
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
// Iframe load
|
|
123
|
+
|
|
124
|
+
function onIframeLoad () {
|
|
125
|
+
isIframeLoaded.value = true
|
|
126
|
+
syncState()
|
|
127
|
+
syncSettings()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
</script>
|
|
131
|
+
|
|
132
|
+
<template>
|
|
133
|
+
<StoryResponsivePreview
|
|
134
|
+
v-slot="{ isResponsiveEnabled, finalWidth, finalHeight, resizing }"
|
|
135
|
+
:variant="variant"
|
|
136
|
+
>
|
|
137
|
+
<iframe
|
|
138
|
+
ref="iframe"
|
|
139
|
+
:src="sandboxUrl"
|
|
140
|
+
class="htw-w-full htw-h-full htw-relative"
|
|
141
|
+
:class="{
|
|
142
|
+
'htw-invisible': !isIframeLoaded,
|
|
143
|
+
'htw-pointer-events-none': resizing,
|
|
144
|
+
}"
|
|
145
|
+
:style="isResponsiveEnabled ? {
|
|
146
|
+
width: finalWidth ? `${finalWidth}px` : null,
|
|
147
|
+
height: finalHeight ? `${finalHeight}px` : null,
|
|
148
|
+
} : undefined"
|
|
149
|
+
data-test-id="preview-iframe"
|
|
150
|
+
@load="onIframeLoad()"
|
|
151
|
+
/>
|
|
152
|
+
</StoryResponsivePreview>
|
|
153
|
+
</template>
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import type { Story, Variant } from '../../types'
|
|
3
|
-
import StoryResponsivePreview from './StoryResponsivePreview.vue'
|
|
4
3
|
import { isMobile } from '../../util/responsive'
|
|
5
|
-
import StoryVariantTitle from '
|
|
6
|
-
import StoryVariantResponsiveSize from '
|
|
7
|
-
import StoryVariantBackground from '
|
|
8
|
-
import StoryVariantNewTab from '
|
|
4
|
+
import StoryVariantTitle from '../toolbar/StoryVariantTitle.vue'
|
|
5
|
+
import StoryVariantResponsiveSize from '../toolbar/StoryVariantResponsiveSize.vue'
|
|
6
|
+
import StoryVariantBackground from '../toolbar/StoryVariantBackground.vue'
|
|
7
|
+
import StoryVariantNewTab from '../toolbar/StoryVariantNewTab.vue'
|
|
8
|
+
import StoryVariantSinglePreviewNative from './StoryVariantSinglePreviewNative.vue'
|
|
9
|
+
import StoryVariantSinglePreviewRemote from './StoryVariantSinglePreviewRemote.vue'
|
|
9
10
|
|
|
10
11
|
defineProps<{
|
|
11
12
|
variant: Variant
|
|
@@ -37,7 +38,13 @@ defineProps<{
|
|
|
37
38
|
</div>
|
|
38
39
|
|
|
39
40
|
<!-- Preview -->
|
|
40
|
-
<
|
|
41
|
+
<StoryVariantSinglePreviewNative
|
|
42
|
+
v-if="story.layout.iframe === false"
|
|
43
|
+
:story="story"
|
|
44
|
+
:variant="variant"
|
|
45
|
+
/>
|
|
46
|
+
<StoryVariantSinglePreviewRemote
|
|
47
|
+
v-else
|
|
41
48
|
:story="story"
|
|
42
49
|
:variant="variant"
|
|
43
50
|
/>
|