histoire 0.0.0 → 0.0.3
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/client.d.ts +2 -0
- package/dist/client/app/App.vue +84 -21
- package/dist/client/app/assets/histoire-text-dark.svg +89 -0
- package/dist/client/app/assets/histoire-text.svg +89 -0
- package/dist/client/app/assets/histoire.svg +51 -0
- package/dist/client/app/codegen/serialize-js.d.ts +1 -0
- package/dist/client/app/codegen/serialize-js.js +113 -0
- package/dist/client/app/codegen/serialize-js.ts +119 -0
- package/dist/client/app/codegen/util.d.ts +10 -0
- package/dist/client/app/codegen/util.js +70 -0
- package/dist/client/app/codegen/util.ts +79 -0
- package/dist/client/app/codegen/vue3.d.ts +2 -0
- package/dist/client/app/codegen/vue3.js +238 -0
- package/dist/client/app/codegen/vue3.ts +240 -0
- package/dist/client/app/components/HomeView.vue +15 -1
- package/dist/client/app/components/StoryControls.vue +7 -2
- package/dist/client/app/components/StoryList.vue +20 -13
- package/dist/client/app/components/StoryListFolder.vue +87 -0
- package/dist/client/app/components/StoryListItem.vue +38 -12
- package/dist/client/app/components/StorySourceCode.vue +121 -0
- package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
- package/dist/client/app/components/StoryVariantListItem.vue +46 -0
- package/dist/client/app/components/StoryVariantSingleView.vue +145 -15
- package/dist/client/app/components/StoryView.vue +88 -54
- package/dist/client/app/components/app/AppHeader.vue +56 -0
- package/dist/client/app/components/app/AppLogo.vue +24 -0
- package/dist/client/app/components/base/BaseEmpty.vue +1 -1
- package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
- package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
- package/dist/client/app/components/exposed/Story.vue +23 -58
- package/dist/client/app/components/exposed/Variant.vue +24 -47
- package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
- package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
- package/dist/client/app/components/search/SearchItem.vue +110 -0
- package/dist/client/app/components/search/SearchModal.vue +179 -0
- package/dist/client/app/composable/variant.js +0 -1
- package/dist/client/app/composable/variant.ts +20 -0
- package/dist/client/app/global-components.js +0 -1
- package/dist/client/app/global-components.ts +10 -0
- package/dist/client/app/index.d.ts +1 -0
- package/dist/client/app/index.js +10 -2
- package/dist/client/app/index.ts +24 -0
- package/dist/client/app/router.js +0 -1
- package/dist/client/app/router.ts +17 -0
- package/dist/client/app/sandbox.d.ts +1 -0
- package/dist/client/app/sandbox.js +53 -0
- package/dist/client/app/sandbox.ts +60 -0
- package/dist/client/app/stores/story.d.ts +167 -50
- package/dist/client/app/stores/story.js +33 -16
- package/dist/client/app/stores/story.ts +58 -0
- package/dist/client/app/style/floating-vue.css +31 -0
- package/dist/client/app/style/main.css +17 -2
- package/dist/client/app/style/sandbox.css +14 -0
- package/dist/client/app/types.d.ts +36 -4
- package/dist/client/app/types.js +0 -1
- package/dist/client/app/types.ts +59 -0
- package/dist/client/app/util/config.d.ts +3 -0
- package/dist/client/app/util/config.js +4 -0
- package/dist/client/app/util/config.ts +6 -0
- package/dist/client/app/util/const.d.ts +1 -0
- package/dist/client/app/util/const.js +1 -0
- package/dist/client/app/util/const.ts +1 -0
- package/dist/client/app/util/dark.d.ts +2 -0
- package/dist/client/app/util/dark.js +3 -0
- package/dist/client/app/util/dark.ts +4 -0
- package/dist/client/app/util/env.d.ts +1 -0
- package/dist/client/app/util/env.js +1 -0
- package/dist/client/app/util/env.ts +1 -0
- package/dist/client/app/util/keyboard.d.ts +8 -0
- package/dist/client/app/util/keyboard.js +82 -0
- package/dist/client/app/util/keyboard.ts +99 -0
- package/dist/client/app/util/mapping.d.ts +3 -0
- package/dist/client/app/util/mapping.js +39 -0
- package/dist/client/app/util/mapping.ts +41 -0
- package/dist/client/app/util/tooltip.d.ts +6 -0
- package/dist/client/app/util/tooltip.js +11 -0
- package/dist/client/app/util/tooltip.ts +13 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.ts +12 -0
- package/dist/client/server/Story.server.vue +65 -0
- package/dist/client/server/Variant.server.vue +50 -0
- package/dist/client/server/index.d.ts +2 -0
- package/dist/client/server/index.js +25 -0
- package/dist/client/server/index.ts +29 -0
- package/dist/client/shim.d.ts +5 -0
- package/dist/node/alias.js +0 -1
- package/dist/node/bin.js +8 -3
- package/dist/node/build.d.ts +2 -0
- package/dist/node/build.js +71 -0
- package/dist/node/collect.d.ts +12 -0
- package/dist/node/collect.js +65 -0
- package/dist/node/colors.d.ts +286 -0
- package/dist/node/colors.js +324 -0
- package/dist/node/commands/build.d.ts +1 -0
- package/dist/node/commands/build.js +10 -0
- package/dist/node/commands/dev.d.ts +1 -1
- package/dist/node/commands/dev.js +45 -13
- package/dist/node/config.d.ts +112 -1
- package/dist/node/config.js +124 -2
- package/dist/node/context.d.ts +13 -0
- package/dist/node/context.js +12 -2
- package/dist/node/dom/dom-keys.d.ts +4 -0
- package/dist/node/dom/dom-keys.js +223 -0
- package/dist/node/dom/env.d.ts +5 -0
- package/dist/node/dom/env.js +22 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +2 -2
- package/dist/node/plugin.d.ts +8 -2
- package/dist/node/plugin.js +150 -22
- package/dist/node/server.d.ts +4 -1
- package/dist/node/server.js +80 -21
- package/dist/node/stories.d.ts +8 -9
- package/dist/node/stories.js +42 -23
- package/dist/node/tree.d.ts +19 -0
- package/dist/node/tree.js +54 -0
- package/dist/node/types.d.ts +38 -0
- package/dist/node/types.js +1 -0
- package/dist/style.css +610 -53
- package/package.json +45 -25
- package/scripts/copy.mjs +11 -0
- package/src/client/app/App.vue +84 -21
- package/src/client/app/assets/histoire-text-dark.svg +89 -0
- package/src/client/app/assets/histoire-text.svg +89 -0
- package/src/client/app/assets/histoire.svg +51 -0
- package/src/client/app/codegen/serialize-js.ts +119 -0
- package/src/client/app/codegen/util.ts +79 -0
- package/src/client/app/codegen/vue3.ts +240 -0
- package/src/client/app/components/HomeView.vue +15 -1
- package/src/client/app/components/StoryControls.vue +7 -2
- package/src/client/app/components/StoryList.vue +20 -13
- package/src/client/app/components/StoryListFolder.vue +87 -0
- package/src/client/app/components/StoryListItem.vue +38 -12
- package/src/client/app/components/StorySourceCode.vue +121 -0
- package/src/client/app/components/StoryVariantGridItem.vue +32 -17
- package/src/client/app/components/StoryVariantListItem.vue +46 -0
- package/src/client/app/components/StoryVariantSingleView.vue +145 -15
- package/src/client/app/components/StoryView.vue +88 -54
- package/src/client/app/components/app/AppHeader.vue +56 -0
- package/src/client/app/components/app/AppLogo.vue +24 -0
- package/src/client/app/components/base/BaseEmpty.vue +1 -1
- package/src/client/app/components/base/BaseListItemLink.vue +55 -0
- package/src/client/app/components/base/BaseSplitPane.vue +57 -21
- package/src/client/app/components/exposed/Story.vue +23 -58
- package/src/client/app/components/exposed/Variant.vue +24 -47
- package/src/client/app/components/misc/HatchedPattern.vue +25 -0
- package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
- package/src/client/app/components/search/SearchItem.vue +110 -0
- package/src/client/app/components/search/SearchModal.vue +179 -0
- package/src/client/app/index.ts +10 -1
- package/src/client/app/sandbox.ts +60 -0
- package/src/client/app/stores/story.ts +39 -15
- package/src/client/app/style/floating-vue.css +31 -0
- package/src/client/app/style/main.css +17 -2
- package/src/client/app/style/sandbox.css +14 -0
- package/src/client/app/types.ts +42 -4
- package/src/client/app/util/config.ts +6 -0
- package/src/client/app/util/const.ts +1 -0
- package/src/client/app/util/dark.ts +4 -0
- package/src/client/app/util/env.ts +1 -0
- package/src/client/app/util/keyboard.ts +99 -0
- package/src/client/app/util/mapping.ts +41 -0
- package/src/client/app/util/tooltip.ts +13 -0
- package/src/client/index.ts +12 -0
- package/src/client/server/Story.server.vue +65 -0
- package/src/client/server/Variant.server.vue +50 -0
- package/src/client/server/index.ts +29 -0
- package/src/node/bin.ts +9 -2
- package/src/node/build.ts +80 -0
- package/src/node/collect.ts +78 -0
- package/src/node/colors.ts +340 -0
- package/src/node/commands/build.ts +12 -0
- package/src/node/commands/dev.ts +49 -12
- package/src/node/config.ts +240 -1
- package/src/node/context.ts +21 -1
- package/src/node/dom/dom-keys.ts +227 -0
- package/src/node/dom/env.ts +26 -0
- package/src/node/index.ts +2 -0
- package/src/node/plugin.ts +155 -22
- package/src/node/server.ts +95 -20
- package/src/node/stories.ts +53 -31
- package/src/node/tree.spec.ts +28 -0
- package/src/node/tree.ts +88 -0
- package/src/node/types.ts +40 -0
- package/tailwind.config.cjs +41 -1
- package/tsconfig.json +2 -1
- package/dist/client/app/components/StoryVariantItem.vue +0 -29
- package/dist/client/app/composable/variant.js.map +0 -1
- package/dist/client/app/global-components.js.map +0 -1
- package/dist/client/app/index.js.map +0 -1
- package/dist/client/app/router.js.map +0 -1
- package/dist/client/app/stores/story.js.map +0 -1
- package/dist/client/app/types.js.map +0 -1
- package/dist/node/alias.js.map +0 -1
- package/dist/node/bin.js.map +0 -1
- package/dist/node/commands/dev.js.map +0 -1
- package/dist/node/config.js.map +0 -1
- package/dist/node/context.js.map +0 -1
- package/dist/node/index.js.map +0 -1
- package/dist/node/plugin.js.map +0 -1
- package/dist/node/server.js.map +0 -1
- package/dist/node/stories.js.map +0 -1
- package/src/client/app/components/StoryVariantItem.vue +0 -29
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { RouteLocationRaw } from 'vue-router'
|
|
2
|
+
|
|
3
|
+
export interface StoryFile {
|
|
4
|
+
id: string
|
|
5
|
+
framework: string
|
|
6
|
+
component: any
|
|
7
|
+
story: Story
|
|
8
|
+
path: string[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Story {
|
|
12
|
+
id: string
|
|
13
|
+
title: string
|
|
14
|
+
variants: Variant[]
|
|
15
|
+
layout?: {
|
|
16
|
+
type: 'single'
|
|
17
|
+
} | {
|
|
18
|
+
type: 'grid'
|
|
19
|
+
width: number
|
|
20
|
+
}
|
|
21
|
+
icon?: string
|
|
22
|
+
iconColor?: string
|
|
23
|
+
file?: StoryFile
|
|
24
|
+
lastSelectedVariant?: Variant
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface Variant {
|
|
28
|
+
id: string
|
|
29
|
+
title: string
|
|
30
|
+
icon?: string
|
|
31
|
+
iconColor?: string
|
|
32
|
+
initState?: () => any
|
|
33
|
+
slots?: () => Readonly<any>
|
|
34
|
+
state?: any
|
|
35
|
+
source?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type TreeLeaf = {
|
|
39
|
+
title: string
|
|
40
|
+
index: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type TreeFolder = {
|
|
44
|
+
title: string
|
|
45
|
+
children: (TreeFolder | TreeLeaf)[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type Tree = (TreeFolder | TreeLeaf)[]
|
|
49
|
+
|
|
50
|
+
export interface SearchResult {
|
|
51
|
+
kind: 'story' | 'variant'
|
|
52
|
+
rank: number
|
|
53
|
+
id: string
|
|
54
|
+
title: string
|
|
55
|
+
route: RouteLocationRaw
|
|
56
|
+
path?: string[]
|
|
57
|
+
icon?: string
|
|
58
|
+
iconColor?: string
|
|
59
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HistoireConfig } from '../../../node/config'
|
|
2
|
+
// @ts-expect-error virtual module
|
|
3
|
+
import { config as configRaw, logos as logosRaw } from '$histoire-config'
|
|
4
|
+
|
|
5
|
+
export const histoireConfig: HistoireConfig = configRaw
|
|
6
|
+
export const customLogos: HistoireConfig['theme']['logo'] = logosRaw
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const STATE_SYNC = "__histoire:state-sync";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const STATE_SYNC = '__histoire:state-sync';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const STATE_SYNC = '__histoire:state-sync'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isMac: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isMac = navigator.platform.toLowerCase().includes('mac');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isMac = navigator.platform.toLowerCase().includes('mac')
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
export declare type KeyboardShortcut = string[];
|
|
3
|
+
export declare type KeyboardHandler = (event: KeyboardEvent) => unknown;
|
|
4
|
+
export interface KeyboardShortcutOptions {
|
|
5
|
+
event?: 'keyup' | 'keydown' | 'keypress';
|
|
6
|
+
}
|
|
7
|
+
export declare function onKeyboardShortcut(shortcut: KeyboardShortcut | Ref<KeyboardShortcut>, handler: KeyboardHandler, options?: KeyboardShortcutOptions): void;
|
|
8
|
+
export declare function formatKey(key: string): string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { useEventListener } from '@vueuse/core';
|
|
2
|
+
import { isRef } from 'vue';
|
|
3
|
+
import { isMac } from './env.js';
|
|
4
|
+
export function onKeyboardShortcut(shortcut, handler, options = {}) {
|
|
5
|
+
useEventListener(options.event ?? 'keydown', event => {
|
|
6
|
+
if (isMatchingShortcut(isRef(shortcut) ? shortcut.value : shortcut)) {
|
|
7
|
+
handler(event);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
const modifiers = {
|
|
12
|
+
ctrl: { key: 'Control', pressed: false },
|
|
13
|
+
alt: { key: 'Alt', pressed: false },
|
|
14
|
+
shift: { key: 'Shift', pressed: false },
|
|
15
|
+
meta: { key: 'Meta', pressed: false },
|
|
16
|
+
};
|
|
17
|
+
const pressedKeys = new Set();
|
|
18
|
+
window.addEventListener('keydown', event => {
|
|
19
|
+
for (const i in modifiers) {
|
|
20
|
+
const mod = modifiers[i];
|
|
21
|
+
if (mod.key === event.key) {
|
|
22
|
+
mod.pressed = true;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
pressedKeys.add(event.key.toLocaleLowerCase());
|
|
27
|
+
});
|
|
28
|
+
window.addEventListener('keyup', event => {
|
|
29
|
+
requestAnimationFrame(() => {
|
|
30
|
+
pressedKeys.clear();
|
|
31
|
+
for (const i in modifiers) {
|
|
32
|
+
const mod = modifiers[i];
|
|
33
|
+
if (mod.key === event.key) {
|
|
34
|
+
mod.pressed = false;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
window.addEventListener('blur', () => {
|
|
41
|
+
pressedKeys.clear();
|
|
42
|
+
for (const i in modifiers) {
|
|
43
|
+
const mod = modifiers[i];
|
|
44
|
+
mod.pressed = false;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
function isMatchingShortcut(shortcut) {
|
|
48
|
+
for (const combination of shortcut) {
|
|
49
|
+
if (isMatchingCombination(combination.toLowerCase())) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
function isMatchingCombination(combination) {
|
|
56
|
+
const splitted = combination.split('+').map(key => key.trim());
|
|
57
|
+
const targetKey = splitted.pop();
|
|
58
|
+
for (const mod in modifiers) {
|
|
59
|
+
const containsMod = splitted.includes(mod);
|
|
60
|
+
const isPressed = modifiers[mod].pressed;
|
|
61
|
+
if (containsMod !== isPressed) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return pressedKeys.has(targetKey);
|
|
66
|
+
}
|
|
67
|
+
export function formatKey(key) {
|
|
68
|
+
key = key.toLowerCase();
|
|
69
|
+
if (key === 'ctrl') {
|
|
70
|
+
return isMac ? '^' : 'Ctrl';
|
|
71
|
+
}
|
|
72
|
+
if (key === 'alt') {
|
|
73
|
+
return isMac ? '⎇' : 'Alt';
|
|
74
|
+
}
|
|
75
|
+
if (key === 'shift') {
|
|
76
|
+
return '⇧';
|
|
77
|
+
}
|
|
78
|
+
if (key === 'meta') {
|
|
79
|
+
return '⌘';
|
|
80
|
+
}
|
|
81
|
+
return key.charAt(0).toUpperCase() + key.substring(1).toLowerCase();
|
|
82
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useEventListener } from '@vueuse/core'
|
|
2
|
+
import { isRef, Ref } from 'vue'
|
|
3
|
+
import { isMac } from './env.js'
|
|
4
|
+
|
|
5
|
+
export type KeyboardShortcut = string[]
|
|
6
|
+
|
|
7
|
+
export type KeyboardHandler = (event: KeyboardEvent) => unknown
|
|
8
|
+
|
|
9
|
+
export interface KeyboardShortcutOptions {
|
|
10
|
+
event?: 'keyup' | 'keydown' | 'keypress'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function onKeyboardShortcut (shortcut: KeyboardShortcut | Ref<KeyboardShortcut>, handler: KeyboardHandler, options: KeyboardShortcutOptions = {}) {
|
|
14
|
+
useEventListener(options.event ?? 'keydown', event => {
|
|
15
|
+
if (isMatchingShortcut(isRef(shortcut) ? shortcut.value : shortcut)) {
|
|
16
|
+
handler(event)
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const modifiers: { [i: string]: { key: string, pressed: boolean } } = {
|
|
22
|
+
ctrl: { key: 'Control', pressed: false },
|
|
23
|
+
alt: { key: 'Alt', pressed: false },
|
|
24
|
+
shift: { key: 'Shift', pressed: false },
|
|
25
|
+
meta: { key: 'Meta', pressed: false },
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const pressedKeys = new Set<string>()
|
|
29
|
+
|
|
30
|
+
window.addEventListener('keydown', event => {
|
|
31
|
+
for (const i in modifiers) {
|
|
32
|
+
const mod = modifiers[i]
|
|
33
|
+
if (mod.key === event.key) {
|
|
34
|
+
mod.pressed = true
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
pressedKeys.add(event.key.toLocaleLowerCase())
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
window.addEventListener('keyup', event => {
|
|
42
|
+
requestAnimationFrame(() => {
|
|
43
|
+
pressedKeys.clear()
|
|
44
|
+
for (const i in modifiers) {
|
|
45
|
+
const mod = modifiers[i]
|
|
46
|
+
if (mod.key === event.key) {
|
|
47
|
+
mod.pressed = false
|
|
48
|
+
break
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
window.addEventListener('blur', () => {
|
|
55
|
+
pressedKeys.clear()
|
|
56
|
+
for (const i in modifiers) {
|
|
57
|
+
const mod = modifiers[i]
|
|
58
|
+
mod.pressed = false
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
function isMatchingShortcut (shortcut: KeyboardShortcut): boolean {
|
|
63
|
+
for (const combination of shortcut) {
|
|
64
|
+
if (isMatchingCombination(combination.toLowerCase())) {
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function isMatchingCombination (combination: string): boolean {
|
|
72
|
+
const splitted = combination.split('+').map(key => key.trim())
|
|
73
|
+
const targetKey = splitted.pop()
|
|
74
|
+
for (const mod in modifiers) {
|
|
75
|
+
const containsMod = splitted.includes(mod)
|
|
76
|
+
const isPressed = modifiers[mod].pressed
|
|
77
|
+
if (containsMod !== isPressed) {
|
|
78
|
+
return false
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return pressedKeys.has(targetKey)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function formatKey (key: string) {
|
|
85
|
+
key = key.toLowerCase()
|
|
86
|
+
if (key === 'ctrl') {
|
|
87
|
+
return isMac ? '^' : 'Ctrl'
|
|
88
|
+
}
|
|
89
|
+
if (key === 'alt') {
|
|
90
|
+
return isMac ? '⎇' : 'Alt'
|
|
91
|
+
}
|
|
92
|
+
if (key === 'shift') {
|
|
93
|
+
return '⇧'
|
|
94
|
+
}
|
|
95
|
+
if (key === 'meta') {
|
|
96
|
+
return '⌘'
|
|
97
|
+
}
|
|
98
|
+
return key.charAt(0).toUpperCase() + key.substring(1).toLowerCase()
|
|
99
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { markRaw } from 'vue';
|
|
2
|
+
export function mapFile(file, existingFile) {
|
|
3
|
+
const result = {
|
|
4
|
+
...file,
|
|
5
|
+
component: markRaw(file.component),
|
|
6
|
+
story: {
|
|
7
|
+
...file.story,
|
|
8
|
+
title: file.story.title,
|
|
9
|
+
file: markRaw(file),
|
|
10
|
+
variants: file.story.variants.map(v => mapVariant(v)),
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
if (existingFile) {
|
|
14
|
+
for (const index in result.story.variants) {
|
|
15
|
+
const variant = result.story.variants[index];
|
|
16
|
+
const existingVariant = existingFile.story.variants[index];
|
|
17
|
+
if (existingVariant) {
|
|
18
|
+
if (existingVariant.state)
|
|
19
|
+
Object.assign(variant.state, existingVariant.state);
|
|
20
|
+
if (existingVariant.initState)
|
|
21
|
+
variant.initState = existingVariant.initState;
|
|
22
|
+
if (existingVariant.slots)
|
|
23
|
+
variant.slots = existingVariant.slots;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (existingFile.story.lastSelectedVariant) {
|
|
27
|
+
result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
export function mapVariant(variant) {
|
|
33
|
+
return {
|
|
34
|
+
...variant,
|
|
35
|
+
state: {},
|
|
36
|
+
initState: null,
|
|
37
|
+
slots: () => ({}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { markRaw } from 'vue'
|
|
2
|
+
import type { StoryFile, Variant } from '../types'
|
|
3
|
+
|
|
4
|
+
export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
|
|
5
|
+
const result: StoryFile = {
|
|
6
|
+
...file,
|
|
7
|
+
component: markRaw(file.component),
|
|
8
|
+
story: {
|
|
9
|
+
...file.story,
|
|
10
|
+
title: file.story.title,
|
|
11
|
+
file: markRaw(file),
|
|
12
|
+
variants: file.story.variants.map(v => mapVariant(v)),
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (existingFile) {
|
|
17
|
+
for (const index in result.story.variants) {
|
|
18
|
+
const variant = result.story.variants[index]
|
|
19
|
+
const existingVariant = existingFile.story.variants[index]
|
|
20
|
+
if (existingVariant) {
|
|
21
|
+
if (existingVariant.state) Object.assign(variant.state, existingVariant.state)
|
|
22
|
+
if (existingVariant.initState) variant.initState = existingVariant.initState
|
|
23
|
+
if (existingVariant.slots) variant.slots = existingVariant.slots
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (existingFile.story.lastSelectedVariant) {
|
|
27
|
+
result.story.lastSelectedVariant = result.story.variants.find(v => v.id === existingFile.story.lastSelectedVariant.id)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return result
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function mapVariant (variant: Variant): Variant {
|
|
35
|
+
return {
|
|
36
|
+
...variant,
|
|
37
|
+
state: {},
|
|
38
|
+
initState: null,
|
|
39
|
+
slots: () => ({}),
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isMac } from './env.js';
|
|
2
|
+
import { formatKey } from './keyboard.js';
|
|
3
|
+
export function makeTooltip(descriptionHtml, keyboardShortcut) {
|
|
4
|
+
return {
|
|
5
|
+
content: `<div>${descriptionHtml}</div><div class="htw-flex htw-items-center htw-gap-1 htw-mt-2 htw-text-sm">${genKeyboardShortcutHtml(keyboardShortcut({ isMac }))}</div>`,
|
|
6
|
+
html: true,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function genKeyboardShortcutHtml(shortcut) {
|
|
10
|
+
return shortcut.split('+').map(k => k.trim()).map(key => `<span class="htw-bg-gray-500 htw-border-b-2 htw-border-gray-600 htw-px-1 htw-rounded-sm">${formatKey(key)}</span>`).join('');
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isMac } from './env.js'
|
|
2
|
+
import { formatKey } from './keyboard.js'
|
|
3
|
+
|
|
4
|
+
export function makeTooltip (descriptionHtml: string, keyboardShortcut: ({ 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 shortcut.split('+').map(k => k.trim()).map(key => `<span class="htw-bg-gray-500 htw-border-b-2 htw-border-gray-600 htw-px-1 htw-rounded-sm">${formatKey(key)}</span>`).join('')
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
import type { Story, Variant } from './app/types.js';
|
|
3
|
+
export declare type Vue3StorySetupHandler = (payload: {
|
|
4
|
+
app: App;
|
|
5
|
+
story: Story;
|
|
6
|
+
variant: Variant;
|
|
7
|
+
}) => Promise<void> | void;
|
|
8
|
+
export declare function defineVue3StorySetup(handler: Vue3StorySetupHandler): Vue3StorySetupHandler;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { App } from 'vue'
|
|
2
|
+
import type { Story, Variant } from './app/types.js'
|
|
3
|
+
|
|
4
|
+
export type Vue3StorySetupHandler = (payload: {
|
|
5
|
+
app: App
|
|
6
|
+
story: Story
|
|
7
|
+
variant: Variant
|
|
8
|
+
}) => Promise<void> | void
|
|
9
|
+
|
|
10
|
+
export function defineVue3StorySetup (handler: Vue3StorySetupHandler): Vue3StorySetupHandler {
|
|
11
|
+
return handler
|
|
12
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { defineComponent, inject, PropType, provide, useAttrs } from 'vue'
|
|
3
|
+
import type { StoryFile, Story, Variant } from '../../node/types'
|
|
4
|
+
|
|
5
|
+
export default defineComponent({
|
|
6
|
+
inheritAttrs: false,
|
|
7
|
+
|
|
8
|
+
props: {
|
|
9
|
+
title: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
layout: {
|
|
15
|
+
type: Object as PropType<Story['layout']>,
|
|
16
|
+
default: () => ({ type: 'single' }),
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
icon: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: null,
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
iconColor: {
|
|
25
|
+
type: String,
|
|
26
|
+
default: null,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
setup (props) {
|
|
31
|
+
const attrs = useAttrs() as {
|
|
32
|
+
data: StoryFile
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Story
|
|
36
|
+
|
|
37
|
+
const story: Story = {
|
|
38
|
+
id: attrs.data.id,
|
|
39
|
+
title: props.title,
|
|
40
|
+
layout: props.layout,
|
|
41
|
+
icon: props.icon,
|
|
42
|
+
iconColor: props.iconColor,
|
|
43
|
+
variants: [],
|
|
44
|
+
}
|
|
45
|
+
const addStory = inject('addStory', null)
|
|
46
|
+
addStory?.(story)
|
|
47
|
+
|
|
48
|
+
// Variants
|
|
49
|
+
|
|
50
|
+
provide('story', story)
|
|
51
|
+
|
|
52
|
+
provide('addVariant', (variant: Variant) => {
|
|
53
|
+
story.variants.push(variant)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
story,
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
render () {
|
|
62
|
+
return this.$slots.default()
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
</script>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { defineComponent, inject } from 'vue'
|
|
3
|
+
import type { Story, Variant } from '../../node/types'
|
|
4
|
+
|
|
5
|
+
export default defineComponent({
|
|
6
|
+
props: {
|
|
7
|
+
title: {
|
|
8
|
+
type: String,
|
|
9
|
+
default: 'untitled',
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
id: {
|
|
13
|
+
type: String,
|
|
14
|
+
default: null,
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
icon: {
|
|
18
|
+
type: String,
|
|
19
|
+
default: null,
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
iconColor: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: null,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
setup (props) {
|
|
29
|
+
const story = inject<Story>('story')
|
|
30
|
+
|
|
31
|
+
function generateId () {
|
|
32
|
+
return `${story.id}-${story.variants.length}`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const variant: Variant = {
|
|
36
|
+
id: props.id ?? generateId(),
|
|
37
|
+
title: props.title,
|
|
38
|
+
icon: props.icon,
|
|
39
|
+
iconColor: props.iconColor,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const addVariant = inject('addVariant') as (variant: Variant) => void
|
|
43
|
+
addVariant(variant)
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
render () {
|
|
47
|
+
return null
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
</script>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createApp, h } from 'vue';
|
|
2
|
+
import Story from './Story.server.vue';
|
|
3
|
+
import Variant from './Variant.server.vue';
|
|
4
|
+
export async function run(file, storyData, el) {
|
|
5
|
+
const { default: Comp } = await import(file.moduleId);
|
|
6
|
+
const app = createApp({
|
|
7
|
+
provide: {
|
|
8
|
+
addStory(data) {
|
|
9
|
+
storyData.push(data);
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
render() {
|
|
13
|
+
return h(Comp, {
|
|
14
|
+
ref: 'comp',
|
|
15
|
+
data: file,
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
// eslint-disable-next-line vue/multi-word-component-names
|
|
20
|
+
app.component('Story', Story);
|
|
21
|
+
// eslint-disable-next-line vue/multi-word-component-names
|
|
22
|
+
app.component('Variant', Variant);
|
|
23
|
+
app.mount(el);
|
|
24
|
+
app.unmount();
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createApp, h } from 'vue'
|
|
2
|
+
import type { StoryFile } from '../../node/types'
|
|
3
|
+
import Story from './Story.server.vue'
|
|
4
|
+
import Variant from './Variant.server.vue'
|
|
5
|
+
|
|
6
|
+
export async function run (file: StoryFile, storyData, el) {
|
|
7
|
+
const { default: Comp } = await import(file.moduleId)
|
|
8
|
+
const app = createApp({
|
|
9
|
+
provide: {
|
|
10
|
+
addStory (data) {
|
|
11
|
+
storyData.push(data)
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
render () {
|
|
15
|
+
return h(Comp, {
|
|
16
|
+
ref: 'comp',
|
|
17
|
+
data: file,
|
|
18
|
+
})
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line vue/multi-word-component-names
|
|
23
|
+
app.component('Story', Story)
|
|
24
|
+
// eslint-disable-next-line vue/multi-word-component-names
|
|
25
|
+
app.component('Variant', Variant)
|
|
26
|
+
|
|
27
|
+
app.mount(el)
|
|
28
|
+
app.unmount()
|
|
29
|
+
}
|
package/dist/node/alias.js
CHANGED
package/dist/node/bin.js
CHANGED
|
@@ -10,8 +10,13 @@ program.command('dev')
|
|
|
10
10
|
.describe('open the stories in your browser for development')
|
|
11
11
|
.option('-p, --port <port>', 'Listening port of the server')
|
|
12
12
|
.action(async (options) => {
|
|
13
|
-
const {
|
|
14
|
-
return
|
|
13
|
+
const { devCommand } = await import('./commands/dev.js');
|
|
14
|
+
return devCommand(options);
|
|
15
|
+
});
|
|
16
|
+
program.command('build')
|
|
17
|
+
.describe('build the histoire final app you can deploy')
|
|
18
|
+
.action(async () => {
|
|
19
|
+
const { buildCommand } = await import('./commands/build.js');
|
|
20
|
+
return buildCommand();
|
|
15
21
|
});
|
|
16
22
|
program.parse(process.argv);
|
|
17
|
-
//# sourceMappingURL=bin.js.map
|