histoire 0.0.0 → 0.0.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/LICENSE +21 -0
- package/client.d.ts +2 -0
- package/dist/client/app/App.vue +84 -21
- package/dist/client/app/assets/histoire-text-dark.svg +89 -0
- package/dist/client/app/assets/histoire-text.svg +89 -0
- package/dist/client/app/assets/histoire.svg +51 -0
- package/dist/client/app/codegen/serialize-js.d.ts +1 -0
- package/dist/client/app/codegen/serialize-js.js +114 -0
- package/dist/client/app/codegen/serialize-js.js.map +1 -0
- package/dist/client/app/codegen/serialize-js.ts +119 -0
- package/dist/client/app/codegen/util.d.ts +10 -0
- package/dist/client/app/codegen/util.js +71 -0
- package/dist/client/app/codegen/util.js.map +1 -0
- package/dist/client/app/codegen/util.ts +79 -0
- package/dist/client/app/codegen/vue3.d.ts +2 -0
- package/dist/client/app/codegen/vue3.js +239 -0
- package/dist/client/app/codegen/vue3.js.map +1 -0
- package/dist/client/app/codegen/vue3.ts +240 -0
- package/dist/client/app/components/HomeView.vue +15 -1
- package/dist/client/app/components/StoryControls.vue +7 -2
- package/dist/client/app/components/StoryList.vue +20 -13
- package/dist/client/app/components/StoryListFolder.vue +80 -0
- package/dist/client/app/components/StoryListItem.vue +38 -12
- package/dist/client/app/components/StorySourceCode.vue +121 -0
- package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
- package/dist/client/app/components/StoryVariantListItem.vue +46 -0
- package/dist/client/app/components/StoryVariantSingleView.vue +117 -15
- package/dist/client/app/components/StoryView.vue +88 -54
- package/dist/client/app/components/app/AppHeader.vue +56 -0
- package/dist/client/app/components/app/AppLogo.vue +24 -0
- package/dist/client/app/components/base/BaseEmpty.vue +1 -1
- package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
- package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
- package/dist/client/app/components/exposed/Story.vue +23 -58
- package/dist/client/app/components/exposed/Variant.vue +24 -47
- package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
- package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
- package/dist/client/app/components/search/SearchItem.vue +110 -0
- package/dist/client/app/components/search/SearchModal.vue +179 -0
- package/dist/client/app/composable/variant.ts +20 -0
- package/dist/client/app/global-components.ts +10 -0
- package/dist/client/app/index.d.ts +1 -0
- package/dist/client/app/index.js +4 -1
- package/dist/client/app/index.js.map +1 -1
- package/dist/client/app/index.ts +18 -0
- package/dist/client/app/router.ts +17 -0
- package/dist/client/app/sandbox.d.ts +1 -0
- package/dist/client/app/sandbox.js +54 -0
- package/dist/client/app/sandbox.js.map +1 -0
- package/dist/client/app/sandbox.ts +60 -0
- package/dist/client/app/stores/story.d.ts +161 -50
- package/dist/client/app/stores/story.js +5 -16
- package/dist/client/app/stores/story.js.map +1 -1
- package/dist/client/app/stores/story.ts +22 -0
- package/dist/client/app/style/main.css +16 -2
- package/dist/client/app/style/sandbox.css +14 -0
- package/dist/client/app/types.d.ts +36 -4
- package/dist/client/app/types.ts +45 -0
- package/dist/client/app/util/config.d.ts +3 -0
- package/dist/client/app/util/config.js +5 -0
- package/dist/client/app/util/config.js.map +1 -0
- package/dist/client/app/util/config.ts +6 -0
- package/dist/client/app/util/const.d.ts +1 -0
- package/dist/client/app/util/const.js +2 -0
- package/dist/client/app/util/const.js.map +1 -0
- package/dist/client/app/util/const.ts +1 -0
- package/dist/client/app/util/dark.d.ts +2 -0
- package/dist/client/app/util/dark.js +4 -0
- package/dist/client/app/util/dark.js.map +1 -0
- package/dist/client/app/util/dark.ts +4 -0
- package/dist/client/app/util/env.d.ts +1 -0
- package/dist/client/app/util/env.js +2 -0
- package/dist/client/app/util/env.js.map +1 -0
- package/dist/client/app/util/keyboard.d.ts +8 -0
- package/dist/client/app/util/keyboard.js +83 -0
- package/dist/client/app/util/keyboard.js.map +1 -0
- package/dist/client/app/util/mapping.d.ts +3 -0
- package/dist/client/app/util/mapping.js +37 -0
- package/dist/client/app/util/mapping.js.map +1 -0
- package/dist/client/app/util/mapping.ts +38 -0
- package/dist/client/app/util/tooltip.d.ts +6 -0
- package/dist/client/app/util/tooltip.js +12 -0
- package/dist/client/app/util/tooltip.js.map +1 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +4 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.ts +12 -0
- package/dist/client/server/Story.server.vue +65 -0
- package/dist/client/server/Variant.server.vue +50 -0
- package/dist/client/server/index.d.ts +2 -0
- package/dist/client/server/index.js +26 -0
- package/dist/client/server/index.js.map +1 -0
- package/dist/client/server/index.ts +29 -0
- package/dist/client/shim.d.ts +5 -0
- package/dist/node/bin.js +8 -2
- package/dist/node/bin.js.map +1 -1
- package/dist/node/build.d.ts +2 -0
- package/dist/node/build.js +72 -0
- package/dist/node/build.js.map +1 -0
- package/dist/node/collect.d.ts +12 -0
- package/dist/node/collect.js +66 -0
- package/dist/node/collect.js.map +1 -0
- package/dist/node/colors.d.ts +274 -0
- package/dist/node/colors.js +313 -0
- package/dist/node/colors.js.map +1 -0
- package/dist/node/commands/build.d.ts +1 -0
- package/dist/node/commands/build.js +11 -0
- package/dist/node/commands/build.js.map +1 -0
- package/dist/node/commands/dev.d.ts +1 -1
- package/dist/node/commands/dev.js +6 -11
- package/dist/node/commands/dev.js.map +1 -1
- package/dist/node/config.d.ts +99 -1
- package/dist/node/config.js +90 -1
- package/dist/node/config.js.map +1 -1
- package/dist/node/context.d.ts +13 -0
- package/dist/node/context.js +12 -1
- package/dist/node/context.js.map +1 -1
- package/dist/node/dom/dom-keys.d.ts +4 -0
- package/dist/node/dom/dom-keys.js +224 -0
- package/dist/node/dom/dom-keys.js.map +1 -0
- package/dist/node/dom/env.d.ts +5 -0
- package/dist/node/dom/env.js +23 -0
- package/dist/node/dom/env.js.map +1 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +2 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/plugin.d.ts +8 -2
- package/dist/node/plugin.js +142 -21
- package/dist/node/plugin.js.map +1 -1
- package/dist/node/server.d.ts +4 -1
- package/dist/node/server.js +80 -20
- package/dist/node/server.js.map +1 -1
- package/dist/node/stories.d.ts +8 -9
- package/dist/node/stories.js +42 -22
- package/dist/node/stories.js.map +1 -1
- package/dist/node/tree.d.ts +19 -0
- package/dist/node/tree.js +55 -0
- package/dist/node/tree.js.map +1 -0
- package/dist/node/types.d.ts +38 -0
- package/dist/node/types.js +2 -0
- package/dist/node/types.js.map +1 -0
- package/dist/style.css +558 -52
- package/package.json +42 -25
- package/scripts/copy.mjs +11 -0
- package/src/client/app/App.vue +84 -21
- package/src/client/app/assets/histoire-text-dark.svg +89 -0
- package/src/client/app/assets/histoire-text.svg +89 -0
- package/src/client/app/assets/histoire.svg +51 -0
- package/src/client/app/codegen/serialize-js.ts +119 -0
- package/src/client/app/codegen/util.ts +79 -0
- package/src/client/app/codegen/vue3.ts +240 -0
- package/src/client/app/components/HomeView.vue +15 -1
- package/src/client/app/components/StoryControls.vue +7 -2
- package/src/client/app/components/StoryList.vue +20 -13
- package/src/client/app/components/StoryListFolder.vue +80 -0
- package/src/client/app/components/StoryListItem.vue +38 -12
- package/src/client/app/components/StorySourceCode.vue +121 -0
- package/src/client/app/components/StoryVariantGridItem.vue +32 -17
- package/src/client/app/components/StoryVariantListItem.vue +46 -0
- package/src/client/app/components/StoryVariantSingleView.vue +117 -15
- package/src/client/app/components/StoryView.vue +88 -54
- package/src/client/app/components/app/AppHeader.vue +56 -0
- package/src/client/app/components/app/AppLogo.vue +24 -0
- package/src/client/app/components/base/BaseEmpty.vue +1 -1
- package/src/client/app/components/base/BaseListItemLink.vue +55 -0
- package/src/client/app/components/base/BaseSplitPane.vue +57 -21
- package/src/client/app/components/exposed/Story.vue +23 -58
- package/src/client/app/components/exposed/Variant.vue +24 -47
- package/src/client/app/components/misc/HatchedPattern.vue +25 -0
- package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
- package/src/client/app/components/search/SearchItem.vue +110 -0
- package/src/client/app/components/search/SearchModal.vue +179 -0
- package/src/client/app/index.ts +4 -1
- package/src/client/app/sandbox.ts +60 -0
- package/src/client/app/stores/story.ts +6 -18
- package/src/client/app/style/main.css +16 -2
- package/src/client/app/style/sandbox.css +14 -0
- package/src/client/app/types.ts +42 -4
- package/src/client/app/util/config.ts +6 -0
- package/src/client/app/util/const.ts +1 -0
- package/src/client/app/util/dark.ts +4 -0
- package/src/client/app/util/env.ts +1 -0
- package/src/client/app/util/keyboard.ts +99 -0
- package/src/client/app/util/mapping.ts +38 -0
- package/src/client/app/util/tooltip.ts +13 -0
- package/src/client/index.ts +12 -0
- package/src/client/server/Story.server.vue +65 -0
- package/src/client/server/Variant.server.vue +50 -0
- package/src/client/server/index.ts +29 -0
- package/src/node/bin.ts +9 -2
- package/src/node/build.ts +80 -0
- package/src/node/collect.ts +78 -0
- package/src/node/colors.ts +328 -0
- package/src/node/commands/build.ts +12 -0
- package/src/node/commands/dev.ts +6 -13
- package/src/node/config.ts +193 -1
- package/src/node/context.ts +21 -1
- package/src/node/dom/dom-keys.ts +227 -0
- package/src/node/dom/env.ts +26 -0
- package/src/node/index.ts +2 -0
- package/src/node/plugin.ts +146 -22
- package/src/node/server.ts +95 -20
- package/src/node/stories.ts +53 -31
- package/src/node/tree.ts +88 -0
- package/src/node/types.ts +40 -0
- package/tailwind.config.cjs +41 -1
- package/dist/client/app/components/StoryVariantItem.vue +0 -29
- package/src/client/app/components/StoryVariantItem.vue +0 -29
|
@@ -1,74 +1,51 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { defineComponent,
|
|
3
|
-
import {
|
|
2
|
+
import { defineComponent, getCurrentInstance, PropType, useAttrs } from 'vue'
|
|
3
|
+
import { Variant } from '../../types'
|
|
4
4
|
|
|
5
5
|
export default defineComponent({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
required: true,
|
|
10
|
-
},
|
|
6
|
+
// eslint-disable-next-line vue/multi-word-component-names
|
|
7
|
+
name: 'Variant',
|
|
8
|
+
__histoireType: 'variant',
|
|
11
9
|
|
|
10
|
+
props: {
|
|
12
11
|
initState: {
|
|
13
12
|
type: Function as PropType<() => any | Promise<any>>,
|
|
14
13
|
default: null,
|
|
15
14
|
},
|
|
15
|
+
|
|
16
|
+
source: {
|
|
17
|
+
type: String,
|
|
18
|
+
default: null,
|
|
19
|
+
},
|
|
16
20
|
},
|
|
17
21
|
|
|
18
22
|
setup (props) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
function generateId () {
|
|
22
|
-
let index = 0
|
|
23
|
-
const idMap = story.value.variants.reduce((acc, variant) => {
|
|
24
|
-
acc[variant.id] = true
|
|
25
|
-
return acc
|
|
26
|
-
}, {} as Record<string, boolean>)
|
|
27
|
-
while (idMap[`${story.value.id}-${index}`]) {
|
|
28
|
-
index++
|
|
29
|
-
}
|
|
30
|
-
return `${story.value.id}-${index}`
|
|
23
|
+
const attrs = useAttrs() as {
|
|
24
|
+
variant: Variant
|
|
31
25
|
}
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
const vm = getCurrentInstance()
|
|
28
|
+
|
|
29
|
+
function updateVariant () {
|
|
30
|
+
Object.assign(attrs.variant, {
|
|
36
31
|
initState: async () => {
|
|
37
32
|
if (typeof props.initState === 'function') {
|
|
38
|
-
variant.
|
|
33
|
+
attrs.variant.state = await props.initState()
|
|
39
34
|
}
|
|
40
35
|
},
|
|
41
|
-
slots: () =>
|
|
42
|
-
|
|
36
|
+
slots: () => vm.proxy.$slots,
|
|
37
|
+
source: props.source,
|
|
38
|
+
})
|
|
43
39
|
}
|
|
44
40
|
|
|
45
|
-
const variant = ref<Variant>(null)
|
|
46
|
-
|
|
47
|
-
const addVariant = inject('addVariant') as (variant: Variant) => void
|
|
48
|
-
onBeforeMount(() => {
|
|
49
|
-
variant.value = {
|
|
50
|
-
id: generateId(),
|
|
51
|
-
state: reactive<any>({}),
|
|
52
|
-
...getVariantData(),
|
|
53
|
-
}
|
|
54
|
-
addVariant(variant.value)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
const removeVariant = inject('removeVariant') as (variant: Variant) => void
|
|
58
|
-
onBeforeUnmount(() => {
|
|
59
|
-
removeVariant(variant.value)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
41
|
return {
|
|
63
|
-
|
|
64
|
-
getVariantData,
|
|
42
|
+
updateVariant,
|
|
65
43
|
}
|
|
66
44
|
},
|
|
67
45
|
|
|
68
46
|
render () {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
})
|
|
47
|
+
// Trigger variant updates to (re-)render slots
|
|
48
|
+
this.updateVariant()
|
|
72
49
|
return null
|
|
73
50
|
},
|
|
74
51
|
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<svg fill="none">
|
|
3
|
+
<pattern
|
|
4
|
+
id="hatch"
|
|
5
|
+
width="32"
|
|
6
|
+
height="32"
|
|
7
|
+
patternUnits="userSpaceOnUse"
|
|
8
|
+
>
|
|
9
|
+
<path
|
|
10
|
+
d="M32,0 L0,32
|
|
11
|
+
M-1,1 l2,-2
|
|
12
|
+
M31,33 l2,-2"
|
|
13
|
+
stroke-width="2"
|
|
14
|
+
stroke="currentColor"
|
|
15
|
+
/>
|
|
16
|
+
</pattern>
|
|
17
|
+
<rect
|
|
18
|
+
x="0"
|
|
19
|
+
y="0"
|
|
20
|
+
width="100%"
|
|
21
|
+
height="100%"
|
|
22
|
+
fill="url(#hatch)"
|
|
23
|
+
/>
|
|
24
|
+
</svg>
|
|
25
|
+
</template>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import { App, createApp, onMounted, onUnmounted, PropType, ref } from 'vue'
|
|
3
|
-
import { Story, Variant } from '
|
|
2
|
+
import { App, createApp, onMounted, onUnmounted, PropType, ref, watch } from 'vue'
|
|
3
|
+
import { Story, Variant } from '../../types'
|
|
4
|
+
// @ts-expect-error virtual module id
|
|
5
|
+
import setup from '$histoire-setup'
|
|
4
6
|
|
|
5
7
|
const props = defineProps({
|
|
6
8
|
variant: {
|
|
@@ -21,32 +23,49 @@ const props = defineProps({
|
|
|
21
23
|
|
|
22
24
|
const sandbox = ref<HTMLDivElement>()
|
|
23
25
|
let app: App
|
|
24
|
-
|
|
26
|
+
let mounting = false
|
|
27
|
+
|
|
28
|
+
async function mountVariant () {
|
|
29
|
+
mounting = true
|
|
25
30
|
|
|
26
|
-
onMounted(async () => {
|
|
27
31
|
await props.variant.initState()
|
|
28
32
|
|
|
29
33
|
app = createApp({
|
|
30
34
|
render: () => {
|
|
31
|
-
|
|
32
|
-
appRenderForcer.value
|
|
33
|
-
return props.variant.slots()?.[props.slotName]({
|
|
35
|
+
return props.variant.slots()?.[props.slotName]?.({
|
|
34
36
|
state: props.variant.state,
|
|
35
37
|
})
|
|
36
38
|
},
|
|
37
39
|
})
|
|
40
|
+
|
|
41
|
+
if (typeof setup === 'function') {
|
|
42
|
+
await setup({
|
|
43
|
+
app,
|
|
44
|
+
story: props.story,
|
|
45
|
+
variant: props.variant,
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
38
49
|
const target = document.createElement('div')
|
|
39
50
|
sandbox.value.appendChild(target)
|
|
40
51
|
app.mount(target)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onMounted(async () => {
|
|
55
|
+
if (props.variant.initState) {
|
|
56
|
+
await mountVariant()
|
|
57
|
+
}
|
|
41
58
|
})
|
|
42
59
|
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
watch(() => props.variant.initState, value => {
|
|
61
|
+
if (value && !mounting) {
|
|
62
|
+
mountVariant()
|
|
63
|
+
}
|
|
45
64
|
})
|
|
46
65
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
66
|
+
onUnmounted(() => {
|
|
67
|
+
app?.unmount()
|
|
68
|
+
})
|
|
50
69
|
</script>
|
|
51
70
|
|
|
52
71
|
<template>
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { computed, PropType, ref, watch } from 'vue'
|
|
3
|
+
import { useRouter } from 'vue-router'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
import { SearchResult } from '../../types'
|
|
6
|
+
import { onKeyboardShortcut } from '../../util/keyboard.js'
|
|
7
|
+
import BaseListItemLink from '../base/BaseListItemLink.vue'
|
|
8
|
+
|
|
9
|
+
const props = defineProps({
|
|
10
|
+
result: {
|
|
11
|
+
type: Object as PropType<SearchResult>,
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
selected: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
default: false,
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const emit = defineEmits({
|
|
22
|
+
close: () => true,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const el = ref<HTMLDivElement>()
|
|
26
|
+
|
|
27
|
+
watch(() => props.selected, value => {
|
|
28
|
+
if (value) {
|
|
29
|
+
el.value.scrollIntoView()
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const router = useRouter()
|
|
34
|
+
|
|
35
|
+
onKeyboardShortcut(['enter'], () => {
|
|
36
|
+
if (!props.selected) return
|
|
37
|
+
router.push(props.result.route)
|
|
38
|
+
emit('close')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const defaultIcons = {
|
|
42
|
+
story: 'carbon:cube',
|
|
43
|
+
variant: 'carbon:cube',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const iconColor = computed(() => props.result.iconColor)
|
|
47
|
+
|
|
48
|
+
const kindLabels = {
|
|
49
|
+
story: 'Story',
|
|
50
|
+
variant: 'Variant',
|
|
51
|
+
}
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<template>
|
|
55
|
+
<div ref="el">
|
|
56
|
+
<BaseListItemLink
|
|
57
|
+
:to="result.route"
|
|
58
|
+
:is-active="selected"
|
|
59
|
+
class="htw-px-6 htw-py-4 htw-gap-4"
|
|
60
|
+
@navigate="$emit('close')"
|
|
61
|
+
>
|
|
62
|
+
<Icon
|
|
63
|
+
:icon="result.icon ?? defaultIcons[result.kind]"
|
|
64
|
+
class="htw-w-5 htw-h-5"
|
|
65
|
+
:class="[
|
|
66
|
+
!selected ? [
|
|
67
|
+
result.iconColor
|
|
68
|
+
?'bind-icon-color'
|
|
69
|
+
: {
|
|
70
|
+
'htw-text-primary-500': result.kind === 'story',
|
|
71
|
+
'htw-text-gray-500': result.kind === 'variant',
|
|
72
|
+
}
|
|
73
|
+
] : [],
|
|
74
|
+
]"
|
|
75
|
+
/>
|
|
76
|
+
<div class="htw-flex-1">
|
|
77
|
+
<div class="htw-flex">
|
|
78
|
+
{{ result.title }}
|
|
79
|
+
<span class="htw-ml-auto htw-opacity-40">
|
|
80
|
+
{{ kindLabels[result.kind] }}
|
|
81
|
+
</span>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<div
|
|
85
|
+
v-if="result.path?.length"
|
|
86
|
+
class="htw-flex htw-items-center htw-gap-0.5 htw-opacity-60"
|
|
87
|
+
>
|
|
88
|
+
<div
|
|
89
|
+
v-for="(p, index) of result.path"
|
|
90
|
+
:key="index"
|
|
91
|
+
class="htw-flex htw-items-center htw-gap-0.5"
|
|
92
|
+
>
|
|
93
|
+
<Icon
|
|
94
|
+
v-if="index > 0"
|
|
95
|
+
icon="carbon:chevron-right"
|
|
96
|
+
class="htw-w-4 htw-h-4 htw-mt-0.5 htw-opacity-50"
|
|
97
|
+
/>
|
|
98
|
+
<span>{{ p }}</span>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
</BaseListItemLink>
|
|
103
|
+
</div>
|
|
104
|
+
</template>
|
|
105
|
+
|
|
106
|
+
<style scoped>
|
|
107
|
+
.bind-icon-color {
|
|
108
|
+
color: v-bind(iconColor);
|
|
109
|
+
}
|
|
110
|
+
</style>
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { useFocus } from '@vueuse/core'
|
|
3
|
+
import { computed, ref, watch } from 'vue'
|
|
4
|
+
import { Icon } from '@iconify/vue'
|
|
5
|
+
import { useStoryStore } from '../../stores/story'
|
|
6
|
+
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
7
|
+
import type { SearchResult, Story, Variant } from '../../types'
|
|
8
|
+
import SearchItem from './SearchItem.vue'
|
|
9
|
+
|
|
10
|
+
const props = defineProps({
|
|
11
|
+
shown: {
|
|
12
|
+
type: Boolean,
|
|
13
|
+
default: false,
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const emit = defineEmits({
|
|
18
|
+
close: () => true,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
function close () {
|
|
22
|
+
emit('close')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Autofocus
|
|
26
|
+
|
|
27
|
+
const input = ref<HTMLInputElement>()
|
|
28
|
+
const { focused } = useFocus({
|
|
29
|
+
target: input,
|
|
30
|
+
initialValue: true,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
watch(() => props.shown, value => {
|
|
34
|
+
if (value) {
|
|
35
|
+
requestAnimationFrame(() => {
|
|
36
|
+
focused.value = true
|
|
37
|
+
input.value.select()
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// Search
|
|
43
|
+
|
|
44
|
+
const search = ref('')
|
|
45
|
+
|
|
46
|
+
const storyStore = useStoryStore()
|
|
47
|
+
|
|
48
|
+
function storyResultFactory (story: Story, rank: number): SearchResult {
|
|
49
|
+
return {
|
|
50
|
+
kind: 'story',
|
|
51
|
+
rank,
|
|
52
|
+
id: story.id,
|
|
53
|
+
title: story.title,
|
|
54
|
+
route: {
|
|
55
|
+
name: 'story',
|
|
56
|
+
params: {
|
|
57
|
+
storyId: story.id,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
path: story.file.path.slice(0, -1),
|
|
61
|
+
icon: story.icon,
|
|
62
|
+
iconColor: story.iconColor,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function variantResultFactory (story: Story, variant: Variant, rank: number): SearchResult {
|
|
67
|
+
return {
|
|
68
|
+
kind: 'variant',
|
|
69
|
+
rank,
|
|
70
|
+
id: variant.id,
|
|
71
|
+
title: variant.title,
|
|
72
|
+
route: {
|
|
73
|
+
name: 'story',
|
|
74
|
+
params: {
|
|
75
|
+
storyId: story.id,
|
|
76
|
+
},
|
|
77
|
+
query: {
|
|
78
|
+
variantId: variant.id,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
path: [...story.file.path ?? [], story.title],
|
|
82
|
+
icon: variant.icon,
|
|
83
|
+
iconColor: variant.iconColor,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const results = computed(() => {
|
|
88
|
+
const list: SearchResult[] = []
|
|
89
|
+
if (search.value) {
|
|
90
|
+
const s = search.value.toLowerCase()
|
|
91
|
+
for (const story of storyStore.stories) {
|
|
92
|
+
const storyMatched = story.title.toLowerCase().includes(s)
|
|
93
|
+
let storyPathMatched = false
|
|
94
|
+
if (storyMatched || (storyPathMatched = story.file.path.some(p => p.toLowerCase().includes(s)))) {
|
|
95
|
+
list.push(storyResultFactory(story, storyMatched ? 1 : 4))
|
|
96
|
+
}
|
|
97
|
+
for (const variant of story.variants) {
|
|
98
|
+
const variantMatched = variant.title.toLowerCase().includes(s)
|
|
99
|
+
if (storyMatched || storyPathMatched || variantMatched) {
|
|
100
|
+
list.push(variantResultFactory(story, variant, variantMatched ? 2 : storyMatched ? 3 : 5))
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return list.sort((a, b) => a.rank - b.rank)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
// Selection
|
|
109
|
+
|
|
110
|
+
const selectedIndex = ref(0)
|
|
111
|
+
|
|
112
|
+
watch(results, () => {
|
|
113
|
+
selectedIndex.value = 0
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
function selectNext () {
|
|
117
|
+
selectedIndex.value++
|
|
118
|
+
if (selectedIndex.value > results.value.length - 1) {
|
|
119
|
+
selectedIndex.value = 0
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function selectPrevious () {
|
|
124
|
+
selectedIndex.value--
|
|
125
|
+
if (selectedIndex.value < 0) {
|
|
126
|
+
selectedIndex.value = results.value.length - 1
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<template>
|
|
132
|
+
<div
|
|
133
|
+
v-show="shown"
|
|
134
|
+
class="htw-fixed htw-inset-0 htw-bg-white/80 dark:htw-bg-gray-700/80"
|
|
135
|
+
>
|
|
136
|
+
<div
|
|
137
|
+
class="htw-absolute htw-inset-0"
|
|
138
|
+
@click="close()"
|
|
139
|
+
/>
|
|
140
|
+
<div class="htw-bg-white dark:htw-bg-gray-700 md:htw-mt-16 md:htw-mx-auto htw-w-screen htw-max-w-[512px] htw-shadow-xl htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded-lg htw-relative htw-divide-y htw-divide-gray-200 dark:htw-divide-gray-850">
|
|
141
|
+
<div
|
|
142
|
+
class="htw-flex htw-items-center htw-gap-4 htw-pl-6 htw-border htw-border-transparent focus-visible:htw-border-primary-500"
|
|
143
|
+
@click="focused = true"
|
|
144
|
+
>
|
|
145
|
+
<Icon
|
|
146
|
+
icon="carbon:search"
|
|
147
|
+
class="flex-none htw-w-5 htw-h-5"
|
|
148
|
+
/>
|
|
149
|
+
|
|
150
|
+
<input
|
|
151
|
+
ref="input"
|
|
152
|
+
v-model="search"
|
|
153
|
+
placeholder="Search for stories, variants..."
|
|
154
|
+
class="htw-bg-transparent htw-w-full htw-flex-1 htw-pl-0 htw-pr-6 htw-py-4 htw-outline-none"
|
|
155
|
+
@keydown.down="selectNext()"
|
|
156
|
+
@keydown.up="selectPrevious()"
|
|
157
|
+
@keydown.escape="close()"
|
|
158
|
+
>
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<BaseEmpty v-if="search && !results.length">
|
|
162
|
+
No results
|
|
163
|
+
</BaseEmpty>
|
|
164
|
+
|
|
165
|
+
<div
|
|
166
|
+
v-else-if="results.length"
|
|
167
|
+
class="htw-max-h-[400px] htw-overflow-y-auto htw-rounded-b-lg"
|
|
168
|
+
>
|
|
169
|
+
<SearchItem
|
|
170
|
+
v-for="(result, index) of results"
|
|
171
|
+
:key="`${result.kind}-${result.id}`"
|
|
172
|
+
:result="result"
|
|
173
|
+
:selected="index === selectedIndex"
|
|
174
|
+
@close="close()"
|
|
175
|
+
/>
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { computed, Ref } from 'vue'
|
|
2
|
+
import { useRoute } from 'vue-router'
|
|
3
|
+
import { Variant } from '../types'
|
|
4
|
+
|
|
5
|
+
export function useCurrentVariantRoute (variant: Ref<Variant>) {
|
|
6
|
+
const route = useRoute()
|
|
7
|
+
const isActive = computed(() => route.query.variantId === variant.value.id)
|
|
8
|
+
const targetRoute = computed(() => ({
|
|
9
|
+
...route,
|
|
10
|
+
query: {
|
|
11
|
+
...route.query,
|
|
12
|
+
variantId: variant.value.id,
|
|
13
|
+
},
|
|
14
|
+
}))
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
isActive,
|
|
18
|
+
targetRoute,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { App } from 'vue'
|
|
2
|
+
import Story from './components/exposed/Story.vue'
|
|
3
|
+
import Variant from './components/exposed/Variant.vue'
|
|
4
|
+
|
|
5
|
+
export function registerGlobalComponents (app: App) {
|
|
6
|
+
// eslint-disable-next-line vue/multi-word-component-names
|
|
7
|
+
app.component('Story', Story)
|
|
8
|
+
// eslint-disable-next-line vue/multi-word-component-names
|
|
9
|
+
app.component('Variant', Variant)
|
|
10
|
+
}
|
package/dist/client/app/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import '$histoire-theme';
|
|
1
2
|
import '../../style.css';
|
|
2
3
|
import { createApp } from 'vue';
|
|
3
4
|
import { createPinia } from 'pinia';
|
|
@@ -7,7 +8,9 @@ import { registerGlobalComponents } from './global-components.js';
|
|
|
7
8
|
import { router } from './router';
|
|
8
9
|
const app = createApp(App);
|
|
9
10
|
app.use(createPinia());
|
|
10
|
-
app.use(FloatingVue
|
|
11
|
+
app.use(FloatingVue, {
|
|
12
|
+
overflowPadding: 4,
|
|
13
|
+
});
|
|
11
14
|
app.use(router);
|
|
12
15
|
registerGlobalComponents(app);
|
|
13
16
|
app.mount('#app');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAA;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,GAAG,MAAM,WAAW,CAAA;AAC3B,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAA;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;AAC1B,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA;AACtB,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAA;AACxB,OAAO,iBAAiB,CAAA;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,GAAG,MAAM,WAAW,CAAA;AAC3B,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAA;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;AAC1B,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA;AACtB,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE;IACnB,eAAe,EAAE,CAAC;CACnB,CAAC,CAAA;AACF,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AACf,wBAAwB,CAAC,GAAG,CAAC,CAAA;AAC7B,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import '$histoire-theme'
|
|
2
|
+
import '../../style.css'
|
|
3
|
+
|
|
4
|
+
import { createApp } from 'vue'
|
|
5
|
+
import { createPinia } from 'pinia'
|
|
6
|
+
import FloatingVue from 'floating-vue'
|
|
7
|
+
import App from './App.vue'
|
|
8
|
+
import { registerGlobalComponents } from './global-components.js'
|
|
9
|
+
import { router } from './router'
|
|
10
|
+
|
|
11
|
+
const app = createApp(App)
|
|
12
|
+
app.use(createPinia())
|
|
13
|
+
app.use(FloatingVue, {
|
|
14
|
+
overflowPadding: 4,
|
|
15
|
+
})
|
|
16
|
+
app.use(router)
|
|
17
|
+
registerGlobalComponents(app)
|
|
18
|
+
app.mount('#app')
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createRouter, createWebHistory } from 'vue-router'
|
|
2
|
+
|
|
3
|
+
export const router = createRouter({
|
|
4
|
+
history: createWebHistory(),
|
|
5
|
+
routes: [
|
|
6
|
+
{
|
|
7
|
+
path: '/',
|
|
8
|
+
name: 'home',
|
|
9
|
+
component: () => import('./components/HomeView.vue'),
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
path: '/story/:storyId',
|
|
13
|
+
name: 'story',
|
|
14
|
+
component: () => import('./components/StoryView.vue'),
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './style/sandbox.css';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import './style/sandbox.css';
|
|
2
|
+
import { parseQuery } from 'vue-router';
|
|
3
|
+
import { computed, createApp, h, ref, toRaw, watch } from 'vue';
|
|
4
|
+
import { createPinia } from 'pinia';
|
|
5
|
+
import { registerGlobalComponents } from './global-components';
|
|
6
|
+
import SandboxVue3 from './components/sandbox/SandboxVue3.vue';
|
|
7
|
+
import { mapFile } from './util/mapping';
|
|
8
|
+
// @ts-expect-error virtual module
|
|
9
|
+
import { files } from '$histoire-stories';
|
|
10
|
+
import { STATE_SYNC } from './util/const.js';
|
|
11
|
+
const query = parseQuery(window.location.search);
|
|
12
|
+
const file = ref(mapFile(files.find(f => f.id === query.storyId)));
|
|
13
|
+
const app = createApp({
|
|
14
|
+
setup() {
|
|
15
|
+
const story = computed(() => file.value.story);
|
|
16
|
+
const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId));
|
|
17
|
+
window.addEventListener('message', event => {
|
|
18
|
+
if (event.data?.type === STATE_SYNC) {
|
|
19
|
+
Object.assign(variant.value.state, event.data.state);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
watch(() => variant.value.state, value => {
|
|
23
|
+
window.parent?.postMessage({
|
|
24
|
+
type: STATE_SYNC,
|
|
25
|
+
state: toRaw(value),
|
|
26
|
+
});
|
|
27
|
+
}, {
|
|
28
|
+
deep: true,
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
story,
|
|
32
|
+
variant,
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
render() {
|
|
36
|
+
return [
|
|
37
|
+
h('div', { class: 'htw-sandbox-hidden' }, [
|
|
38
|
+
h(file.value.component, {
|
|
39
|
+
story: file.value.story,
|
|
40
|
+
}),
|
|
41
|
+
]),
|
|
42
|
+
this.story && this.variant
|
|
43
|
+
? h(SandboxVue3, {
|
|
44
|
+
story: this.story,
|
|
45
|
+
variant: this.variant,
|
|
46
|
+
})
|
|
47
|
+
: null,
|
|
48
|
+
];
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
app.use(createPinia());
|
|
52
|
+
registerGlobalComponents(app);
|
|
53
|
+
app.mount('#app');
|
|
54
|
+
//# sourceMappingURL=sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../../../src/client/app/sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,WAAW,MAAM,sCAAsC,CAAA;AAE9D,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,kCAAkC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAChD,MAAM,IAAI,GAAG,GAAG,CAAY,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AAE7E,MAAM,GAAG,GAAG,SAAS,CAAC;IACpB,KAAK;QACH,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC9C,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC,CAAA;QAEzF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE;YACzC,IAAI,KAAK,CAAC,IAAI,EAAE,IAAI,KAAK,UAAU,EAAE;gBACnC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;aACrD;QACH,CAAC,CAAC,CAAA;QAEF,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE;YACvC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC;gBACzB,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;aACpB,CAAC,CAAA;QACJ,CAAC,EAAE;YACD,IAAI,EAAE,IAAI;SACX,CAAC,CAAA;QAEF,OAAO;YACL,KAAK;YACL,OAAO;SACR,CAAA;IACH,CAAC;IAED,MAAM;QACJ,OAAO;YACL,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE,EAAE;gBACxC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;oBACtB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK;iBACxB,CAAC;aACH,CAAC;YACF,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO;gBACxB,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;oBACf,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC;gBACF,CAAC,CAAC,IAAI;SACT,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AACF,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA;AACtB,wBAAwB,CAAC,GAAG,CAAC,CAAA;AAC7B,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA"}
|