histoire 0.2.4 → 0.3.1
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 +9 -4
- 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 +82 -21
- package/dist/client/app/components/app/Breadcrumb.vue +1 -1
- package/dist/client/app/components/base/BaseEmpty.vue +17 -1
- package/dist/client/app/components/exposed/Story.vue +22 -1
- package/dist/client/app/components/exposed/Variant.vue +13 -1
- package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -4
- package/dist/client/app/components/sandbox/lib.js +2 -1
- package/dist/client/app/components/search/SearchItem.vue +1 -0
- 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 +7 -0
- package/dist/client/app/components/story/StoryControls.vue +5 -0
- package/dist/client/app/components/story/StoryDocs.vue +18 -11
- package/dist/client/app/components/story/StoryEvent.vue +53 -0
- package/dist/client/app/components/story/StoryEvents.vue +45 -0
- package/dist/client/app/components/story/StoryResponsivePreview.vue +41 -8
- package/dist/client/app/components/story/StorySidePanel.vue +28 -3
- package/dist/client/app/components/story/StorySourceCode.vue +24 -14
- package/dist/client/app/components/story/StoryView.vue +16 -2
- package/dist/client/app/components/tree/StoryGroup.vue +75 -0
- package/dist/client/app/components/{story → tree}/StoryList.vue +8 -2
- package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListFolder.vue +10 -8
- package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListItem.vue +7 -4
- package/dist/client/app/router.d.ts +1 -0
- package/dist/client/app/router.js +3 -1
- package/dist/client/app/sandbox.js +11 -1
- package/dist/client/app/stores/events.d.ts +29 -0
- package/dist/client/app/stores/events.js +25 -0
- package/dist/client/app/stores/folder.d.ts +10 -0
- package/dist/client/app/stores/folder.js +47 -0
- package/dist/client/app/stores/story.d.ts +20 -8
- package/dist/client/app/stores/story.js +20 -28
- package/dist/client/app/style/floating-vue.pcss +3 -1
- package/dist/client/app/style/main.pcss +5 -0
- package/dist/client/app/style/sandbox.css +2 -0
- package/dist/client/app/types.d.ts +9 -1
- 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 +31 -0
- package/dist/client/app/util/mapping.js +2 -2
- package/dist/client/index.d.ts +4 -3
- package/dist/client/index.js +2 -1
- 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} +21 -4
- 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/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 +5 -3
- package/dist/node/collect/worker.js +6 -2
- package/dist/node/commands/preview.js +4 -25
- package/dist/node/config.d.ts +111 -5
- 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 +9 -4
- package/dist/node/tree.d.ts +16 -12
- package/dist/node/tree.js +45 -5
- package/dist/node/types.d.ts +11 -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 -36
- package/package.json +7 -6
- package/scripts/copy.mjs +2 -1
- package/src/client/app/App.vue +9 -4
- package/src/client/app/codegen/const.ts +3 -0
- package/src/client/app/codegen/vue3.ts +80 -22
- package/src/client/app/components/app/Breadcrumb.vue +1 -1
- package/src/client/app/components/base/BaseEmpty.vue +17 -1
- package/src/client/app/components/exposed/Story.vue +22 -1
- package/src/client/app/components/exposed/Variant.vue +13 -1
- package/src/client/app/components/sandbox/SandboxVue3.vue +6 -4
- package/src/client/app/components/sandbox/lib.ts +3 -1
- package/src/client/app/components/search/SearchItem.vue +1 -0
- 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/StoryControls.vue +5 -0
- package/src/client/app/components/story/StoryDocs.vue +18 -11
- package/src/client/app/components/story/StoryEvent.vue +53 -0
- package/src/client/app/components/story/StoryEvents.vue +45 -0
- package/src/client/app/components/story/StoryResponsivePreview.vue +41 -8
- package/src/client/app/components/story/StorySidePanel.vue +28 -3
- package/src/client/app/components/story/StorySourceCode.vue +24 -14
- package/src/client/app/components/story/StoryView.vue +16 -2
- package/src/client/app/components/tree/StoryGroup.vue +75 -0
- package/src/client/app/components/{story → tree}/StoryList.vue +8 -2
- package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListFolder.vue +10 -8
- package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListItem.vue +7 -4
- package/src/client/app/router.ts +4 -1
- package/src/client/app/sandbox.ts +12 -2
- package/src/client/app/stores/events.ts +36 -0
- package/src/client/app/stores/folder.ts +59 -0
- package/src/client/app/stores/story.ts +20 -35
- package/src/client/app/style/floating-vue.pcss +3 -1
- package/src/client/app/style/main.pcss +5 -0
- package/src/client/app/style/sandbox.css +2 -0
- package/src/client/app/types.ts +10 -1
- 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 +2 -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} +21 -4
- 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 +6 -4
- package/src/node/collect/worker.ts +7 -2
- package/src/node/commands/preview.ts +4 -33
- package/src/node/config.ts +62 -29
- 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 +9 -4
- package/src/node/tree.spec.ts +35 -17
- package/src/node/tree.ts +64 -10
- package/src/node/types.ts +12 -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/stores/story.ts +0 -62
- package/dist/client/app/types.ts +0 -70
- 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,45 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { ref, computed, watch, onMounted, nextTick } from 'vue'
|
|
3
|
+
import { Icon } from '@iconify/vue'
|
|
4
|
+
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
5
|
+
import { useEventsStore } from '../../stores/events'
|
|
6
|
+
import StoryEvent from './StoryEvent.vue'
|
|
7
|
+
|
|
8
|
+
const eventsStore = useEventsStore()
|
|
9
|
+
|
|
10
|
+
const hasEvents = computed(() => eventsStore.events.length)
|
|
11
|
+
|
|
12
|
+
onMounted(resetUnseen)
|
|
13
|
+
watch(() => eventsStore.unseen, resetUnseen)
|
|
14
|
+
|
|
15
|
+
async function resetUnseen () {
|
|
16
|
+
if (eventsStore.unseen > 0) {
|
|
17
|
+
eventsStore.unseen = 0
|
|
18
|
+
}
|
|
19
|
+
await nextTick()
|
|
20
|
+
eventsElement.value.scrollTo({ top: eventsElement.value.scrollHeight })
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const eventsElement = ref<HTMLDivElement>()
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<div ref="eventsElement">
|
|
28
|
+
<BaseEmpty
|
|
29
|
+
v-if="!hasEvents"
|
|
30
|
+
>
|
|
31
|
+
<Icon
|
|
32
|
+
icon="carbon:event-schedule"
|
|
33
|
+
class="htw-w-8 htw-h-8 htw-opacity-50 htw-mb-6"
|
|
34
|
+
/>
|
|
35
|
+
No event fired
|
|
36
|
+
</BaseEmpty>
|
|
37
|
+
<div v-else>
|
|
38
|
+
<StoryEvent
|
|
39
|
+
v-for="(event, key) of eventsStore.events"
|
|
40
|
+
:key="key"
|
|
41
|
+
:event="event"
|
|
42
|
+
/>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
import { computed, onUnmounted, Ref, ref, toRaw, watch } 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'
|
|
5
|
+
import { STATE_SYNC, PREVIEW_SETTINGS_SYNC, SANDBOX_READY, EVENT_SEND } from '../../util/const'
|
|
6
6
|
import type { Story, Variant } from '../../types'
|
|
7
7
|
import HatchedPattern from '../misc/HatchedPattern.vue'
|
|
8
8
|
import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
|
|
9
9
|
import { toRawDeep } from '../../util/reactivity'
|
|
10
10
|
import { getSandboxUrl } from '../sandbox/lib'
|
|
11
11
|
import { usePreviewSettingsStore } from '../../stores/preview-settings'
|
|
12
|
+
import { HstEvent, useEventsStore } from '../../stores/events'
|
|
12
13
|
|
|
13
14
|
const props = defineProps<{
|
|
14
15
|
story: Story
|
|
@@ -46,17 +47,49 @@ watch(() => props.variant.state, () => {
|
|
|
46
47
|
Object.assign(props.variant, {
|
|
47
48
|
previewReady: false,
|
|
48
49
|
})
|
|
50
|
+
|
|
49
51
|
useEventListener(window, 'message', (event) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
|
57
62
|
}
|
|
58
63
|
})
|
|
59
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
|
+
|
|
60
93
|
const sandboxUrl = computed(() => {
|
|
61
94
|
return getSandboxUrl(props.story, props.variant)
|
|
62
95
|
})
|
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
+
import { computed } from 'vue'
|
|
2
3
|
import { useRoute, useRouter } from 'vue-router'
|
|
3
4
|
import { useStoryStore } from '../../stores/story'
|
|
5
|
+
import { useEventsStore } from '../../stores/events'
|
|
4
6
|
|
|
5
7
|
import BaseSplitPane from '../base/BaseSplitPane.vue'
|
|
6
8
|
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
7
9
|
import BaseTab from '../base/BaseTab.vue'
|
|
8
10
|
import StoryControls from './StoryControls.vue'
|
|
9
11
|
import StoryDocs from './StoryDocs.vue'
|
|
12
|
+
import StoryEvents from './StoryEvents.vue'
|
|
10
13
|
import StorySourceCode from './StorySourceCode.vue'
|
|
11
14
|
|
|
12
15
|
const storyStore = useStoryStore()
|
|
16
|
+
const eventsStore = useEventsStore()
|
|
13
17
|
|
|
14
18
|
const router = useRouter()
|
|
15
19
|
const route = useRoute()
|
|
20
|
+
|
|
21
|
+
const panelContentComponent = computed(() => {
|
|
22
|
+
switch (route.query.tab) {
|
|
23
|
+
case 'docs':
|
|
24
|
+
return StoryDocs
|
|
25
|
+
case 'events':
|
|
26
|
+
return StoryEvents
|
|
27
|
+
default:
|
|
28
|
+
return StoryControls
|
|
29
|
+
}
|
|
30
|
+
})
|
|
16
31
|
</script>
|
|
17
32
|
|
|
18
33
|
<template>
|
|
@@ -46,12 +61,22 @@ const route = useRoute()
|
|
|
46
61
|
>
|
|
47
62
|
Docs
|
|
48
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>
|
|
49
76
|
</nav>
|
|
50
77
|
|
|
51
78
|
<component
|
|
52
|
-
:is="
|
|
53
|
-
? StoryDocs
|
|
54
|
-
: StoryControls"
|
|
79
|
+
:is="panelContentComponent"
|
|
55
80
|
:story="storyStore.currentStory"
|
|
56
81
|
:variant="storyStore.currentVariant"
|
|
57
82
|
class="htw-h-full htw-overflow-auto"
|
|
@@ -62,9 +62,23 @@ const sourceHtml = computed(() => highlighter.value?.codeToHtml(sourceCode.value
|
|
|
62
62
|
|
|
63
63
|
<template>
|
|
64
64
|
<div
|
|
65
|
-
class="htw-bg-gray-100 dark:htw-bg-gray-800 htw-h-full htw-overflow-hidden htw-
|
|
66
|
-
data-test-id="story-source-code"
|
|
65
|
+
class="htw-bg-gray-100 dark:htw-bg-gray-800 htw-h-full htw-overflow-hidden htw-flex htw-flex-col"
|
|
67
66
|
>
|
|
67
|
+
<!-- Toolbar -->
|
|
68
|
+
<div
|
|
69
|
+
v-if="!error"
|
|
70
|
+
class="htw-h-10 htw-flex-none htw-border-b htw-border-solid htw-border-gray-150 dark:htw-border-gray-850 htw-px-4 htw-flex htw-items-center"
|
|
71
|
+
>
|
|
72
|
+
<div class="htw-text-gray-900 dark:htw-text-gray-100">
|
|
73
|
+
Source
|
|
74
|
+
</div>
|
|
75
|
+
<div class="htw-flex-1" />
|
|
76
|
+
<HstCopyIcon
|
|
77
|
+
:content="sourceCode"
|
|
78
|
+
class="htw-flex-none"
|
|
79
|
+
/>
|
|
80
|
+
</div>
|
|
81
|
+
|
|
68
82
|
<div
|
|
69
83
|
v-if="error"
|
|
70
84
|
class="htw-text-red-500 htw-h-full htw-p-2 htw-overflow-auto htw-font-mono htw-text-sm"
|
|
@@ -74,27 +88,23 @@ const sourceHtml = computed(() => highlighter.value?.codeToHtml(sourceCode.value
|
|
|
74
88
|
|
|
75
89
|
<textarea
|
|
76
90
|
v-else-if="!sourceHtml"
|
|
77
|
-
class="__histoire-code-placeholder htw-w-full htw-h-full htw-p-
|
|
91
|
+
class="__histoire-code-placeholder htw-w-full htw-h-full htw-p-4 htw-outline-none htw-bg-transparent htw-resize-none htw-m-0"
|
|
78
92
|
:value="sourceCode"
|
|
79
93
|
readonly
|
|
94
|
+
data-test-id="story-source-code"
|
|
80
95
|
/>
|
|
81
96
|
<!-- eslint-disable vue/no-v-html -->
|
|
82
97
|
<div
|
|
83
98
|
v-else
|
|
84
|
-
class="
|
|
85
|
-
|
|
86
|
-
/>
|
|
87
|
-
<!-- eslint-enable vue/no-v-html -->
|
|
88
|
-
|
|
89
|
-
<!-- Toolbar -->
|
|
90
|
-
<div
|
|
91
|
-
v-if="!error"
|
|
92
|
-
class="htw-absolute htw-top-2 htw-right-6 htw-p-1 htw-bg-gray-100 dark:htw-bg-gray-800"
|
|
99
|
+
class="htw-w-full htw-h-full htw-overflow-auto"
|
|
100
|
+
data-test-id="story-source-code"
|
|
93
101
|
>
|
|
94
|
-
<
|
|
95
|
-
|
|
102
|
+
<div
|
|
103
|
+
class="__histoire-code htw-p-4 htw-w-fit"
|
|
104
|
+
v-html="sourceHtml"
|
|
96
105
|
/>
|
|
97
106
|
</div>
|
|
107
|
+
<!-- eslint-enable vue/no-v-html -->
|
|
98
108
|
</div>
|
|
99
109
|
</template>
|
|
100
110
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { watch } from 'vue'
|
|
3
3
|
import { useRoute, useRouter } from 'vue-router'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
4
5
|
import { useStoryStore } from '../../stores/story'
|
|
5
6
|
|
|
6
7
|
import BaseSplitPane from '../base/BaseSplitPane.vue'
|
|
@@ -8,6 +9,7 @@ import BaseEmpty from '../base/BaseEmpty.vue'
|
|
|
8
9
|
import { isMobile } from '../../util/responsive'
|
|
9
10
|
import StoryViewer from './StoryViewer.vue'
|
|
10
11
|
import StorySidePanel from './StorySidePanel.vue'
|
|
12
|
+
import StoryDocs from './StoryDocs.vue'
|
|
11
13
|
|
|
12
14
|
const storyStore = useStoryStore()
|
|
13
15
|
|
|
@@ -52,14 +54,26 @@ function setVariant (variantId: string) {
|
|
|
52
54
|
|
|
53
55
|
<template>
|
|
54
56
|
<BaseEmpty v-if="!storyStore.currentStory">
|
|
55
|
-
<
|
|
57
|
+
<Icon
|
|
58
|
+
icon="carbon:software-resource-resource"
|
|
59
|
+
class="htw-w-16 htw-h-16 htw-opacity-50"
|
|
60
|
+
/>
|
|
56
61
|
</BaseEmpty>
|
|
57
62
|
|
|
58
63
|
<div
|
|
59
64
|
v-else
|
|
60
65
|
class="htw-h-full"
|
|
61
66
|
>
|
|
62
|
-
<
|
|
67
|
+
<div
|
|
68
|
+
v-if="storyStore.currentStory.docsOnly"
|
|
69
|
+
class="htw-h-full htw-overflow-auto"
|
|
70
|
+
>
|
|
71
|
+
<StoryDocs
|
|
72
|
+
:story="storyStore.currentStory"
|
|
73
|
+
class="md:htw-p-12 htw-w-full md:htw-max-w-[600px] lg:htw-max-w-[800px] xl:htw-max-w-[900px]"
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
76
|
+
<template v-else-if="isMobile">
|
|
63
77
|
<StoryViewer />
|
|
64
78
|
</template>
|
|
65
79
|
<BaseSplitPane
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { Story, TreeGroup, TreeFolder, TreeLeaf } from '../../types'
|
|
3
|
+
import StoryListItem from './StoryListItem.vue'
|
|
4
|
+
import StoryListFolder from './StoryListFolder.vue'
|
|
5
|
+
import { Icon } from '@iconify/vue'
|
|
6
|
+
import { computed, withDefaults } from 'vue'
|
|
7
|
+
import { useFolderStore } from '../../stores/folder'
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(defineProps<{
|
|
10
|
+
path?: Array<string>
|
|
11
|
+
group: TreeGroup
|
|
12
|
+
stories: Story[]
|
|
13
|
+
}>(), {
|
|
14
|
+
path: () => [],
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const folderStore = useFolderStore()
|
|
18
|
+
|
|
19
|
+
const folderPath = computed(() => [...props.path, props.group.title])
|
|
20
|
+
const isFolderOpen = computed(() => folderStore.isFolderOpened(folderPath.value, true))
|
|
21
|
+
|
|
22
|
+
function toggleOpen () {
|
|
23
|
+
folderStore.toggleFolder(folderPath.value, false)
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div
|
|
29
|
+
data-test-id="story-group"
|
|
30
|
+
class="htw-my-2 first:htw-mt-0 last:htw-mb-0"
|
|
31
|
+
>
|
|
32
|
+
<div
|
|
33
|
+
v-if="group.title"
|
|
34
|
+
role="button"
|
|
35
|
+
tabindex="0"
|
|
36
|
+
class="htw-px-0.5 htw-py-2 md:htw-py-1.5 htw-mx-1 htw-rounded-sm hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900 htw-cursor-pointer htw-select-none htw-flex htw-items-center htw-gap-1 htw-min-w-0"
|
|
37
|
+
@click="toggleOpen"
|
|
38
|
+
@keyup.enter="toggleOpen"
|
|
39
|
+
@keyup.space="toggleOpen"
|
|
40
|
+
>
|
|
41
|
+
<Icon
|
|
42
|
+
icon="carbon:caret-right"
|
|
43
|
+
class="htw-w-4 htw-h-4 htw-transition-transform htw-duration-150 htw-opacity-30 htw-flex-none"
|
|
44
|
+
:class="{
|
|
45
|
+
'htw-rotate-90': isFolderOpen,
|
|
46
|
+
}"
|
|
47
|
+
/>
|
|
48
|
+
<span class="htw-truncate htw-opacity-50">{{ group.title }}</span>
|
|
49
|
+
<span class="htw-h-[1px] htw-flex-1 htw-bg-gray-500/10 htw-mx-2" />
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<!-- Children -->
|
|
53
|
+
<div
|
|
54
|
+
v-if="isFolderOpen"
|
|
55
|
+
>
|
|
56
|
+
<template
|
|
57
|
+
v-for="element of group.children"
|
|
58
|
+
:key="element.title"
|
|
59
|
+
>
|
|
60
|
+
<StoryListFolder
|
|
61
|
+
v-if="(element as TreeFolder).children"
|
|
62
|
+
:path="folderPath"
|
|
63
|
+
:folder="(element as TreeFolder)"
|
|
64
|
+
:stories="stories"
|
|
65
|
+
:depth="0"
|
|
66
|
+
/>
|
|
67
|
+
<StoryListItem
|
|
68
|
+
v-else
|
|
69
|
+
:story="stories[(element as TreeLeaf).index]"
|
|
70
|
+
:depth="0"
|
|
71
|
+
/>
|
|
72
|
+
</template>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</template>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import type { Story, Tree, TreeFolder, TreeLeaf } from '../../types'
|
|
2
|
+
import type { Story, Tree, TreeGroup, TreeFolder, TreeLeaf } from '../../types'
|
|
3
3
|
import StoryListItem from './StoryListItem.vue'
|
|
4
4
|
import StoryListFolder from './StoryListFolder.vue'
|
|
5
|
+
import StoryGroup from './StoryGroup.vue'
|
|
5
6
|
|
|
6
7
|
const props = defineProps<{
|
|
7
8
|
tree: Tree
|
|
@@ -15,8 +16,13 @@ const props = defineProps<{
|
|
|
15
16
|
v-for="element of tree"
|
|
16
17
|
:key="element.title"
|
|
17
18
|
>
|
|
19
|
+
<StoryGroup
|
|
20
|
+
v-if="(element as TreeGroup).group"
|
|
21
|
+
:group="(element as TreeGroup)"
|
|
22
|
+
:stories="stories"
|
|
23
|
+
/>
|
|
18
24
|
<StoryListFolder
|
|
19
|
-
v-if="(element as TreeFolder).children"
|
|
25
|
+
v-else-if="(element as TreeFolder).children"
|
|
20
26
|
:folder="(element as TreeFolder)"
|
|
21
27
|
:stories="stories"
|
|
22
28
|
/>
|
package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListFolder.vue
RENAMED
|
@@ -3,7 +3,7 @@ import type { Story, TreeFolder, TreeLeaf } from '../../types'
|
|
|
3
3
|
import StoryListItem from './StoryListItem.vue'
|
|
4
4
|
import { Icon } from '@iconify/vue'
|
|
5
5
|
import { computed, withDefaults } from 'vue'
|
|
6
|
-
import {
|
|
6
|
+
import { useFolderStore } from '../../stores/folder'
|
|
7
7
|
|
|
8
8
|
const props = withDefaults(defineProps<{
|
|
9
9
|
path?: Array<string>
|
|
@@ -15,17 +15,17 @@ const props = withDefaults(defineProps<{
|
|
|
15
15
|
path: () => [],
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const folderStore = useFolderStore()
|
|
19
19
|
|
|
20
20
|
const folderPath = computed(() => [...props.path, props.folder.title])
|
|
21
|
-
const isFolderOpen = computed(() =>
|
|
21
|
+
const isFolderOpen = computed(() => folderStore.isFolderOpened(folderPath.value))
|
|
22
22
|
|
|
23
23
|
function toggleOpen () {
|
|
24
|
-
|
|
24
|
+
folderStore.toggleFolder(folderPath.value)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const folderPadding = computed(() => {
|
|
28
|
-
return (props.depth *
|
|
28
|
+
return (props.depth * 12) + 'px'
|
|
29
29
|
})
|
|
30
30
|
</script>
|
|
31
31
|
|
|
@@ -34,13 +34,13 @@ const folderPadding = computed(() => {
|
|
|
34
34
|
<div
|
|
35
35
|
role="button"
|
|
36
36
|
tabindex="0"
|
|
37
|
-
class="htw-px-0.5 htw-py-2 md:htw-py-1.5 htw-
|
|
37
|
+
class="htw-px-0.5 htw-py-2 md:htw-py-1.5 htw-mx-1 htw-rounded-sm hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900 htw-cursor-pointer htw-select-none htw-flex"
|
|
38
38
|
@click="toggleOpen"
|
|
39
39
|
@keyup.enter="toggleOpen"
|
|
40
40
|
@keyup.space="toggleOpen"
|
|
41
41
|
>
|
|
42
42
|
<span class="bind-tree-padding htw-flex htw-items-center htw-gap-2 htw-min-w-0">
|
|
43
|
-
<span class="htw-flex htw-
|
|
43
|
+
<span class="htw-flex htw-flex-none htw-items-center">
|
|
44
44
|
<Icon
|
|
45
45
|
icon="carbon:caret-right"
|
|
46
46
|
class="htw-w-4 htw-h-4 htw-transition-transform htw-duration-150 htw-opacity-30"
|
|
@@ -56,6 +56,8 @@ const folderPadding = computed(() => {
|
|
|
56
56
|
<span class="htw-truncate">{{ folder.title }}</span>
|
|
57
57
|
</span>
|
|
58
58
|
</div>
|
|
59
|
+
|
|
60
|
+
<!-- Children -->
|
|
59
61
|
<div
|
|
60
62
|
v-if="isFolderOpen"
|
|
61
63
|
>
|
|
@@ -66,7 +68,7 @@ const folderPadding = computed(() => {
|
|
|
66
68
|
<StoryListFolder
|
|
67
69
|
v-if="(element as TreeFolder).children"
|
|
68
70
|
:path="folderPath"
|
|
69
|
-
:folder="element"
|
|
71
|
+
:folder="(element as TreeFolder)"
|
|
70
72
|
:stories="stories"
|
|
71
73
|
:depth="depth + 1"
|
|
72
74
|
/>
|
package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListItem.vue
RENAMED
|
@@ -14,7 +14,7 @@ const props = withDefaults(defineProps<{
|
|
|
14
14
|
})
|
|
15
15
|
|
|
16
16
|
const filePadding = computed(() => {
|
|
17
|
-
return (props.depth *
|
|
17
|
+
return (props.depth * 12) + 'px'
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
const route = useRoute()
|
|
@@ -36,9 +36,9 @@ useScrollOnActive(active, el)
|
|
|
36
36
|
storyId: story.id,
|
|
37
37
|
},
|
|
38
38
|
}"
|
|
39
|
-
class="htw-pl-0.5 htw-pr-2 htw-py-2 md:htw-py-1.5 htw-
|
|
39
|
+
class="htw-pl-0.5 htw-pr-2 htw-py-2 md:htw-py-1.5 htw-mx-1 htw-rounded-sm"
|
|
40
40
|
>
|
|
41
|
-
<span class="bind-tree-margin htw-flex htw-items-center htw-gap-2 htw-pl-
|
|
41
|
+
<span class="bind-tree-margin htw-flex htw-items-center htw-gap-2 htw-pl-4 htw-min-w-0">
|
|
42
42
|
<Icon
|
|
43
43
|
:icon="story.icon ?? 'carbon:cube'"
|
|
44
44
|
class="base-list-item-link-icon htw-w-5 htw-h-5 sm:htw-w-4 sm:htw-h-4 htw-flex-none"
|
|
@@ -50,7 +50,10 @@ useScrollOnActive(active, el)
|
|
|
50
50
|
<span class="htw-truncate">{{ story.title }}</span>
|
|
51
51
|
</span>
|
|
52
52
|
|
|
53
|
-
<span
|
|
53
|
+
<span
|
|
54
|
+
v-if="!story.docsOnly"
|
|
55
|
+
class="htw-opacity-40 htw-text-sm"
|
|
56
|
+
>
|
|
54
57
|
{{ story.variants.length }}
|
|
55
58
|
</span>
|
|
56
59
|
</BaseListItemLink>
|
package/src/client/app/router.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { createRouter, createWebHistory } from 'vue-router'
|
|
2
2
|
|
|
3
|
+
// @ts-expect-error env not defined
|
|
4
|
+
export const base = import.meta.env.BASE_URL
|
|
5
|
+
|
|
3
6
|
export const router = createRouter({
|
|
4
|
-
history: createWebHistory(),
|
|
7
|
+
history: createWebHistory(base),
|
|
5
8
|
routes: [
|
|
6
9
|
{
|
|
7
10
|
path: '/',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './style/sandbox.css'
|
|
2
2
|
import { parseQuery } from 'vue-router'
|
|
3
|
-
import { computed, createApp, h, onMounted, ref, watch } from 'vue'
|
|
3
|
+
import { computed, createApp, h, onMounted, ref, watch, isRef } from 'vue'
|
|
4
4
|
import { createPinia } from 'pinia'
|
|
5
5
|
import { registerGlobalComponents } from './global-components'
|
|
6
6
|
import SandboxVue3 from './components/sandbox/SandboxVue3.vue'
|
|
@@ -18,6 +18,8 @@ const query = parseQuery(window.location.search)
|
|
|
18
18
|
const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
|
|
19
19
|
|
|
20
20
|
const app = createApp({
|
|
21
|
+
name: 'SandboxApp',
|
|
22
|
+
|
|
21
23
|
setup () {
|
|
22
24
|
const story = computed(() => file.value.story)
|
|
23
25
|
const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId))
|
|
@@ -29,7 +31,15 @@ const app = createApp({
|
|
|
29
31
|
if (event.data?.type === STATE_SYNC) {
|
|
30
32
|
if (!mounted) return
|
|
31
33
|
synced = true
|
|
32
|
-
|
|
34
|
+
if (variant.value.state) {
|
|
35
|
+
for (const key in event.data.state) {
|
|
36
|
+
if (typeof variant.value.state[key] === 'object') {
|
|
37
|
+
Object.assign(variant.value.state[key], event.data.state[key])
|
|
38
|
+
} else {
|
|
39
|
+
variant.value.state[key] = event.data.state[key]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
33
43
|
} else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
|
|
34
44
|
applyPreviewSettings(event.data.settings)
|
|
35
45
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { defineStore } from 'pinia'
|
|
2
|
+
import { ref, reactive, watch } from 'vue'
|
|
3
|
+
import { useStoryStore } from './story.js'
|
|
4
|
+
|
|
5
|
+
export type HstEvent = {
|
|
6
|
+
name: string
|
|
7
|
+
argument: unknown
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const useEventsStore = defineStore('events', () => {
|
|
11
|
+
const storyStore = useStoryStore()
|
|
12
|
+
|
|
13
|
+
const events = reactive<Array<HstEvent>>([])
|
|
14
|
+
const unseen = ref(0)
|
|
15
|
+
|
|
16
|
+
function addEvent (event: HstEvent) {
|
|
17
|
+
events.push(event)
|
|
18
|
+
unseen.value++
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function reset () {
|
|
22
|
+
events.length = 0
|
|
23
|
+
unseen.value = 0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
watch(() => storyStore.currentVariant, () => {
|
|
27
|
+
reset()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
addEvent,
|
|
32
|
+
reset,
|
|
33
|
+
events,
|
|
34
|
+
unseen,
|
|
35
|
+
}
|
|
36
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { defineStore } from 'pinia'
|
|
2
|
+
import { watch } from 'vue'
|
|
3
|
+
import { useStorage } from '@vueuse/core'
|
|
4
|
+
import { useStoryStore } from './story'
|
|
5
|
+
|
|
6
|
+
export const useFolderStore = defineStore('folder', () => {
|
|
7
|
+
const openedFolders = useStorage<Map<string, boolean>>(
|
|
8
|
+
'_histoire-tree-state',
|
|
9
|
+
new Map(),
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
function getStringPath (path: Array<string>) {
|
|
13
|
+
return path.join('␜')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function toggleFolder (path: Array<string>, defaultToggleValue = true) {
|
|
17
|
+
const stringPath = getStringPath(path)
|
|
18
|
+
|
|
19
|
+
const currentValue = openedFolders.value.get(stringPath)
|
|
20
|
+
|
|
21
|
+
if (currentValue == null) {
|
|
22
|
+
setFolderOpen(stringPath, defaultToggleValue)
|
|
23
|
+
} else if (currentValue) {
|
|
24
|
+
setFolderOpen(stringPath, false)
|
|
25
|
+
} else {
|
|
26
|
+
setFolderOpen(stringPath, true)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function setFolderOpen (path: Array<string> | string, value: boolean) {
|
|
31
|
+
const stringPath = typeof path === 'string' ? path : getStringPath(path)
|
|
32
|
+
openedFolders.value.set(stringPath, value)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function isFolderOpened (path: Array<string>, defaultValue = false) {
|
|
36
|
+
const value = openedFolders.value.get(getStringPath(path))
|
|
37
|
+
if (value == null) {
|
|
38
|
+
return defaultValue
|
|
39
|
+
}
|
|
40
|
+
return value
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function openFileFolders (path: Array<string>) {
|
|
44
|
+
for (let pathLength = 1; pathLength < path.length; pathLength++) {
|
|
45
|
+
setFolderOpen(path.slice(0, pathLength), true)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const storyStore = useStoryStore()
|
|
50
|
+
|
|
51
|
+
watch(() => storyStore.currentStory, (story) => {
|
|
52
|
+
openFileFolders(story.file.path)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
isFolderOpened,
|
|
57
|
+
toggleFolder,
|
|
58
|
+
}
|
|
59
|
+
})
|