@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
@@ -54,7 +54,10 @@ const autoApplyContrastColor = computed(() => !!histoireConfig.autoApplyContrast
54
54
  :variant="variant"
55
55
  :story="story"
56
56
  class="htw-h-full"
57
- :class="[ isDark ? histoireConfig.sandboxDarkClass : undefined ]"
57
+ :class="{
58
+ [histoireConfig.sandboxDarkClass]: isDark, // @TODO remove
59
+ [histoireConfig.theme.darkClass]: isDark,
60
+ }"
58
61
  :dir="settings.textDirection"
59
62
  @ready="onReady"
60
63
  />
@@ -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 -->
@@ -82,6 +82,7 @@ function scrollDocsToTop () {
82
82
  >
83
83
  <StoryDocs
84
84
  :story="storyStore.currentStory"
85
+ standalone
85
86
  class="md:htw-p-12 htw-w-full md:htw-max-w-[600px] lg:htw-max-w-[800px] xl:htw-max-w-[900px]"
86
87
  @scroll-top="scrollDocsToTop()"
87
88
  />
@@ -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
+ }
@@ -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)))
@@ -88,10 +88,17 @@ app.mount('#app')
88
88
 
89
89
  watch(isDark, value => {
90
90
  if (value) {
91
- document.documentElement.classList.add(histoireConfig.sandboxDarkClass)
91
+ document.documentElement.classList.add(histoireConfig.sandboxDarkClass) // @TODO remove
92
+ document.documentElement.classList.add(histoireConfig.theme.darkClass)
92
93
  } else {
93
- document.documentElement.classList.remove(histoireConfig.sandboxDarkClass)
94
+ document.documentElement.classList.remove(histoireConfig.sandboxDarkClass) // @TODO remove
95
+ document.documentElement.classList.remove(histoireConfig.theme.darkClass)
94
96
  }
95
97
  }, {
96
98
  immediate: true,
97
99
  })
100
+
101
+ if (import.meta.hot) {
102
+ // eslint-disable-next-line spaced-comment
103
+ /*#__PURE__*/ setupPluginApi()
104
+ }
@@ -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 SearchResult {
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
+ }
@@ -1,5 +1,4 @@
1
1
  import type { HistoireConfig } from '@histoire/shared'
2
- // @ts-expect-error virtual module
3
2
  import { config as configRaw, logos as logosRaw } from 'virtual:$histoire-config'
4
3
 
5
4
  export const histoireConfig: HistoireConfig = configRaw
@@ -5,7 +5,8 @@ import { histoireConfig } from './config.js'
5
5
  export const isDark = useDark({
6
6
  valueDark: 'htw-dark',
7
7
  initialValue: histoireConfig.theme.defaultColorScheme,
8
- storageKey: histoireConfig.theme.storeColorScheme ? 'histoire-color-scheme' : null,
8
+ storageKey: 'histoire-color-scheme',
9
+ storage: histoireConfig.theme.storeColorScheme ? localStorage : sessionStorage,
9
10
  })
10
11
  export const toggleDark = useToggle(isDark)
11
12
 
@@ -95,5 +95,8 @@ export function formatKey (key: string) {
95
95
  if (key === 'meta') {
96
96
  return '⌘'
97
97
  }
98
+ if (key === 'enter') {
99
+ return '⏎'
100
+ }
98
101
  return key.charAt(0).toUpperCase() + key.substring(1).toLowerCase()
99
102
  }
@@ -0,0 +1,3 @@
1
+ export function openInEditor (file: string) {
2
+ return fetch(`${import.meta.env.BASE_URL}__open-in-editor?file=${encodeURIComponent(file)}`)
3
+ }
@@ -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
+ }
@@ -9,5 +9,5 @@ export function makeTooltip (descriptionHtml: string, keyboardShortcut: ({ isMac
9
9
  }
10
10
 
11
11
  function genKeyboardShortcutHtml (shortcut: string) {
12
- return shortcut.split('+').map(k => k.trim()).map(key => `<span class="htw-bg-gray-500 htw-border-b-2 htw-border-gray-600 htw-px-1 htw-rounded-sm">${formatKey(key)}</span>`).join('')
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
  }
@@ -0,0 +1,6 @@
1
+ declare module 'virtual:$histoire-commands' {
2
+ import type { ClientCommand } from '@histoire/shared'
3
+ export const registeredCommands: ClientCommand[]
4
+ }
5
+
6
+ declare module 'virtual:*';