histoire 0.0.2 → 0.0.5
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/README.md +11 -0
- package/dist/client/app/App.vue +8 -8
- package/dist/client/app/codegen/vue3.js +28 -4
- package/dist/client/app/codegen/vue3.ts +32 -4
- package/dist/client/app/components/app/AppHeader.vue +10 -3
- package/dist/client/app/components/base/BaseTab.vue +46 -0
- package/dist/client/app/components/exposed/Story.vue +21 -1
- package/dist/client/app/components/exposed/Variant.vue +1 -0
- package/dist/client/app/components/misc/CheckerboardPattern.vue +32 -0
- package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -0
- package/dist/client/app/components/search/SearchItem.vue +5 -9
- package/dist/client/app/components/{StoryControls.vue → story/StoryControls.vue} +3 -3
- package/dist/client/app/components/story/StoryDocs.vue +37 -0
- package/dist/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
- package/{src/client/app/components → dist/client/app/components/story}/StoryListFolder.vue +5 -5
- package/{src/client/app/components → dist/client/app/components/story}/StoryListItem.vue +11 -6
- package/dist/client/app/components/story/StoryResponsivePreview.vue +214 -0
- package/dist/client/app/components/{StorySourceCode.vue → story/StorySourceCode.vue} +4 -8
- package/{src/client/app/components → dist/client/app/components/story}/StoryVariantGridItem.vue +14 -6
- package/dist/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
- package/dist/client/app/components/story/StoryVariantSingleView.vue +182 -0
- package/dist/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
- package/dist/client/app/global-components.js +2 -0
- package/dist/client/app/global-components.ts +3 -0
- package/dist/client/app/index.js +10 -0
- package/dist/client/app/index.ts +10 -0
- package/dist/client/app/router.js +1 -1
- package/dist/client/app/router.ts +1 -1
- package/dist/client/app/sandbox.js +37 -3
- package/dist/client/app/sandbox.ts +37 -3
- package/dist/client/app/stores/story.d.ts +15 -0
- package/dist/client/app/style/floating-vue.css +31 -0
- package/dist/client/app/style/main.css +17 -1
- package/dist/client/app/style/sandbox.css +5 -0
- package/dist/client/app/style/transitions.css +12 -0
- package/dist/client/app/types.d.ts +1 -0
- package/dist/client/app/types.ts +1 -0
- package/dist/client/app/util/const.d.ts +2 -0
- package/dist/client/app/util/const.js +2 -0
- package/dist/client/app/util/const.ts +2 -0
- package/dist/client/app/util/mapping.js +6 -0
- package/dist/client/app/util/mapping.ts +5 -0
- package/dist/client/app/util/preview-settings.d.ts +16 -0
- package/dist/client/app/util/preview-settings.js +15 -0
- package/dist/client/app/util/preview-settings.ts +26 -0
- package/dist/client/app/util/reactivity.d.ts +1 -0
- package/dist/client/app/util/reactivity.js +16 -0
- package/dist/client/app/util/reactivity.ts +22 -0
- package/dist/client/app/util/scroll.d.ts +2 -0
- package/dist/client/app/util/scroll.js +24 -0
- package/dist/client/app/util/scroll.ts +27 -0
- package/dist/client/app/{composable → util}/variant.d.ts +0 -0
- package/dist/client/app/{composable → util}/variant.js +0 -0
- package/dist/client/app/{composable → util}/variant.ts +0 -0
- package/dist/client/server/Story.server.vue +25 -2
- package/dist/client/server/index.js +2 -0
- package/dist/client/server/index.ts +3 -0
- package/dist/controls.d.ts +1 -0
- package/dist/controls.js +1 -0
- package/dist/node/build.js +36 -11
- package/dist/node/collect.js +12 -3
- package/dist/node/commands/dev.js +43 -5
- package/dist/node/config.d.ts +35 -0
- package/dist/node/config.js +75 -1
- package/dist/node/markdown.d.ts +2 -0
- package/dist/node/markdown.js +48 -0
- package/dist/node/plugin.js +35 -0
- package/dist/node/util/slugify.d.ts +1 -0
- package/dist/node/util/slugify.js +22 -0
- package/dist/style.css +869 -159
- package/package.json +15 -6
- package/src/client/app/App.vue +8 -8
- package/src/client/app/codegen/vue3.ts +32 -4
- package/src/client/app/components/app/AppHeader.vue +10 -3
- package/src/client/app/components/base/BaseTab.vue +46 -0
- package/src/client/app/components/exposed/Story.vue +21 -1
- package/src/client/app/components/exposed/Variant.vue +1 -0
- package/src/client/app/components/misc/CheckerboardPattern.vue +32 -0
- package/src/client/app/components/sandbox/SandboxVue3.vue +6 -0
- package/src/client/app/components/search/SearchItem.vue +5 -9
- package/src/client/app/components/{StoryControls.vue → story/StoryControls.vue} +3 -3
- package/src/client/app/components/story/StoryDocs.vue +37 -0
- package/src/client/app/components/{StoryList.vue → story/StoryList.vue} +4 -4
- package/{dist/client/app/components → src/client/app/components/story}/StoryListFolder.vue +5 -5
- package/{dist/client/app/components → src/client/app/components/story}/StoryListItem.vue +11 -6
- package/src/client/app/components/story/StoryResponsivePreview.vue +214 -0
- package/src/client/app/components/{StorySourceCode.vue → story/StorySourceCode.vue} +4 -8
- package/{dist/client/app/components → src/client/app/components/story}/StoryVariantGridItem.vue +14 -6
- package/src/client/app/components/{StoryVariantListItem.vue → story/StoryVariantListItem.vue} +9 -8
- package/src/client/app/components/story/StoryVariantSingleView.vue +182 -0
- package/src/client/app/components/{StoryView.vue → story/StoryView.vue} +37 -10
- package/src/client/app/global-components.ts +3 -0
- package/src/client/app/index.ts +10 -0
- package/src/client/app/router.ts +1 -1
- package/src/client/app/sandbox.ts +37 -3
- package/src/client/app/style/floating-vue.css +31 -0
- package/src/client/app/style/main.css +17 -1
- package/src/client/app/style/sandbox.css +5 -0
- package/src/client/app/style/transitions.css +12 -0
- package/src/client/app/types.ts +1 -0
- package/src/client/app/util/const.ts +2 -0
- package/src/client/app/util/mapping.ts +5 -0
- package/src/client/app/util/preview-settings.ts +26 -0
- package/src/client/app/util/reactivity.ts +22 -0
- package/src/client/app/util/scroll.ts +27 -0
- package/src/client/app/{composable → util}/variant.ts +0 -0
- package/src/client/server/Story.server.vue +25 -2
- package/src/client/server/index.ts +3 -0
- package/src/controls.ts +1 -0
- package/src/node/build.ts +43 -11
- package/src/node/collect.ts +12 -3
- package/src/node/commands/dev.ts +49 -5
- package/src/node/config.ts +112 -2
- package/src/node/markdown.ts +56 -0
- package/src/node/plugin.ts +38 -0
- package/src/node/util/slugify.ts +26 -0
- package/tailwind.config.cjs +79 -4
- package/dist/client/app/components/StoryVariantSingleView.vue +0 -145
- package/src/client/app/components/StoryVariantSingleView.vue +0 -145
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createApp, h } from 'vue'
|
|
2
|
+
import { registerVueComponents } from '@histoire/controls'
|
|
2
3
|
import type { StoryFile } from '../../node/types'
|
|
3
4
|
import Story from './Story.server.vue'
|
|
4
5
|
import Variant from './Variant.server.vue'
|
|
@@ -24,6 +25,8 @@ export async function run (file: StoryFile, storyData, el) {
|
|
|
24
25
|
// eslint-disable-next-line vue/multi-word-component-names
|
|
25
26
|
app.component('Variant', Variant)
|
|
26
27
|
|
|
28
|
+
registerVueComponents(app)
|
|
29
|
+
|
|
27
30
|
app.mount(el)
|
|
28
31
|
app.unmount()
|
|
29
32
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@histoire/controls';
|
package/dist/controls.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@histoire/controls';
|
package/dist/node/build.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { join } from 'pathe';
|
|
2
|
-
import { build as viteBuild, createServer as createViteServer
|
|
2
|
+
import { build as viteBuild, createServer as createViteServer } from 'vite';
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
4
|
import { lookup as lookupMime } from 'mrmime';
|
|
5
|
+
import pc from 'picocolors';
|
|
6
|
+
import { performance } from 'perf_hooks';
|
|
5
7
|
import { APP_PATH } from './alias.js';
|
|
6
8
|
import { createVitePlugins } from './plugin.js';
|
|
7
9
|
import { findAllStories } from './stories.js';
|
|
8
10
|
import { useCollectStories } from './collect.js';
|
|
11
|
+
const PRELOAD_MODULES = [
|
|
12
|
+
'vendor',
|
|
13
|
+
];
|
|
14
|
+
const PREFETCHED_MODULES = [
|
|
15
|
+
'StoryView',
|
|
16
|
+
'reactivity',
|
|
17
|
+
'global-components',
|
|
18
|
+
];
|
|
9
19
|
export async function build(ctx) {
|
|
20
|
+
const startTime = performance.now();
|
|
10
21
|
await findAllStories(ctx);
|
|
11
22
|
// Collect story data
|
|
12
|
-
const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
|
|
13
|
-
const plugins = [];
|
|
14
|
-
const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue');
|
|
15
|
-
if (!hasVuePlugin) {
|
|
16
|
-
plugins.push((await import('@vitejs/plugin-vue')).default());
|
|
17
|
-
}
|
|
18
23
|
const server = await createViteServer({
|
|
19
|
-
plugins,
|
|
24
|
+
plugins: await createVitePlugins(ctx),
|
|
20
25
|
});
|
|
21
26
|
await server.pluginContainer.buildStart({});
|
|
22
27
|
const { executeStoryFile, destroy: destroyCollectStories } = useCollectStories({
|
|
@@ -28,6 +33,9 @@ export async function build(ctx) {
|
|
|
28
33
|
}
|
|
29
34
|
await server.close();
|
|
30
35
|
await destroyCollectStories();
|
|
36
|
+
const storyCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ? 1 : 0), 0);
|
|
37
|
+
const variantCount = ctx.storyFiles.reduce((sum, file) => sum + (file.story?.variants.length ?? 0), 0);
|
|
38
|
+
const emptyStoryCount = ctx.storyFiles.length - storyCount;
|
|
31
39
|
const results = await viteBuild({
|
|
32
40
|
plugins: await createVitePlugins(ctx),
|
|
33
41
|
build: {
|
|
@@ -44,14 +52,27 @@ export async function build(ctx) {
|
|
|
44
52
|
});
|
|
45
53
|
const result = Array.isArray(results) ? results[0] : results;
|
|
46
54
|
const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset');
|
|
55
|
+
// Preload
|
|
56
|
+
const preloadOutputs = result.output.filter(o => PRELOAD_MODULES.includes(o.name) && o.type === 'chunk');
|
|
57
|
+
const preloadHtml = generateScriptLinks(preloadOutputs.map(o => o.fileName), 'preload');
|
|
58
|
+
// Prefetch
|
|
59
|
+
const prefetchOutputs = result.output.filter(o => PREFETCHED_MODULES.includes(o.name) && o.type === 'chunk');
|
|
60
|
+
const prefetchHtml = generateScriptLinks(prefetchOutputs.map(o => o.fileName), 'prefetch');
|
|
47
61
|
// Index
|
|
48
62
|
const indexOutput = result.output.find(o => o.name === 'index' && o.type === 'chunk');
|
|
49
|
-
await writeHtml(indexOutput.fileName, styleOutput.fileName, 'index.html',
|
|
63
|
+
await writeHtml(indexOutput.fileName, styleOutput.fileName, 'index.html', {
|
|
64
|
+
HEAD: `${preloadHtml}${prefetchHtml}`,
|
|
65
|
+
}, ctx);
|
|
50
66
|
// Sandbox
|
|
51
67
|
const sandboxOutput = result.output.find(o => o.name === 'sandbox' && o.type === 'chunk');
|
|
52
|
-
await writeHtml(sandboxOutput.fileName, styleOutput.fileName, '__sandbox.html', ctx);
|
|
68
|
+
await writeHtml(sandboxOutput.fileName, styleOutput.fileName, '__sandbox.html', {}, ctx);
|
|
69
|
+
const duration = performance.now() - startTime;
|
|
70
|
+
if (emptyStoryCount) {
|
|
71
|
+
console.warn(pc.yellow(`⚠️ ${emptyStoryCount} empty story file`));
|
|
72
|
+
}
|
|
73
|
+
console.log(pc.green(`✅ Built ${storyCount} stories (${variantCount} variants) in ${Math.round(duration / 1000 * 100) / 100}s`));
|
|
53
74
|
}
|
|
54
|
-
async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, ctx) {
|
|
75
|
+
async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, variables, ctx) {
|
|
55
76
|
const code = `<!DOCTYPE html>
|
|
56
77
|
<html>
|
|
57
78
|
<head>
|
|
@@ -61,6 +82,7 @@ async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, ctx) {
|
|
|
61
82
|
<meta name="description" content="">
|
|
62
83
|
<link rel="stylesheet" href="/${cssEntryFile}">
|
|
63
84
|
${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${ctx.config.theme.favicon}"/>` : ''}
|
|
85
|
+
${variables.HEAD ?? ''}
|
|
64
86
|
</head>
|
|
65
87
|
<body>
|
|
66
88
|
<div id="app"></div>
|
|
@@ -69,3 +91,6 @@ async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, ctx) {
|
|
|
69
91
|
</html>`;
|
|
70
92
|
await fs.writeFile(join(ctx.config.outDir, htmlFileName), code, 'utf8');
|
|
71
93
|
}
|
|
94
|
+
function generateScriptLinks(prefetchScripts, rel) {
|
|
95
|
+
return prefetchScripts.map(s => `<link rel="${rel}" href="${s}" as="script" crossOrigin="anonymous">`).join('');
|
|
96
|
+
}
|
package/dist/node/collect.js
CHANGED
|
@@ -9,7 +9,13 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
9
9
|
export function useCollectStories(options, ctx) {
|
|
10
10
|
const { server } = options;
|
|
11
11
|
const { destroy: destroyDomEnv } = createDomEnv();
|
|
12
|
-
const node = new ViteNodeServer(server
|
|
12
|
+
const node = new ViteNodeServer(server, {
|
|
13
|
+
deps: {
|
|
14
|
+
inline: [
|
|
15
|
+
/histoire\/dist/,
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
});
|
|
13
19
|
const runner = new ViteNodeRunner({
|
|
14
20
|
root: server.config.root,
|
|
15
21
|
base: server.config.base,
|
|
@@ -20,6 +26,9 @@ export function useCollectStories(options, ctx) {
|
|
|
20
26
|
}
|
|
21
27
|
return node.fetchModule(id);
|
|
22
28
|
},
|
|
29
|
+
resolveId(id, importer) {
|
|
30
|
+
return node.resolveId(id, importer);
|
|
31
|
+
},
|
|
23
32
|
});
|
|
24
33
|
function clearCache() {
|
|
25
34
|
node.fetchCache.clear();
|
|
@@ -33,11 +42,11 @@ export function useCollectStories(options, ctx) {
|
|
|
33
42
|
const storyData = [];
|
|
34
43
|
await run(storyFile, storyData, el);
|
|
35
44
|
if (storyData.length === 0) {
|
|
36
|
-
console.warn(pc.yellow(
|
|
45
|
+
console.warn(pc.yellow(`⚠️ No story found for ${storyFile.path}`));
|
|
37
46
|
return;
|
|
38
47
|
}
|
|
39
48
|
else if (storyData.length > 1) {
|
|
40
|
-
console.warn(pc.yellow(
|
|
49
|
+
console.warn(pc.yellow(`⚠️ Multiple stories not supported: ${storyFile.path}`));
|
|
41
50
|
}
|
|
42
51
|
storyFile.story = storyData[0];
|
|
43
52
|
const file = {
|
|
@@ -1,9 +1,47 @@
|
|
|
1
|
+
import { resolveConfigFile } from '../config.js';
|
|
1
2
|
import { createContext } from '../context.js';
|
|
2
3
|
import { createServer } from '../server.js';
|
|
4
|
+
import chokidar from 'chokidar';
|
|
5
|
+
import pc from 'picocolors';
|
|
3
6
|
export async function devCommand(options) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
let stop;
|
|
8
|
+
async function start() {
|
|
9
|
+
const ctx = await createContext({
|
|
10
|
+
mode: 'dev',
|
|
11
|
+
});
|
|
12
|
+
const { server, close } = await createServer(ctx, options.port);
|
|
13
|
+
server.printUrls();
|
|
14
|
+
// Histoire config watcher
|
|
15
|
+
let watcher;
|
|
16
|
+
if (server.config.configFile) {
|
|
17
|
+
watcher = chokidar.watch(server.config.configFile, {
|
|
18
|
+
ignoreInitial: true,
|
|
19
|
+
});
|
|
20
|
+
watcher.on('change', () => {
|
|
21
|
+
restart('Vite');
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return async () => {
|
|
25
|
+
await watcher?.close();
|
|
26
|
+
await close();
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async function restart(source) {
|
|
30
|
+
if (stop) {
|
|
31
|
+
console.log(pc.blue(`${source} config changed, restarting...`));
|
|
32
|
+
stop();
|
|
33
|
+
stop = null; // Don't call stop again until new start() is done
|
|
34
|
+
stop = await start();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
stop = await start();
|
|
38
|
+
const configFile = await resolveConfigFile();
|
|
39
|
+
if (configFile) {
|
|
40
|
+
const watcher = chokidar.watch(configFile, {
|
|
41
|
+
ignoreInitial: true,
|
|
42
|
+
});
|
|
43
|
+
watcher.on('change', () => {
|
|
44
|
+
restart('Histoire');
|
|
45
|
+
});
|
|
46
|
+
}
|
|
9
47
|
}
|
package/dist/node/config.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
import { UserConfig as ViteConfig, ConfigEnv as ViteConfigEnv } from 'vite';
|
|
1
2
|
import { TreeFile } from './tree.js';
|
|
3
|
+
import type MarkdownIt from 'markdown-it';
|
|
2
4
|
declare type CustomizableColors = 'primary' | 'gray';
|
|
3
5
|
declare type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
|
|
4
6
|
declare type GrayColorKeys = ColorKeys | '750' | '850' | '950';
|
|
7
|
+
interface ResponsivePreset {
|
|
8
|
+
label: string;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
interface BackgroundPreset {
|
|
13
|
+
label: string;
|
|
14
|
+
color: string;
|
|
15
|
+
}
|
|
5
16
|
export interface HistoireConfig {
|
|
6
17
|
/**
|
|
7
18
|
* Output directory.
|
|
@@ -74,6 +85,10 @@ export interface HistoireConfig {
|
|
|
74
85
|
[key in ColorKeys]?: string;
|
|
75
86
|
};
|
|
76
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Add a link to the main logo
|
|
90
|
+
*/
|
|
91
|
+
logoHref?: string;
|
|
77
92
|
};
|
|
78
93
|
/**
|
|
79
94
|
* Setup file exposting a default function executed when setting up each story preview.
|
|
@@ -83,6 +98,26 @@ export interface HistoireConfig {
|
|
|
83
98
|
* Example: `'/src/histoire-setup.ts'`
|
|
84
99
|
*/
|
|
85
100
|
setupFile?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Predefined responsive sizes for story playgrounds.
|
|
103
|
+
*/
|
|
104
|
+
responsivePresets?: ResponsivePreset[];
|
|
105
|
+
/**
|
|
106
|
+
* Background color of the story preview.
|
|
107
|
+
*/
|
|
108
|
+
backgroundPresets?: BackgroundPreset[];
|
|
109
|
+
/**
|
|
110
|
+
* Class added to the html root of the story preview when dark mode is enabled.
|
|
111
|
+
*/
|
|
112
|
+
sandboxDarkClass?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Customize the markdown-it renderer
|
|
115
|
+
*/
|
|
116
|
+
markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>;
|
|
117
|
+
/**
|
|
118
|
+
* Vite config override
|
|
119
|
+
*/
|
|
120
|
+
vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>);
|
|
86
121
|
}
|
|
87
122
|
export declare function getDefaultConfig(): HistoireConfig;
|
|
88
123
|
export declare const configFileNames: string[];
|
package/dist/node/config.js
CHANGED
|
@@ -22,6 +22,71 @@ export function getDefaultConfig() {
|
|
|
22
22
|
gray: defaultColors.zinc,
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
|
+
responsivePresets: [
|
|
26
|
+
{
|
|
27
|
+
label: 'Mobile (Small)',
|
|
28
|
+
width: 320,
|
|
29
|
+
height: 560,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: 'Mobile (Medium)',
|
|
33
|
+
width: 360,
|
|
34
|
+
height: 640,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
label: 'Mobile (Large)',
|
|
38
|
+
width: 414,
|
|
39
|
+
height: 896,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
label: 'Tablet',
|
|
43
|
+
width: 768,
|
|
44
|
+
height: 1024,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
label: 'Laptop (Small)',
|
|
48
|
+
width: 1024,
|
|
49
|
+
height: null,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
label: 'Laptop (Large)',
|
|
53
|
+
width: 1366,
|
|
54
|
+
height: null,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
label: 'Desktop',
|
|
58
|
+
width: 1920,
|
|
59
|
+
height: null,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: '4K',
|
|
63
|
+
width: 3840,
|
|
64
|
+
height: null,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
backgroundPresets: [
|
|
68
|
+
{
|
|
69
|
+
label: 'Transparent',
|
|
70
|
+
color: 'transparent',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
label: 'White',
|
|
74
|
+
color: '#fff',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
label: 'Light gray',
|
|
78
|
+
color: '#aaa',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: 'Dark gray',
|
|
82
|
+
color: '#333',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
label: 'Black',
|
|
86
|
+
color: '#000',
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
sandboxDarkClass: 'dark',
|
|
25
90
|
};
|
|
26
91
|
}
|
|
27
92
|
export const configFileNames = [
|
|
@@ -52,12 +117,21 @@ export async function loadConfigFile(configFile) {
|
|
|
52
117
|
try {
|
|
53
118
|
const server = await createServer();
|
|
54
119
|
await server.pluginContainer.buildStart({});
|
|
55
|
-
const node = new ViteNodeServer(server
|
|
120
|
+
const node = new ViteNodeServer(server, {
|
|
121
|
+
deps: {
|
|
122
|
+
inline: [
|
|
123
|
+
/histoire\/dist/,
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
});
|
|
56
127
|
const runner = new ViteNodeRunner({
|
|
57
128
|
root: path.dirname(configFile),
|
|
58
129
|
fetchModule(id) {
|
|
59
130
|
return node.fetchModule(id);
|
|
60
131
|
},
|
|
132
|
+
resolveId(id, importer) {
|
|
133
|
+
return node.resolveId(id, importer);
|
|
134
|
+
},
|
|
61
135
|
});
|
|
62
136
|
const result = await runner.executeFile(configFile);
|
|
63
137
|
await server.close();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import shiki from 'shiki';
|
|
3
|
+
import anchor from 'markdown-it-anchor';
|
|
4
|
+
import attrs from 'markdown-it-attrs';
|
|
5
|
+
import emoji from 'markdown-it-emoji';
|
|
6
|
+
import { slugify } from './util/slugify.js';
|
|
7
|
+
export async function createMarkdownRenderer() {
|
|
8
|
+
const highlighter = await shiki.getHighlighter({
|
|
9
|
+
theme: 'github-dark',
|
|
10
|
+
});
|
|
11
|
+
const md = new MarkdownIt({
|
|
12
|
+
highlight: (code, lang) => `<div class="htw-relative htw-not-prose __histoire-code"><div class="htw-absolute htw-top-0 htw-right-0 htw-text-xs htw-text-white/40">${lang}</div>${highlighter.codeToHtml(code, {
|
|
13
|
+
lang,
|
|
14
|
+
})}</div>`,
|
|
15
|
+
linkify: true,
|
|
16
|
+
html: true,
|
|
17
|
+
breaks: true,
|
|
18
|
+
});
|
|
19
|
+
md.use(anchor, {
|
|
20
|
+
slugify,
|
|
21
|
+
permalink: anchor.permalink.ariaHidden({}),
|
|
22
|
+
})
|
|
23
|
+
.use(attrs)
|
|
24
|
+
.use(emoji);
|
|
25
|
+
// External links
|
|
26
|
+
{
|
|
27
|
+
const defaultRender = md.renderer.rules.link_open || function (tokens, idx, options, env, self) {
|
|
28
|
+
return self.renderToken(tokens, idx, options);
|
|
29
|
+
};
|
|
30
|
+
md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
|
|
31
|
+
const hrefIndex = tokens[idx].attrIndex('href');
|
|
32
|
+
const classIndex = tokens[idx].attrIndex('class');
|
|
33
|
+
if (hrefIndex >= 0 && !tokens[idx].attrs[hrefIndex][1].startsWith('/') && (classIndex < 0 || !tokens[idx].attrs[classIndex][1].includes('header-anchor'))) {
|
|
34
|
+
// If you are sure other plugins can't add `target` - drop check below
|
|
35
|
+
const aIndex = tokens[idx].attrIndex('target');
|
|
36
|
+
if (aIndex < 0) {
|
|
37
|
+
tokens[idx].attrPush(['target', '_blank']); // add new attribute
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
tokens[idx].attrs[aIndex][1] = '_blank'; // replace value of existing attr
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// pass token to default renderer.
|
|
44
|
+
return defaultRender(tokens, idx, options, env, self);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return md;
|
|
48
|
+
}
|
package/dist/node/plugin.js
CHANGED
|
@@ -5,6 +5,7 @@ import { APP_PATH, DIST_CLIENT_PATH } from './alias.js';
|
|
|
5
5
|
import { notifyStoryChange } from './stories.js';
|
|
6
6
|
import { makeTree } from './tree.js';
|
|
7
7
|
import { parseColor } from './colors.js';
|
|
8
|
+
import { createMarkdownRenderer } from './markdown.js';
|
|
8
9
|
export const STORIES_ID = '$histoire-stories';
|
|
9
10
|
export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`;
|
|
10
11
|
export const SETUP_ID = '$histoire-setup';
|
|
@@ -20,6 +21,14 @@ export async function createVitePlugins(ctx) {
|
|
|
20
21
|
if (!hasVuePlugin) {
|
|
21
22
|
plugins.push((await import('@vitejs/plugin-vue')).default());
|
|
22
23
|
}
|
|
24
|
+
if (ctx.config.vite) {
|
|
25
|
+
plugins.push({
|
|
26
|
+
name: 'histoire-vite-config-override',
|
|
27
|
+
config(config, env) {
|
|
28
|
+
return typeof ctx.config.vite === 'function' ? ctx.config.vite(config, env) : ctx.config.vite;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
23
32
|
plugins.push({
|
|
24
33
|
name: 'histoire-vite-plugin',
|
|
25
34
|
config() {
|
|
@@ -180,6 +189,8 @@ if (import.meta.hot) {
|
|
|
180
189
|
};
|
|
181
190
|
},
|
|
182
191
|
});
|
|
192
|
+
// Custom blocks
|
|
193
|
+
plugins.push(...await createCustomBlocksPlugins(ctx));
|
|
183
194
|
if (ctx.mode === 'build') {
|
|
184
195
|
// Add file name in build mode to have components names instead of <Anonymous>
|
|
185
196
|
const include = [/\.vue$/];
|
|
@@ -201,3 +212,27 @@ if (import.meta.hot) {
|
|
|
201
212
|
}
|
|
202
213
|
return plugins;
|
|
203
214
|
}
|
|
215
|
+
async function createCustomBlocksPlugins(ctx) {
|
|
216
|
+
const plugins = [];
|
|
217
|
+
let md = await createMarkdownRenderer();
|
|
218
|
+
if (ctx.config.markdown) {
|
|
219
|
+
const result = await ctx.config.markdown(md);
|
|
220
|
+
if (result) {
|
|
221
|
+
md = result;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
plugins.push({
|
|
225
|
+
name: 'histoire-vue-docs-block',
|
|
226
|
+
transform(code, id) {
|
|
227
|
+
if (!id.includes('?vue&type=docs'))
|
|
228
|
+
return;
|
|
229
|
+
if (!id.includes('lang.md'))
|
|
230
|
+
return;
|
|
231
|
+
const html = md.render(code);
|
|
232
|
+
return `export default Comp => {
|
|
233
|
+
Comp.doc = ${JSON.stringify(html)}
|
|
234
|
+
}`;
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
return plugins;
|
|
238
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const slugify: (str: string) => string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// From vitepress
|
|
2
|
+
// string.js slugify drops non ascii chars so we have to
|
|
3
|
+
// use a custom implementation here
|
|
4
|
+
import { remove as removeDiacritics } from 'diacritics';
|
|
5
|
+
// eslint-disable-next-line no-control-regex
|
|
6
|
+
const rControl = /[\u0000-\u001f]/g;
|
|
7
|
+
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g;
|
|
8
|
+
export const slugify = (str) => {
|
|
9
|
+
return (removeDiacritics(str)
|
|
10
|
+
// Remove control characters
|
|
11
|
+
.replace(rControl, '')
|
|
12
|
+
// Replace special characters
|
|
13
|
+
.replace(rSpecial, '-')
|
|
14
|
+
// Remove continuous separators
|
|
15
|
+
.replace(/-{2,}/g, '-')
|
|
16
|
+
// Remove prefixing and trailing separators
|
|
17
|
+
.replace(/^-+|-+$/g, '')
|
|
18
|
+
// ensure it doesn't start with a number (#121)
|
|
19
|
+
.replace(/^(\d)/, '_$1')
|
|
20
|
+
// lowercase
|
|
21
|
+
.toLowerCase());
|
|
22
|
+
};
|