-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: open in editor command in search
- Loading branch information
Showing
11 changed files
with
248 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/histoire-app/src/app/components/base/BaseListItem.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<script lang="ts" setup> | ||
defineProps<{ | ||
isActive?: boolean | ||
}>() | ||
const emit = defineEmits<{ | ||
(e: 'navigate'): void | ||
}>() | ||
function handleNavigate () { | ||
emit('navigate') | ||
} | ||
</script> | ||
|
||
<template> | ||
<a | ||
class="istoire-base-list-ite htw-flex htw-items-center htw-gap-2 htw-text-gray-900 dark:htw-text-gray-100" | ||
:class="[ | ||
$attrs.class, | ||
isActive | ||
? 'active htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black' | ||
: 'hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900' | ||
]" | ||
@click="handleNavigate()" | ||
@keyup.enter="handleNavigate()" | ||
@keyup.space="handleNavigate()" | ||
> | ||
<slot /> | ||
</a> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/histoire-app/src/app/components/search/SearchItemContent.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<script lang="ts" setup> | ||
import { Icon } from '@iconify/vue' | ||
import type { SearchResult } from '../../types.js' | ||
defineProps<{ | ||
result: SearchResult | ||
selected: boolean | ||
}>() | ||
const defaultIcons = { | ||
story: 'carbon:cube', | ||
variant: 'carbon:cube', | ||
} | ||
const kindLabels = { | ||
story: 'Story', | ||
variant: 'Variant', | ||
command: 'Command', | ||
} | ||
</script> | ||
|
||
<template> | ||
<Icon | ||
:icon="result.icon ?? defaultIcons[result.kind]" | ||
class="htw-w-4 htw-h-4" | ||
:class="[ | ||
!selected ? [ | ||
result.iconColor | ||
?'bind-icon-color' | ||
: { | ||
'htw-text-primary-500': result.kind === 'story', | ||
'htw-text-gray-500': result.kind === 'variant', | ||
} | ||
] : [], | ||
]" | ||
/> | ||
<div class="htw-flex-1"> | ||
<div class="htw-flex"> | ||
{{ result.title }} | ||
<span class="htw-ml-auto htw-opacity-40"> | ||
{{ kindLabels[result.kind] }} | ||
</span> | ||
</div> | ||
|
||
<div | ||
v-if="result.path?.length" | ||
class="htw-flex htw-items-center htw-gap-0.5 htw-opacity-60" | ||
> | ||
<div | ||
v-for="(p, index) of result.path" | ||
:key="index" | ||
class="htw-flex htw-items-center htw-gap-0.5" | ||
> | ||
<Icon | ||
v-if="index > 0" | ||
icon="carbon:chevron-right" | ||
class="htw-w-4 htw-h-4 htw-mt-0.5 htw-opacity-50" | ||
/> | ||
<span>{{ p }}</span> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/histoire-app/src/app/components/search/dev-commands.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { openInEditor } from '../../util/open-in-editor.js' | ||
import { useStoryStore } from '../../stores/story.js' | ||
import type { SearchCommand } from '../../types.js' | ||
|
||
const storyStore = useStoryStore() | ||
|
||
export const devCommands: SearchCommand[] = [ | ||
{ | ||
id: 'open-in-editor', | ||
label: 'Open file in editor', | ||
icon: 'carbon:script-reference', | ||
showIf: ({ route }) => route.name === 'story' && !!storyStore.currentStory, | ||
getParams: () => { | ||
const story = storyStore.currentStory | ||
let file: string | ||
if (story.docsOnly) { | ||
file = story.file?.docsFilePath ?? story.file?.filePath | ||
} else { | ||
file = story.file?.filePath | ||
} | ||
return { | ||
file, | ||
} | ||
}, | ||
clientAction: ({ file }) => { | ||
openInEditor(file) | ||
}, | ||
}, | ||
] | ||
|
||
export function executeCommand (command: SearchCommand, params: Record<string, any>) { | ||
if (import.meta.hot) { | ||
import.meta.hot.send('histoire:dev-command', { | ||
id: command.id, | ||
params, | ||
}) | ||
|
||
command.clientAction?.(params) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type CommandId = 'open-in-editor' | ||
|
||
export interface Command { | ||
id: CommandId | ||
label: string | ||
} |
Oops, something went wrong.