@histoire/app 0.13.1 → 0.14.0
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 +11 -2
- package/dist/bundled/api.js +8 -1
- package/dist/bundled/components/app/AppHeader.vue2.js +4 -3
- package/dist/bundled/components/base/BaseButton.vue.js +5 -0
- package/dist/bundled/components/base/BaseButton.vue2.js +39 -0
- package/dist/bundled/components/base/BaseIcon.vue.js +8 -0
- package/dist/bundled/components/base/BaseIcon.vue2.js +30 -0
- package/dist/bundled/components/base/BaseIcon.vue3.js +4 -0
- package/dist/bundled/components/base/BaseKeyboardShortcut.vue.js +5 -0
- package/dist/bundled/components/base/BaseKeyboardShortcut.vue2.js +20 -0
- package/dist/bundled/components/base/BaseListItem.vue.js +5 -0
- package/dist/bundled/components/base/BaseListItem.vue2.js +32 -0
- package/dist/bundled/components/command/CommandPrompts.vue.js +5 -0
- package/dist/bundled/components/command/CommandPrompts.vue2.js +95 -0
- package/dist/bundled/components/command/CommandPromptsModal.vue.js +5 -0
- package/dist/bundled/components/command/CommandPromptsModal.vue2.js +44 -0
- package/dist/bundled/components/command/PromptSelect.vue.js +5 -0
- package/dist/bundled/components/command/PromptSelect.vue2.js +142 -0
- package/dist/bundled/components/command/PromptText.vue.js +5 -0
- package/dist/bundled/components/command/PromptText.vue2.js +67 -0
- package/dist/bundled/components/panel/StoryDocs.vue2.js +25 -3
- package/dist/bundled/components/panel/StorySourceCode.vue.js +1 -1
- package/dist/bundled/components/panel/StorySourceCode.vue2.js +1 -1
- package/dist/bundled/components/panel/StorySourceCode.vue3.js +2 -2
- package/dist/bundled/components/search/SearchItem.vue.js +1 -1
- package/dist/bundled/components/search/SearchItem.vue2.js +42 -62
- package/dist/bundled/components/search/SearchItem.vue3.js +2 -2
- package/dist/bundled/components/search/SearchItemContent.vue.js +5 -0
- package/dist/bundled/components/search/SearchItemContent.vue2.js +72 -0
- package/dist/bundled/components/search/SearchModal.vue2.js +2 -2
- package/dist/bundled/components/search/SearchPane.vue2.js +46 -24
- package/dist/bundled/components/story/StoryVariantGrid.vue2.js +10 -2
- package/dist/bundled/components/story/StoryVariantSingleView.vue2.js +13 -6
- package/dist/bundled/components/story/StoryView.vue2.js +1 -0
- package/dist/bundled/components/toolbar/DevOnlyToolbarOpenInEditor.vue.js +5 -0
- package/dist/bundled/components/toolbar/DevOnlyToolbarOpenInEditor.vue2.js +31 -0
- package/dist/bundled/index.js +3 -1
- package/dist/bundled/plugin.js +50 -0
- package/dist/bundled/sandbox.js +4 -0
- package/dist/bundled/stores/command.js +26 -0
- package/dist/bundled/style.css +22 -18
- package/dist/bundled/util/commands.js +59 -0
- package/dist/bundled/util/dark.js +6 -1
- package/dist/bundled/util/keyboard.js +3 -0
- package/dist/bundled/util/open-in-editor.js +6 -0
- package/dist/bundled/util/select.js +28 -0
- package/dist/bundled/util/tooltip.js +1 -1
- package/dist/style.css +116 -63
- package/package.json +4 -4
- package/src/app/App.vue +10 -1
- package/src/app/api.ts +8 -0
- package/src/app/components/app/AppHeader.vue +1 -0
- package/src/app/components/base/BaseButton.vue +33 -0
- package/src/app/components/base/BaseIcon.vue +31 -0
- package/src/app/components/base/BaseKeyboardShortcut.vue +16 -0
- package/src/app/components/base/BaseListItem.vue +30 -0
- package/src/app/components/command/CommandPrompts.vue +97 -0
- package/src/app/components/command/CommandPromptsModal.vue +40 -0
- package/src/app/components/command/PromptSelect.vue +140 -0
- package/src/app/components/command/PromptText.vue +64 -0
- package/src/app/components/panel/StoryDocs.vue +25 -2
- package/src/app/components/panel/StorySourceCode.vue +0 -1
- package/src/app/components/search/SearchItem.vue +29 -52
- package/src/app/components/search/SearchItemContent.vue +67 -0
- package/src/app/components/search/SearchModal.vue +2 -2
- package/src/app/components/search/SearchPane.vue +50 -22
- package/src/app/components/search/search-docs-data.ts +0 -1
- package/src/app/components/search/search-title-data.ts +0 -1
- package/src/app/components/story/GenericMountStory.vue +0 -1
- package/src/app/components/story/GenericRenderStory.vue +0 -1
- package/src/app/components/story/StoryVariantGrid.vue +7 -0
- package/src/app/components/story/StoryVariantSingleView.vue +7 -0
- package/src/app/components/story/StoryView.vue +1 -0
- package/src/app/components/toolbar/DevOnlyToolbarOpenInEditor.vue +23 -0
- package/src/app/index.ts +5 -1
- package/src/app/plugin.ts +58 -0
- package/src/app/sandbox.ts +6 -1
- package/src/app/stores/command.ts +25 -0
- package/src/app/types.ts +26 -4
- package/src/app/util/commands.ts +56 -0
- package/src/app/util/config.ts +0 -1
- package/src/app/util/dark.ts +6 -1
- package/src/app/util/keyboard.ts +3 -0
- package/src/app/util/open-in-editor.ts +3 -0
- package/src/app/util/select.ts +29 -0
- package/src/app/util/tooltip.ts +1 -1
- package/src/virtual.d.ts +6 -0
|
@@ -6,6 +6,7 @@ import ToolbarResponsiveSize from '../toolbar/ToolbarResponsiveSize.vue'
|
|
|
6
6
|
import ToolbarBackground from '../toolbar/ToolbarBackground.vue'
|
|
7
7
|
import ToolbarTextDirection from '../toolbar/ToolbarTextDirection.vue'
|
|
8
8
|
import ToolbarNewTab from '../toolbar/ToolbarNewTab.vue'
|
|
9
|
+
import DevOnlyToolbarOpenInEditor from '../toolbar/DevOnlyToolbarOpenInEditor.vue'
|
|
9
10
|
import StoryVariantSinglePreviewNative from './StoryVariantSinglePreviewNative.vue'
|
|
10
11
|
import StoryVariantSinglePreviewRemote from './StoryVariantSinglePreviewRemote.vue'
|
|
11
12
|
|
|
@@ -37,6 +38,12 @@ defineProps<{
|
|
|
37
38
|
:variant="variant"
|
|
38
39
|
:story="story"
|
|
39
40
|
/>
|
|
41
|
+
|
|
42
|
+
<DevOnlyToolbarOpenInEditor
|
|
43
|
+
v-if="__HISTOIRE_DEV__"
|
|
44
|
+
:file="story.file?.filePath"
|
|
45
|
+
tooltip="Edit story in editor"
|
|
46
|
+
/>
|
|
40
47
|
</div>
|
|
41
48
|
|
|
42
49
|
<!-- Preview -->
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { Icon } from '@iconify/vue'
|
|
3
|
+
import { openInEditor } from '../../util/open-in-editor.js'
|
|
4
|
+
|
|
5
|
+
defineProps<{
|
|
6
|
+
file: string
|
|
7
|
+
tooltip: string
|
|
8
|
+
}>()
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<template>
|
|
12
|
+
<a
|
|
13
|
+
v-tooltip="tooltip"
|
|
14
|
+
target="_blank"
|
|
15
|
+
class="histoire-toolbar-open-in-editor htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2 hover:htw-text-primary-500 htw-opacity-50 hover:htw-opacity-100 dark:hover:htw-text-primary-400 htw-text-gray-900 dark:htw-text-gray-100"
|
|
16
|
+
@click="openInEditor(file)"
|
|
17
|
+
>
|
|
18
|
+
<Icon
|
|
19
|
+
icon="carbon:script-reference"
|
|
20
|
+
class="htw-w-4 htw-h-4"
|
|
21
|
+
/>
|
|
22
|
+
</a>
|
|
23
|
+
</template>
|
package/src/app/index.ts
CHANGED
|
@@ -4,8 +4,9 @@ import { createPinia } from 'pinia'
|
|
|
4
4
|
import FloatingVue from 'floating-vue'
|
|
5
5
|
import App from './App.vue'
|
|
6
6
|
import { router } from './router'
|
|
7
|
+
import { setupPluginApi } from './plugin.js'
|
|
7
8
|
|
|
8
|
-
export function mountMainApp () {
|
|
9
|
+
export async function mountMainApp () {
|
|
9
10
|
const app = createApp(App)
|
|
10
11
|
app.use(createPinia())
|
|
11
12
|
app.use(FloatingVue, {
|
|
@@ -26,5 +27,8 @@ export function mountMainApp () {
|
|
|
26
27
|
|
|
27
28
|
if (import.meta.hot) {
|
|
28
29
|
import.meta.hot.send('histoire:mount', {})
|
|
30
|
+
|
|
31
|
+
// eslint-disable-next-line spaced-comment
|
|
32
|
+
/*#__PURE__*/ setupPluginApi()
|
|
29
33
|
}
|
|
30
34
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { router } from './router.js'
|
|
2
|
+
|
|
3
|
+
export function setupPluginApi () {
|
|
4
|
+
if (!import.meta.hot) return
|
|
5
|
+
|
|
6
|
+
const listeners: Record<string, Set<(result: any) => unknown>> = {}
|
|
7
|
+
|
|
8
|
+
import.meta.hot.on('histoire:dev-event-result', ({ event, result }) => {
|
|
9
|
+
const set = listeners[event]
|
|
10
|
+
if (set) {
|
|
11
|
+
for (const listener of set) {
|
|
12
|
+
listener(result)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
function addDevEventListener (event: string, listener: (result: any) => unknown) {
|
|
18
|
+
let set = listeners[event]
|
|
19
|
+
if (!set) {
|
|
20
|
+
set = new Set()
|
|
21
|
+
listeners[event] = set
|
|
22
|
+
}
|
|
23
|
+
set.add(listener)
|
|
24
|
+
return () => {
|
|
25
|
+
set.delete(listener)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// function removeDevEventListener (event: string, listener: (result: any) => unknown) {
|
|
30
|
+
// const set = listeners[event]
|
|
31
|
+
// if (set) {
|
|
32
|
+
// set.delete(listener)
|
|
33
|
+
// }
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
window.__HST_PLUGIN_API__ = {
|
|
37
|
+
sendEvent: (event: string, payload?: any) => {
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
import.meta.hot.send(`histoire:dev-event`, {
|
|
40
|
+
event,
|
|
41
|
+
payload,
|
|
42
|
+
})
|
|
43
|
+
if (event.startsWith('on')) {
|
|
44
|
+
resolve(undefined)
|
|
45
|
+
} else {
|
|
46
|
+
const off = addDevEventListener(event, (result: any) => {
|
|
47
|
+
off()
|
|
48
|
+
resolve(result)
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
openStory: (storyId: string) => {
|
|
55
|
+
router.push({ name: 'story', params: { storyId } })
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/app/sandbox.ts
CHANGED
|
@@ -6,13 +6,13 @@ import GenericMountStory from './components/story/GenericMountStory.vue'
|
|
|
6
6
|
import GenericRenderStory from './components/story/GenericRenderStory.vue'
|
|
7
7
|
import type { StoryFile } from './types'
|
|
8
8
|
import { mapFile } from './util/mapping'
|
|
9
|
-
// @ts-expect-error virtual module
|
|
10
9
|
import { files } from 'virtual:$histoire-stories'
|
|
11
10
|
import { PREVIEW_SETTINGS_SYNC, STATE_SYNC, SANDBOX_READY } from './util/const.js'
|
|
12
11
|
import { applyPreviewSettings } from './util/preview-settings.js'
|
|
13
12
|
import { isDark } from './util/dark.js'
|
|
14
13
|
import { histoireConfig } from './util/config.js'
|
|
15
14
|
import { toRawDeep } from './util/state.js'
|
|
15
|
+
import { setupPluginApi } from './plugin.js'
|
|
16
16
|
|
|
17
17
|
const query = parseQuery(window.location.search)
|
|
18
18
|
const file = ref<StoryFile>(mapFile(files.find(f => f.id === query.storyId)))
|
|
@@ -95,3 +95,8 @@ watch(isDark, value => {
|
|
|
95
95
|
}, {
|
|
96
96
|
immediate: true,
|
|
97
97
|
})
|
|
98
|
+
|
|
99
|
+
if (import.meta.hot) {
|
|
100
|
+
// eslint-disable-next-line spaced-comment
|
|
101
|
+
/*#__PURE__*/ setupPluginApi()
|
|
102
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ClientCommand } from '@histoire/shared'
|
|
2
|
+
import { defineStore } from 'pinia'
|
|
3
|
+
import { ref } from 'vue'
|
|
4
|
+
import { executeCommand, getCommandContext } from '../util/commands.js'
|
|
5
|
+
|
|
6
|
+
export const useCommandStore = defineStore('command', () => {
|
|
7
|
+
const selectedCommand = ref<ClientCommand | null>(null)
|
|
8
|
+
const showPromptsModal = ref(false)
|
|
9
|
+
|
|
10
|
+
function activateCommand (command: ClientCommand) {
|
|
11
|
+
selectedCommand.value = command
|
|
12
|
+
if (command.prompts?.length) {
|
|
13
|
+
showPromptsModal.value = true
|
|
14
|
+
} else {
|
|
15
|
+
const params = command.getParams?.(getCommandContext()) ?? {}
|
|
16
|
+
executeCommand(command, params)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
selectedCommand,
|
|
22
|
+
showPromptsModal,
|
|
23
|
+
activateCommand,
|
|
24
|
+
}
|
|
25
|
+
})
|
package/src/app/types.ts
CHANGED
|
@@ -28,18 +28,23 @@ export type Tree = (TreeGroup | TreeFolder | TreeLeaf)[]
|
|
|
28
28
|
|
|
29
29
|
export type SearchResultType = 'title' | 'docs'
|
|
30
30
|
|
|
31
|
-
export interface
|
|
32
|
-
kind: 'story' | 'variant'
|
|
31
|
+
export interface SearchResultBase {
|
|
32
|
+
kind: 'story' | 'variant' | 'command'
|
|
33
33
|
rank: number
|
|
34
34
|
id: string
|
|
35
35
|
title: string
|
|
36
|
-
route: RouteLocationRaw
|
|
37
|
-
type: SearchResultType
|
|
38
36
|
path?: string[]
|
|
39
37
|
icon?: string
|
|
40
38
|
iconColor?: string
|
|
39
|
+
type?: SearchResultType
|
|
41
40
|
}
|
|
42
41
|
|
|
42
|
+
export type SearchResult = SearchResultBase & ({
|
|
43
|
+
route: RouteLocationRaw
|
|
44
|
+
} | {
|
|
45
|
+
onActivate: () => unknown
|
|
46
|
+
})
|
|
47
|
+
|
|
43
48
|
export interface PreviewSettings {
|
|
44
49
|
responsiveWidth: number
|
|
45
50
|
responsiveHeight: number
|
|
@@ -48,3 +53,20 @@ export interface PreviewSettings {
|
|
|
48
53
|
checkerboard: boolean
|
|
49
54
|
textDirection: 'ltr' | 'rtl'
|
|
50
55
|
}
|
|
56
|
+
|
|
57
|
+
declare module 'vue' {
|
|
58
|
+
interface ComponentCustomProperties {
|
|
59
|
+
__HISTOIRE_DEV__: boolean
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
declare global {
|
|
64
|
+
const __HISTOIRE_DEV__: boolean
|
|
65
|
+
|
|
66
|
+
interface Window {
|
|
67
|
+
__HST_PLUGIN_API__: {
|
|
68
|
+
sendEvent: (event: string, payload: any) => Promise<any>
|
|
69
|
+
openStory: (storyId: string) => void
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ClientCommand, ClientCommandContext } from '@histoire/shared'
|
|
2
|
+
import { router } from '../router.js'
|
|
3
|
+
import { openInEditor } from './open-in-editor.js'
|
|
4
|
+
import { useStoryStore } from '../stores/story.js'
|
|
5
|
+
|
|
6
|
+
export const builtinCommands: ClientCommand[] = [
|
|
7
|
+
{
|
|
8
|
+
id: 'builtin:open-in-editor',
|
|
9
|
+
label: 'Open file in editor',
|
|
10
|
+
icon: 'carbon:script-reference',
|
|
11
|
+
showIf: ({ route }) => route.name === 'story' && !!useStoryStore().currentStory,
|
|
12
|
+
getParams: () => {
|
|
13
|
+
const story = useStoryStore().currentStory
|
|
14
|
+
let file: string
|
|
15
|
+
if (story.docsOnly) {
|
|
16
|
+
file = story.file?.docsFilePath ?? story.file?.filePath
|
|
17
|
+
} else {
|
|
18
|
+
file = story.file?.filePath
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
file,
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
clientAction: ({ file }) => {
|
|
25
|
+
openInEditor(file)
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'builtin:histoire-docs',
|
|
30
|
+
label: 'Open Histoire Documentation',
|
|
31
|
+
icon: 'carbon:help',
|
|
32
|
+
clientAction: () => {
|
|
33
|
+
window.open('https://histoire.dev/guide/getting-started.html', '_blank')
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
export function executeCommand (command: ClientCommand, params: Record<string, any>) {
|
|
39
|
+
if (import.meta.hot) {
|
|
40
|
+
import.meta.hot.send('histoire:dev-command', {
|
|
41
|
+
id: command.id,
|
|
42
|
+
params,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
command.clientAction?.(params, getCommandContext())
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getCommandContext (): ClientCommandContext {
|
|
50
|
+
const storyStore = useStoryStore()
|
|
51
|
+
return {
|
|
52
|
+
route: router.currentRoute.value,
|
|
53
|
+
currentStory: storyStore.currentStory,
|
|
54
|
+
currentVariant: storyStore.currentVariant,
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/app/util/config.ts
CHANGED
package/src/app/util/dark.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { watch } from 'vue'
|
|
2
2
|
import { useDark, useToggle } from '@vueuse/core'
|
|
3
|
+
import { histoireConfig } from './config.js'
|
|
3
4
|
|
|
4
|
-
export const isDark = useDark({
|
|
5
|
+
export const isDark = useDark({
|
|
6
|
+
valueDark: 'htw-dark',
|
|
7
|
+
initialValue: histoireConfig.theme.defaultColorScheme,
|
|
8
|
+
storageKey: histoireConfig.theme.storeColorScheme ? 'histoire-color-scheme' : null,
|
|
9
|
+
})
|
|
5
10
|
export const toggleDark = useToggle(isDark)
|
|
6
11
|
|
|
7
12
|
function applyDarkToControls () {
|
package/src/app/util/keyboard.ts
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Ref, ref, watch, computed } from 'vue'
|
|
2
|
+
|
|
3
|
+
export function useSelection (list: Ref<any[]>) {
|
|
4
|
+
const selectedIndex = ref(0)
|
|
5
|
+
|
|
6
|
+
watch(list, () => {
|
|
7
|
+
selectedIndex.value = 0
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
function selectNext () {
|
|
11
|
+
selectedIndex.value++
|
|
12
|
+
if (selectedIndex.value > list.value.length - 1) {
|
|
13
|
+
selectedIndex.value = 0
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function selectPrevious () {
|
|
18
|
+
selectedIndex.value--
|
|
19
|
+
if (selectedIndex.value < 0) {
|
|
20
|
+
selectedIndex.value = list.value.length - 1
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
selectedIndex: computed(() => selectedIndex.value),
|
|
26
|
+
selectNext,
|
|
27
|
+
selectPrevious,
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/app/util/tooltip.ts
CHANGED
|
@@ -9,5 +9,5 @@ export function makeTooltip (descriptionHtml: string, keyboardShortcut: ({ isMac
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function genKeyboardShortcutHtml (shortcut: string) {
|
|
12
|
-
return
|
|
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
|
}
|