@histoire/app 0.13.2 → 0.14.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.
Files changed (89) hide show
  1. package/dist/bundled/App.vue2.js +11 -2
  2. package/dist/bundled/components/base/BaseButton.vue.js +5 -0
  3. package/dist/bundled/components/base/BaseButton.vue2.js +39 -0
  4. package/dist/bundled/components/base/BaseIcon.vue.js +8 -0
  5. package/dist/bundled/components/base/BaseIcon.vue2.js +30 -0
  6. package/dist/bundled/components/base/BaseIcon.vue3.js +4 -0
  7. package/dist/bundled/components/base/BaseKeyboardShortcut.vue.js +5 -0
  8. package/dist/bundled/components/base/BaseKeyboardShortcut.vue2.js +20 -0
  9. package/dist/bundled/components/base/BaseListItem.vue.js +5 -0
  10. package/dist/bundled/components/base/BaseListItem.vue2.js +32 -0
  11. package/dist/bundled/components/command/CommandPrompts.vue.js +5 -0
  12. package/dist/bundled/components/command/CommandPrompts.vue2.js +95 -0
  13. package/dist/bundled/components/command/CommandPromptsModal.vue.js +5 -0
  14. package/dist/bundled/components/command/CommandPromptsModal.vue2.js +44 -0
  15. package/dist/bundled/components/command/PromptSelect.vue.js +5 -0
  16. package/dist/bundled/components/command/PromptSelect.vue2.js +142 -0
  17. package/dist/bundled/components/command/PromptText.vue.js +5 -0
  18. package/dist/bundled/components/command/PromptText.vue2.js +67 -0
  19. package/dist/bundled/components/panel/StoryDocs.vue2.js +25 -3
  20. package/dist/bundled/components/panel/StorySourceCode.vue.js +1 -1
  21. package/dist/bundled/components/panel/StorySourceCode.vue2.js +1 -1
  22. package/dist/bundled/components/panel/StorySourceCode.vue3.js +2 -2
  23. package/dist/bundled/components/search/SearchItem.vue.js +1 -1
  24. package/dist/bundled/components/search/SearchItem.vue2.js +42 -62
  25. package/dist/bundled/components/search/SearchItem.vue3.js +2 -2
  26. package/dist/bundled/components/search/SearchItemContent.vue.js +5 -0
  27. package/dist/bundled/components/search/SearchItemContent.vue2.js +72 -0
  28. package/dist/bundled/components/search/SearchModal.vue2.js +2 -2
  29. package/dist/bundled/components/search/SearchPane.vue2.js +46 -24
  30. package/dist/bundled/components/story/StoryVariantGrid.vue2.js +10 -2
  31. package/dist/bundled/components/story/StoryVariantGridItem.vue.js +1 -1
  32. package/dist/bundled/components/story/StoryVariantGridItem.vue2.js +8 -4
  33. package/dist/bundled/components/story/StoryVariantGridItem.vue3.js +2 -2
  34. package/dist/bundled/components/story/StoryVariantSinglePreviewNative.vue2.js +5 -1
  35. package/dist/bundled/components/story/StoryVariantSingleView.vue2.js +13 -6
  36. package/dist/bundled/components/story/StoryView.vue2.js +1 -0
  37. package/dist/bundled/components/toolbar/DevOnlyToolbarOpenInEditor.vue.js +5 -0
  38. package/dist/bundled/components/toolbar/DevOnlyToolbarOpenInEditor.vue2.js +31 -0
  39. package/dist/bundled/index.js +3 -1
  40. package/dist/bundled/plugin.js +50 -0
  41. package/dist/bundled/sandbox.js +6 -0
  42. package/dist/bundled/stores/command.js +26 -0
  43. package/dist/bundled/style.css +22 -18
  44. package/dist/bundled/util/commands.js +59 -0
  45. package/dist/bundled/util/dark.js +2 -1
  46. package/dist/bundled/util/keyboard.js +3 -0
  47. package/dist/bundled/util/open-in-editor.js +6 -0
  48. package/dist/bundled/util/select.js +28 -0
  49. package/dist/bundled/util/tooltip.js +1 -1
  50. package/dist/style.css +116 -63
  51. package/package.json +4 -4
  52. package/src/app/App.vue +10 -1
  53. package/src/app/components/base/BaseButton.vue +33 -0
  54. package/src/app/components/base/BaseIcon.vue +31 -0
  55. package/src/app/components/base/BaseKeyboardShortcut.vue +16 -0
  56. package/src/app/components/base/BaseListItem.vue +30 -0
  57. package/src/app/components/command/CommandPrompts.vue +97 -0
  58. package/src/app/components/command/CommandPromptsModal.vue +40 -0
  59. package/src/app/components/command/PromptSelect.vue +140 -0
  60. package/src/app/components/command/PromptText.vue +64 -0
  61. package/src/app/components/panel/StoryDocs.vue +25 -2
  62. package/src/app/components/panel/StorySourceCode.vue +0 -1
  63. package/src/app/components/search/SearchItem.vue +29 -52
  64. package/src/app/components/search/SearchItemContent.vue +67 -0
  65. package/src/app/components/search/SearchModal.vue +2 -2
  66. package/src/app/components/search/SearchPane.vue +50 -22
  67. package/src/app/components/search/search-docs-data.ts +0 -1
  68. package/src/app/components/search/search-title-data.ts +0 -1
  69. package/src/app/components/story/GenericMountStory.vue +0 -1
  70. package/src/app/components/story/GenericRenderStory.vue +0 -1
  71. package/src/app/components/story/StoryVariantGrid.vue +7 -0
  72. package/src/app/components/story/StoryVariantGridItem.vue +4 -0
  73. package/src/app/components/story/StoryVariantSinglePreviewNative.vue +4 -1
  74. package/src/app/components/story/StoryVariantSingleView.vue +7 -0
  75. package/src/app/components/story/StoryView.vue +1 -0
  76. package/src/app/components/toolbar/DevOnlyToolbarOpenInEditor.vue +23 -0
  77. package/src/app/index.ts +5 -1
  78. package/src/app/plugin.ts +58 -0
  79. package/src/app/sandbox.ts +10 -3
  80. package/src/app/stores/command.ts +25 -0
  81. package/src/app/types.ts +26 -4
  82. package/src/app/util/commands.ts +56 -0
  83. package/src/app/util/config.ts +0 -1
  84. package/src/app/util/dark.ts +2 -1
  85. package/src/app/util/keyboard.ts +3 -0
  86. package/src/app/util/open-in-editor.ts +3 -0
  87. package/src/app/util/select.ts +29 -0
  88. package/src/app/util/tooltip.ts +1 -1
  89. package/src/virtual.d.ts +6 -0
@@ -0,0 +1,40 @@
1
+ <script lang="ts" setup>
2
+ import { defineAsyncComponent } from 'vue'
3
+ import { useCommandStore } from '../../stores/command.js'
4
+ const CommandPrompts = defineAsyncComponent(() => import('./CommandPrompts.vue'))
5
+
6
+ defineProps({
7
+ shown: {
8
+ type: Boolean,
9
+ default: false,
10
+ },
11
+ })
12
+
13
+ const emit = defineEmits({
14
+ close: () => true,
15
+ })
16
+
17
+ function close () {
18
+ emit('close')
19
+ }
20
+
21
+ const commandStore = useCommandStore()
22
+ </script>
23
+
24
+ <template>
25
+ <div
26
+ v-if="shown"
27
+ class="histoire-command-prompts-modal htw-fixed htw-inset-0 htw-bg-white/80 dark:htw-bg-gray-900/80 htw-z-20"
28
+ >
29
+ <div
30
+ class="htw-absolute htw-inset-0"
31
+ @click="close()"
32
+ />
33
+ <div class="htw-bg-white dark:htw-bg-gray-900 md:htw-mt-16 md:htw-mx-auto htw-w-screen htw-max-w-[512px] htw-max-h-[80vh] htw-overflow-y-auto htw-scroll-smooth htw-shadow-xl htw-border htw-border-gray-200 dark:htw-border-gray-750 htw-rounded-lg htw-relative htw-divide-y htw-divide-gray-200 dark:htw-divide-gray-850">
34
+ <CommandPrompts
35
+ :command="commandStore.selectedCommand"
36
+ @close="close()"
37
+ />
38
+ </div>
39
+ </div>
40
+ </template>
@@ -0,0 +1,140 @@
1
+ <script lang="ts" setup>
2
+ import type { SelectPrompt, SelectPromptOption } from '@histoire/shared'
3
+ import { computed, ref, watchEffect } from 'vue'
4
+ import { Icon } from '@iconify/vue'
5
+ import { useSelection } from '../../util/select.js'
6
+ import BaseKeyboardShortcut from '../base/BaseKeyboardShortcut.vue'
7
+
8
+ const props = defineProps<{
9
+ modelValue?: string
10
+ prompt: SelectPrompt
11
+ answers: Record<string, any>
12
+ }>()
13
+
14
+ const emit = defineEmits<{
15
+ (e: 'update:modelValue', value: string): void
16
+ (e: 'next'): void
17
+ }>()
18
+
19
+ const model = computed({
20
+ get: () => props.modelValue,
21
+ set: (value) => {
22
+ emit('update:modelValue', value)
23
+ emit('next')
24
+ },
25
+ })
26
+
27
+ const input = ref<HTMLInputElement>()
28
+
29
+ function focus () {
30
+ input.value?.focus()
31
+ input.value?.select()
32
+ }
33
+
34
+ defineExpose({
35
+ focus,
36
+ })
37
+
38
+ const search = ref('')
39
+
40
+ const options = ref<SelectPromptOption[]>([])
41
+
42
+ let requestId = 0
43
+ watchEffect(async () => {
44
+ if (typeof props.prompt.options === 'function') {
45
+ const rId = ++requestId
46
+ const result = await props.prompt.options(search.value, props.answers)
47
+ if (rId === requestId) {
48
+ options.value = result
49
+ }
50
+ } else {
51
+ options.value = props.prompt.options
52
+ }
53
+ })
54
+
55
+ const formattedOptions = computed(() => {
56
+ return options.value.map((option) => {
57
+ if (typeof option === 'string') {
58
+ return {
59
+ value: option,
60
+ label: option,
61
+ }
62
+ } else {
63
+ return option
64
+ }
65
+ })
66
+ })
67
+
68
+ // Keyboard navigation
69
+
70
+ const {
71
+ selectedIndex,
72
+ selectNext,
73
+ selectPrevious,
74
+ } = useSelection(formattedOptions)
75
+
76
+ function selectIndex (index: number) {
77
+ const result = formattedOptions.value[index].value
78
+ if (result) {
79
+ model.value = result
80
+ }
81
+ }
82
+ </script>
83
+
84
+ <template>
85
+ <div class="histoire-prompt-select htw-relative htw-group">
86
+ <input
87
+ v-model="model"
88
+ :required="prompt.required"
89
+ tabindex="-1"
90
+ class="htw-absolute htw-inset-0 htw-opacity-0 htw-pointer-events-none"
91
+ >
92
+ <label class="htw-flex htw-flex-col htw-gap-2 htw-p-2">
93
+ <span class="htw-px-2 htw-flex">
94
+ <span>{{ prompt.label }}</span>
95
+ <span
96
+ v-if="prompt.required"
97
+ class="htw-opacity-70"
98
+ >*</span>
99
+
100
+ <span class="htw-opacity-40 htw-text-sm htw-ml-auto htw-invisible group-focus-within:htw-visible">
101
+ Press <BaseKeyboardShortcut shortcut="Space" /> to select
102
+ </span>
103
+ </span>
104
+ <input
105
+ ref="input"
106
+ v-model="search"
107
+ class="htw-bg-transparent htw-w-full htw-p-2 htw-border htw-border-gray-500/50 focus:htw-border-primary-500/50 htw-rounded htw-outline-none"
108
+ @keydown.down.prevent="selectNext()"
109
+ @keydown.up.prevent="selectPrevious()"
110
+ @keydown.space.prevent="selectIndex(selectedIndex)"
111
+ >
112
+ </label>
113
+
114
+ <div class="htw-overflow-auto max-h-[300px] htw-mb-2">
115
+ <button
116
+ v-for="(option, index) of formattedOptions"
117
+ :key="option.value"
118
+ type="button"
119
+ tabindex="-1"
120
+ :class="[
121
+ model === option.value
122
+ ? 'htw-bg-primary-500/20'
123
+ : index === selectedIndex
124
+ ? 'htw-bg-primary-500/10'
125
+ : 'htw-bg-transparent',
126
+ ]"
127
+ class="htw-w-full htw-text-left htw-px-4 htw-py-2 hover:htw-bg-primary-500/10 htw-flex htw-items-center"
128
+ @click="model = option.value"
129
+ >
130
+ <span class="htw-flex-1">{{ option.label }}</span>
131
+
132
+ <Icon
133
+ v-if="model === option.value"
134
+ icon="carbon:checkmark"
135
+ class="htw-w-4 htw-h-4 htw-text-primary-500"
136
+ />
137
+ </button>
138
+ </div>
139
+ </div>
140
+ </template>
@@ -0,0 +1,64 @@
1
+ <script lang="ts" setup>
2
+ import type { TextPrompt } from '@histoire/shared'
3
+ import { computed, ref, watch } from 'vue'
4
+
5
+ const props = defineProps<{
6
+ modelValue?: string
7
+ prompt: TextPrompt
8
+ answers: Record<string, any>
9
+ }>()
10
+
11
+ const emit = defineEmits<{
12
+ (e: 'update:modelValue', value: string): void
13
+ }>()
14
+
15
+ const model = computed({
16
+ get: () => props.modelValue,
17
+ set: (value) => emit('update:modelValue', value),
18
+ })
19
+
20
+ const input = ref<HTMLInputElement>()
21
+
22
+ function focus () {
23
+ input.value?.focus()
24
+ input.value?.select()
25
+ }
26
+
27
+ defineExpose({
28
+ focus,
29
+ })
30
+
31
+ // Default value
32
+
33
+ const defaultValue = computed(() => {
34
+ if (typeof props.prompt.defaultValue === 'function') {
35
+ return props.prompt.defaultValue(props.answers)
36
+ } else {
37
+ return props.prompt.defaultValue
38
+ }
39
+ })
40
+
41
+ watch(defaultValue, (value) => {
42
+ model.value = value
43
+ })
44
+ </script>
45
+
46
+ <template>
47
+ <div class="histoire-prompt-text">
48
+ <label class="htw-flex htw-flex-col htw-gap-2 htw-p-2">
49
+ <span class="htw-px-2">
50
+ <span>{{ prompt.label }}</span>
51
+ <span
52
+ v-if="prompt.required"
53
+ class="htw-opacity-70"
54
+ >*</span>
55
+ </span>
56
+ <input
57
+ ref="input"
58
+ v-model="model"
59
+ class="htw-bg-transparent htw-w-full htw-p-2 htw-border htw-border-gray-500/50 focus:htw-border-primary-500/50 htw-rounded htw-outline-none"
60
+ :required="prompt.required"
61
+ >
62
+ </label>
63
+ </div>
64
+ </template>
@@ -1,9 +1,9 @@
1
1
  <script lang="ts">
2
- import { nextTick, PropType, Ref, ref, toRefs, watch, watchEffect } from 'vue'
2
+ import { nextTick, PropType, Ref, ref, toRefs, watch, watchEffect, computed } from 'vue'
3
3
  import type { Story } from '../../types'
4
- // @ts-expect-error virtual module
5
4
  import { markdownFiles } from 'virtual:$histoire-markdown-files'
6
5
  import { histoireConfig } from '../../util/config.js'
6
+ import DevOnlyToolbarOpenInEditor from '../toolbar/DevOnlyToolbarOpenInEditor.vue'
7
7
 
8
8
  export function useStoryDoc (story: Ref<Story>) {
9
9
  const renderedDoc = ref('')
@@ -56,6 +56,11 @@ const props = defineProps({
56
56
  type: Object as PropType<Story>,
57
57
  required: true,
58
58
  },
59
+
60
+ standalone: {
61
+ type: Boolean,
62
+ default: false,
63
+ },
59
64
  })
60
65
 
61
66
  const emit = defineEmits<{
@@ -148,6 +153,10 @@ watch(renderedDoc, () => {
148
153
  }, {
149
154
  immediate: true,
150
155
  })
156
+
157
+ // Open in editor
158
+
159
+ const filePath = computed(() => story.value.file?.docsFilePath ?? (props.standalone && story.value.file?.filePath))
151
160
  </script>
152
161
 
153
162
  <template>
@@ -155,6 +164,20 @@ watch(renderedDoc, () => {
155
164
  class="histoire-story-docs"
156
165
  @click.capture="onClick"
157
166
  >
167
+ <div
168
+ v-if="__HISTOIRE_DEV__ && renderedDoc && filePath"
169
+ class="htw-flex htw-items-center htw-gap-2 htw-p-2"
170
+ :class="{
171
+ 'htw-pt-4': !standalone,
172
+ }"
173
+ >
174
+ <DevOnlyToolbarOpenInEditor
175
+ v-if="filePath"
176
+ :file="filePath"
177
+ tooltip="Edit docs in editor"
178
+ />
179
+ </div>
180
+
158
181
  <BaseEmpty
159
182
  v-if="!renderedDoc"
160
183
  >
@@ -4,7 +4,6 @@ import { Icon } from '@iconify/vue'
4
4
  import { getHighlighter, Highlighter } from 'shiki-es'
5
5
  import { HstCopyIcon } from '@histoire/controls'
6
6
  import { unindent } from '@histoire/shared'
7
- // @ts-expect-error virtual module
8
7
  import { clientSupportPlugins } from 'virtual:$histoire-support-plugins-client'
9
8
  import type { Variant, Story } from '../../types'
10
9
  import { isDark } from '../../util/dark'
@@ -1,11 +1,12 @@
1
1
  <script lang="ts" setup>
2
2
  import { PropType, ref, toRefs } from 'vue'
3
3
  import { useRouter } from 'vue-router'
4
- import { Icon } from '@iconify/vue'
5
4
  import { SearchResult } from '../../types'
6
5
  import { onKeyboardShortcut } from '../../util/keyboard'
7
- import BaseListItemLink from '../base/BaseListItemLink.vue'
8
6
  import { useScrollOnActive } from '../../util/scroll'
7
+ import BaseListItemLink from '../base/BaseListItemLink.vue'
8
+ import BaseListItem from '../base/BaseListItem.vue'
9
+ import SearchItemContent from './SearchItemContent.vue'
9
10
 
10
11
  const props = defineProps({
11
12
  result: {
@@ -32,18 +33,17 @@ const router = useRouter()
32
33
 
33
34
  onKeyboardShortcut(['enter'], () => {
34
35
  if (!props.selected) return
35
- router.push(props.result.route)
36
- emit('close')
36
+ action()
37
37
  })
38
38
 
39
- const defaultIcons = {
40
- story: 'carbon:cube',
41
- variant: 'carbon:cube',
42
- }
43
-
44
- const kindLabels = {
45
- story: 'Story',
46
- variant: 'Variant',
39
+ function action (fromClick = false) {
40
+ if ('route' in props.result && !fromClick) {
41
+ router.push(props.result.route)
42
+ }
43
+ if ('onActivate' in props.result) {
44
+ props.result.onActivate()
45
+ }
46
+ emit('close')
47
47
  }
48
48
  </script>
49
49
 
@@ -55,52 +55,29 @@ const kindLabels = {
55
55
  :data-selected="selected ? '' : undefined"
56
56
  >
57
57
  <BaseListItemLink
58
+ v-if="'route' in result"
58
59
  :to="result.route"
59
60
  :is-active="selected"
60
61
  class="htw-px-6 htw-py-4 htw-gap-4"
61
- @navigate="$emit('close')"
62
+ @navigate="action(true)"
62
63
  >
63
- <Icon
64
- :icon="result.icon ?? defaultIcons[result.kind]"
65
- class="htw-w-4 htw-h-4"
66
- :class="[
67
- !selected ? [
68
- result.iconColor
69
- ?'bind-icon-color'
70
- : {
71
- 'htw-text-primary-500': result.kind === 'story',
72
- 'htw-text-gray-500': result.kind === 'variant',
73
- }
74
- ] : [],
75
- ]"
64
+ <SearchItemContent
65
+ :result="result"
66
+ :selected="selected"
76
67
  />
77
- <div class="htw-flex-1">
78
- <div class="htw-flex">
79
- {{ result.title }}
80
- <span class="htw-ml-auto htw-opacity-40">
81
- {{ kindLabels[result.kind] }}
82
- </span>
83
- </div>
84
-
85
- <div
86
- v-if="result.path?.length"
87
- class="htw-flex htw-items-center htw-gap-0.5 htw-opacity-60"
88
- >
89
- <div
90
- v-for="(p, index) of result.path"
91
- :key="index"
92
- class="htw-flex htw-items-center htw-gap-0.5"
93
- >
94
- <Icon
95
- v-if="index > 0"
96
- icon="carbon:chevron-right"
97
- class="htw-w-4 htw-h-4 htw-mt-0.5 htw-opacity-50"
98
- />
99
- <span>{{ p }}</span>
100
- </div>
101
- </div>
102
- </div>
103
68
  </BaseListItemLink>
69
+
70
+ <BaseListItem
71
+ v-if="'onActivate' in result"
72
+ :is-active="selected"
73
+ class="htw-px-6 htw-py-4 htw-gap-4"
74
+ @navigate="action(true)"
75
+ >
76
+ <SearchItemContent
77
+ :result="result"
78
+ :selected="selected"
79
+ />
80
+ </BaseListItem>
104
81
  </div>
105
82
  </template>
106
83
 
@@ -0,0 +1,67 @@
1
+ <script lang="ts" setup>
2
+ import { Icon } from '@iconify/vue'
3
+ import BaseIcon from '../base/BaseIcon.vue'
4
+ import type { SearchResult } from '../../types.js'
5
+
6
+ defineProps<{
7
+ result: SearchResult
8
+ selected: boolean
9
+ }>()
10
+
11
+ const defaultIcons = {
12
+ story: 'carbon:cube',
13
+ variant: 'carbon:cube',
14
+ }
15
+
16
+ const kindLabels = {
17
+ story: 'Story',
18
+ variant: 'Variant',
19
+ command: 'Command',
20
+ }
21
+ </script>
22
+
23
+ <template>
24
+ <BaseIcon
25
+ :icon="result.icon ?? defaultIcons[result.kind]"
26
+ class="htw-w-4 htw-h-4"
27
+ :class="[
28
+ !selected ? [
29
+ result.iconColor
30
+ ?'bind-icon-color'
31
+ : {
32
+ 'htw-text-primary-500': result.kind === 'story',
33
+ 'htw-text-gray-500': result.kind === 'variant',
34
+ }
35
+ ] : [],
36
+ {
37
+ 'colorize-black': selected,
38
+ }
39
+ ]"
40
+ />
41
+ <div class="htw-flex-1">
42
+ <div class="htw-flex">
43
+ {{ result.title }}
44
+ <span class="htw-ml-auto htw-opacity-40">
45
+ {{ kindLabels[result.kind] }}
46
+ </span>
47
+ </div>
48
+
49
+ <div
50
+ v-if="result.path?.length"
51
+ class="htw-flex htw-items-center htw-gap-0.5 htw-opacity-60"
52
+ >
53
+ <div
54
+ v-for="(p, index) of result.path"
55
+ :key="index"
56
+ class="htw-flex htw-items-center htw-gap-0.5"
57
+ >
58
+ <Icon
59
+ v-if="index > 0"
60
+ icon="carbon:chevron-right"
61
+ class="htw-w-4 htw-h-4 htw-mt-0.5 htw-opacity-50"
62
+ />
63
+ <span>{{ p }}</span>
64
+ </div>
65
+ </div>
66
+ </div>
67
+ </template>
@@ -26,14 +26,14 @@ function close () {
26
26
  <template>
27
27
  <div
28
28
  v-show="shown"
29
- class="histoire-search-modal htw-fixed htw-inset-0 htw-bg-white/80 dark:htw-bg-gray-700/80 htw-z-20"
29
+ class="histoire-search-modal htw-fixed htw-inset-0 htw-bg-white/80 dark:htw-bg-gray-900/80 htw-z-20"
30
30
  data-test-id="search-modal"
31
31
  >
32
32
  <div
33
33
  class="htw-absolute htw-inset-0"
34
34
  @click="close()"
35
35
  />
36
- <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">
36
+ <div class="htw-bg-white dark:htw-bg-gray-900 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-750 htw-rounded-lg htw-relative htw-divide-y htw-divide-gray-200 dark:htw-divide-gray-850">
37
37
  <SearchPane
38
38
  :shown="shown"
39
39
  @close="close()"
@@ -5,12 +5,17 @@ import { Icon } from '@iconify/vue'
5
5
  import * as flexsearch from 'flexsearch'
6
6
  import charset from 'flexsearch/dist/module/lang/latin/advanced.js'
7
7
  import language from 'flexsearch/dist/module/lang/en.js'
8
+ import type { ClientCommand } from '@histoire/shared'
9
+ import { registeredCommands } from 'virtual:$histoire-commands'
8
10
  import { useStoryStore } from '../../stores/story'
9
11
  import BaseEmpty from '../base/BaseEmpty.vue'
10
12
  import type { SearchResult, SearchResultType, Story, Variant } from '../../types'
11
13
  import SearchItem from './SearchItem.vue'
12
14
  import { searchData, onUpdate } from './search-title-data'
13
15
  import type { SearchData } from './types'
16
+ import { builtinCommands, getCommandContext } from '../../util/commands.js'
17
+ import { useCommandStore } from '../../stores/command.js'
18
+ import { useSelection } from '../../util/select.js'
14
19
 
15
20
  const DocSearchData = () => import('./search-docs-data')
16
21
 
@@ -194,7 +199,6 @@ function storyResultFactory (story: Story, rank: number, type: SearchResultType
194
199
  path: story.file.path.slice(0, -1),
195
200
  icon: story.icon,
196
201
  iconColor: story.iconColor,
197
- type,
198
202
  }
199
203
  }
200
204
 
@@ -219,12 +223,50 @@ function variantResultFactory (story: Story, variant: Variant, rank: number, typ
219
223
  path: [...story.file.path ?? [], story.title],
220
224
  icon: variant.icon,
221
225
  iconColor: variant.iconColor,
222
- type,
223
226
  }
224
227
  }
225
228
 
229
+ // Commands
230
+
231
+ const allCommands = [
232
+ ...builtinCommands,
233
+ ...registeredCommands,
234
+ ]
235
+
236
+ const commandResults = computed(() => {
237
+ if (__HISTOIRE_DEV__) {
238
+ const commandCtx = getCommandContext()
239
+ const searchText = searchInputText.value.toLowerCase()
240
+ return allCommands
241
+ .filter(command => !command.showIf || command.showIf(commandCtx))
242
+ .filter(command => command.label.toLowerCase().includes(searchText) || command.searchText?.toLowerCase().includes(searchText))
243
+ .map((command) => commandResultFactory(command, 0))
244
+ }
245
+ return []
246
+ })
247
+
248
+ const commandStore = useCommandStore()
249
+
250
+ function commandResultFactory (command: ClientCommand, rank: number): SearchResult {
251
+ return {
252
+ kind: 'command',
253
+ rank,
254
+ id: `_command:${command.id}`,
255
+ title: command.label,
256
+ icon: command.icon ?? 'carbon:chevron-right',
257
+ onActivate: () => {
258
+ commandStore.activateCommand(command)
259
+ },
260
+ }
261
+ }
262
+
263
+ // Results
264
+
226
265
  const results = computed(() => {
227
- const list = [...titleResults.value]
266
+ const list = [
267
+ ...commandResults.value,
268
+ ...titleResults.value,
269
+ ]
228
270
  const seen = {}
229
271
  for (const r of titleResults.value) {
230
272
  seen[r.id] = true
@@ -239,25 +281,11 @@ const results = computed(() => {
239
281
 
240
282
  // Selection
241
283
 
242
- const selectedIndex = ref(0)
243
-
244
- watch(results, () => {
245
- selectedIndex.value = 0
246
- })
247
-
248
- function selectNext () {
249
- selectedIndex.value++
250
- if (selectedIndex.value > results.value.length - 1) {
251
- selectedIndex.value = 0
252
- }
253
- }
254
-
255
- function selectPrevious () {
256
- selectedIndex.value--
257
- if (selectedIndex.value < 0) {
258
- selectedIndex.value = results.value.length - 1
259
- }
260
- }
284
+ const {
285
+ selectedIndex,
286
+ selectNext,
287
+ selectPrevious,
288
+ } = useSelection(results)
261
289
  </script>
262
290
 
263
291
  <template>
@@ -1,5 +1,4 @@
1
1
  import { markRaw } from 'vue'
2
- // @ts-expect-error virtual module
3
2
  import { searchData as _searchData, onUpdate as _onUpdate } from 'virtual:$histoire-search-docs-data'
4
3
  import type { SearchData } from './types.js'
5
4
 
@@ -1,5 +1,4 @@
1
1
  import { markRaw } from 'vue'
2
- // @ts-expect-error virtual module
3
2
  import { searchData as _searchData, onUpdate as _onUpdate } from 'virtual:$histoire-search-title-data'
4
3
  import type { SearchData } from './types.js'
5
4
 
@@ -5,7 +5,6 @@ export default {
5
5
  </script>
6
6
 
7
7
  <script lang="ts" setup>
8
- // @ts-expect-error virtual module
9
8
  import { clientSupportPlugins } from 'virtual:$histoire-support-plugins-client'
10
9
  import { ref, watchEffect, markRaw } from 'vue'
11
10
  import type { Story } from '../../types'
@@ -5,7 +5,6 @@ export default {
5
5
  </script>
6
6
 
7
7
  <script lang="ts" setup>
8
- // @ts-expect-error virtual module
9
8
  import { clientSupportPlugins } from 'virtual:$histoire-support-plugins-client'
10
9
  import { ref, watchEffect, markRaw } from 'vue'
11
10
  import type { Story } from '../../types'
@@ -6,6 +6,7 @@ import { isMobile } from '../../util/responsive'
6
6
  import StoryVariantGridItem from './StoryVariantGridItem.vue'
7
7
  import ToolbarBackground from '../toolbar/ToolbarBackground.vue'
8
8
  import ToolbarTextDirection from '../toolbar/ToolbarTextDirection.vue'
9
+ import DevOnlyToolbarOpenInEditor from '../toolbar/DevOnlyToolbarOpenInEditor.vue'
9
10
 
10
11
  const storyStore = useStoryStore()
11
12
 
@@ -125,6 +126,12 @@ const columnCount = computed(() => Math.min(storyStore.currentStory.variants.len
125
126
  >
126
127
  <ToolbarBackground />
127
128
  <ToolbarTextDirection />
129
+
130
+ <DevOnlyToolbarOpenInEditor
131
+ v-if="__HISTOIRE_DEV__"
132
+ :file="storyStore.currentStory.file?.filePath"
133
+ tooltip="Edit story in editor"
134
+ />
128
135
  </div>
129
136
 
130
137
  <div
@@ -9,6 +9,7 @@ import { useScrollOnActive } from '../../util/scroll'
9
9
  import { usePreviewSettingsStore } from '../../stores/preview-settings'
10
10
  import { getContrastColor } from '../../util/preview-settings'
11
11
  import { histoireConfig } from '../../util/config'
12
+ import { isDark } from '../../util/dark'
12
13
  import GenericRenderStory from './GenericRenderStory.vue'
13
14
  import ToolbarNewTab from '../toolbar/ToolbarNewTab.vue'
14
15
  import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
@@ -136,6 +137,9 @@ const autoApplyContrastColor = computed(() => !!histoireConfig.autoApplyContrast
136
137
  :variant="variant"
137
138
  :story="story"
138
139
  :dir="settings.textDirection"
140
+ :class="{
141
+ [histoireConfig.theme.darkClass]: isDark,
142
+ }"
139
143
  @ready="onReady"
140
144
  />
141
145
  </div>