@ohos-ports/histoire-app 1.0.0-beta.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.
Files changed (309) hide show
  1. package/LICENSE +21 -0
  2. package/dist/app/assets/histoire-text-dark.svg +89 -0
  3. package/dist/app/assets/histoire-text.svg +89 -0
  4. package/dist/app/assets/histoire.svg +51 -0
  5. package/dist/app/style/floating.pcss +34 -0
  6. package/dist/app/style/main.pcss +100 -0
  7. package/dist/app/style/sandbox.css +24 -0
  8. package/dist/app/style/transitions.pcss +51 -0
  9. package/dist/bundle-index.js +3 -0
  10. package/dist/bundle-main-dev.js +4 -0
  11. package/dist/bundle-main.js +5 -0
  12. package/dist/bundle-sandbox-dev.js +2 -0
  13. package/dist/bundle-sandbox.js +2 -0
  14. package/dist/bundled/App.vue.js +5 -0
  15. package/dist/bundled/App.vue2.js +167 -0
  16. package/dist/bundled/_virtual/_node-dom-env.js +188 -0
  17. package/dist/bundled/_virtual/_node-dom-polyfill.js +152 -0
  18. package/dist/bundled/_virtual/_plugin-vue_export-helper.js +10 -0
  19. package/dist/bundled/_virtual/histoire-commands.js +8 -0
  20. package/dist/bundled/_virtual/histoire-config.js +42 -0
  21. package/dist/bundled/_virtual/histoire-markdown-files.js +8 -0
  22. package/dist/bundled/_virtual/histoire-search-docs-data.js +11 -0
  23. package/dist/bundled/_virtual/histoire-search-title-data.js +11 -0
  24. package/dist/bundled/_virtual/histoire-stories.js +17 -0
  25. package/dist/bundled/_virtual/histoire-support-plugins-client.js +8 -0
  26. package/dist/bundled/_virtual/histoire-theme.js +8 -0
  27. package/dist/bundled/api.js +12 -0
  28. package/dist/bundled/app.css +116 -0
  29. package/dist/bundled/assets/histoire-text-dark.svg.js +4 -0
  30. package/dist/bundled/assets/histoire-text.svg.js +4 -0
  31. package/dist/bundled/assets/histoire.svg.js +4 -0
  32. package/dist/bundled/components/HomeView.vue.js +5 -0
  33. package/dist/bundled/components/HomeView.vue2.js +66 -0
  34. package/dist/bundled/components/app/AppHeader.vue.js +5 -0
  35. package/dist/bundled/components/app/AppHeader.vue2.js +71 -0
  36. package/dist/bundled/components/app/AppLogo.vue.js +5 -0
  37. package/dist/bundled/components/app/AppLogo.vue2.js +29 -0
  38. package/dist/bundled/components/app/Breadcrumb.vue.js +8 -0
  39. package/dist/bundled/components/app/Breadcrumb.vue2.js +91 -0
  40. package/dist/bundled/components/app/HomeCounter.vue.js +5 -0
  41. package/dist/bundled/components/app/HomeCounter.vue2.js +42 -0
  42. package/dist/bundled/components/app/InitialLoading.vue.js +5 -0
  43. package/dist/bundled/components/app/InitialLoading.vue2.js +51 -0
  44. package/dist/bundled/components/app/MobileOverlay.vue.js +5 -0
  45. package/dist/bundled/components/app/MobileOverlay.vue2.js +45 -0
  46. package/dist/bundled/components/base/BaseButton.vue.js +5 -0
  47. package/dist/bundled/components/base/BaseButton.vue2.js +39 -0
  48. package/dist/bundled/components/base/BaseCheckbox.vue.js +5 -0
  49. package/dist/bundled/components/base/BaseCheckbox.vue2.js +78 -0
  50. package/dist/bundled/components/base/BaseEmpty.vue.js +14 -0
  51. package/dist/bundled/components/base/BaseIcon.vue.js +8 -0
  52. package/dist/bundled/components/base/BaseIcon.vue2.js +29 -0
  53. package/dist/bundled/components/base/BaseKeyboardShortcut.vue.js +5 -0
  54. package/dist/bundled/components/base/BaseKeyboardShortcut.vue2.js +20 -0
  55. package/dist/bundled/components/base/BaseListItem.vue.js +5 -0
  56. package/dist/bundled/components/base/BaseListItem.vue2.js +33 -0
  57. package/dist/bundled/components/base/BaseListItemLink.vue.js +33 -0
  58. package/dist/bundled/components/base/BaseListItemLink.vue2.js +26 -0
  59. package/dist/bundled/components/base/BaseOverflowMenu.vue.js +5 -0
  60. package/dist/bundled/components/base/BaseOverflowMenu.vue2.js +100 -0
  61. package/dist/bundled/components/base/BaseOverflowTab.vue.js +36 -0
  62. package/dist/bundled/components/base/BaseOverflowTab.vue2.js +18 -0
  63. package/dist/bundled/components/base/BaseSelect.vue.js +5 -0
  64. package/dist/bundled/components/base/BaseSelect.vue2.js +77 -0
  65. package/dist/bundled/components/base/BaseSplitPane.vue.js +8 -0
  66. package/dist/bundled/components/base/BaseSplitPane.vue2.js +183 -0
  67. package/dist/bundled/components/base/BaseTab.vue.js +36 -0
  68. package/dist/bundled/components/base/BaseTab.vue2.js +18 -0
  69. package/dist/bundled/components/base/BaseTag.vue.js +13 -0
  70. package/dist/bundled/components/command/CommandPrompts.vue.js +5 -0
  71. package/dist/bundled/components/command/CommandPrompts.vue2.js +91 -0
  72. package/dist/bundled/components/command/CommandPromptsModal.vue.js +5 -0
  73. package/dist/bundled/components/command/CommandPromptsModal.vue2.js +45 -0
  74. package/dist/bundled/components/command/PromptSelect.vue.js +5 -0
  75. package/dist/bundled/components/command/PromptSelect.vue2.js +142 -0
  76. package/dist/bundled/components/command/PromptText.vue.js +5 -0
  77. package/dist/bundled/components/command/PromptText.vue2.js +67 -0
  78. package/dist/bundled/components/misc/CheckerboardPattern.vue.js +40 -0
  79. package/dist/bundled/components/misc/HatchedPattern.vue.js +12 -0
  80. package/dist/bundled/components/panel/ControlsComponentPropItem.vue.js +5 -0
  81. package/dist/bundled/components/panel/ControlsComponentPropItem.vue2.js +72 -0
  82. package/dist/bundled/components/panel/ControlsComponentProps.vue.js +5 -0
  83. package/dist/bundled/components/panel/ControlsComponentProps.vue2.js +45 -0
  84. package/dist/bundled/components/panel/ControlsComponentState.vue.js +5 -0
  85. package/dist/bundled/components/panel/ControlsComponentState.vue2.js +41 -0
  86. package/dist/bundled/components/panel/ControlsComponentStateItem.vue.js +5 -0
  87. package/dist/bundled/components/panel/ControlsComponentStateItem.vue2.js +46 -0
  88. package/dist/bundled/components/panel/PaneTabs.vue.js +5 -0
  89. package/dist/bundled/components/panel/PaneTabs.vue2.js +114 -0
  90. package/dist/bundled/components/panel/StatePresets.vue.js +5 -0
  91. package/dist/bundled/components/panel/StatePresets.vue2.js +193 -0
  92. package/dist/bundled/components/panel/StoryControls.vue.js +5 -0
  93. package/dist/bundled/components/panel/StoryControls.vue2.js +87 -0
  94. package/dist/bundled/components/panel/StoryDocs.vue.js +7 -0
  95. package/dist/bundled/components/panel/StoryDocs.vue2.js +161 -0
  96. package/dist/bundled/components/panel/StoryEvent.vue.js +5 -0
  97. package/dist/bundled/components/panel/StoryEvent.vue2.js +59 -0
  98. package/dist/bundled/components/panel/StoryEvents.vue.js +5 -0
  99. package/dist/bundled/components/panel/StoryEvents.vue2.js +53 -0
  100. package/dist/bundled/components/panel/StorySidePanel.vue.js +5 -0
  101. package/dist/bundled/components/panel/StorySidePanel.vue2.js +83 -0
  102. package/dist/bundled/components/panel/StorySourceCode.vue.js +8 -0
  103. package/dist/bundled/components/panel/StorySourceCode.vue2.js +204 -0
  104. package/dist/bundled/components/search/SearchItem.vue.js +8 -0
  105. package/dist/bundled/components/search/SearchItem.vue2.js +93 -0
  106. package/dist/bundled/components/search/SearchItemContent.vue.js +5 -0
  107. package/dist/bundled/components/search/SearchItemContent.vue2.js +71 -0
  108. package/dist/bundled/components/search/SearchLoading.vue.js +5 -0
  109. package/dist/bundled/components/search/SearchLoading.vue2.js +21 -0
  110. package/dist/bundled/components/search/SearchModal.vue.js +5 -0
  111. package/dist/bundled/components/search/SearchModal.vue2.js +51 -0
  112. package/dist/bundled/components/search/SearchPane.vue.js +5 -0
  113. package/dist/bundled/components/search/SearchPane.vue2.js +272 -0
  114. package/dist/bundled/components/search/search-docs-data.js +11 -0
  115. package/dist/bundled/components/search/search-title-data.js +11 -0
  116. package/dist/bundled/components/story/GenericMountStory.vue.js +5 -0
  117. package/dist/bundled/components/story/GenericMountStory.vue2.js +34 -0
  118. package/dist/bundled/components/story/GenericRenderStory.vue.js +5 -0
  119. package/dist/bundled/components/story/GenericRenderStory.vue2.js +39 -0
  120. package/dist/bundled/components/story/StoryResponsivePreview.vue.js +8 -0
  121. package/dist/bundled/components/story/StoryResponsivePreview.vue2.js +207 -0
  122. package/dist/bundled/components/story/StoryVariantGrid.vue.js +5 -0
  123. package/dist/bundled/components/story/StoryVariantGrid.vue2.js +146 -0
  124. package/dist/bundled/components/story/StoryVariantGridItem.vue.js +8 -0
  125. package/dist/bundled/components/story/StoryVariantGridItem.vue2.js +153 -0
  126. package/dist/bundled/components/story/StoryVariantListItem.vue.js +8 -0
  127. package/dist/bundled/components/story/StoryVariantListItem.vue2.js +55 -0
  128. package/dist/bundled/components/story/StoryVariantSingle.vue.js +8 -0
  129. package/dist/bundled/components/story/StoryVariantSingle.vue2.js +107 -0
  130. package/dist/bundled/components/story/StoryVariantSinglePreviewNative.vue.js +5 -0
  131. package/dist/bundled/components/story/StoryVariantSinglePreviewNative.vue2.js +70 -0
  132. package/dist/bundled/components/story/StoryVariantSinglePreviewRemote.vue.js +5 -0
  133. package/dist/bundled/components/story/StoryVariantSinglePreviewRemote.vue2.js +128 -0
  134. package/dist/bundled/components/story/StoryVariantSingleView.vue.js +5 -0
  135. package/dist/bundled/components/story/StoryVariantSingleView.vue2.js +66 -0
  136. package/dist/bundled/components/story/StoryView.vue.js +5 -0
  137. package/dist/bundled/components/story/StoryView.vue2.js +104 -0
  138. package/dist/bundled/components/story/StoryViewer.vue.js +8 -0
  139. package/dist/bundled/components/story/StoryViewer.vue2.js +55 -0
  140. package/dist/bundled/components/toolbar/DevOnlyToolbarOpenInEditor.vue.js +5 -0
  141. package/dist/bundled/components/toolbar/DevOnlyToolbarOpenInEditor.vue2.js +31 -0
  142. package/dist/bundled/components/toolbar/ToolbarBackground.vue.js +8 -0
  143. package/dist/bundled/components/toolbar/ToolbarBackground.vue2.js +98 -0
  144. package/dist/bundled/components/toolbar/ToolbarNewTab.vue.js +5 -0
  145. package/dist/bundled/components/toolbar/ToolbarNewTab.vue2.js +36 -0
  146. package/dist/bundled/components/toolbar/ToolbarResponsiveSize.vue.js +5 -0
  147. package/dist/bundled/components/toolbar/ToolbarResponsiveSize.vue2.js +127 -0
  148. package/dist/bundled/components/toolbar/ToolbarTextDirection.vue.js +5 -0
  149. package/dist/bundled/components/toolbar/ToolbarTextDirection.vue2.js +27 -0
  150. package/dist/bundled/components/toolbar/ToolbarTitle.vue.js +5 -0
  151. package/dist/bundled/components/toolbar/ToolbarTitle.vue2.js +26 -0
  152. package/dist/bundled/components/tree/StoryGroup.vue.js +5 -0
  153. package/dist/bundled/components/tree/StoryGroup.vue2.js +74 -0
  154. package/dist/bundled/components/tree/StoryList.vue.js +5 -0
  155. package/dist/bundled/components/tree/StoryList.vue2.js +41 -0
  156. package/dist/bundled/components/tree/StoryListFolder.vue.js +8 -0
  157. package/dist/bundled/components/tree/StoryListFolder.vue2.js +86 -0
  158. package/dist/bundled/components/tree/StoryListItem.vue.js +8 -0
  159. package/dist/bundled/components/tree/StoryListItem.vue2.js +69 -0
  160. package/dist/bundled/index.js +36 -0
  161. package/dist/bundled/plugin.js +49 -0
  162. package/dist/bundled/router.js +32 -0
  163. package/dist/bundled/sandbox.js +87 -0
  164. package/dist/bundled/stores/command.js +25 -0
  165. package/dist/bundled/stores/events.js +29 -0
  166. package/dist/bundled/stores/folder.js +54 -0
  167. package/dist/bundled/stores/preview-settings.js +19 -0
  168. package/dist/bundled/stores/story.js +43 -0
  169. package/dist/bundled/util/commands.js +57 -0
  170. package/dist/bundled/util/config.js +8 -0
  171. package/dist/bundled/util/const.js +10 -0
  172. package/dist/bundled/util/dark.js +28 -0
  173. package/dist/bundled/util/docs.js +26 -0
  174. package/dist/bundled/util/env.js +4 -0
  175. package/dist/bundled/util/events.js +33 -0
  176. package/dist/bundled/util/keyboard.js +90 -0
  177. package/dist/bundled/util/mapping.js +70 -0
  178. package/dist/bundled/util/open-in-editor.js +7 -0
  179. package/dist/bundled/util/preview-settings.js +21 -0
  180. package/dist/bundled/util/responsive.js +6 -0
  181. package/dist/bundled/util/sandbox.js +11 -0
  182. package/dist/bundled/util/scroll.js +31 -0
  183. package/dist/bundled/util/select.js +28 -0
  184. package/dist/bundled/util/state.js +41 -0
  185. package/dist/bundled/util/tooltip.js +15 -0
  186. package/dist/bundled/util/variant.js +21 -0
  187. package/dist/style.css +2853 -0
  188. package/package.json +62 -0
  189. package/postcss-scope-wrapper.cjs +35 -0
  190. package/postcss.config.cjs +9 -0
  191. package/scripts/copy.mjs +12 -0
  192. package/scripts/watchAndCopy.mjs +15 -0
  193. package/src/app/App.vue +172 -0
  194. package/src/app/api.ts +9 -0
  195. package/src/app/assets/histoire-text-dark.svg +89 -0
  196. package/src/app/assets/histoire-text.svg +89 -0
  197. package/src/app/assets/histoire.svg +51 -0
  198. package/src/app/components/HomeView.vue +61 -0
  199. package/src/app/components/app/AppHeader.vue +65 -0
  200. package/src/app/components/app/AppLogo.vue +25 -0
  201. package/src/app/components/app/Breadcrumb.vue +98 -0
  202. package/src/app/components/app/HomeCounter.vue +39 -0
  203. package/src/app/components/app/InitialLoading.vue +44 -0
  204. package/src/app/components/app/MobileOverlay.vue +33 -0
  205. package/src/app/components/base/BaseButton.vue +33 -0
  206. package/src/app/components/base/BaseCheckbox.vue +76 -0
  207. package/src/app/components/base/BaseCopyIcon.vue +34 -0
  208. package/src/app/components/base/BaseEmpty.vue +21 -0
  209. package/src/app/components/base/BaseIcon.vue +31 -0
  210. package/src/app/components/base/BaseKeyboardShortcut.vue +16 -0
  211. package/src/app/components/base/BaseListItem.vue +30 -0
  212. package/src/app/components/base/BaseListItemLink.vue +56 -0
  213. package/src/app/components/base/BaseOverflowMenu.vue +119 -0
  214. package/src/app/components/base/BaseOverflowTab.vue +47 -0
  215. package/src/app/components/base/BaseSelect.vue +75 -0
  216. package/src/app/components/base/BaseSplitPane.vue +244 -0
  217. package/src/app/components/base/BaseTab.vue +47 -0
  218. package/src/app/components/base/BaseTag.vue +5 -0
  219. package/src/app/components/command/CommandPrompts.vue +95 -0
  220. package/src/app/components/command/CommandPromptsModal.vue +41 -0
  221. package/src/app/components/command/PromptSelect.vue +142 -0
  222. package/src/app/components/command/PromptText.vue +65 -0
  223. package/src/app/components/misc/CheckerboardPattern.vue +32 -0
  224. package/src/app/components/misc/HatchedPattern.vue +13 -0
  225. package/src/app/components/panel/ControlsComponentPropItem.vue +73 -0
  226. package/src/app/components/panel/ControlsComponentProps.vue +34 -0
  227. package/src/app/components/panel/ControlsComponentState.vue +38 -0
  228. package/src/app/components/panel/ControlsComponentStateItem.vue +44 -0
  229. package/src/app/components/panel/PaneTabs.vue +84 -0
  230. package/src/app/components/panel/StatePresets.vue +199 -0
  231. package/src/app/components/panel/StoryControls.vue +97 -0
  232. package/src/app/components/panel/StoryDocs.vue +202 -0
  233. package/src/app/components/panel/StoryEvent.vue +54 -0
  234. package/src/app/components/panel/StoryEvents.vue +48 -0
  235. package/src/app/components/panel/StorySidePanel.vue +76 -0
  236. package/src/app/components/panel/StorySourceCode.vue +248 -0
  237. package/src/app/components/search/SearchItem.vue +89 -0
  238. package/src/app/components/search/SearchItemContent.vue +67 -0
  239. package/src/app/components/search/SearchLoading.vue +16 -0
  240. package/src/app/components/search/SearchModal.vue +44 -0
  241. package/src/app/components/search/SearchPane.vue +319 -0
  242. package/src/app/components/search/search-docs-data.ts +9 -0
  243. package/src/app/components/search/search-title-data.ts +9 -0
  244. package/src/app/components/search/types.ts +4 -0
  245. package/src/app/components/story/GenericMountStory.vue +35 -0
  246. package/src/app/components/story/GenericRenderStory.vue +41 -0
  247. package/src/app/components/story/StoryResponsivePreview.vue +216 -0
  248. package/src/app/components/story/StoryVariantGrid.vue +169 -0
  249. package/src/app/components/story/StoryVariantGridItem.vue +163 -0
  250. package/src/app/components/story/StoryVariantListItem.vue +52 -0
  251. package/src/app/components/story/StoryVariantSingle.vue +105 -0
  252. package/src/app/components/story/StoryVariantSinglePreviewNative.vue +66 -0
  253. package/src/app/components/story/StoryVariantSinglePreviewRemote.vue +143 -0
  254. package/src/app/components/story/StoryVariantSingleView.vue +61 -0
  255. package/src/app/components/story/StoryView.vue +110 -0
  256. package/src/app/components/story/StoryViewer.vue +52 -0
  257. package/src/app/components/toolbar/DevOnlyToolbarOpenInEditor.vue +23 -0
  258. package/src/app/components/toolbar/ToolbarBackground.vue +81 -0
  259. package/src/app/components/toolbar/ToolbarNewTab.vue +29 -0
  260. package/src/app/components/toolbar/ToolbarResponsiveSize.vue +82 -0
  261. package/src/app/components/toolbar/ToolbarTextDirection.vue +19 -0
  262. package/src/app/components/toolbar/ToolbarTitle.vue +21 -0
  263. package/src/app/components/tree/StoryGroup.vue +73 -0
  264. package/src/app/components/tree/StoryList.vue +35 -0
  265. package/src/app/components/tree/StoryListFolder.vue +88 -0
  266. package/src/app/components/tree/StoryListItem.vue +72 -0
  267. package/src/app/index.ts +33 -0
  268. package/src/app/plugin.ts +59 -0
  269. package/src/app/router.ts +29 -0
  270. package/src/app/sandbox.ts +101 -0
  271. package/src/app/stores/command.ts +26 -0
  272. package/src/app/stores/events.ts +36 -0
  273. package/src/app/stores/folder.ts +63 -0
  274. package/src/app/stores/preview-settings.ts +18 -0
  275. package/src/app/stores/story.ts +47 -0
  276. package/src/app/style/floating.pcss +34 -0
  277. package/src/app/style/main.pcss +100 -0
  278. package/src/app/style/sandbox.css +24 -0
  279. package/src/app/style/transitions.pcss +51 -0
  280. package/src/app/types.ts +72 -0
  281. package/src/app/util/commands.ts +57 -0
  282. package/src/app/util/config.ts +5 -0
  283. package/src/app/util/const.ts +4 -0
  284. package/src/app/util/dark.ts +27 -0
  285. package/src/app/util/docs.ts +27 -0
  286. package/src/app/util/env.ts +1 -0
  287. package/src/app/util/events.ts +31 -0
  288. package/src/app/util/keyboard.ts +103 -0
  289. package/src/app/util/mapping.ts +80 -0
  290. package/src/app/util/open-in-editor.ts +3 -0
  291. package/src/app/util/preview-settings.ts +23 -0
  292. package/src/app/util/responsive.ts +3 -0
  293. package/src/app/util/sandbox.ts +9 -0
  294. package/src/app/util/scroll.ts +32 -0
  295. package/src/app/util/select.ts +30 -0
  296. package/src/app/util/state.ts +45 -0
  297. package/src/app/util/tooltip.ts +13 -0
  298. package/src/app/util/variant.ts +21 -0
  299. package/src/bundle-index.js +1 -0
  300. package/src/bundle-main-dev.js +4 -0
  301. package/src/bundle-main.js +5 -0
  302. package/src/bundle-sandbox-dev.js +2 -0
  303. package/src/bundle-sandbox.js +2 -0
  304. package/src/index.ts +1 -0
  305. package/src/shim.d.ts +10 -0
  306. package/src/virtual.d.ts +7 -0
  307. package/tailwind.config.cjs +137 -0
  308. package/tsconfig.json +53 -0
  309. package/vite.config.ts +88 -0
@@ -0,0 +1,72 @@
1
+ import type { RouteLocationRaw } from 'vue-router'
2
+
3
+ export type {
4
+ Story,
5
+ StoryFile,
6
+ StoryLayout,
7
+ Variant,
8
+ } from '@histoire/shared'
9
+
10
+ export interface TreeLeaf {
11
+ title: string
12
+ index: number
13
+ }
14
+
15
+ export interface TreeFolder {
16
+ title: string
17
+ children: (TreeFolder | TreeLeaf)[]
18
+ }
19
+
20
+ export interface TreeGroup {
21
+ group: true
22
+ id: string
23
+ title: string
24
+ children: (TreeFolder | TreeLeaf)[]
25
+ }
26
+
27
+ export type Tree = (TreeGroup | TreeFolder | TreeLeaf)[]
28
+
29
+ export type SearchResultType = 'title' | 'docs'
30
+
31
+ export interface SearchResultBase {
32
+ kind: 'story' | 'variant' | 'command'
33
+ rank: number
34
+ id: string
35
+ title: string
36
+ path?: string[]
37
+ icon?: string
38
+ iconColor?: string
39
+ type?: SearchResultType
40
+ }
41
+
42
+ export type SearchResult = SearchResultBase & ({
43
+ route: RouteLocationRaw
44
+ } | {
45
+ onActivate: () => unknown
46
+ })
47
+
48
+ export interface PreviewSettings {
49
+ responsiveWidth: number
50
+ responsiveHeight: number
51
+ rotate: boolean
52
+ backgroundColor: string
53
+ checkerboard: boolean
54
+ textDirection: 'ltr' | 'rtl'
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,57 @@
1
+ import type { ClientCommand, ClientCommandContext } from '@histoire/shared'
2
+ import { router } from '../router.js'
3
+ import { useStoryStore } from '../stores/story.js'
4
+ import { openInEditor } from './open-in-editor.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
+ }
18
+ else {
19
+ file = story.file?.filePath
20
+ }
21
+ return {
22
+ file,
23
+ }
24
+ },
25
+ clientAction: ({ file }) => {
26
+ openInEditor(file)
27
+ },
28
+ },
29
+ {
30
+ id: 'builtin:histoire-docs',
31
+ label: 'Open Histoire Documentation',
32
+ icon: 'carbon:help',
33
+ clientAction: () => {
34
+ window.open('https://histoire.dev/guide/getting-started.html', '_blank')
35
+ },
36
+ },
37
+ ]
38
+
39
+ export function executeCommand(command: ClientCommand, params: Record<string, any>) {
40
+ if (import.meta.hot) {
41
+ import.meta.hot.send('histoire:dev-command', {
42
+ id: command.id,
43
+ params,
44
+ })
45
+
46
+ command.clientAction?.(params, getCommandContext())
47
+ }
48
+ }
49
+
50
+ export function getCommandContext(): ClientCommandContext {
51
+ const storyStore = useStoryStore()
52
+ return {
53
+ route: router.currentRoute.value,
54
+ currentStory: storyStore.currentStory,
55
+ currentVariant: storyStore.currentVariant,
56
+ }
57
+ }
@@ -0,0 +1,5 @@
1
+ import type { HistoireConfig } from '@histoire/shared'
2
+ import { config as configRaw, logos as logosRaw } from 'virtual:$histoire-config'
3
+
4
+ export const histoireConfig: HistoireConfig = configRaw
5
+ export const customLogos: HistoireConfig['theme']['logo'] = logosRaw
@@ -0,0 +1,4 @@
1
+ export const STATE_SYNC = '__histoire:state-sync'
2
+ export const SANDBOX_READY = '__histoire:sandbox-ready'
3
+ export const EVENT_SEND = '__histoire:event'
4
+ export const PREVIEW_SETTINGS_SYNC = '__histoire:preview-settings-sync'
@@ -0,0 +1,27 @@
1
+ import { useDark, useToggle } from '@vueuse/core'
2
+ import { watch } from 'vue'
3
+ import { histoireConfig } from './config.js'
4
+
5
+ export const isDark = useDark({
6
+ valueDark: 'htw-dark',
7
+ initialValue: histoireConfig.theme.defaultColorScheme,
8
+ storageKey: 'histoire-color-scheme',
9
+ storage: histoireConfig.theme.storeColorScheme ? localStorage : sessionStorage,
10
+ })
11
+ export const toggleDark = useToggle(isDark)
12
+
13
+ function applyDarkToControls() {
14
+ window.__hst_controls_dark?.forEach((ref) => {
15
+ ref.value = isDark.value
16
+ })
17
+ }
18
+
19
+ watch(isDark, () => {
20
+ applyDarkToControls()
21
+ }, {
22
+ immediate: true,
23
+ })
24
+
25
+ window.__hst_controls_dark_ready = () => {
26
+ applyDarkToControls()
27
+ }
@@ -0,0 +1,27 @@
1
+ import type { Story, Variant } from '../types'
2
+ import { unindent } from '@histoire/shared'
3
+ import { clientSupportPlugins } from 'virtual:$histoire-support-plugins-client'
4
+
5
+ export async function getSourceCode(story: Story, variant: Variant) {
6
+ if (variant.source) {
7
+ return variant.source
8
+ }
9
+ else if (variant.slots?.().source) {
10
+ const source = variant.slots?.().source()[0].children
11
+ if (source) {
12
+ return unindent(source)
13
+ }
14
+ }
15
+ else {
16
+ const clientPlugin = clientSupportPlugins[story.file?.supportPluginId]
17
+ if (clientPlugin) {
18
+ const pluginModule = await clientPlugin()
19
+ return pluginModule.generateSourceCode(variant)
20
+ }
21
+ }
22
+
23
+ const sourceLoader = story.file?.source
24
+ if (sourceLoader) {
25
+ return (await sourceLoader()).default
26
+ }
27
+ }
@@ -0,0 +1 @@
1
+ export const isMac = navigator.platform.toLowerCase().includes('mac')
@@ -0,0 +1,31 @@
1
+ import { EVENT_SEND } from './const'
2
+
3
+ export async function logEvent(name: string, argument) {
4
+ console.log('[histoire] Event fired', { name, argument })
5
+ const event = {
6
+ name,
7
+ argument: JSON.parse(stringifyEvent(argument)), // Needed for HTMLEvent that can't be cloned
8
+ }
9
+ if (location.href.includes('__sandbox')) {
10
+ window.parent?.postMessage({
11
+ type: EVENT_SEND,
12
+ event,
13
+ })
14
+ }
15
+ else {
16
+ const { useEventsStore } = await import('../stores/events.js')
17
+ useEventsStore().addEvent(event)
18
+ }
19
+ }
20
+
21
+ function stringifyEvent(e) {
22
+ const obj = {}
23
+ for (const k in e) {
24
+ obj[k] = e[k]
25
+ }
26
+ return JSON.stringify(obj, (k, v) => {
27
+ if (v instanceof Node) return 'Node'
28
+ if (v instanceof Window) return 'Window'
29
+ return v
30
+ }, ' ')
31
+ }
@@ -0,0 +1,103 @@
1
+ import type { Ref } from 'vue'
2
+ import { useEventListener } from '@vueuse/core'
3
+ import { isRef } from 'vue'
4
+ import { isMac } from './env.js'
5
+
6
+ export type KeyboardShortcut = string[]
7
+
8
+ export type KeyboardHandler = (event: KeyboardEvent) => unknown
9
+
10
+ export interface KeyboardShortcutOptions {
11
+ event?: 'keyup' | 'keydown' | 'keypress'
12
+ }
13
+
14
+ export function onKeyboardShortcut(shortcut: KeyboardShortcut | Ref<KeyboardShortcut>, handler: KeyboardHandler, options: KeyboardShortcutOptions = {}) {
15
+ useEventListener(options.event ?? 'keydown', (event) => {
16
+ if (isMatchingShortcut(isRef(shortcut) ? shortcut.value : shortcut)) {
17
+ handler(event)
18
+ }
19
+ })
20
+ }
21
+
22
+ const modifiers: { [i: string]: { key: string, pressed: boolean } } = {
23
+ ctrl: { key: 'Control', pressed: false },
24
+ alt: { key: 'Alt', pressed: false },
25
+ shift: { key: 'Shift', pressed: false },
26
+ meta: { key: 'Meta', pressed: false },
27
+ }
28
+
29
+ const pressedKeys = new Set<string>()
30
+
31
+ window.addEventListener('keydown', (event) => {
32
+ for (const i in modifiers) {
33
+ const mod = modifiers[i]
34
+ if (mod.key === event.key) {
35
+ mod.pressed = true
36
+ return
37
+ }
38
+ }
39
+ pressedKeys.add(event.key.toLocaleLowerCase())
40
+ })
41
+
42
+ window.addEventListener('keyup', (event) => {
43
+ requestAnimationFrame(() => {
44
+ pressedKeys.clear()
45
+ for (const i in modifiers) {
46
+ const mod = modifiers[i]
47
+ if (mod.key === event.key) {
48
+ mod.pressed = false
49
+ break
50
+ }
51
+ }
52
+ })
53
+ })
54
+
55
+ window.addEventListener('blur', () => {
56
+ pressedKeys.clear()
57
+ for (const i in modifiers) {
58
+ const mod = modifiers[i]
59
+ mod.pressed = false
60
+ }
61
+ })
62
+
63
+ function isMatchingShortcut(shortcut: KeyboardShortcut): boolean {
64
+ for (const combination of shortcut) {
65
+ if (isMatchingCombination(combination.toLowerCase())) {
66
+ return true
67
+ }
68
+ }
69
+ return false
70
+ }
71
+
72
+ function isMatchingCombination(combination: string): boolean {
73
+ const splitted = combination.split('+').map(key => key.trim())
74
+ const targetKey = splitted.pop()
75
+ for (const mod in modifiers) {
76
+ const containsMod = splitted.includes(mod)
77
+ const isPressed = modifiers[mod].pressed
78
+ if (containsMod !== isPressed) {
79
+ return false
80
+ }
81
+ }
82
+ return pressedKeys.has(targetKey)
83
+ }
84
+
85
+ export function formatKey(key: string) {
86
+ key = key.toLowerCase()
87
+ if (key === 'ctrl') {
88
+ return isMac ? '^' : 'Ctrl'
89
+ }
90
+ if (key === 'alt') {
91
+ return isMac ? '⎇' : 'Alt'
92
+ }
93
+ if (key === 'shift') {
94
+ return '⇧'
95
+ }
96
+ if (key === 'meta') {
97
+ return '⌘'
98
+ }
99
+ if (key === 'enter') {
100
+ return '⏎'
101
+ }
102
+ return key.charAt(0).toUpperCase() + key.substring(1).toLowerCase()
103
+ }
@@ -0,0 +1,80 @@
1
+ import type { StoryFile, Variant } from '../types'
2
+ import { markRaw, reactive } from 'vue'
3
+
4
+ const copiedFromExistingVariant = [
5
+ 'state',
6
+ 'slots',
7
+ 'source',
8
+ 'responsiveDisabled',
9
+ 'autoPropsDisabled',
10
+ 'setupApp',
11
+ 'configReady',
12
+ 'previewReady',
13
+ ]
14
+
15
+ export function mapFile(file: StoryFile, existingFile?: StoryFile): StoryFile {
16
+ let result: StoryFile
17
+
18
+ if (existingFile) {
19
+ // Update
20
+ result = existingFile
21
+ for (const key in file) {
22
+ if (key === 'story') {
23
+ result.story = {
24
+ ...result.story,
25
+ ...file.story,
26
+ file: markRaw(result),
27
+ variants: file.story.variants.map(v => mapVariant(v, existingFile.story.variants.find(item => item.id === v.id))),
28
+ }
29
+ }
30
+ else if (key !== 'component') {
31
+ result[key] = file[key]
32
+ }
33
+ }
34
+ }
35
+ else {
36
+ // Create
37
+ result = {
38
+ ...file,
39
+ component: markRaw(file.component),
40
+ story: {
41
+ ...file.story,
42
+ title: file.story.title,
43
+ file: markRaw(file),
44
+ variants: file.story.variants.map(v => mapVariant(v)),
45
+ slots: () => ({}),
46
+ },
47
+ }
48
+ }
49
+
50
+ return result
51
+ }
52
+
53
+ export function mapVariant(variant: Variant, existingVariant?: Variant): Variant {
54
+ let result: Variant
55
+
56
+ if (existingVariant) {
57
+ // Update
58
+ result = existingVariant
59
+ for (const key in variant) {
60
+ if (!copiedFromExistingVariant.includes(key)) {
61
+ result[key] = variant[key]
62
+ }
63
+ }
64
+ }
65
+ else {
66
+ // Create
67
+ result = {
68
+ ...variant,
69
+ state: reactive({
70
+ _hPropState: {},
71
+ _hPropDefs: {},
72
+ }),
73
+ setupApp: null,
74
+ slots: () => ({}),
75
+ previewReady: false,
76
+ }
77
+ }
78
+
79
+ return result
80
+ }
@@ -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,23 @@
1
+ import type { PreviewSettings } from '../types'
2
+ import { reactive } from 'vue'
3
+ import { histoireConfig } from './config'
4
+
5
+ export const receivedSettings = reactive<PreviewSettings>({} as PreviewSettings)
6
+
7
+ export function applyPreviewSettings(settings: PreviewSettings) {
8
+ Object.assign(receivedSettings, settings)
9
+
10
+ // Text direction
11
+ document.documentElement.setAttribute('dir', settings.textDirection)
12
+
13
+ // Contrast color
14
+ const contrastColor = getContrastColor(settings)
15
+ document.documentElement.style.setProperty('--histoire-contrast-color', contrastColor)
16
+ if (histoireConfig.autoApplyContrastColor) {
17
+ document.documentElement.style.color = contrastColor
18
+ }
19
+ }
20
+
21
+ export function getContrastColor(setting: PreviewSettings) {
22
+ return histoireConfig.backgroundPresets.find(preset => preset.color === setting.backgroundColor)?.contrastColor ?? 'unset'
23
+ }
@@ -0,0 +1,3 @@
1
+ import { useMediaQuery } from '@vueuse/core'
2
+
3
+ export const isMobile = useMediaQuery('(max-width: 640px)')
@@ -0,0 +1,9 @@
1
+ import type { Story, Variant } from '../types'
2
+ import { base } from '../router'
3
+
4
+ export function getSandboxUrl(story: Story, variant: Variant) {
5
+ const url = new URLSearchParams()
6
+ url.append('storyId', story.id)
7
+ url.append('variantId', variant.id)
8
+ return `${base}__sandbox.html?${url.toString()}`
9
+ }
@@ -0,0 +1,32 @@
1
+ import type { Ref } from 'vue'
2
+ import scrollIntoView from 'scroll-into-view-if-needed'
3
+ import { onMounted, watch } from 'vue'
4
+
5
+ export function useScrollOnActive(active: Ref<boolean>, el: Ref<HTMLElement>) {
6
+ watch(active, (value) => {
7
+ if (value) {
8
+ autoScroll()
9
+ }
10
+ })
11
+
12
+ function autoScroll() {
13
+ if (el.value) {
14
+ scrollIntoView(el.value, {
15
+ scrollMode: 'if-needed',
16
+ block: 'center',
17
+ inline: 'nearest',
18
+ behavior: 'smooth',
19
+ })
20
+ }
21
+ }
22
+
23
+ onMounted(() => {
24
+ if (active.value) {
25
+ autoScroll()
26
+ }
27
+ })
28
+
29
+ return {
30
+ autoScroll,
31
+ }
32
+ }
@@ -0,0 +1,30 @@
1
+ import type { Ref } from 'vue'
2
+ import { computed, ref, watch } from 'vue'
3
+
4
+ export function useSelection(list: Ref<any[]>) {
5
+ const selectedIndex = ref(0)
6
+
7
+ watch(list, () => {
8
+ selectedIndex.value = 0
9
+ })
10
+
11
+ function selectNext() {
12
+ selectedIndex.value++
13
+ if (selectedIndex.value > list.value.length - 1) {
14
+ selectedIndex.value = 0
15
+ }
16
+ }
17
+
18
+ function selectPrevious() {
19
+ selectedIndex.value--
20
+ if (selectedIndex.value < 0) {
21
+ selectedIndex.value = list.value.length - 1
22
+ }
23
+ }
24
+
25
+ return {
26
+ selectedIndex: computed(() => selectedIndex.value),
27
+ selectNext,
28
+ selectPrevious,
29
+ }
30
+ }
@@ -0,0 +1,45 @@
1
+ import { isRef, unref } from 'vue'
2
+
3
+ const isObject = val => val !== null && typeof val === 'object'
4
+
5
+ export function toRawDeep(val, clean = false, seen = new WeakMap()) {
6
+ const unwrappedValue = isRef(val) ? unref(val) : val
7
+
8
+ if (typeof unwrappedValue === 'symbol') {
9
+ return unwrappedValue.toString()
10
+ }
11
+
12
+ if (!isObject(unwrappedValue)) {
13
+ return unwrappedValue
14
+ }
15
+
16
+ if (seen.has(unwrappedValue)) {
17
+ return seen.get(unwrappedValue)
18
+ }
19
+
20
+ if (Array.isArray(unwrappedValue)) {
21
+ const result = []
22
+ seen.set(unwrappedValue, result)
23
+ let list = unwrappedValue.map(value => toRawDeep(value, clean, seen))
24
+ if (clean) {
25
+ list = list.filter(value => typeof value !== 'function')
26
+ }
27
+ result.push(...list)
28
+ return result
29
+ }
30
+ else {
31
+ const result = {}
32
+ seen.set(unwrappedValue, result)
33
+ toRawObject(unwrappedValue, result, clean, seen)
34
+ return result
35
+ }
36
+ }
37
+
38
+ function toRawObject(obj: Record<any, any>, target: Record<any, any>, clean = false, seen = new WeakMap()) {
39
+ Object.keys(obj).forEach((key) => {
40
+ if (clean && typeof obj[key] === 'function') {
41
+ return
42
+ }
43
+ target[key] = toRawDeep(obj[key], clean, seen)
44
+ })
45
+ }
@@ -0,0 +1,13 @@
1
+ import { isMac } from './env.js'
2
+ import { formatKey } from './keyboard.js'
3
+
4
+ export function makeTooltip(descriptionHtml: string, keyboardShortcut: (options: { isMac: boolean }) => string) {
5
+ return {
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
+ html: true,
8
+ }
9
+ }
10
+
11
+ function genKeyboardShortcutHtml(shortcut: string) {
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
+ }
@@ -0,0 +1,21 @@
1
+ import type { Ref } from 'vue'
2
+ import type { Variant } from '../types'
3
+ import { computed } from 'vue'
4
+ import { useRoute } from 'vue-router'
5
+
6
+ export function useCurrentVariantRoute(variant: Ref<Variant>) {
7
+ const route = useRoute()
8
+ const isActive = computed(() => route.query.variantId === variant.value.id)
9
+ const targetRoute = computed(() => ({
10
+ ...route,
11
+ query: {
12
+ ...route.query,
13
+ variantId: variant.value.id,
14
+ },
15
+ }))
16
+
17
+ return {
18
+ isActive,
19
+ targetRoute,
20
+ }
21
+ }
@@ -0,0 +1 @@
1
+ export * from './bundled/api.js'
@@ -0,0 +1,4 @@
1
+ import { mountMainApp } from './app/index'
2
+ import './app/style/main.pcss'
3
+
4
+ mountMainApp()
@@ -0,0 +1,5 @@
1
+ import { mountMainApp } from './bundled/index.js'
2
+ import './style.css'
3
+ import './bundled/app.css'
4
+
5
+ mountMainApp()
@@ -0,0 +1,2 @@
1
+ import './app/style/sandbox.css'
2
+ import './app/sandbox'
@@ -0,0 +1,2 @@
1
+ import './app/style/sandbox.css'
2
+ import './bundled/sandbox.js'
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './app/api.js'
package/src/shim.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ import type { Ref } from '@histoire/vendors/vue'
4
+
5
+ global {
6
+ interface Window {
7
+ __hst_controls_dark: Ref<boolean>[]
8
+ __hst_controls_dark_ready: () => void
9
+ }
10
+ }
@@ -0,0 +1,7 @@
1
+ declare module 'virtual:$histoire-commands' {
2
+ import type { ClientCommand } from '@histoire/shared'
3
+
4
+ export const registeredCommands: ClientCommand[]
5
+ }
6
+
7
+ declare module 'virtual:*';