@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.
- package/LICENSE +21 -0
- package/dist/app/assets/histoire-text-dark.svg +89 -0
- package/dist/app/assets/histoire-text.svg +89 -0
- package/dist/app/assets/histoire.svg +51 -0
- package/dist/app/style/floating.pcss +34 -0
- package/dist/app/style/main.pcss +100 -0
- package/dist/app/style/sandbox.css +24 -0
- package/dist/app/style/transitions.pcss +51 -0
- package/dist/bundle-index.js +3 -0
- package/dist/bundle-main-dev.js +4 -0
- package/dist/bundle-main.js +5 -0
- package/dist/bundle-sandbox-dev.js +2 -0
- package/dist/bundle-sandbox.js +2 -0
- package/dist/bundled/App.vue.js +5 -0
- package/dist/bundled/App.vue2.js +167 -0
- package/dist/bundled/_virtual/_node-dom-env.js +188 -0
- package/dist/bundled/_virtual/_node-dom-polyfill.js +152 -0
- package/dist/bundled/_virtual/_plugin-vue_export-helper.js +10 -0
- package/dist/bundled/_virtual/histoire-commands.js +8 -0
- package/dist/bundled/_virtual/histoire-config.js +42 -0
- package/dist/bundled/_virtual/histoire-markdown-files.js +8 -0
- package/dist/bundled/_virtual/histoire-search-docs-data.js +11 -0
- package/dist/bundled/_virtual/histoire-search-title-data.js +11 -0
- package/dist/bundled/_virtual/histoire-stories.js +17 -0
- package/dist/bundled/_virtual/histoire-support-plugins-client.js +8 -0
- package/dist/bundled/_virtual/histoire-theme.js +8 -0
- package/dist/bundled/api.js +12 -0
- package/dist/bundled/app.css +116 -0
- package/dist/bundled/assets/histoire-text-dark.svg.js +4 -0
- package/dist/bundled/assets/histoire-text.svg.js +4 -0
- package/dist/bundled/assets/histoire.svg.js +4 -0
- package/dist/bundled/components/HomeView.vue.js +5 -0
- package/dist/bundled/components/HomeView.vue2.js +66 -0
- package/dist/bundled/components/app/AppHeader.vue.js +5 -0
- package/dist/bundled/components/app/AppHeader.vue2.js +71 -0
- package/dist/bundled/components/app/AppLogo.vue.js +5 -0
- package/dist/bundled/components/app/AppLogo.vue2.js +29 -0
- package/dist/bundled/components/app/Breadcrumb.vue.js +8 -0
- package/dist/bundled/components/app/Breadcrumb.vue2.js +91 -0
- package/dist/bundled/components/app/HomeCounter.vue.js +5 -0
- package/dist/bundled/components/app/HomeCounter.vue2.js +42 -0
- package/dist/bundled/components/app/InitialLoading.vue.js +5 -0
- package/dist/bundled/components/app/InitialLoading.vue2.js +51 -0
- package/dist/bundled/components/app/MobileOverlay.vue.js +5 -0
- package/dist/bundled/components/app/MobileOverlay.vue2.js +45 -0
- package/dist/bundled/components/base/BaseButton.vue.js +5 -0
- package/dist/bundled/components/base/BaseButton.vue2.js +39 -0
- package/dist/bundled/components/base/BaseCheckbox.vue.js +5 -0
- package/dist/bundled/components/base/BaseCheckbox.vue2.js +78 -0
- package/dist/bundled/components/base/BaseEmpty.vue.js +14 -0
- package/dist/bundled/components/base/BaseIcon.vue.js +8 -0
- package/dist/bundled/components/base/BaseIcon.vue2.js +29 -0
- package/dist/bundled/components/base/BaseKeyboardShortcut.vue.js +5 -0
- package/dist/bundled/components/base/BaseKeyboardShortcut.vue2.js +20 -0
- package/dist/bundled/components/base/BaseListItem.vue.js +5 -0
- package/dist/bundled/components/base/BaseListItem.vue2.js +33 -0
- package/dist/bundled/components/base/BaseListItemLink.vue.js +33 -0
- package/dist/bundled/components/base/BaseListItemLink.vue2.js +26 -0
- package/dist/bundled/components/base/BaseOverflowMenu.vue.js +5 -0
- package/dist/bundled/components/base/BaseOverflowMenu.vue2.js +100 -0
- package/dist/bundled/components/base/BaseOverflowTab.vue.js +36 -0
- package/dist/bundled/components/base/BaseOverflowTab.vue2.js +18 -0
- package/dist/bundled/components/base/BaseSelect.vue.js +5 -0
- package/dist/bundled/components/base/BaseSelect.vue2.js +77 -0
- package/dist/bundled/components/base/BaseSplitPane.vue.js +8 -0
- package/dist/bundled/components/base/BaseSplitPane.vue2.js +183 -0
- package/dist/bundled/components/base/BaseTab.vue.js +36 -0
- package/dist/bundled/components/base/BaseTab.vue2.js +18 -0
- package/dist/bundled/components/base/BaseTag.vue.js +13 -0
- package/dist/bundled/components/command/CommandPrompts.vue.js +5 -0
- package/dist/bundled/components/command/CommandPrompts.vue2.js +91 -0
- package/dist/bundled/components/command/CommandPromptsModal.vue.js +5 -0
- package/dist/bundled/components/command/CommandPromptsModal.vue2.js +45 -0
- package/dist/bundled/components/command/PromptSelect.vue.js +5 -0
- package/dist/bundled/components/command/PromptSelect.vue2.js +142 -0
- package/dist/bundled/components/command/PromptText.vue.js +5 -0
- package/dist/bundled/components/command/PromptText.vue2.js +67 -0
- package/dist/bundled/components/misc/CheckerboardPattern.vue.js +40 -0
- package/dist/bundled/components/misc/HatchedPattern.vue.js +12 -0
- package/dist/bundled/components/panel/ControlsComponentPropItem.vue.js +5 -0
- package/dist/bundled/components/panel/ControlsComponentPropItem.vue2.js +72 -0
- package/dist/bundled/components/panel/ControlsComponentProps.vue.js +5 -0
- package/dist/bundled/components/panel/ControlsComponentProps.vue2.js +45 -0
- package/dist/bundled/components/panel/ControlsComponentState.vue.js +5 -0
- package/dist/bundled/components/panel/ControlsComponentState.vue2.js +41 -0
- package/dist/bundled/components/panel/ControlsComponentStateItem.vue.js +5 -0
- package/dist/bundled/components/panel/ControlsComponentStateItem.vue2.js +46 -0
- package/dist/bundled/components/panel/PaneTabs.vue.js +5 -0
- package/dist/bundled/components/panel/PaneTabs.vue2.js +114 -0
- package/dist/bundled/components/panel/StatePresets.vue.js +5 -0
- package/dist/bundled/components/panel/StatePresets.vue2.js +193 -0
- package/dist/bundled/components/panel/StoryControls.vue.js +5 -0
- package/dist/bundled/components/panel/StoryControls.vue2.js +87 -0
- package/dist/bundled/components/panel/StoryDocs.vue.js +7 -0
- package/dist/bundled/components/panel/StoryDocs.vue2.js +161 -0
- package/dist/bundled/components/panel/StoryEvent.vue.js +5 -0
- package/dist/bundled/components/panel/StoryEvent.vue2.js +59 -0
- package/dist/bundled/components/panel/StoryEvents.vue.js +5 -0
- package/dist/bundled/components/panel/StoryEvents.vue2.js +53 -0
- package/dist/bundled/components/panel/StorySidePanel.vue.js +5 -0
- package/dist/bundled/components/panel/StorySidePanel.vue2.js +83 -0
- package/dist/bundled/components/panel/StorySourceCode.vue.js +8 -0
- package/dist/bundled/components/panel/StorySourceCode.vue2.js +204 -0
- package/dist/bundled/components/search/SearchItem.vue.js +8 -0
- package/dist/bundled/components/search/SearchItem.vue2.js +93 -0
- package/dist/bundled/components/search/SearchItemContent.vue.js +5 -0
- package/dist/bundled/components/search/SearchItemContent.vue2.js +71 -0
- package/dist/bundled/components/search/SearchLoading.vue.js +5 -0
- package/dist/bundled/components/search/SearchLoading.vue2.js +21 -0
- package/dist/bundled/components/search/SearchModal.vue.js +5 -0
- package/dist/bundled/components/search/SearchModal.vue2.js +51 -0
- package/dist/bundled/components/search/SearchPane.vue.js +5 -0
- package/dist/bundled/components/search/SearchPane.vue2.js +272 -0
- package/dist/bundled/components/search/search-docs-data.js +11 -0
- package/dist/bundled/components/search/search-title-data.js +11 -0
- package/dist/bundled/components/story/GenericMountStory.vue.js +5 -0
- package/dist/bundled/components/story/GenericMountStory.vue2.js +34 -0
- package/dist/bundled/components/story/GenericRenderStory.vue.js +5 -0
- package/dist/bundled/components/story/GenericRenderStory.vue2.js +39 -0
- package/dist/bundled/components/story/StoryResponsivePreview.vue.js +8 -0
- package/dist/bundled/components/story/StoryResponsivePreview.vue2.js +207 -0
- package/dist/bundled/components/story/StoryVariantGrid.vue.js +5 -0
- package/dist/bundled/components/story/StoryVariantGrid.vue2.js +146 -0
- package/dist/bundled/components/story/StoryVariantGridItem.vue.js +8 -0
- package/dist/bundled/components/story/StoryVariantGridItem.vue2.js +153 -0
- package/dist/bundled/components/story/StoryVariantListItem.vue.js +8 -0
- package/dist/bundled/components/story/StoryVariantListItem.vue2.js +55 -0
- package/dist/bundled/components/story/StoryVariantSingle.vue.js +8 -0
- package/dist/bundled/components/story/StoryVariantSingle.vue2.js +107 -0
- package/dist/bundled/components/story/StoryVariantSinglePreviewNative.vue.js +5 -0
- package/dist/bundled/components/story/StoryVariantSinglePreviewNative.vue2.js +70 -0
- package/dist/bundled/components/story/StoryVariantSinglePreviewRemote.vue.js +5 -0
- package/dist/bundled/components/story/StoryVariantSinglePreviewRemote.vue2.js +128 -0
- package/dist/bundled/components/story/StoryVariantSingleView.vue.js +5 -0
- package/dist/bundled/components/story/StoryVariantSingleView.vue2.js +66 -0
- package/dist/bundled/components/story/StoryView.vue.js +5 -0
- package/dist/bundled/components/story/StoryView.vue2.js +104 -0
- package/dist/bundled/components/story/StoryViewer.vue.js +8 -0
- package/dist/bundled/components/story/StoryViewer.vue2.js +55 -0
- package/dist/bundled/components/toolbar/DevOnlyToolbarOpenInEditor.vue.js +5 -0
- package/dist/bundled/components/toolbar/DevOnlyToolbarOpenInEditor.vue2.js +31 -0
- package/dist/bundled/components/toolbar/ToolbarBackground.vue.js +8 -0
- package/dist/bundled/components/toolbar/ToolbarBackground.vue2.js +98 -0
- package/dist/bundled/components/toolbar/ToolbarNewTab.vue.js +5 -0
- package/dist/bundled/components/toolbar/ToolbarNewTab.vue2.js +36 -0
- package/dist/bundled/components/toolbar/ToolbarResponsiveSize.vue.js +5 -0
- package/dist/bundled/components/toolbar/ToolbarResponsiveSize.vue2.js +127 -0
- package/dist/bundled/components/toolbar/ToolbarTextDirection.vue.js +5 -0
- package/dist/bundled/components/toolbar/ToolbarTextDirection.vue2.js +27 -0
- package/dist/bundled/components/toolbar/ToolbarTitle.vue.js +5 -0
- package/dist/bundled/components/toolbar/ToolbarTitle.vue2.js +26 -0
- package/dist/bundled/components/tree/StoryGroup.vue.js +5 -0
- package/dist/bundled/components/tree/StoryGroup.vue2.js +74 -0
- package/dist/bundled/components/tree/StoryList.vue.js +5 -0
- package/dist/bundled/components/tree/StoryList.vue2.js +41 -0
- package/dist/bundled/components/tree/StoryListFolder.vue.js +8 -0
- package/dist/bundled/components/tree/StoryListFolder.vue2.js +86 -0
- package/dist/bundled/components/tree/StoryListItem.vue.js +8 -0
- package/dist/bundled/components/tree/StoryListItem.vue2.js +69 -0
- package/dist/bundled/index.js +36 -0
- package/dist/bundled/plugin.js +49 -0
- package/dist/bundled/router.js +32 -0
- package/dist/bundled/sandbox.js +87 -0
- package/dist/bundled/stores/command.js +25 -0
- package/dist/bundled/stores/events.js +29 -0
- package/dist/bundled/stores/folder.js +54 -0
- package/dist/bundled/stores/preview-settings.js +19 -0
- package/dist/bundled/stores/story.js +43 -0
- package/dist/bundled/util/commands.js +57 -0
- package/dist/bundled/util/config.js +8 -0
- package/dist/bundled/util/const.js +10 -0
- package/dist/bundled/util/dark.js +28 -0
- package/dist/bundled/util/docs.js +26 -0
- package/dist/bundled/util/env.js +4 -0
- package/dist/bundled/util/events.js +33 -0
- package/dist/bundled/util/keyboard.js +90 -0
- package/dist/bundled/util/mapping.js +70 -0
- package/dist/bundled/util/open-in-editor.js +7 -0
- package/dist/bundled/util/preview-settings.js +21 -0
- package/dist/bundled/util/responsive.js +6 -0
- package/dist/bundled/util/sandbox.js +11 -0
- package/dist/bundled/util/scroll.js +31 -0
- package/dist/bundled/util/select.js +28 -0
- package/dist/bundled/util/state.js +41 -0
- package/dist/bundled/util/tooltip.js +15 -0
- package/dist/bundled/util/variant.js +21 -0
- package/dist/style.css +2853 -0
- package/package.json +62 -0
- package/postcss-scope-wrapper.cjs +35 -0
- package/postcss.config.cjs +9 -0
- package/scripts/copy.mjs +12 -0
- package/scripts/watchAndCopy.mjs +15 -0
- package/src/app/App.vue +172 -0
- package/src/app/api.ts +9 -0
- package/src/app/assets/histoire-text-dark.svg +89 -0
- package/src/app/assets/histoire-text.svg +89 -0
- package/src/app/assets/histoire.svg +51 -0
- package/src/app/components/HomeView.vue +61 -0
- package/src/app/components/app/AppHeader.vue +65 -0
- package/src/app/components/app/AppLogo.vue +25 -0
- package/src/app/components/app/Breadcrumb.vue +98 -0
- package/src/app/components/app/HomeCounter.vue +39 -0
- package/src/app/components/app/InitialLoading.vue +44 -0
- package/src/app/components/app/MobileOverlay.vue +33 -0
- package/src/app/components/base/BaseButton.vue +33 -0
- package/src/app/components/base/BaseCheckbox.vue +76 -0
- package/src/app/components/base/BaseCopyIcon.vue +34 -0
- package/src/app/components/base/BaseEmpty.vue +21 -0
- package/src/app/components/base/BaseIcon.vue +31 -0
- package/src/app/components/base/BaseKeyboardShortcut.vue +16 -0
- package/src/app/components/base/BaseListItem.vue +30 -0
- package/src/app/components/base/BaseListItemLink.vue +56 -0
- package/src/app/components/base/BaseOverflowMenu.vue +119 -0
- package/src/app/components/base/BaseOverflowTab.vue +47 -0
- package/src/app/components/base/BaseSelect.vue +75 -0
- package/src/app/components/base/BaseSplitPane.vue +244 -0
- package/src/app/components/base/BaseTab.vue +47 -0
- package/src/app/components/base/BaseTag.vue +5 -0
- package/src/app/components/command/CommandPrompts.vue +95 -0
- package/src/app/components/command/CommandPromptsModal.vue +41 -0
- package/src/app/components/command/PromptSelect.vue +142 -0
- package/src/app/components/command/PromptText.vue +65 -0
- package/src/app/components/misc/CheckerboardPattern.vue +32 -0
- package/src/app/components/misc/HatchedPattern.vue +13 -0
- package/src/app/components/panel/ControlsComponentPropItem.vue +73 -0
- package/src/app/components/panel/ControlsComponentProps.vue +34 -0
- package/src/app/components/panel/ControlsComponentState.vue +38 -0
- package/src/app/components/panel/ControlsComponentStateItem.vue +44 -0
- package/src/app/components/panel/PaneTabs.vue +84 -0
- package/src/app/components/panel/StatePresets.vue +199 -0
- package/src/app/components/panel/StoryControls.vue +97 -0
- package/src/app/components/panel/StoryDocs.vue +202 -0
- package/src/app/components/panel/StoryEvent.vue +54 -0
- package/src/app/components/panel/StoryEvents.vue +48 -0
- package/src/app/components/panel/StorySidePanel.vue +76 -0
- package/src/app/components/panel/StorySourceCode.vue +248 -0
- package/src/app/components/search/SearchItem.vue +89 -0
- package/src/app/components/search/SearchItemContent.vue +67 -0
- package/src/app/components/search/SearchLoading.vue +16 -0
- package/src/app/components/search/SearchModal.vue +44 -0
- package/src/app/components/search/SearchPane.vue +319 -0
- package/src/app/components/search/search-docs-data.ts +9 -0
- package/src/app/components/search/search-title-data.ts +9 -0
- package/src/app/components/search/types.ts +4 -0
- package/src/app/components/story/GenericMountStory.vue +35 -0
- package/src/app/components/story/GenericRenderStory.vue +41 -0
- package/src/app/components/story/StoryResponsivePreview.vue +216 -0
- package/src/app/components/story/StoryVariantGrid.vue +169 -0
- package/src/app/components/story/StoryVariantGridItem.vue +163 -0
- package/src/app/components/story/StoryVariantListItem.vue +52 -0
- package/src/app/components/story/StoryVariantSingle.vue +105 -0
- package/src/app/components/story/StoryVariantSinglePreviewNative.vue +66 -0
- package/src/app/components/story/StoryVariantSinglePreviewRemote.vue +143 -0
- package/src/app/components/story/StoryVariantSingleView.vue +61 -0
- package/src/app/components/story/StoryView.vue +110 -0
- package/src/app/components/story/StoryViewer.vue +52 -0
- package/src/app/components/toolbar/DevOnlyToolbarOpenInEditor.vue +23 -0
- package/src/app/components/toolbar/ToolbarBackground.vue +81 -0
- package/src/app/components/toolbar/ToolbarNewTab.vue +29 -0
- package/src/app/components/toolbar/ToolbarResponsiveSize.vue +82 -0
- package/src/app/components/toolbar/ToolbarTextDirection.vue +19 -0
- package/src/app/components/toolbar/ToolbarTitle.vue +21 -0
- package/src/app/components/tree/StoryGroup.vue +73 -0
- package/src/app/components/tree/StoryList.vue +35 -0
- package/src/app/components/tree/StoryListFolder.vue +88 -0
- package/src/app/components/tree/StoryListItem.vue +72 -0
- package/src/app/index.ts +33 -0
- package/src/app/plugin.ts +59 -0
- package/src/app/router.ts +29 -0
- package/src/app/sandbox.ts +101 -0
- package/src/app/stores/command.ts +26 -0
- package/src/app/stores/events.ts +36 -0
- package/src/app/stores/folder.ts +63 -0
- package/src/app/stores/preview-settings.ts +18 -0
- package/src/app/stores/story.ts +47 -0
- package/src/app/style/floating.pcss +34 -0
- package/src/app/style/main.pcss +100 -0
- package/src/app/style/sandbox.css +24 -0
- package/src/app/style/transitions.pcss +51 -0
- package/src/app/types.ts +72 -0
- package/src/app/util/commands.ts +57 -0
- package/src/app/util/config.ts +5 -0
- package/src/app/util/const.ts +4 -0
- package/src/app/util/dark.ts +27 -0
- package/src/app/util/docs.ts +27 -0
- package/src/app/util/env.ts +1 -0
- package/src/app/util/events.ts +31 -0
- package/src/app/util/keyboard.ts +103 -0
- package/src/app/util/mapping.ts +80 -0
- package/src/app/util/open-in-editor.ts +3 -0
- package/src/app/util/preview-settings.ts +23 -0
- package/src/app/util/responsive.ts +3 -0
- package/src/app/util/sandbox.ts +9 -0
- package/src/app/util/scroll.ts +32 -0
- package/src/app/util/select.ts +30 -0
- package/src/app/util/state.ts +45 -0
- package/src/app/util/tooltip.ts +13 -0
- package/src/app/util/variant.ts +21 -0
- package/src/bundle-index.js +1 -0
- package/src/bundle-main-dev.js +4 -0
- package/src/bundle-main.js +5 -0
- package/src/bundle-sandbox-dev.js +2 -0
- package/src/bundle-sandbox.js +2 -0
- package/src/index.ts +1 -0
- package/src/shim.d.ts +10 -0
- package/src/virtual.d.ts +7 -0
- package/tailwind.config.cjs +137 -0
- package/tsconfig.json +53 -0
- package/vite.config.ts +88 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { Highlighter } from 'shiki'
|
|
3
|
+
import type { Story, Variant } from '../../types'
|
|
4
|
+
import { HstCopyIcon } from '@histoire/controls'
|
|
5
|
+
import { unindent } from '@histoire/shared'
|
|
6
|
+
import { Icon } from '@iconify/vue'
|
|
7
|
+
import { createHighlighter } from 'shiki'
|
|
8
|
+
import { clientSupportPlugins } from 'virtual:$histoire-support-plugins-client'
|
|
9
|
+
import { computed, markRaw, nextTick, onMounted, ref, shallowRef, watch, watchEffect } from 'vue'
|
|
10
|
+
import { isDark } from '../../util/dark'
|
|
11
|
+
import BaseEmpty from '../base/BaseEmpty.vue'
|
|
12
|
+
|
|
13
|
+
const props = defineProps<{
|
|
14
|
+
story: Story
|
|
15
|
+
variant: Variant
|
|
16
|
+
}>()
|
|
17
|
+
|
|
18
|
+
const generateSourceCodeFn = ref(null)
|
|
19
|
+
|
|
20
|
+
watchEffect(async () => {
|
|
21
|
+
const clientPlugin = clientSupportPlugins[props.story.file?.supportPluginId]
|
|
22
|
+
if (clientPlugin) {
|
|
23
|
+
const pluginModule = await clientPlugin()
|
|
24
|
+
generateSourceCodeFn.value = markRaw(pluginModule.generateSourceCode)
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const highlighter = shallowRef<Highlighter>()
|
|
29
|
+
|
|
30
|
+
const dynamicSourceCode = ref('')
|
|
31
|
+
const error = ref<string>(null)
|
|
32
|
+
|
|
33
|
+
watch(() => [props.variant, generateSourceCodeFn.value], async () => {
|
|
34
|
+
if (!generateSourceCodeFn.value) return
|
|
35
|
+
error.value = null
|
|
36
|
+
dynamicSourceCode.value = ''
|
|
37
|
+
try {
|
|
38
|
+
if (props.variant.source) {
|
|
39
|
+
dynamicSourceCode.value = props.variant.source
|
|
40
|
+
}
|
|
41
|
+
else if (props.variant.slots?.().source) {
|
|
42
|
+
const source = props.variant.slots?.().source()[0].children
|
|
43
|
+
if (source) {
|
|
44
|
+
dynamicSourceCode.value = await unindent(source)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
dynamicSourceCode.value = await generateSourceCodeFn.value(props.variant)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
console.error(e)
|
|
53
|
+
error.value = e.message
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Auto-switch
|
|
57
|
+
if (!dynamicSourceCode.value) {
|
|
58
|
+
displayedSource.value = 'static'
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
deep: true,
|
|
62
|
+
immediate: true,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
// Static file source
|
|
66
|
+
|
|
67
|
+
const staticSourceCode = ref('')
|
|
68
|
+
watch(() => [props.story, props.story?.file?.source], async () => {
|
|
69
|
+
staticSourceCode.value = ''
|
|
70
|
+
const sourceLoader = props.story.file?.source
|
|
71
|
+
if (sourceLoader) {
|
|
72
|
+
staticSourceCode.value = (await sourceLoader()).default
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
immediate: true,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const displayedSource = ref<'dynamic' | 'static'>('dynamic')
|
|
79
|
+
|
|
80
|
+
const displayedSourceCode = computed(() => {
|
|
81
|
+
if (displayedSource.value === 'dynamic') {
|
|
82
|
+
return dynamicSourceCode.value
|
|
83
|
+
}
|
|
84
|
+
return staticSourceCode.value
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
// HTML render
|
|
88
|
+
|
|
89
|
+
onMounted(async () => {
|
|
90
|
+
highlighter.value = await createHighlighter({
|
|
91
|
+
langs: [
|
|
92
|
+
'html',
|
|
93
|
+
'jsx',
|
|
94
|
+
],
|
|
95
|
+
themes: [
|
|
96
|
+
'github-light',
|
|
97
|
+
'github-dark',
|
|
98
|
+
],
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const sourceHtml = computed(() => displayedSourceCode.value
|
|
103
|
+
? highlighter.value?.codeToHtml(displayedSourceCode.value, {
|
|
104
|
+
lang: 'html',
|
|
105
|
+
theme: isDark.value ? 'github-dark' : 'github-light',
|
|
106
|
+
})
|
|
107
|
+
: '')
|
|
108
|
+
|
|
109
|
+
// Scrolling
|
|
110
|
+
|
|
111
|
+
let lastScroll = 0
|
|
112
|
+
|
|
113
|
+
// Reset
|
|
114
|
+
watch(() => props.variant, () => {
|
|
115
|
+
lastScroll = 0
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const scroller = ref<HTMLElement>()
|
|
119
|
+
|
|
120
|
+
function onScroll(event) {
|
|
121
|
+
if (sourceHtml.value) {
|
|
122
|
+
lastScroll = event.target.scrollTop
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
watch(sourceHtml, async () => {
|
|
127
|
+
await nextTick()
|
|
128
|
+
if (scroller.value) {
|
|
129
|
+
scroller.value.scrollTop = lastScroll
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
</script>
|
|
133
|
+
|
|
134
|
+
<template>
|
|
135
|
+
<div
|
|
136
|
+
class="histoire-story-source-code htw-bg-gray-50 dark:htw-bg-gray-750 htw-h-full htw-overflow-hidden htw-flex htw-flex-col"
|
|
137
|
+
>
|
|
138
|
+
<!-- Toolbar -->
|
|
139
|
+
<div
|
|
140
|
+
v-if="!error"
|
|
141
|
+
class="htw-h-10 htw-flex-none htw-border-b htw-border-solid htw-border-gray-500/5 htw-px-4 htw-flex htw-items-center htw-gap-2"
|
|
142
|
+
>
|
|
143
|
+
<div class="htw-text-gray-900 dark:htw-text-gray-100">
|
|
144
|
+
Source
|
|
145
|
+
</div>
|
|
146
|
+
<div class="htw-flex-1" />
|
|
147
|
+
|
|
148
|
+
<!-- Display source modes -->
|
|
149
|
+
<div class="htw-flex htw-flex-none htw-gap-px htw-h-full htw-py-2">
|
|
150
|
+
<button
|
|
151
|
+
v-tooltip="!dynamicSourceCode ? 'Dynamic source code is not available' : displayedSource !== 'dynamic' ? 'Switch to dynamic source' : null"
|
|
152
|
+
class="htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-1 htw-bg-gray-500/10 htw-rounded-l htw-transition-all htw-ease-[cubic-bezier(0,1,.6,1)] htw-duration-300 htw-overflow-hidden"
|
|
153
|
+
:class="[
|
|
154
|
+
displayedSource !== 'dynamic' ? 'htw-max-w-6 htw-opacity-70' : 'htw-max-w-[82px] htw-text-primary-600 dark:htw-text-primary-400',
|
|
155
|
+
dynamicSourceCode ? 'htw-cursor-pointer hover:htw-bg-gray-500/30 active:htw-bg-gray-600/50' : 'htw-opacity-50',
|
|
156
|
+
]"
|
|
157
|
+
@click="dynamicSourceCode && (displayedSource = 'dynamic')"
|
|
158
|
+
>
|
|
159
|
+
<Icon
|
|
160
|
+
icon="carbon:flash"
|
|
161
|
+
class="htw-w-4 htw-h-4 htw-flex-none"
|
|
162
|
+
/>
|
|
163
|
+
<span
|
|
164
|
+
class="transition-opacity duration-300"
|
|
165
|
+
:class="{
|
|
166
|
+
'opacity-0': displayedSource !== 'dynamic',
|
|
167
|
+
}"
|
|
168
|
+
>
|
|
169
|
+
Dynamic
|
|
170
|
+
</span>
|
|
171
|
+
</button>
|
|
172
|
+
<button
|
|
173
|
+
v-tooltip="!staticSourceCode ? 'Static source code is not available' : displayedSource !== 'static' ? 'Switch to static source' : null"
|
|
174
|
+
class="htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-1 htw-bg-gray-500/10 htw-rounded-r htw-transition-all htw-ease-[cubic-bezier(0,1,.6,1)] htw-duration-300 htw-overflow-hidden"
|
|
175
|
+
:class="[
|
|
176
|
+
displayedSource !== 'static' ? 'htw-max-w-6 htw-opacity-70' : 'htw-max-w-[63px] htw-text-primary-600 dark:htw-text-primary-400',
|
|
177
|
+
staticSourceCode ? 'htw-cursor-pointer hover:htw-bg-gray-500/30 active:htw-bg-gray-600/50' : 'htw-opacity-50',
|
|
178
|
+
]"
|
|
179
|
+
@click="staticSourceCode && (displayedSource = 'static')"
|
|
180
|
+
>
|
|
181
|
+
<Icon
|
|
182
|
+
icon="carbon:document"
|
|
183
|
+
class="htw-w-4 htw-h-4 htw-flex-none"
|
|
184
|
+
/>
|
|
185
|
+
<span
|
|
186
|
+
class="transition-opacity duration-300"
|
|
187
|
+
:class="{
|
|
188
|
+
'opacity-0': displayedSource !== 'static',
|
|
189
|
+
}"
|
|
190
|
+
>
|
|
191
|
+
Static
|
|
192
|
+
</span>
|
|
193
|
+
</button>
|
|
194
|
+
</div>
|
|
195
|
+
|
|
196
|
+
<HstCopyIcon
|
|
197
|
+
:content="displayedSourceCode"
|
|
198
|
+
class="htw-flex-none"
|
|
199
|
+
/>
|
|
200
|
+
</div>
|
|
201
|
+
|
|
202
|
+
<div
|
|
203
|
+
v-if="error"
|
|
204
|
+
class="htw-text-red-500 htw-h-full htw-p-2 htw-overflow-auto htw-font-mono htw-text-sm"
|
|
205
|
+
>
|
|
206
|
+
Error: {{ error }}
|
|
207
|
+
</div>
|
|
208
|
+
|
|
209
|
+
<BaseEmpty v-else-if="!displayedSourceCode">
|
|
210
|
+
<Icon
|
|
211
|
+
icon="carbon:code-hide"
|
|
212
|
+
class="htw-w-8 htw-h-8 htw-opacity-50 htw-mb-6"
|
|
213
|
+
/>
|
|
214
|
+
<span>Not available</span>
|
|
215
|
+
</BaseEmpty>
|
|
216
|
+
|
|
217
|
+
<textarea
|
|
218
|
+
v-else-if="!sourceHtml"
|
|
219
|
+
ref="scroller"
|
|
220
|
+
class="__histoire-code-placeholder htw-w-full htw-h-full htw-p-4 htw-outline-none htw-bg-transparent htw-resize-none htw-m-0"
|
|
221
|
+
:value="displayedSourceCode"
|
|
222
|
+
readonly
|
|
223
|
+
data-test-id="story-source-code"
|
|
224
|
+
@scroll="onScroll"
|
|
225
|
+
/>
|
|
226
|
+
<!-- eslint-disable vue/no-v-html -->
|
|
227
|
+
<div
|
|
228
|
+
v-else
|
|
229
|
+
ref="scroller"
|
|
230
|
+
class="htw-w-full htw-h-full htw-overflow-auto"
|
|
231
|
+
data-test-id="story-source-code"
|
|
232
|
+
@scroll="onScroll"
|
|
233
|
+
>
|
|
234
|
+
<div
|
|
235
|
+
class="__histoire-code htw-p-4 htw-w-fit"
|
|
236
|
+
v-html="sourceHtml"
|
|
237
|
+
/>
|
|
238
|
+
</div>
|
|
239
|
+
<!-- eslint-enable vue/no-v-html -->
|
|
240
|
+
</div>
|
|
241
|
+
</template>
|
|
242
|
+
|
|
243
|
+
<style scoped>
|
|
244
|
+
.__histoire-code-placeholder {
|
|
245
|
+
color: inherit;
|
|
246
|
+
font-size: inherit;
|
|
247
|
+
}
|
|
248
|
+
</style>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { PropType } from 'vue'
|
|
3
|
+
import type { SearchResult } from '../../types'
|
|
4
|
+
import { ref, toRefs } from 'vue'
|
|
5
|
+
import { useRouter } from 'vue-router'
|
|
6
|
+
import { onKeyboardShortcut } from '../../util/keyboard'
|
|
7
|
+
import { useScrollOnActive } from '../../util/scroll'
|
|
8
|
+
import BaseListItem from '../base/BaseListItem.vue'
|
|
9
|
+
import BaseListItemLink from '../base/BaseListItemLink.vue'
|
|
10
|
+
import SearchItemContent from './SearchItemContent.vue'
|
|
11
|
+
|
|
12
|
+
const props = defineProps({
|
|
13
|
+
result: {
|
|
14
|
+
type: Object as PropType<SearchResult>,
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
selected: {
|
|
19
|
+
type: Boolean,
|
|
20
|
+
default: false,
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const emit = defineEmits({
|
|
25
|
+
close: () => true,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const el = ref<HTMLDivElement>()
|
|
29
|
+
|
|
30
|
+
const { selected } = toRefs(props)
|
|
31
|
+
useScrollOnActive(selected, el)
|
|
32
|
+
|
|
33
|
+
const router = useRouter()
|
|
34
|
+
|
|
35
|
+
onKeyboardShortcut(['enter'], () => {
|
|
36
|
+
if (!props.selected) return
|
|
37
|
+
action()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
function action(fromClick = false) {
|
|
41
|
+
if ('route' in props.result && !fromClick) {
|
|
42
|
+
router.push(props.result.route)
|
|
43
|
+
}
|
|
44
|
+
if ('onActivate' in props.result) {
|
|
45
|
+
props.result.onActivate()
|
|
46
|
+
}
|
|
47
|
+
emit('close')
|
|
48
|
+
}
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<template>
|
|
52
|
+
<div
|
|
53
|
+
ref="el"
|
|
54
|
+
class="histoire-search-item"
|
|
55
|
+
data-test-id="search-item"
|
|
56
|
+
:data-selected="selected ? '' : undefined"
|
|
57
|
+
>
|
|
58
|
+
<BaseListItemLink
|
|
59
|
+
v-if="'route' in result"
|
|
60
|
+
:to="result.route"
|
|
61
|
+
:is-active="selected"
|
|
62
|
+
class="htw-px-6 htw-py-4 htw-gap-4"
|
|
63
|
+
@navigate="action(true)"
|
|
64
|
+
>
|
|
65
|
+
<SearchItemContent
|
|
66
|
+
:result="result"
|
|
67
|
+
:selected="selected"
|
|
68
|
+
/>
|
|
69
|
+
</BaseListItemLink>
|
|
70
|
+
|
|
71
|
+
<BaseListItem
|
|
72
|
+
v-if="'onActivate' in result"
|
|
73
|
+
:is-active="selected"
|
|
74
|
+
class="htw-px-6 htw-py-4 htw-gap-4"
|
|
75
|
+
@navigate="action(true)"
|
|
76
|
+
>
|
|
77
|
+
<SearchItemContent
|
|
78
|
+
:result="result"
|
|
79
|
+
:selected="selected"
|
|
80
|
+
/>
|
|
81
|
+
</BaseListItem>
|
|
82
|
+
</div>
|
|
83
|
+
</template>
|
|
84
|
+
|
|
85
|
+
<style scoped>
|
|
86
|
+
.bind-icon-color {
|
|
87
|
+
color: v-bind('result.iconColor');
|
|
88
|
+
}
|
|
89
|
+
</style>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import type { SearchResult } from '../../types.js'
|
|
3
|
+
import { Icon } from '@iconify/vue'
|
|
4
|
+
import BaseIcon from '../base/BaseIcon.vue'
|
|
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>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { Icon } from '@iconify/vue'
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<template>
|
|
6
|
+
<div
|
|
7
|
+
class="histoire-search-loading htw-flex htw-items-center htw-gap-4 htw-pl-6 htw-border htw-border-transparent focus-visible:htw-border-primary-500 htw-h-[51px] htw-opacity-30"
|
|
8
|
+
>
|
|
9
|
+
<Icon
|
|
10
|
+
icon="carbon:search"
|
|
11
|
+
class="flex-none htw-w-4 htw-h-4"
|
|
12
|
+
/>
|
|
13
|
+
|
|
14
|
+
Loading...
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { defineAsyncComponent } from 'vue'
|
|
3
|
+
import SearchLoading from './SearchLoading.vue'
|
|
4
|
+
|
|
5
|
+
const SearchPane = defineAsyncComponent({
|
|
6
|
+
loader: () => import('./SearchPane.vue'),
|
|
7
|
+
loadingComponent: SearchLoading,
|
|
8
|
+
delay: 0,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
defineProps({
|
|
12
|
+
shown: {
|
|
13
|
+
type: Boolean,
|
|
14
|
+
default: false,
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const emit = defineEmits({
|
|
19
|
+
close: () => true,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
function close() {
|
|
23
|
+
emit('close')
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div
|
|
29
|
+
v-show="shown"
|
|
30
|
+
class="histoire-search-modal htw-fixed htw-inset-0 htw-bg-white/80 dark:htw-bg-gray-900/80 htw-z-20"
|
|
31
|
+
data-test-id="search-modal"
|
|
32
|
+
>
|
|
33
|
+
<div
|
|
34
|
+
class="htw-absolute htw-inset-0"
|
|
35
|
+
@click="close()"
|
|
36
|
+
/>
|
|
37
|
+
<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">
|
|
38
|
+
<SearchPane
|
|
39
|
+
:shown="shown"
|
|
40
|
+
@close="close()"
|
|
41
|
+
/>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|