@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.
Files changed (126) hide show
  1. package/dist/bundled/App.vue2.js +1 -1
  2. package/dist/bundled/components/app/AppHeader.vue2.js +1 -1
  3. package/dist/bundled/components/app/AppLogo.vue2.js +1 -1
  4. package/dist/bundled/components/app/Breadcrumb.vue.js +1 -1
  5. package/dist/bundled/components/app/Breadcrumb.vue2.js +3 -3
  6. package/dist/bundled/components/app/HomeCounter.vue2.js +2 -7
  7. package/dist/bundled/components/base/BaseCheckbox.vue2.js +1 -2
  8. package/dist/bundled/components/base/BaseIcon.vue.js +1 -1
  9. package/dist/bundled/components/base/BaseIcon.vue2.js +1 -1
  10. package/dist/bundled/components/base/BaseOverflowMenu.vue2.js +4 -4
  11. package/dist/bundled/components/base/BaseSplitPane.vue.js +1 -1
  12. package/dist/bundled/components/base/BaseSplitPane.vue2.js +2 -3
  13. package/dist/bundled/components/panel/PaneTabs.vue2.js +1 -1
  14. package/dist/bundled/components/panel/StoryDocs.vue2.js +4 -4
  15. package/dist/bundled/components/panel/StorySourceCode.vue.js +1 -1
  16. package/dist/bundled/components/panel/StorySourceCode.vue2.js +1 -1
  17. package/dist/bundled/components/search/SearchItem.vue.js +1 -1
  18. package/dist/bundled/components/search/SearchItem.vue2.js +2 -2
  19. package/dist/bundled/components/search/SearchPane.vue2.js +2 -2
  20. package/dist/bundled/components/story/StoryResponsivePreview.vue.js +1 -1
  21. package/dist/bundled/components/story/StoryResponsivePreview.vue2.js +8 -7
  22. package/dist/bundled/components/story/StoryVariantGrid.vue2.js +4 -4
  23. package/dist/bundled/components/story/StoryVariantGridItem.vue.js +1 -1
  24. package/dist/bundled/components/story/StoryVariantGridItem.vue2.js +6 -7
  25. package/dist/bundled/components/story/StoryVariantListItem.vue.js +1 -1
  26. package/dist/bundled/components/story/StoryVariantListItem.vue2.js +3 -3
  27. package/dist/bundled/components/story/StoryVariantSingle.vue.js +1 -1
  28. package/dist/bundled/components/story/StoryVariantSingle.vue2.js +5 -5
  29. package/dist/bundled/components/story/StoryVariantSinglePreviewNative.vue2.js +1 -1
  30. package/dist/bundled/components/story/StoryVariantSinglePreviewRemote.vue2.js +1 -1
  31. package/dist/bundled/components/story/StoryView.vue2.js +1 -1
  32. package/dist/bundled/components/story/StoryViewer.vue.js +1 -1
  33. package/dist/bundled/components/story/StoryViewer.vue2.js +3 -3
  34. package/dist/bundled/components/tree/StoryGroup.vue2.js +2 -2
  35. package/dist/bundled/components/tree/StoryListFolder.vue.js +1 -1
  36. package/dist/bundled/components/tree/StoryListFolder.vue2.js +4 -4
  37. package/dist/bundled/components/tree/StoryListItem.vue.js +1 -1
  38. package/dist/bundled/components/tree/StoryListItem.vue2.js +5 -5
  39. package/dist/bundled/sandbox.js +1 -1
  40. package/dist/bundled/style.css +36 -36
  41. package/dist/bundled/util/commands.js +1 -1
  42. package/dist/bundled/util/state.js +2 -2
  43. package/dist/style.css +1 -1
  44. package/package.json +7 -7
  45. package/scripts/copy.mjs +1 -1
  46. package/scripts/watchAndCopy.mjs +4 -4
  47. package/src/app/App.vue +6 -6
  48. package/src/app/api.ts +1 -1
  49. package/src/app/components/HomeView.vue +4 -3
  50. package/src/app/components/app/AppHeader.vue +1 -1
  51. package/src/app/components/app/AppLogo.vue +3 -3
  52. package/src/app/components/app/Breadcrumb.vue +4 -4
  53. package/src/app/components/app/HomeCounter.vue +1 -10
  54. package/src/app/components/app/MobileOverlay.vue +1 -1
  55. package/src/app/components/base/BaseCheckbox.vue +2 -3
  56. package/src/app/components/base/BaseIcon.vue +2 -2
  57. package/src/app/components/base/BaseKeyboardShortcut.vue +1 -1
  58. package/src/app/components/base/BaseListItem.vue +2 -2
  59. package/src/app/components/base/BaseListItemLink.vue +3 -3
  60. package/src/app/components/base/BaseOverflowMenu.vue +4 -4
  61. package/src/app/components/base/BaseSelect.vue +5 -4
  62. package/src/app/components/base/BaseSplitPane.vue +19 -15
  63. package/src/app/components/command/CommandPrompts.vue +6 -5
  64. package/src/app/components/command/CommandPromptsModal.vue +2 -1
  65. package/src/app/components/command/PromptSelect.vue +6 -4
  66. package/src/app/components/command/PromptText.vue +4 -3
  67. package/src/app/components/panel/ControlsComponentPropItem.vue +1 -1
  68. package/src/app/components/panel/ControlsComponentProps.vue +1 -1
  69. package/src/app/components/panel/ControlsComponentState.vue +1 -1
  70. package/src/app/components/panel/PaneTabs.vue +1 -1
  71. package/src/app/components/panel/StatePresets.vue +13 -10
  72. package/src/app/components/panel/StoryControls.vue +2 -2
  73. package/src/app/components/panel/StoryDocs.vue +28 -24
  74. package/src/app/components/panel/StoryEvent.vue +2 -2
  75. package/src/app/components/panel/StoryEvents.vue +2 -2
  76. package/src/app/components/panel/StorySourceCode.vue +10 -6
  77. package/src/app/components/search/SearchItem.vue +4 -3
  78. package/src/app/components/search/SearchItemContent.vue +3 -3
  79. package/src/app/components/search/SearchModal.vue +2 -1
  80. package/src/app/components/search/SearchPane.vue +18 -18
  81. package/src/app/components/search/search-docs-data.ts +2 -2
  82. package/src/app/components/search/search-title-data.ts +2 -2
  83. package/src/app/components/story/GenericMountStory.vue +1 -1
  84. package/src/app/components/story/GenericRenderStory.vue +3 -2
  85. package/src/app/components/story/StoryResponsivePreview.vue +16 -14
  86. package/src/app/components/story/StoryVariantGrid.vue +9 -8
  87. package/src/app/components/story/StoryVariantGridItem.vue +7 -7
  88. package/src/app/components/story/StoryVariantListItem.vue +3 -2
  89. package/src/app/components/story/StoryVariantSingle.vue +3 -3
  90. package/src/app/components/story/StoryVariantSinglePreviewNative.vue +2 -2
  91. package/src/app/components/story/StoryVariantSinglePreviewRemote.vue +10 -10
  92. package/src/app/components/story/StoryView.vue +4 -4
  93. package/src/app/components/story/StoryViewer.vue +2 -3
  94. package/src/app/components/toolbar/ToolbarNewTab.vue +1 -1
  95. package/src/app/components/tree/StoryGroup.vue +4 -4
  96. package/src/app/components/tree/StoryList.vue +1 -1
  97. package/src/app/components/tree/StoryListFolder.vue +4 -4
  98. package/src/app/components/tree/StoryListItem.vue +3 -3
  99. package/src/app/index.ts +2 -3
  100. package/src/app/plugin.ts +4 -3
  101. package/src/app/router.ts +2 -2
  102. package/src/app/sandbox.ts +12 -11
  103. package/src/app/stores/command.ts +4 -3
  104. package/src/app/stores/events.ts +4 -4
  105. package/src/app/stores/folder.ts +9 -7
  106. package/src/app/stores/story.ts +4 -4
  107. package/src/app/types.ts +2 -2
  108. package/src/app/util/commands.ts +5 -4
  109. package/src/app/util/dark.ts +2 -2
  110. package/src/app/util/docs.ts +6 -4
  111. package/src/app/util/events.ts +4 -3
  112. package/src/app/util/keyboard.ts +9 -8
  113. package/src/app/util/mapping.ts +8 -5
  114. package/src/app/util/open-in-editor.ts +1 -1
  115. package/src/app/util/preview-settings.ts +3 -3
  116. package/src/app/util/sandbox.ts +2 -3
  117. package/src/app/util/scroll.ts +5 -4
  118. package/src/app/util/select.ts +5 -4
  119. package/src/app/util/state.ts +6 -5
  120. package/src/app/util/tooltip.ts +2 -2
  121. package/src/app/util/variant.ts +3 -2
  122. package/src/shim.d.ts +0 -6
  123. package/src/virtual.d.ts +1 -0
  124. package/tailwind.config.cjs +19 -20
  125. package/tsconfig.json +26 -26
  126. 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 (props.depth * 12) + 'px'
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
- // eslint-disable-next-line spaced-comment
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 (event: string, listener: (result: any) => unknown) {
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
- } else {
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, createWebHistory, createWebHashHistory } from 'vue-router'
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':
@@ -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 { files } from 'virtual:$histoire-stories'
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
- } else if (event.data?.type === PREVIEW_SETTINGS_SYNC) {
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
- } else {
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
- // eslint-disable-next-line spaced-comment
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 (command: ClientCommand) {
10
+ function activateCommand(command: ClientCommand) {
11
11
  selectedCommand.value = command
12
12
  if (command.prompts?.length) {
13
13
  showPromptsModal.value = true
14
- } else {
14
+ }
15
+ else {
15
16
  const params = command.getParams?.(getCommandContext()) ?? {}
16
17
  executeCommand(command, params)
17
18
  }
@@ -1,8 +1,8 @@
1
1
  import { defineStore } from 'pinia'
2
- import { ref, reactive, watch } from 'vue'
2
+ import { reactive, ref, watch } from 'vue'
3
3
  import { useStoryStore } from './story.js'
4
4
 
5
- export type HstEvent = {
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 (event: HstEvent) {
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
  }
@@ -9,30 +9,32 @@ export const useFolderStore = defineStore('folder', () => {
9
9
  new Map(),
10
10
  )
11
11
 
12
- function getStringPath (path: Array<string>) {
12
+ function getStringPath(path: Array<string>) {
13
13
  return path.join('␜')
14
14
  }
15
15
 
16
- function toggleFolder (path: Array<string>, defaultToggleValue = true) {
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
- } else if (currentValue) {
23
+ }
24
+ else if (currentValue) {
24
25
  setFolderOpen(stringPath, false)
25
- } else {
26
+ }
27
+ else {
26
28
  setFolderOpen(stringPath, true)
27
29
  }
28
30
  }
29
31
 
30
- function setFolderOpen (path: Array<string> | string, value: boolean) {
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 (path: Array<string>, defaultValue = false) {
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 (path: Array<string>) {
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
  }
@@ -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 (value: Story[]) {
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 (id: string) {
31
+ function getStoryById(id: string) {
32
32
  return maps.value.stories.get(id)
33
33
  }
34
34
 
35
- function getVariantById (idWithStoryId: string) {
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 type TreeLeaf = {
10
+ export interface TreeLeaf {
11
11
  title: string
12
12
  index: number
13
13
  }
14
14
 
15
- export type TreeFolder = {
15
+ export interface TreeFolder {
16
16
  title: string
17
17
  children: (TreeFolder | TreeLeaf)[]
18
18
  }
@@ -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
- } else {
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 (command: ClientCommand, params: Record<string, any>) {
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 (): ClientCommandContext {
50
+ export function getCommandContext(): ClientCommandContext {
50
51
  const storyStore = useStoryStore()
51
52
  return {
52
53
  route: router.currentRoute.value,
@@ -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
  }
@@ -1,16 +1,18 @@
1
1
  import { unindent } from '@histoire/shared'
2
2
  import { clientSupportPlugins } from 'virtual:$histoire-support-plugins-client'
3
- import type { Variant, Story } from '../types'
3
+ import type { Story, Variant } from '../types'
4
4
 
5
- export async function getSourceCode (story: Story, variant: Variant) {
5
+ export async function getSourceCode(story: Story, variant: Variant) {
6
6
  if (variant.source) {
7
7
  return variant.source
8
- } else if (variant.slots?.().source) {
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
- } else {
14
+ }
15
+ else {
14
16
  const clientPlugin = clientSupportPlugins[story.file?.supportPluginId]
15
17
  if (clientPlugin) {
16
18
  const pluginModule = await clientPlugin()
@@ -1,6 +1,6 @@
1
1
  import { EVENT_SEND } from './const'
2
2
 
3
- export async function logEvent (name: string, argument) {
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
- } else {
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 (e) {
21
+ function stringifyEvent(e) {
21
22
  const obj = {}
22
23
  for (const k in e) {
23
24
  obj[k] = e[k]
@@ -1,5 +1,6 @@
1
1
  import { useEventListener } from '@vueuse/core'
2
- import { isRef, Ref } from 'vue'
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 (shortcut: KeyboardShortcut | Ref<KeyboardShortcut>, handler: KeyboardHandler, options: KeyboardShortcutOptions = {}) {
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 (shortcut: KeyboardShortcut): boolean {
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 (combination: string): boolean {
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 (key: string) {
85
+ export function formatKey(key: string) {
85
86
  key = key.toLowerCase()
86
87
  if (key === 'ctrl') {
87
88
  return isMac ? '^' : 'Ctrl'
@@ -12,7 +12,7 @@ const copiedFromExistingVariant = [
12
12
  'previewReady',
13
13
  ]
14
14
 
15
- export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
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
- } else if (key !== 'component') {
29
+ }
30
+ else if (key !== 'component') {
30
31
  result[key] = file[key]
31
32
  }
32
33
  }
33
- } else {
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 (variant: Variant, existingVariant?: Variant): Variant {
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
- } else {
64
+ }
65
+ else {
63
66
  // Create
64
67
  result = {
65
68
  ...variant,
@@ -1,3 +1,3 @@
1
- export function openInEditor (file: string) {
1
+ export function openInEditor(file: string) {
2
2
  return fetch(`${import.meta.env.BASE_URL}__open-in-editor?file=${encodeURIComponent(file)}`)
3
3
  }
@@ -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 (settings: PreviewSettings) {
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 (setting: PreviewSettings) {
21
+ export function getContrastColor(setting: PreviewSettings) {
22
22
  return histoireConfig.backgroundPresets.find(preset => preset.color === setting.backgroundColor)?.contrastColor ?? 'unset'
23
23
  }
@@ -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 (story: Story, variant: Variant) {
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)
@@ -1,14 +1,15 @@
1
- import { watch, onMounted, Ref } from 'vue'
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 (active: Ref<boolean>, el: Ref<HTMLElement>) {
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',
@@ -1,20 +1,21 @@
1
- import { Ref, ref, watch, computed } from 'vue'
1
+ import type { Ref } from 'vue'
2
+ import { computed, ref, watch } from 'vue'
2
3
 
3
- export function useSelection (list: Ref<any[]>) {
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
@@ -1,8 +1,8 @@
1
- import { unref, isRef } from 'vue'
1
+ import { isRef, unref } from 'vue'
2
2
 
3
- const isObject = (val) => val !== null && typeof val === 'object'
3
+ const isObject = val => val !== null && typeof val === 'object'
4
4
 
5
- export function toRawDeep (val, clean = false, seen = new WeakMap()) {
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
- } else {
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
- const toRawObject = (obj: Record<any, any>, target: Record<any, any>, clean = false, seen = new WeakMap()) => {
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
@@ -1,13 +1,13 @@
1
1
  import { isMac } from './env.js'
2
2
  import { formatKey } from './keyboard.js'
3
3
 
4
- export function makeTooltip (descriptionHtml: string, keyboardShortcut: (options: { isMac: boolean }) => string) {
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 (shortcut: string) {
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
  }
@@ -1,8 +1,9 @@
1
- import { computed, Ref } from 'vue'
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 (variant: Ref<Variant>) {
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
@@ -2,12 +2,6 @@
2
2
 
3
3
  import type { Ref } from '@histoire/vendors/vue'
4
4
 
5
- declare module '*.vue' {
6
- import { ComponentOptions } from 'vue'
7
- const comp: ComponentOptions
8
- export default comp
9
- }
10
-
11
5
  global {
12
6
  interface Window {
13
7
  __hst_controls_dark: Ref<boolean>[]