@histoire/app 0.17.15 → 0.17.17
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/bundled/App.vue2.js +1 -1
- package/dist/bundled/components/app/AppHeader.vue2.js +1 -1
- package/dist/bundled/components/app/AppLogo.vue2.js +1 -1
- package/dist/bundled/components/app/Breadcrumb.vue.js +1 -1
- package/dist/bundled/components/app/Breadcrumb.vue2.js +3 -3
- package/dist/bundled/components/app/HomeCounter.vue2.js +2 -7
- package/dist/bundled/components/base/BaseCheckbox.vue2.js +1 -2
- package/dist/bundled/components/base/BaseIcon.vue.js +1 -1
- package/dist/bundled/components/base/BaseIcon.vue2.js +1 -1
- package/dist/bundled/components/base/BaseOverflowMenu.vue2.js +4 -4
- package/dist/bundled/components/base/BaseSplitPane.vue.js +1 -1
- package/dist/bundled/components/base/BaseSplitPane.vue2.js +2 -3
- package/dist/bundled/components/panel/PaneTabs.vue2.js +1 -1
- package/dist/bundled/components/panel/StoryDocs.vue2.js +4 -4
- package/dist/bundled/components/panel/StorySourceCode.vue.js +1 -1
- package/dist/bundled/components/panel/StorySourceCode.vue2.js +1 -1
- package/dist/bundled/components/search/SearchItem.vue.js +1 -1
- package/dist/bundled/components/search/SearchItem.vue2.js +2 -2
- package/dist/bundled/components/search/SearchPane.vue2.js +2 -2
- package/dist/bundled/components/story/StoryResponsivePreview.vue.js +1 -1
- package/dist/bundled/components/story/StoryResponsivePreview.vue2.js +8 -7
- package/dist/bundled/components/story/StoryVariantGrid.vue2.js +4 -4
- package/dist/bundled/components/story/StoryVariantGridItem.vue.js +1 -1
- package/dist/bundled/components/story/StoryVariantGridItem.vue2.js +6 -7
- package/dist/bundled/components/story/StoryVariantListItem.vue.js +1 -1
- package/dist/bundled/components/story/StoryVariantListItem.vue2.js +3 -3
- package/dist/bundled/components/story/StoryVariantSingle.vue.js +1 -1
- package/dist/bundled/components/story/StoryVariantSingle.vue2.js +5 -5
- package/dist/bundled/components/story/StoryVariantSinglePreviewNative.vue2.js +1 -1
- package/dist/bundled/components/story/StoryVariantSinglePreviewRemote.vue2.js +1 -1
- package/dist/bundled/components/story/StoryView.vue2.js +1 -1
- package/dist/bundled/components/story/StoryViewer.vue.js +1 -1
- package/dist/bundled/components/story/StoryViewer.vue2.js +3 -3
- package/dist/bundled/components/tree/StoryGroup.vue2.js +2 -2
- package/dist/bundled/components/tree/StoryListFolder.vue.js +1 -1
- package/dist/bundled/components/tree/StoryListFolder.vue2.js +4 -4
- package/dist/bundled/components/tree/StoryListItem.vue.js +1 -1
- package/dist/bundled/components/tree/StoryListItem.vue2.js +5 -5
- package/dist/bundled/sandbox.js +1 -1
- package/dist/bundled/style.css +36 -36
- package/dist/bundled/util/commands.js +1 -1
- package/dist/bundled/util/state.js +2 -2
- package/dist/style.css +1 -1
- package/package.json +7 -7
- package/scripts/copy.mjs +1 -1
- package/scripts/watchAndCopy.mjs +4 -4
- package/src/app/App.vue +6 -6
- package/src/app/api.ts +1 -1
- package/src/app/components/HomeView.vue +4 -3
- package/src/app/components/app/AppHeader.vue +1 -1
- package/src/app/components/app/AppLogo.vue +3 -3
- package/src/app/components/app/Breadcrumb.vue +4 -4
- package/src/app/components/app/HomeCounter.vue +1 -10
- package/src/app/components/app/MobileOverlay.vue +1 -1
- package/src/app/components/base/BaseCheckbox.vue +2 -3
- package/src/app/components/base/BaseIcon.vue +2 -2
- package/src/app/components/base/BaseKeyboardShortcut.vue +1 -1
- package/src/app/components/base/BaseListItem.vue +2 -2
- package/src/app/components/base/BaseListItemLink.vue +3 -3
- package/src/app/components/base/BaseOverflowMenu.vue +4 -4
- package/src/app/components/base/BaseSelect.vue +5 -4
- package/src/app/components/base/BaseSplitPane.vue +19 -15
- package/src/app/components/command/CommandPrompts.vue +6 -5
- package/src/app/components/command/CommandPromptsModal.vue +2 -1
- package/src/app/components/command/PromptSelect.vue +6 -4
- package/src/app/components/command/PromptText.vue +4 -3
- package/src/app/components/panel/ControlsComponentPropItem.vue +1 -1
- package/src/app/components/panel/ControlsComponentProps.vue +1 -1
- package/src/app/components/panel/ControlsComponentState.vue +1 -1
- package/src/app/components/panel/PaneTabs.vue +1 -1
- package/src/app/components/panel/StatePresets.vue +13 -10
- package/src/app/components/panel/StoryControls.vue +2 -2
- package/src/app/components/panel/StoryDocs.vue +28 -24
- package/src/app/components/panel/StoryEvent.vue +2 -2
- package/src/app/components/panel/StoryEvents.vue +2 -2
- package/src/app/components/panel/StorySourceCode.vue +10 -6
- package/src/app/components/search/SearchItem.vue +4 -3
- package/src/app/components/search/SearchItemContent.vue +3 -3
- package/src/app/components/search/SearchModal.vue +2 -1
- package/src/app/components/search/SearchPane.vue +18 -18
- package/src/app/components/search/search-docs-data.ts +2 -2
- package/src/app/components/search/search-title-data.ts +2 -2
- package/src/app/components/story/GenericMountStory.vue +1 -1
- package/src/app/components/story/GenericRenderStory.vue +3 -2
- package/src/app/components/story/StoryResponsivePreview.vue +16 -14
- package/src/app/components/story/StoryVariantGrid.vue +9 -8
- package/src/app/components/story/StoryVariantGridItem.vue +7 -7
- package/src/app/components/story/StoryVariantListItem.vue +3 -2
- package/src/app/components/story/StoryVariantSingle.vue +3 -3
- package/src/app/components/story/StoryVariantSinglePreviewNative.vue +2 -2
- package/src/app/components/story/StoryVariantSinglePreviewRemote.vue +10 -10
- package/src/app/components/story/StoryView.vue +4 -4
- package/src/app/components/story/StoryViewer.vue +2 -3
- package/src/app/components/toolbar/ToolbarNewTab.vue +1 -1
- package/src/app/components/tree/StoryGroup.vue +4 -4
- package/src/app/components/tree/StoryList.vue +1 -1
- package/src/app/components/tree/StoryListFolder.vue +4 -4
- package/src/app/components/tree/StoryListItem.vue +3 -3
- package/src/app/index.ts +2 -3
- package/src/app/plugin.ts +4 -3
- package/src/app/router.ts +2 -2
- package/src/app/sandbox.ts +12 -11
- package/src/app/stores/command.ts +4 -3
- package/src/app/stores/events.ts +4 -4
- package/src/app/stores/folder.ts +9 -7
- package/src/app/stores/story.ts +4 -4
- package/src/app/types.ts +2 -2
- package/src/app/util/commands.ts +5 -4
- package/src/app/util/dark.ts +2 -2
- package/src/app/util/docs.ts +6 -4
- package/src/app/util/events.ts +4 -3
- package/src/app/util/keyboard.ts +9 -8
- package/src/app/util/mapping.ts +8 -5
- package/src/app/util/open-in-editor.ts +1 -1
- package/src/app/util/preview-settings.ts +3 -3
- package/src/app/util/sandbox.ts +2 -3
- package/src/app/util/scroll.ts +5 -4
- package/src/app/util/select.ts +5 -4
- package/src/app/util/state.ts +6 -5
- package/src/app/util/tooltip.ts +2 -2
- package/src/app/util/variant.ts +3 -2
- package/src/shim.d.ts +0 -6
- package/src/virtual.d.ts +1 -0
- package/tailwind.config.cjs +19 -20
- package/tsconfig.json +26 -26
- package/vite.config.ts +7 -6
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import type { Story } from '../../types'
|
|
3
|
-
import BaseListItemLink from '../base/BaseListItemLink.vue'
|
|
4
2
|
import { Icon } from '@iconify/vue'
|
|
5
3
|
import { computed, ref, withDefaults } from 'vue'
|
|
6
4
|
import { useRoute } from 'vue-router'
|
|
5
|
+
import BaseListItemLink from '../base/BaseListItemLink.vue'
|
|
6
|
+
import type { Story } from '../../types'
|
|
7
7
|
import { useScrollOnActive } from '../../util/scroll'
|
|
8
8
|
|
|
9
9
|
const props = withDefaults(defineProps<{
|
|
@@ -14,7 +14,7 @@ const props = withDefaults(defineProps<{
|
|
|
14
14
|
})
|
|
15
15
|
|
|
16
16
|
const filePadding = computed(() => {
|
|
17
|
-
return
|
|
17
|
+
return `${props.depth * 12}px`
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
const route = useRoute()
|
package/src/app/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import App from './App.vue'
|
|
|
6
6
|
import { router } from './router'
|
|
7
7
|
import { setupPluginApi } from './plugin.js'
|
|
8
8
|
|
|
9
|
-
export async function mountMainApp
|
|
9
|
+
export async function mountMainApp() {
|
|
10
10
|
const app = createApp(App)
|
|
11
11
|
app.use(createPinia())
|
|
12
12
|
app.use(FloatingVue, {
|
|
@@ -28,7 +28,6 @@ export async function mountMainApp () {
|
|
|
28
28
|
if (import.meta.hot) {
|
|
29
29
|
import.meta.hot.send('histoire:mount', {})
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
/*#__PURE__*/ setupPluginApi()
|
|
31
|
+
/* #__PURE__ */ setupPluginApi()
|
|
33
32
|
}
|
|
34
33
|
}
|
package/src/app/plugin.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { router } from './router.js'
|
|
2
2
|
|
|
3
|
-
export function setupPluginApi
|
|
3
|
+
export function setupPluginApi() {
|
|
4
4
|
if (!import.meta.hot) return
|
|
5
5
|
|
|
6
6
|
const listeners: Record<string, Set<(result: any) => unknown>> = {}
|
|
@@ -14,7 +14,7 @@ export function setupPluginApi () {
|
|
|
14
14
|
}
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
function addDevEventListener
|
|
17
|
+
function addDevEventListener(event: string, listener: (result: any) => unknown) {
|
|
18
18
|
let set = listeners[event]
|
|
19
19
|
if (!set) {
|
|
20
20
|
set = new Set()
|
|
@@ -42,7 +42,8 @@ export function setupPluginApi () {
|
|
|
42
42
|
})
|
|
43
43
|
if (event.startsWith('on')) {
|
|
44
44
|
resolve(undefined)
|
|
45
|
-
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
46
47
|
const off = addDevEventListener(event, (result: any) => {
|
|
47
48
|
off()
|
|
48
49
|
resolve(result)
|
package/src/app/router.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createRouter,
|
|
1
|
+
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
|
|
2
2
|
import { histoireConfig } from './util/config'
|
|
3
3
|
|
|
4
4
|
export const base = import.meta.env.BASE_URL as string
|
|
5
5
|
|
|
6
|
-
function createRouterHistory
|
|
6
|
+
function createRouterHistory() {
|
|
7
7
|
switch (histoireConfig.routerMode) {
|
|
8
8
|
case 'hash': return createWebHashHistory(base)
|
|
9
9
|
case 'history':
|
package/src/app/sandbox.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { parseQuery } from 'vue-router'
|
|
|
2
2
|
import { computed, createApp, h, onMounted, ref, watch } from 'vue'
|
|
3
3
|
import { createPinia } from 'pinia'
|
|
4
4
|
import { applyState } from '@histoire/shared'
|
|
5
|
+
import { files } from 'virtual:$histoire-stories'
|
|
5
6
|
import GenericMountStory from './components/story/GenericMountStory.vue'
|
|
6
7
|
import GenericRenderStory from './components/story/GenericRenderStory.vue'
|
|
7
8
|
import type { StoryFile } from './types'
|
|
8
9
|
import { mapFile } from './util/mapping'
|
|
9
|
-
import {
|
|
10
|
-
import { PREVIEW_SETTINGS_SYNC, STATE_SYNC, SANDBOX_READY } from './util/const.js'
|
|
10
|
+
import { PREVIEW_SETTINGS_SYNC, SANDBOX_READY, STATE_SYNC } from './util/const.js'
|
|
11
11
|
import { applyPreviewSettings } from './util/preview-settings.js'
|
|
12
12
|
import { isDark } from './util/dark.js'
|
|
13
13
|
import { histoireConfig } from './util/config.js'
|
|
@@ -20,25 +20,26 @@ const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
|
|
|
20
20
|
const app = createApp({
|
|
21
21
|
name: 'SandboxApp',
|
|
22
22
|
|
|
23
|
-
setup
|
|
23
|
+
setup() {
|
|
24
24
|
const story = computed(() => file.value.story)
|
|
25
25
|
const variant = computed(() => story.value?.variants.find(v => v.id === query.variantId))
|
|
26
26
|
|
|
27
27
|
let synced = false
|
|
28
28
|
let mounted = false
|
|
29
29
|
|
|
30
|
-
window.addEventListener('message', event => {
|
|
30
|
+
window.addEventListener('message', (event) => {
|
|
31
31
|
// console.log('[sandbox] received message', event.data)
|
|
32
32
|
if (event.data?.type === STATE_SYNC) {
|
|
33
33
|
if (!mounted) return
|
|
34
34
|
synced = true
|
|
35
35
|
applyState(variant.value.state, event.data.state)
|
|
36
|
-
}
|
|
36
|
+
}
|
|
37
|
+
else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
|
|
37
38
|
applyPreviewSettings(event.data.settings)
|
|
38
39
|
}
|
|
39
40
|
})
|
|
40
41
|
|
|
41
|
-
watch(() => variant.value.state, value => {
|
|
42
|
+
watch(() => variant.value.state, (value) => {
|
|
42
43
|
if (synced && mounted) {
|
|
43
44
|
synced = false
|
|
44
45
|
return
|
|
@@ -61,7 +62,7 @@ const app = createApp({
|
|
|
61
62
|
}
|
|
62
63
|
},
|
|
63
64
|
|
|
64
|
-
render
|
|
65
|
+
render() {
|
|
65
66
|
return [
|
|
66
67
|
h('div', { class: 'htw-sandbox-hidden' }, [
|
|
67
68
|
h(GenericMountStory, {
|
|
@@ -86,11 +87,12 @@ const app = createApp({
|
|
|
86
87
|
app.use(createPinia())
|
|
87
88
|
app.mount('#app')
|
|
88
89
|
|
|
89
|
-
watch(isDark, value => {
|
|
90
|
+
watch(isDark, (value) => {
|
|
90
91
|
if (value) {
|
|
91
92
|
document.documentElement.classList.add(histoireConfig.sandboxDarkClass) // @TODO remove
|
|
92
93
|
document.documentElement.classList.add(histoireConfig.theme.darkClass)
|
|
93
|
-
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
94
96
|
document.documentElement.classList.remove(histoireConfig.sandboxDarkClass) // @TODO remove
|
|
95
97
|
document.documentElement.classList.remove(histoireConfig.theme.darkClass)
|
|
96
98
|
}
|
|
@@ -99,6 +101,5 @@ watch(isDark, value => {
|
|
|
99
101
|
})
|
|
100
102
|
|
|
101
103
|
if (import.meta.hot) {
|
|
102
|
-
|
|
103
|
-
/*#__PURE__*/ setupPluginApi()
|
|
104
|
+
/* #__PURE__ */ setupPluginApi()
|
|
104
105
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClientCommand } from '@histoire/shared'
|
|
1
|
+
import type { ClientCommand } from '@histoire/shared'
|
|
2
2
|
import { defineStore } from 'pinia'
|
|
3
3
|
import { ref } from 'vue'
|
|
4
4
|
import { executeCommand, getCommandContext } from '../util/commands.js'
|
|
@@ -7,11 +7,12 @@ export const useCommandStore = defineStore('command', () => {
|
|
|
7
7
|
const selectedCommand = ref<ClientCommand | null>(null)
|
|
8
8
|
const showPromptsModal = ref(false)
|
|
9
9
|
|
|
10
|
-
function activateCommand
|
|
10
|
+
function activateCommand(command: ClientCommand) {
|
|
11
11
|
selectedCommand.value = command
|
|
12
12
|
if (command.prompts?.length) {
|
|
13
13
|
showPromptsModal.value = true
|
|
14
|
-
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
15
16
|
const params = command.getParams?.(getCommandContext()) ?? {}
|
|
16
17
|
executeCommand(command, params)
|
|
17
18
|
}
|
package/src/app/stores/events.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineStore } from 'pinia'
|
|
2
|
-
import {
|
|
2
|
+
import { reactive, ref, watch } from 'vue'
|
|
3
3
|
import { useStoryStore } from './story.js'
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export interface HstEvent {
|
|
6
6
|
name: string
|
|
7
7
|
argument: unknown
|
|
8
8
|
}
|
|
@@ -13,12 +13,12 @@ export const useEventsStore = defineStore('events', () => {
|
|
|
13
13
|
const events = reactive<Array<HstEvent>>([])
|
|
14
14
|
const unseen = ref(0)
|
|
15
15
|
|
|
16
|
-
function addEvent
|
|
16
|
+
function addEvent(event: HstEvent) {
|
|
17
17
|
events.push(event)
|
|
18
18
|
unseen.value++
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function reset
|
|
21
|
+
function reset() {
|
|
22
22
|
events.length = 0
|
|
23
23
|
unseen.value = 0
|
|
24
24
|
}
|
package/src/app/stores/folder.ts
CHANGED
|
@@ -9,30 +9,32 @@ export const useFolderStore = defineStore('folder', () => {
|
|
|
9
9
|
new Map(),
|
|
10
10
|
)
|
|
11
11
|
|
|
12
|
-
function getStringPath
|
|
12
|
+
function getStringPath(path: Array<string>) {
|
|
13
13
|
return path.join('␜')
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function toggleFolder
|
|
16
|
+
function toggleFolder(path: Array<string>, defaultToggleValue = true) {
|
|
17
17
|
const stringPath = getStringPath(path)
|
|
18
18
|
|
|
19
19
|
const currentValue = openedFolders.value.get(stringPath)
|
|
20
20
|
|
|
21
21
|
if (currentValue == null) {
|
|
22
22
|
setFolderOpen(stringPath, defaultToggleValue)
|
|
23
|
-
}
|
|
23
|
+
}
|
|
24
|
+
else if (currentValue) {
|
|
24
25
|
setFolderOpen(stringPath, false)
|
|
25
|
-
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
26
28
|
setFolderOpen(stringPath, true)
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
function setFolderOpen
|
|
32
|
+
function setFolderOpen(path: Array<string> | string, value: boolean) {
|
|
31
33
|
const stringPath = typeof path === 'string' ? path : getStringPath(path)
|
|
32
34
|
openedFolders.value.set(stringPath, value)
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
function isFolderOpened
|
|
37
|
+
function isFolderOpened(path: Array<string>, defaultValue = false) {
|
|
36
38
|
const value = openedFolders.value.get(getStringPath(path))
|
|
37
39
|
if (value == null) {
|
|
38
40
|
return defaultValue
|
|
@@ -40,7 +42,7 @@ export const useFolderStore = defineStore('folder', () => {
|
|
|
40
42
|
return value
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
function openFileFolders
|
|
45
|
+
function openFileFolders(path: Array<string>) {
|
|
44
46
|
for (let pathLength = 1; pathLength < path.length; pathLength++) {
|
|
45
47
|
setFolderOpen(path.slice(0, pathLength), true)
|
|
46
48
|
}
|
package/src/app/stores/story.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { defineStore } from 'pinia'
|
|
2
2
|
import { computed, ref } from 'vue'
|
|
3
3
|
import { router } from '../router'
|
|
4
|
-
import { Story, Variant } from '../types'
|
|
4
|
+
import type { Story, Variant } from '../types'
|
|
5
5
|
|
|
6
6
|
export const useStoryStore = defineStore('story', () => {
|
|
7
7
|
const stories = ref<Story[]>([])
|
|
8
|
-
function setStories
|
|
8
|
+
function setStories(value: Story[]) {
|
|
9
9
|
stories.value = value
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -28,11 +28,11 @@ export const useStoryStore = defineStore('story', () => {
|
|
|
28
28
|
}
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
function getStoryById
|
|
31
|
+
function getStoryById(id: string) {
|
|
32
32
|
return maps.value.stories.get(id)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function getVariantById
|
|
35
|
+
function getVariantById(idWithStoryId: string) {
|
|
36
36
|
return maps.value.variants.get(idWithStoryId)
|
|
37
37
|
}
|
|
38
38
|
|
package/src/app/types.ts
CHANGED
|
@@ -7,12 +7,12 @@ export type {
|
|
|
7
7
|
Variant,
|
|
8
8
|
} from '@histoire/shared'
|
|
9
9
|
|
|
10
|
-
export
|
|
10
|
+
export interface TreeLeaf {
|
|
11
11
|
title: string
|
|
12
12
|
index: number
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export interface TreeFolder {
|
|
16
16
|
title: string
|
|
17
17
|
children: (TreeFolder | TreeLeaf)[]
|
|
18
18
|
}
|
package/src/app/util/commands.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ClientCommand, ClientCommandContext } from '@histoire/shared'
|
|
2
2
|
import { router } from '../router.js'
|
|
3
|
-
import { openInEditor } from './open-in-editor.js'
|
|
4
3
|
import { useStoryStore } from '../stores/story.js'
|
|
4
|
+
import { openInEditor } from './open-in-editor.js'
|
|
5
5
|
|
|
6
6
|
export const builtinCommands: ClientCommand[] = [
|
|
7
7
|
{
|
|
@@ -14,7 +14,8 @@ export const builtinCommands: ClientCommand[] = [
|
|
|
14
14
|
let file: string
|
|
15
15
|
if (story.docsOnly) {
|
|
16
16
|
file = story.file?.docsFilePath ?? story.file?.filePath
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
18
19
|
file = story.file?.filePath
|
|
19
20
|
}
|
|
20
21
|
return {
|
|
@@ -35,7 +36,7 @@ export const builtinCommands: ClientCommand[] = [
|
|
|
35
36
|
},
|
|
36
37
|
]
|
|
37
38
|
|
|
38
|
-
export function executeCommand
|
|
39
|
+
export function executeCommand(command: ClientCommand, params: Record<string, any>) {
|
|
39
40
|
if (import.meta.hot) {
|
|
40
41
|
import.meta.hot.send('histoire:dev-command', {
|
|
41
42
|
id: command.id,
|
|
@@ -46,7 +47,7 @@ export function executeCommand (command: ClientCommand, params: Record<string, a
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
export function getCommandContext
|
|
50
|
+
export function getCommandContext(): ClientCommandContext {
|
|
50
51
|
const storyStore = useStoryStore()
|
|
51
52
|
return {
|
|
52
53
|
route: router.currentRoute.value,
|
package/src/app/util/dark.ts
CHANGED
|
@@ -10,8 +10,8 @@ export const isDark = useDark({
|
|
|
10
10
|
})
|
|
11
11
|
export const toggleDark = useToggle(isDark)
|
|
12
12
|
|
|
13
|
-
function applyDarkToControls
|
|
14
|
-
window.__hst_controls_dark?.forEach(ref => {
|
|
13
|
+
function applyDarkToControls() {
|
|
14
|
+
window.__hst_controls_dark?.forEach((ref) => {
|
|
15
15
|
ref.value = isDark.value
|
|
16
16
|
})
|
|
17
17
|
}
|
package/src/app/util/docs.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { unindent } from '@histoire/shared'
|
|
2
2
|
import { clientSupportPlugins } from 'virtual:$histoire-support-plugins-client'
|
|
3
|
-
import type {
|
|
3
|
+
import type { Story, Variant } from '../types'
|
|
4
4
|
|
|
5
|
-
export async function getSourceCode
|
|
5
|
+
export async function getSourceCode(story: Story, variant: Variant) {
|
|
6
6
|
if (variant.source) {
|
|
7
7
|
return variant.source
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
|
+
else if (variant.slots?.().source) {
|
|
9
10
|
const source = variant.slots?.().source()[0].children
|
|
10
11
|
if (source) {
|
|
11
12
|
return unindent(source)
|
|
12
13
|
}
|
|
13
|
-
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
14
16
|
const clientPlugin = clientSupportPlugins[story.file?.supportPluginId]
|
|
15
17
|
if (clientPlugin) {
|
|
16
18
|
const pluginModule = await clientPlugin()
|
package/src/app/util/events.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EVENT_SEND } from './const'
|
|
2
2
|
|
|
3
|
-
export async function logEvent
|
|
3
|
+
export async function logEvent(name: string, argument) {
|
|
4
4
|
console.log('[histoire] Event fired', { name, argument })
|
|
5
5
|
const event = {
|
|
6
6
|
name,
|
|
@@ -11,13 +11,14 @@ export async function logEvent (name: string, argument) {
|
|
|
11
11
|
type: EVENT_SEND,
|
|
12
12
|
event,
|
|
13
13
|
})
|
|
14
|
-
}
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
15
16
|
const { useEventsStore } = await import('../stores/events.js')
|
|
16
17
|
useEventsStore().addEvent(event)
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
function stringifyEvent
|
|
21
|
+
function stringifyEvent(e) {
|
|
21
22
|
const obj = {}
|
|
22
23
|
for (const k in e) {
|
|
23
24
|
obj[k] = e[k]
|
package/src/app/util/keyboard.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEventListener } from '@vueuse/core'
|
|
2
|
-
import {
|
|
2
|
+
import type { Ref } from 'vue'
|
|
3
|
+
import { isRef } from 'vue'
|
|
3
4
|
import { isMac } from './env.js'
|
|
4
5
|
|
|
5
6
|
export type KeyboardShortcut = string[]
|
|
@@ -10,8 +11,8 @@ export interface KeyboardShortcutOptions {
|
|
|
10
11
|
event?: 'keyup' | 'keydown' | 'keypress'
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
export function onKeyboardShortcut
|
|
14
|
-
useEventListener(options.event ?? 'keydown', event => {
|
|
14
|
+
export function onKeyboardShortcut(shortcut: KeyboardShortcut | Ref<KeyboardShortcut>, handler: KeyboardHandler, options: KeyboardShortcutOptions = {}) {
|
|
15
|
+
useEventListener(options.event ?? 'keydown', (event) => {
|
|
15
16
|
if (isMatchingShortcut(isRef(shortcut) ? shortcut.value : shortcut)) {
|
|
16
17
|
handler(event)
|
|
17
18
|
}
|
|
@@ -27,7 +28,7 @@ const modifiers: { [i: string]: { key: string, pressed: boolean } } = {
|
|
|
27
28
|
|
|
28
29
|
const pressedKeys = new Set<string>()
|
|
29
30
|
|
|
30
|
-
window.addEventListener('keydown', event => {
|
|
31
|
+
window.addEventListener('keydown', (event) => {
|
|
31
32
|
for (const i in modifiers) {
|
|
32
33
|
const mod = modifiers[i]
|
|
33
34
|
if (mod.key === event.key) {
|
|
@@ -38,7 +39,7 @@ window.addEventListener('keydown', event => {
|
|
|
38
39
|
pressedKeys.add(event.key.toLocaleLowerCase())
|
|
39
40
|
})
|
|
40
41
|
|
|
41
|
-
window.addEventListener('keyup', event => {
|
|
42
|
+
window.addEventListener('keyup', (event) => {
|
|
42
43
|
requestAnimationFrame(() => {
|
|
43
44
|
pressedKeys.clear()
|
|
44
45
|
for (const i in modifiers) {
|
|
@@ -59,7 +60,7 @@ window.addEventListener('blur', () => {
|
|
|
59
60
|
}
|
|
60
61
|
})
|
|
61
62
|
|
|
62
|
-
function isMatchingShortcut
|
|
63
|
+
function isMatchingShortcut(shortcut: KeyboardShortcut): boolean {
|
|
63
64
|
for (const combination of shortcut) {
|
|
64
65
|
if (isMatchingCombination(combination.toLowerCase())) {
|
|
65
66
|
return true
|
|
@@ -68,7 +69,7 @@ function isMatchingShortcut (shortcut: KeyboardShortcut): boolean {
|
|
|
68
69
|
return false
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
function isMatchingCombination
|
|
72
|
+
function isMatchingCombination(combination: string): boolean {
|
|
72
73
|
const splitted = combination.split('+').map(key => key.trim())
|
|
73
74
|
const targetKey = splitted.pop()
|
|
74
75
|
for (const mod in modifiers) {
|
|
@@ -81,7 +82,7 @@ function isMatchingCombination (combination: string): boolean {
|
|
|
81
82
|
return pressedKeys.has(targetKey)
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
export function formatKey
|
|
85
|
+
export function formatKey(key: string) {
|
|
85
86
|
key = key.toLowerCase()
|
|
86
87
|
if (key === 'ctrl') {
|
|
87
88
|
return isMac ? '^' : 'Ctrl'
|
package/src/app/util/mapping.ts
CHANGED
|
@@ -12,7 +12,7 @@ const copiedFromExistingVariant = [
|
|
|
12
12
|
'previewReady',
|
|
13
13
|
]
|
|
14
14
|
|
|
15
|
-
export function mapFile
|
|
15
|
+
export function mapFile(file: StoryFile, existingFile?: StoryFile): StoryFile {
|
|
16
16
|
let result: StoryFile
|
|
17
17
|
|
|
18
18
|
if (existingFile) {
|
|
@@ -26,11 +26,13 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
|
|
|
26
26
|
file: markRaw(result),
|
|
27
27
|
variants: file.story.variants.map(v => mapVariant(v, existingFile.story.variants.find(item => item.id === v.id))),
|
|
28
28
|
}
|
|
29
|
-
}
|
|
29
|
+
}
|
|
30
|
+
else if (key !== 'component') {
|
|
30
31
|
result[key] = file[key]
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
34
36
|
// Create
|
|
35
37
|
result = {
|
|
36
38
|
...file,
|
|
@@ -48,7 +50,7 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
|
|
|
48
50
|
return result
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
export function mapVariant
|
|
53
|
+
export function mapVariant(variant: Variant, existingVariant?: Variant): Variant {
|
|
52
54
|
let result: Variant
|
|
53
55
|
|
|
54
56
|
if (existingVariant) {
|
|
@@ -59,7 +61,8 @@ export function mapVariant (variant: Variant, existingVariant?: Variant): Varian
|
|
|
59
61
|
result[key] = variant[key]
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
|
-
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
63
66
|
// Create
|
|
64
67
|
result = {
|
|
65
68
|
...variant,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { reactive } from 'vue'
|
|
2
|
-
import { histoireConfig } from './config'
|
|
3
2
|
import type { PreviewSettings } from '../types'
|
|
3
|
+
import { histoireConfig } from './config'
|
|
4
4
|
|
|
5
5
|
export const receivedSettings = reactive<PreviewSettings>({} as PreviewSettings)
|
|
6
6
|
|
|
7
|
-
export function applyPreviewSettings
|
|
7
|
+
export function applyPreviewSettings(settings: PreviewSettings) {
|
|
8
8
|
Object.assign(receivedSettings, settings)
|
|
9
9
|
|
|
10
10
|
// Text direction
|
|
@@ -18,6 +18,6 @@ export function applyPreviewSettings (settings: PreviewSettings) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function getContrastColor
|
|
21
|
+
export function getContrastColor(setting: PreviewSettings) {
|
|
22
22
|
return histoireConfig.backgroundPresets.find(preset => preset.color === setting.backgroundColor)?.contrastColor ?? 'unset'
|
|
23
23
|
}
|
package/src/app/util/sandbox.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
1
|
import { base } from '../router'
|
|
3
|
-
import { Story, Variant } from '../types'
|
|
2
|
+
import type { Story, Variant } from '../types'
|
|
4
3
|
|
|
5
|
-
export function getSandboxUrl
|
|
4
|
+
export function getSandboxUrl(story: Story, variant: Variant) {
|
|
6
5
|
const url = new URLSearchParams()
|
|
7
6
|
url.append('storyId', story.id)
|
|
8
7
|
url.append('variantId', variant.id)
|
package/src/app/util/scroll.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
import { onMounted, watch } from 'vue'
|
|
2
3
|
import scrollIntoView from 'scroll-into-view-if-needed'
|
|
3
4
|
|
|
4
|
-
export function useScrollOnActive
|
|
5
|
-
watch(active, value => {
|
|
5
|
+
export function useScrollOnActive(active: Ref<boolean>, el: Ref<HTMLElement>) {
|
|
6
|
+
watch(active, (value) => {
|
|
6
7
|
if (value) {
|
|
7
8
|
autoScroll()
|
|
8
9
|
}
|
|
9
10
|
})
|
|
10
11
|
|
|
11
|
-
function autoScroll
|
|
12
|
+
function autoScroll() {
|
|
12
13
|
if (el.value) {
|
|
13
14
|
scrollIntoView(el.value, {
|
|
14
15
|
scrollMode: 'if-needed',
|
package/src/app/util/select.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { Ref
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
import { computed, ref, watch } from 'vue'
|
|
2
3
|
|
|
3
|
-
export function useSelection
|
|
4
|
+
export function useSelection(list: Ref<any[]>) {
|
|
4
5
|
const selectedIndex = ref(0)
|
|
5
6
|
|
|
6
7
|
watch(list, () => {
|
|
7
8
|
selectedIndex.value = 0
|
|
8
9
|
})
|
|
9
10
|
|
|
10
|
-
function selectNext
|
|
11
|
+
function selectNext() {
|
|
11
12
|
selectedIndex.value++
|
|
12
13
|
if (selectedIndex.value > list.value.length - 1) {
|
|
13
14
|
selectedIndex.value = 0
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
function selectPrevious
|
|
18
|
+
function selectPrevious() {
|
|
18
19
|
selectedIndex.value--
|
|
19
20
|
if (selectedIndex.value < 0) {
|
|
20
21
|
selectedIndex.value = list.value.length - 1
|
package/src/app/util/state.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isRef, unref } from 'vue'
|
|
2
2
|
|
|
3
|
-
const isObject =
|
|
3
|
+
const isObject = val => val !== null && typeof val === 'object'
|
|
4
4
|
|
|
5
|
-
export function toRawDeep
|
|
5
|
+
export function toRawDeep(val, clean = false, seen = new WeakMap()) {
|
|
6
6
|
const unwrappedValue = isRef(val) ? unref(val) : val
|
|
7
7
|
|
|
8
8
|
if (typeof unwrappedValue === 'symbol') {
|
|
@@ -26,7 +26,8 @@ export function toRawDeep (val, clean = false, seen = new WeakMap()) {
|
|
|
26
26
|
}
|
|
27
27
|
result.push(...list)
|
|
28
28
|
return result
|
|
29
|
-
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
30
31
|
const result = {}
|
|
31
32
|
seen.set(unwrappedValue, result)
|
|
32
33
|
toRawObject(unwrappedValue, result, clean, seen)
|
|
@@ -34,7 +35,7 @@ export function toRawDeep (val, clean = false, seen = new WeakMap()) {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
function toRawObject(obj: Record<any, any>, target: Record<any, any>, clean = false, seen = new WeakMap()) {
|
|
38
39
|
Object.keys(obj).forEach((key) => {
|
|
39
40
|
if (clean && typeof obj[key] === 'function') {
|
|
40
41
|
return
|
package/src/app/util/tooltip.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { isMac } from './env.js'
|
|
2
2
|
import { formatKey } from './keyboard.js'
|
|
3
3
|
|
|
4
|
-
export function makeTooltip
|
|
4
|
+
export function makeTooltip(descriptionHtml: string, keyboardShortcut: (options: { isMac: boolean }) => string) {
|
|
5
5
|
return {
|
|
6
6
|
content: `<div>${descriptionHtml}</div><div class="htw-flex htw-items-center htw-gap-1 htw-mt-2 htw-text-sm">${genKeyboardShortcutHtml(keyboardShortcut({ isMac }))}</div>`,
|
|
7
7
|
html: true,
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
function genKeyboardShortcutHtml
|
|
11
|
+
function genKeyboardShortcutHtml(shortcut: string) {
|
|
12
12
|
return `<span class="htw-border htw-border-gray-600 htw-px-1 htw-rounded-sm htw-text-gray-400">${shortcut.split('+').map(k => formatKey(k.trim())).join(' ')}</span>`
|
|
13
13
|
}
|
package/src/app/util/variant.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
import { computed } from 'vue'
|
|
2
3
|
import { useRoute } from 'vue-router'
|
|
3
4
|
import type { Variant } from '../types'
|
|
4
5
|
|
|
5
|
-
export function useCurrentVariantRoute
|
|
6
|
+
export function useCurrentVariantRoute(variant: Ref<Variant>) {
|
|
6
7
|
const route = useRoute()
|
|
7
8
|
const isActive = computed(() => route.query.variantId === variant.value.id)
|
|
8
9
|
const targetRoute = computed(() => ({
|
package/src/shim.d.ts
CHANGED