histoire 0.3.0 → 0.3.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/components/base/BaseEmpty.vue +1 -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 +12 -1
- package/dist/client/app/components/exposed/Variant.vue +6 -0
- package/dist/client/app/components/panel/PaneTabs.vue +64 -0
- package/dist/client/app/components/{story → panel}/StoryControls.vue +1 -1
- package/dist/client/app/components/{story → panel}/StoryDocs.vue +0 -0
- package/{src/client/app/components/story → dist/client/app/components/panel}/StoryEvent.vue +1 -0
- package/dist/client/app/components/{story → panel}/StoryEvents.vue +0 -0
- package/dist/client/app/components/{story → panel}/StorySidePanel.vue +3 -31
- package/dist/client/app/components/{story → panel}/StorySourceCode.vue +0 -0
- package/dist/client/app/components/sandbox/SandboxVue3.vue +10 -0
- package/dist/client/app/components/search/SearchPane.vue +19 -11
- package/dist/client/app/components/search/search-data.d.ts +9 -2
- package/dist/client/app/components/story/StoryResponsivePreview.vue +9 -131
- 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 +2 -2
- package/dist/client/app/components/story/StoryViewer.vue +2 -92
- package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantBackground.vue +3 -3
- package/dist/client/app/components/{story/toolbar → toolbar}/StoryVariantNewTab.vue +2 -2
- package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantResponsiveSize.vue +3 -3
- package/{src/client/app/components/story → dist/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
- package/dist/client/app/stores/events.js +1 -1
- package/dist/client/app/stores/story.d.ts +27 -0
- package/dist/client/app/style/transitions.pcss +13 -0
- package/dist/client/app/types.d.ts +3 -0
- package/dist/client/app/util/mapping.js +2 -0
- package/dist/client/index.d.ts +2 -2
- 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} +1 -1
- 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 +32 -0
- package/dist/node/collect/worker.js +6 -2
- package/dist/node/search.d.ts +7 -1
- package/dist/node/search.js +21 -12
- package/dist/node/vite.js +3 -0
- package/dist/style.css +93 -69
- package/package.json +5 -6
- package/src/client/app/components/base/BaseEmpty.vue +1 -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 +12 -1
- package/src/client/app/components/exposed/Variant.vue +6 -0
- package/src/client/app/components/panel/PaneTabs.vue +64 -0
- package/src/client/app/components/{story → panel}/StoryControls.vue +1 -1
- package/src/client/app/components/{story → panel}/StoryDocs.vue +0 -0
- package/{dist/client/app/components/story → src/client/app/components/panel}/StoryEvent.vue +1 -0
- package/src/client/app/components/{story → panel}/StoryEvents.vue +0 -0
- package/src/client/app/components/{story → panel}/StorySidePanel.vue +3 -31
- package/src/client/app/components/{story → panel}/StorySourceCode.vue +0 -0
- package/src/client/app/components/sandbox/SandboxVue3.vue +10 -0
- package/src/client/app/components/search/SearchPane.vue +19 -11
- package/src/client/app/components/search/search-data.ts +7 -2
- package/src/client/app/components/story/StoryResponsivePreview.vue +9 -131
- 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 +2 -2
- package/src/client/app/components/story/StoryViewer.vue +2 -92
- package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantBackground.vue +3 -3
- package/src/client/app/components/{story/toolbar → toolbar}/StoryVariantNewTab.vue +2 -2
- package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantResponsiveSize.vue +3 -3
- package/{dist/client/app/components/story → src/client/app/components}/toolbar/StoryVariantTitle.vue +1 -1
- package/src/client/app/sandbox.ts +1 -1
- package/src/client/app/stores/events.ts +1 -1
- package/src/client/app/style/transitions.pcss +13 -0
- package/src/client/app/types.ts +4 -0
- package/src/client/app/util/mapping.ts +2 -0
- package/src/client/index.ts +2 -2
- package/src/client/server/index.ts +14 -27
- package/{dist/client/server/Story.server.vue → src/client/server/vue3/Story.vue} +1 -1
- package/src/client/server/{Variant.server.vue → vue3/Variant.vue} +0 -0
- package/src/client/server/vue3/run.ts +38 -0
- package/src/node/collect/worker.ts +7 -2
- package/src/node/search.ts +23 -12
- package/src/node/vite.ts +3 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { ref, h, onBeforeUnmount, reactive, computed } from 'vue'
|
|
3
|
+
import { useResizeObserver } from '@vueuse/core'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
|
|
6
|
+
// Container
|
|
7
|
+
|
|
8
|
+
const overflowButtonWidth = 32
|
|
9
|
+
|
|
10
|
+
const el = ref<HTMLDivElement>()
|
|
11
|
+
|
|
12
|
+
const availableWidth = ref(0)
|
|
13
|
+
|
|
14
|
+
useResizeObserver(el, (entries) => {
|
|
15
|
+
const containerWidth = entries[0].contentRect.width
|
|
16
|
+
availableWidth.value = containerWidth - overflowButtonWidth
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// Children
|
|
20
|
+
|
|
21
|
+
interface ChildState {
|
|
22
|
+
width: number
|
|
23
|
+
index: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const children = ref(new Map<HTMLElement, ChildState>())
|
|
27
|
+
|
|
28
|
+
const visibleChildrenCount = computed(() => {
|
|
29
|
+
let width = 0
|
|
30
|
+
const c = [...children.value.values()].sort((a, b) => a.index - b.index)
|
|
31
|
+
for (let i = 0; i < c.length; i++) {
|
|
32
|
+
width += c[i].width
|
|
33
|
+
if (width > availableWidth.value) {
|
|
34
|
+
return i
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return c.length
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Watches for the size of each child and automatically hide them
|
|
42
|
+
*/
|
|
43
|
+
const ChildWrapper = {
|
|
44
|
+
props: ['index'],
|
|
45
|
+
setup (props, { slots }) {
|
|
46
|
+
const el = ref<HTMLDivElement>()
|
|
47
|
+
|
|
48
|
+
const state = reactive({ width: 0, index: props.index })
|
|
49
|
+
|
|
50
|
+
useResizeObserver(el, (entries) => {
|
|
51
|
+
const width = entries[0].contentRect.width
|
|
52
|
+
if (!children.value.has(el.value)) {
|
|
53
|
+
children.value.set(el.value, state)
|
|
54
|
+
}
|
|
55
|
+
state.width = width
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
onBeforeUnmount(() => {
|
|
59
|
+
children.value.delete(el.value)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const visible = computed(() => visibleChildrenCount.value > state.index)
|
|
63
|
+
|
|
64
|
+
return () => h('div', { ref: el, style: { visibility: visible.value ? 'visible' : 'hidden' } }, slots.default())
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Wraps each child with a <ChildWrapper>
|
|
70
|
+
*/
|
|
71
|
+
const ChildrenRender = (props, { slots }) => {
|
|
72
|
+
const [fragment] = slots.default()
|
|
73
|
+
return fragment.children.map((vnode, index) => h(ChildWrapper, { index }, [vnode]))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Only renders a part of a children list
|
|
78
|
+
*/
|
|
79
|
+
const ChildrenSlice = (props, { slots }) => {
|
|
80
|
+
const [fragment] = slots.default()
|
|
81
|
+
return fragment.children.slice(props.start, props.end)
|
|
82
|
+
}
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<template>
|
|
86
|
+
<div
|
|
87
|
+
ref="el"
|
|
88
|
+
class="htw-flex htw-overflow-hidden htw-relative"
|
|
89
|
+
>
|
|
90
|
+
<ChildrenRender>
|
|
91
|
+
<slot />
|
|
92
|
+
</ChildrenRender>
|
|
93
|
+
|
|
94
|
+
<VDropdown
|
|
95
|
+
v-if="visibleChildrenCount < children.size"
|
|
96
|
+
>
|
|
97
|
+
<div
|
|
98
|
+
role="button"
|
|
99
|
+
class="htw-cursor-pointer hover:htw-bg-primary-50 dark:hover:htw-bg-primary-900 htw-w-8 htw-h-full htw-flex htw-items-center htw-justify-center htw-absolute htw-top-0 htw-right-0"
|
|
100
|
+
>
|
|
101
|
+
<Icon
|
|
102
|
+
icon="carbon:caret-down"
|
|
103
|
+
class="htw-w-4 htw-h-4 htw-opacity-50 group-hover:htw-opacity-100"
|
|
104
|
+
/>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<template #popper>
|
|
108
|
+
<div class="htw-flex htw-flex-col htw-items-stretch">
|
|
109
|
+
<ChildrenSlice
|
|
110
|
+
:start="visibleChildrenCount"
|
|
111
|
+
>
|
|
112
|
+
<slot name="overflow" />
|
|
113
|
+
</ChildrenSlice>
|
|
114
|
+
</div>
|
|
115
|
+
</template>
|
|
116
|
+
</VDropdown>
|
|
117
|
+
</div>
|
|
118
|
+
</template>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { defineComponent } from 'vue'
|
|
3
|
+
|
|
4
|
+
export default defineComponent({
|
|
5
|
+
inheritAttrs: false,
|
|
6
|
+
|
|
7
|
+
props: {
|
|
8
|
+
exact: {
|
|
9
|
+
type: Boolean,
|
|
10
|
+
default: false,
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
matched: {
|
|
14
|
+
type: Boolean,
|
|
15
|
+
default: null,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<router-link
|
|
23
|
+
v-slot="{ isActive, isExactActive, href, navigate }"
|
|
24
|
+
v-bind="$attrs"
|
|
25
|
+
custom
|
|
26
|
+
>
|
|
27
|
+
<a
|
|
28
|
+
v-bind="$attrs"
|
|
29
|
+
:href="href"
|
|
30
|
+
class="htw-px-4 htw-h-10 htw-min-w-[150px] htw-inline-flex htw-items-center hover:htw-bg-primary-50 dark:hover:htw-bg-primary-900 htw-relative htw-text-gray-900 dark:htw-text-gray-100"
|
|
31
|
+
:class="{
|
|
32
|
+
'htw-text-primary-500 dark:htw-text-primary-400': matched != null ? matched : (exact && isExactActive) || (!exact && isActive),
|
|
33
|
+
}"
|
|
34
|
+
@click="navigate"
|
|
35
|
+
>
|
|
36
|
+
<slot />
|
|
37
|
+
|
|
38
|
+
<transition name="__histoire-scale-y">
|
|
39
|
+
<div
|
|
40
|
+
v-if="matched != null ? matched : (exact && isExactActive) || (!exact && isActive)"
|
|
41
|
+
class="htw-absolute htw-top-0 htw-left-0 htw-h-full htw-w-[2px] htw-bg-primary-500 dark:htw-bg-primary-400"
|
|
42
|
+
/>
|
|
43
|
+
</transition>
|
|
44
|
+
</a>
|
|
45
|
+
</router-link>
|
|
46
|
+
</template>
|
|
@@ -18,6 +18,8 @@ export default defineComponent({
|
|
|
18
18
|
},
|
|
19
19
|
|
|
20
20
|
setup () {
|
|
21
|
+
const vm = getCurrentInstance()
|
|
22
|
+
|
|
21
23
|
const attrs = useAttrs() as {
|
|
22
24
|
story: Story
|
|
23
25
|
}
|
|
@@ -25,7 +27,7 @@ export default defineComponent({
|
|
|
25
27
|
const story = computed(() => attrs.story)
|
|
26
28
|
provide('story', story)
|
|
27
29
|
|
|
28
|
-
const storyComponent: any =
|
|
30
|
+
const storyComponent: any = vm.parent
|
|
29
31
|
// Allows tracking reactivity with watchers to sync state
|
|
30
32
|
const implicitState = {
|
|
31
33
|
$data: storyComponent.data,
|
|
@@ -46,12 +48,21 @@ export default defineComponent({
|
|
|
46
48
|
}
|
|
47
49
|
provide('implicitState', () => implicitState)
|
|
48
50
|
|
|
51
|
+
function updateStory () {
|
|
52
|
+
Object.assign(attrs.story, {
|
|
53
|
+
slots: () => vm.proxy.$slots,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
return {
|
|
50
58
|
story,
|
|
59
|
+
updateStory,
|
|
51
60
|
}
|
|
52
61
|
},
|
|
53
62
|
|
|
54
63
|
render () {
|
|
64
|
+
this.updateStory()
|
|
65
|
+
|
|
55
66
|
const [firstVariant] = this.story.variants
|
|
56
67
|
if (firstVariant.id === '_default') {
|
|
57
68
|
return h(Variant, {
|
|
@@ -24,6 +24,11 @@ export default defineComponent({
|
|
|
24
24
|
type: Boolean,
|
|
25
25
|
default: false,
|
|
26
26
|
},
|
|
27
|
+
|
|
28
|
+
setupApp: {
|
|
29
|
+
type: Function,
|
|
30
|
+
default: null,
|
|
31
|
+
},
|
|
27
32
|
},
|
|
28
33
|
|
|
29
34
|
setup (props) {
|
|
@@ -53,6 +58,7 @@ export default defineComponent({
|
|
|
53
58
|
slots: () => vm.proxy.$slots,
|
|
54
59
|
source: props.source,
|
|
55
60
|
responsiveDisabled: props.responsiveDisabled,
|
|
61
|
+
setupApp: props.setupApp,
|
|
56
62
|
configReady: true,
|
|
57
63
|
})
|
|
58
64
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import BaseTab from '../base/BaseTab.vue'
|
|
3
|
+
import { useEventsStore } from '../../stores/events'
|
|
4
|
+
import BaseOverflowMenu from '../base/BaseOverflowMenu.vue'
|
|
5
|
+
import BaseOverflowTab from '../base/BaseOverflowTab.vue'
|
|
6
|
+
|
|
7
|
+
const eventsStore = useEventsStore()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<BaseOverflowMenu class="htw-h-10 htw-flex-none htw-border-b htw-border-gray-100 dark:htw-border-gray-750">
|
|
12
|
+
<BaseTab
|
|
13
|
+
:to="{ ...$route, query: { ...$route.query, tab: '' } }"
|
|
14
|
+
:matched="!$route.query.tab"
|
|
15
|
+
>
|
|
16
|
+
Controls
|
|
17
|
+
</BaseTab>
|
|
18
|
+
<BaseTab
|
|
19
|
+
:to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
|
|
20
|
+
:matched="$route.query.tab === 'docs'"
|
|
21
|
+
>
|
|
22
|
+
Docs
|
|
23
|
+
</BaseTab>
|
|
24
|
+
<BaseTab
|
|
25
|
+
:to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
|
|
26
|
+
:matched="$route.query.tab === 'events'"
|
|
27
|
+
>
|
|
28
|
+
Events
|
|
29
|
+
<span
|
|
30
|
+
v-if="eventsStore.unseen"
|
|
31
|
+
class="htw-text-center htw-text-xs htw-mx-1 htw-px-0.5 htw-h-4 htw-min-w-4 htw-rounded-full active htw-bg-primary-500 htw-text-white dark:htw-text-black"
|
|
32
|
+
>
|
|
33
|
+
{{ eventsStore.unseen <=99 ? eventsStore.unseen : "99+" }}
|
|
34
|
+
</span>
|
|
35
|
+
</BaseTab>
|
|
36
|
+
|
|
37
|
+
<template #overflow>
|
|
38
|
+
<BaseOverflowTab
|
|
39
|
+
:to="{ ...$route, query: { ...$route.query, tab: '' } }"
|
|
40
|
+
:matched="!$route.query.tab"
|
|
41
|
+
>
|
|
42
|
+
Controls
|
|
43
|
+
</BaseOverflowTab>
|
|
44
|
+
<BaseOverflowTab
|
|
45
|
+
:to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
|
|
46
|
+
:matched="$route.query.tab === 'docs'"
|
|
47
|
+
>
|
|
48
|
+
Docs
|
|
49
|
+
</BaseOverflowTab>
|
|
50
|
+
<BaseOverflowTab
|
|
51
|
+
:to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
|
|
52
|
+
:matched="$route.query.tab === 'events'"
|
|
53
|
+
>
|
|
54
|
+
Events
|
|
55
|
+
<span
|
|
56
|
+
v-if="eventsStore.unseen"
|
|
57
|
+
class="htw-text-center htw-text-xs htw-mx-1 htw-px-0.5 htw-h-4 htw-min-w-4 htw-rounded-full active htw-bg-primary-500 htw-text-white dark:htw-text-black"
|
|
58
|
+
>
|
|
59
|
+
{{ eventsStore.unseen <=99 ? eventsStore.unseen : "99+" }}
|
|
60
|
+
</span>
|
|
61
|
+
</BaseOverflowTab>
|
|
62
|
+
</template>
|
|
63
|
+
</BaseOverflowMenu>
|
|
64
|
+
</template>
|
|
File without changes
|
|
File without changes
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computed } from 'vue'
|
|
3
|
-
import { useRoute
|
|
3
|
+
import { useRoute } from 'vue-router'
|
|
4
4
|
import { useStoryStore } from '../../stores/story'
|
|
5
|
-
import { useEventsStore } from '../../stores/events'
|
|
6
5
|
|
|
7
6
|
import BaseSplitPane from '../base/BaseSplitPane.vue'
|
|
8
7
|
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
9
|
-
import BaseTab from '../base/BaseTab.vue'
|
|
10
8
|
import StoryControls from './StoryControls.vue'
|
|
11
9
|
import StoryDocs from './StoryDocs.vue'
|
|
12
10
|
import StoryEvents from './StoryEvents.vue'
|
|
13
11
|
import StorySourceCode from './StorySourceCode.vue'
|
|
12
|
+
import PaneTabs from './PaneTabs.vue'
|
|
14
13
|
|
|
15
14
|
const storyStore = useStoryStore()
|
|
16
|
-
const eventsStore = useEventsStore()
|
|
17
15
|
|
|
18
|
-
const router = useRouter()
|
|
19
16
|
const route = useRoute()
|
|
20
17
|
|
|
21
18
|
const panelContentComponent = computed(() => {
|
|
@@ -48,32 +45,7 @@ const panelContentComponent = computed(() => {
|
|
|
48
45
|
>
|
|
49
46
|
<template #first>
|
|
50
47
|
<div class="htw-flex htw-flex-col htw-h-full">
|
|
51
|
-
<
|
|
52
|
-
<BaseTab
|
|
53
|
-
:to="{ ...$route, query: { ...$route.query, tab: '' } }"
|
|
54
|
-
:matched="!$route.query.tab"
|
|
55
|
-
>
|
|
56
|
-
Controls
|
|
57
|
-
</BaseTab>
|
|
58
|
-
<BaseTab
|
|
59
|
-
:to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
|
|
60
|
-
:matched="$route.query.tab === 'docs'"
|
|
61
|
-
>
|
|
62
|
-
Docs
|
|
63
|
-
</BaseTab>
|
|
64
|
-
<BaseTab
|
|
65
|
-
:to="{ ...$route, query: { ...$route.query, tab: 'events' } }"
|
|
66
|
-
:matched="$route.query.tab === 'events'"
|
|
67
|
-
>
|
|
68
|
-
Events
|
|
69
|
-
<span
|
|
70
|
-
v-if="eventsStore.unseen"
|
|
71
|
-
class="htw-text-center htw-text-gray-900 dark:htw-text-gray-100 htw-text-xs htw-mx-1 htw-px-0.5 htw-h-4 htw-min-w-4 htw-rounded-full active htw-bg-primary-500 htw-text-white dark:htw-text-black"
|
|
72
|
-
>
|
|
73
|
-
{{ eventsStore.unseen <=99 ? eventsStore.unseen : "99+" }}
|
|
74
|
-
</span>
|
|
75
|
-
</BaseTab>
|
|
76
|
-
</nav>
|
|
48
|
+
<PaneTabs />
|
|
77
49
|
|
|
78
50
|
<component
|
|
79
51
|
:is="panelContentComponent"
|
|
File without changes
|
|
@@ -40,6 +40,8 @@ async function mountVariant () {
|
|
|
40
40
|
render: () => {
|
|
41
41
|
return props.variant.slots()?.[props.slotName]?.({
|
|
42
42
|
state: props.variant.state ?? {},
|
|
43
|
+
}) ?? props.story.slots()?.[props.slotName]?.({
|
|
44
|
+
state: props.variant.state ?? {},
|
|
43
45
|
})
|
|
44
46
|
},
|
|
45
47
|
})
|
|
@@ -52,6 +54,14 @@ async function mountVariant () {
|
|
|
52
54
|
})
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
if (typeof props.variant.setupApp === 'function') {
|
|
58
|
+
await props.variant.setupApp({
|
|
59
|
+
app,
|
|
60
|
+
story: props.story,
|
|
61
|
+
variant: props.variant,
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
55
65
|
const target = document.createElement('div')
|
|
56
66
|
sandbox.value.appendChild(target)
|
|
57
67
|
app.mount(target)
|
|
@@ -9,7 +9,7 @@ import { useStoryStore } from '../../stores/story'
|
|
|
9
9
|
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
10
10
|
import type { SearchResult, Story, Variant } from '../../types'
|
|
11
11
|
import SearchItem from './SearchItem.vue'
|
|
12
|
-
import { searchData, onUpdate } from './search-data.js'
|
|
12
|
+
import { searchData, onUpdate, SearchData } from './search-data.js'
|
|
13
13
|
|
|
14
14
|
const props = defineProps({
|
|
15
15
|
shown: {
|
|
@@ -50,8 +50,9 @@ const rateLimitedSearch = useDebounce(searchInputText, 50)
|
|
|
50
50
|
const storyStore = useStoryStore()
|
|
51
51
|
|
|
52
52
|
let searchIndex: flexsearch.Document<any, any>
|
|
53
|
+
let idMap: SearchData['idMap']
|
|
53
54
|
|
|
54
|
-
async function loadSearchIndex (data) {
|
|
55
|
+
async function loadSearchIndex (data: SearchData) {
|
|
55
56
|
searchIndex = new flexsearch.Document({
|
|
56
57
|
preset: 'match',
|
|
57
58
|
document: {
|
|
@@ -67,9 +68,11 @@ async function loadSearchIndex (data) {
|
|
|
67
68
|
tokenize: 'full',
|
|
68
69
|
})
|
|
69
70
|
|
|
70
|
-
for (const key of Object.keys(data)) {
|
|
71
|
-
await searchIndex.import(key, data[key])
|
|
71
|
+
for (const key of Object.keys(data.index)) {
|
|
72
|
+
await searchIndex.import(key, data.index[key])
|
|
72
73
|
}
|
|
74
|
+
|
|
75
|
+
idMap = data.idMap
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
loadSearchIndex(searchData)
|
|
@@ -87,17 +90,19 @@ watch(rateLimitedSearch, async value => {
|
|
|
87
90
|
})
|
|
88
91
|
let rank = 0
|
|
89
92
|
for (const field of raw) {
|
|
90
|
-
for (const
|
|
91
|
-
|
|
93
|
+
for (const id of field.result) {
|
|
94
|
+
const idMapData = idMap[id]
|
|
95
|
+
if (!idMapData) continue
|
|
96
|
+
switch (idMapData.kind) {
|
|
92
97
|
case 'story': {
|
|
93
|
-
list.push(storyResultFactory(storyStore.getStoryById(
|
|
98
|
+
list.push(storyResultFactory(storyStore.getStoryById(idMapData.id), rank))
|
|
94
99
|
rank++
|
|
95
100
|
break
|
|
96
101
|
}
|
|
97
102
|
case 'variant': {
|
|
98
|
-
const [storyId] =
|
|
103
|
+
const [storyId] = idMapData.id.split(':')
|
|
99
104
|
const story = storyStore.getStoryById(storyId)
|
|
100
|
-
const variant = storyStore.getVariantById(
|
|
105
|
+
const variant = storyStore.getVariantById(idMapData.id)
|
|
101
106
|
list.push(variantResultFactory(story, variant, rank))
|
|
102
107
|
rank++
|
|
103
108
|
break
|
|
@@ -130,7 +135,7 @@ function variantResultFactory (story: Story, variant: Variant, rank: number): Se
|
|
|
130
135
|
return {
|
|
131
136
|
kind: 'variant',
|
|
132
137
|
rank,
|
|
133
|
-
id: variant.id
|
|
138
|
+
id: `${story.id}:${variant.id}`,
|
|
134
139
|
title: variant.title,
|
|
135
140
|
route: {
|
|
136
141
|
name: 'story',
|
|
@@ -191,7 +196,10 @@ function selectPrevious () {
|
|
|
191
196
|
>
|
|
192
197
|
</div>
|
|
193
198
|
|
|
194
|
-
<BaseEmpty
|
|
199
|
+
<BaseEmpty
|
|
200
|
+
v-if="rateLimitedSearch && !results.length"
|
|
201
|
+
class="no-animation"
|
|
202
|
+
>
|
|
195
203
|
No results
|
|
196
204
|
</BaseEmpty>
|
|
197
205
|
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export interface SearchData {
|
|
2
|
+
index: Record<string, any>;
|
|
3
|
+
idMap: Record<number, {
|
|
4
|
+
id: string;
|
|
5
|
+
kind: string;
|
|
6
|
+
}>;
|
|
7
|
+
}
|
|
8
|
+
export declare const searchData: SearchData;
|
|
9
|
+
export declare function onUpdate(cb: (data: SearchData) => unknown): void;
|
|
@@ -1,131 +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, EVENT_SEND } 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'
|
|
12
|
-
import {
|
|
8
|
+
import { Variant } from '../../types'
|
|
13
9
|
|
|
14
10
|
const props = defineProps<{
|
|
15
|
-
story: Story
|
|
16
11
|
variant: Variant
|
|
17
12
|
}>()
|
|
18
13
|
|
|
19
14
|
const settings = usePreviewSettingsStore().currentSettings
|
|
20
15
|
|
|
21
|
-
// Iframe
|
|
22
|
-
|
|
23
|
-
const iframe = ref<HTMLIFrameElement>()
|
|
24
|
-
|
|
25
|
-
function syncState () {
|
|
26
|
-
if (iframe.value && props.variant.previewReady) {
|
|
27
|
-
iframe.value.contentWindow.postMessage({
|
|
28
|
-
type: STATE_SYNC,
|
|
29
|
-
state: toRawDeep(props.variant.state),
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let synced = false
|
|
35
|
-
|
|
36
|
-
watch(() => props.variant.state, () => {
|
|
37
|
-
if (synced) {
|
|
38
|
-
synced = false
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
syncState()
|
|
42
|
-
}, {
|
|
43
|
-
deep: true,
|
|
44
|
-
immediate: true,
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
Object.assign(props.variant, {
|
|
48
|
-
previewReady: false,
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
useEventListener(window, 'message', (event) => {
|
|
52
|
-
switch (event.data.type) {
|
|
53
|
-
case STATE_SYNC:
|
|
54
|
-
updateVariantState(event.data.state)
|
|
55
|
-
break
|
|
56
|
-
case EVENT_SEND:
|
|
57
|
-
logEvent(event.data.event)
|
|
58
|
-
break
|
|
59
|
-
case SANDBOX_READY:
|
|
60
|
-
setPreviewReady()
|
|
61
|
-
break
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
function updateVariantState (state: any) {
|
|
66
|
-
synced = true
|
|
67
|
-
if (props.variant.state) {
|
|
68
|
-
for (const key in state) {
|
|
69
|
-
if (typeof props.variant.state[key] === 'object') {
|
|
70
|
-
Object.assign(props.variant.state[key], state[key])
|
|
71
|
-
} else {
|
|
72
|
-
// eslint-disable-next-line vue/no-mutating-props
|
|
73
|
-
props.variant.state[key] = state[key]
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
// eslint-disable-next-line vue/no-mutating-props
|
|
78
|
-
props.variant.state = state
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function logEvent (event: HstEvent) {
|
|
83
|
-
const eventsStore = useEventsStore()
|
|
84
|
-
eventsStore.addEvent(event)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function setPreviewReady () {
|
|
88
|
-
Object.assign(props.variant, {
|
|
89
|
-
previewReady: true,
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const sandboxUrl = computed(() => {
|
|
94
|
-
return getSandboxUrl(props.story, props.variant)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
const isIframeLoaded = ref(false)
|
|
98
|
-
|
|
99
|
-
watch(sandboxUrl, () => {
|
|
100
|
-
isIframeLoaded.value = false
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
// Settings
|
|
104
|
-
|
|
105
|
-
function syncSettings () {
|
|
106
|
-
if (iframe.value) {
|
|
107
|
-
iframe.value.contentWindow.postMessage({
|
|
108
|
-
type: PREVIEW_SETTINGS_SYNC,
|
|
109
|
-
settings: toRaw(settings),
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
watch(() => settings, () => {
|
|
115
|
-
syncSettings()
|
|
116
|
-
}, {
|
|
117
|
-
deep: true,
|
|
118
|
-
immediate: true,
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
// Iframe load
|
|
122
|
-
|
|
123
|
-
function onIframeLoad () {
|
|
124
|
-
isIframeLoaded.value = true
|
|
125
|
-
syncState()
|
|
126
|
-
syncSettings()
|
|
127
|
-
}
|
|
128
|
-
|
|
129
16
|
// Resize
|
|
130
17
|
|
|
131
18
|
const resizing = ref(false)
|
|
@@ -150,7 +37,7 @@ function useDragger (el: Ref<HTMLDivElement>, value: Ref<number>, min: number, m
|
|
|
150
37
|
event.preventDefault()
|
|
151
38
|
event.stopPropagation()
|
|
152
39
|
const start = axis === 'x' ? event.clientX : event.clientY
|
|
153
|
-
const startValue = value.value
|
|
40
|
+
const startValue = value.value
|
|
154
41
|
resizing.value = true
|
|
155
42
|
|
|
156
43
|
const removeListeners = [
|
|
@@ -179,7 +66,7 @@ function useDragger (el: Ref<HTMLDivElement>, value: Ref<number>, min: number, m
|
|
|
179
66
|
event.preventDefault()
|
|
180
67
|
event.stopPropagation()
|
|
181
68
|
const start = axis === 'x' ? event.touches[0].clientX : event.touches[0].clientY
|
|
182
|
-
const startValue = value.value
|
|
69
|
+
const startValue = value.value
|
|
183
70
|
resizing.value = true
|
|
184
71
|
|
|
185
72
|
const removeListeners = [
|
|
@@ -261,20 +148,11 @@ const isResponsiveEnabled = computed(() => !props.variant.responsiveDisabled)
|
|
|
261
148
|
class="htw-absolute htw-inset-0 htw-w-full htw-h-full htw-text-gray-500/20"
|
|
262
149
|
/>
|
|
263
150
|
|
|
264
|
-
<
|
|
265
|
-
|
|
266
|
-
:
|
|
267
|
-
|
|
268
|
-
:
|
|
269
|
-
'htw-invisible': !isIframeLoaded,
|
|
270
|
-
'htw-pointer-events-none': resizing,
|
|
271
|
-
}"
|
|
272
|
-
:style="isResponsiveEnabled ? {
|
|
273
|
-
width: finalWidth ? `${finalWidth}px` : null,
|
|
274
|
-
height: finalHeight ? `${finalHeight}px` : null,
|
|
275
|
-
} : undefined"
|
|
276
|
-
data-test-id="preview-iframe"
|
|
277
|
-
@load="onIframeLoad()"
|
|
151
|
+
<slot
|
|
152
|
+
:is-responsive-enabled="isResponsiveEnabled"
|
|
153
|
+
:final-width="finalWidth"
|
|
154
|
+
:final-height="finalHeight"
|
|
155
|
+
:resizing="resizing"
|
|
278
156
|
/>
|
|
279
157
|
</div>
|
|
280
158
|
|