histoire 0.2.2 → 0.2.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/dist/client/app/App.vue +2 -2
- package/dist/client/app/codegen/vue3.js +11 -2
- package/dist/client/app/codegen/vue3.ts +9 -1
- package/dist/client/app/components/app/AppHeader.vue +2 -2
- package/dist/client/app/components/app/Breadcrumb.vue +1 -1
- package/dist/client/app/components/base/BaseListItemLink.vue +1 -1
- package/dist/client/app/components/base/BaseTab.vue +1 -1
- package/dist/client/app/components/exposed/Story.vue +5 -0
- package/dist/client/app/components/exposed/Variant.vue +7 -0
- package/dist/client/app/components/search/SearchItem.vue +1 -0
- package/dist/client/app/components/search/SearchModal.vue +7 -6
- package/dist/client/app/components/story/StoryResponsivePreview.vue +72 -77
- package/dist/client/app/components/story/StorySidePanel.vue +1 -1
- package/dist/client/app/components/story/StorySourceCode.vue +3 -17
- package/dist/client/app/components/story/StoryVariantGridItem.vue +3 -3
- package/dist/client/app/components/story/StoryVariantSingleView.vue +10 -11
- package/dist/client/app/components/story/StoryViewer.vue +2 -0
- package/dist/client/app/components/story/{variant → toolbar}/StoryVariantBackground.vue +4 -4
- package/dist/client/app/components/story/{variant → toolbar}/StoryVariantNewTab.vue +2 -2
- package/dist/client/app/components/story/{variant → toolbar}/StoryVariantResponsiveSize.vue +5 -5
- package/dist/client/app/components/story/{variant → toolbar}/StoryVariantTitle.vue +0 -0
- package/dist/client/app/components/tree/StoryGroup.vue +75 -0
- package/dist/client/app/components/{story → tree}/StoryList.vue +8 -2
- package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListFolder.vue +6 -4
- package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListItem.vue +3 -3
- package/dist/client/app/global-components.js +0 -1
- package/dist/client/app/index.js +0 -1
- package/dist/client/app/sandbox.js +0 -1
- package/dist/client/app/stores/preview-settings.d.ts +8 -0
- package/dist/client/app/stores/preview-settings.js +14 -0
- package/dist/client/app/stores/preview-settings.ts +17 -0
- package/dist/client/app/stores/story.d.ts +57 -21
- package/dist/client/app/stores/story.js +13 -9
- package/dist/client/app/stores/story.ts +13 -9
- package/dist/client/app/style/floating-vue.pcss +3 -1
- package/dist/client/app/types.d.ts +18 -2
- package/dist/client/app/types.ts +20 -2
- package/dist/client/app/util/keyboard.js +0 -1
- package/dist/client/app/util/mapping.js +10 -10
- package/dist/client/app/util/mapping.ts +10 -5
- package/dist/client/app/util/preview-settings.d.ts +1 -8
- package/dist/client/app/util/preview-settings.js +0 -11
- package/dist/client/app/util/preview-settings.ts +1 -19
- package/dist/client/app/util/reactivity.js +0 -1
- package/dist/client/app/util/scroll.js +0 -1
- package/dist/client/app/util/variant.js +0 -1
- package/dist/client/index.js +0 -1
- package/dist/client/server/Story.server.vue +8 -2
- package/dist/client/server/index.js +0 -1
- package/dist/controls.js +0 -1
- package/dist/node/collect/index.js +2 -2
- package/dist/node/config.d.ts +8 -2
- package/dist/node/plugin.js +15 -7
- package/dist/node/stories.js +6 -1
- package/dist/node/tree.d.ts +16 -12
- package/dist/node/tree.js +45 -5
- package/dist/node/types.d.ts +10 -0
- package/dist/style.css +164 -31
- package/package.json +19 -19
- package/src/client/app/App.vue +2 -2
- package/src/client/app/codegen/vue3.ts +9 -1
- package/src/client/app/components/app/AppHeader.vue +2 -2
- package/src/client/app/components/app/Breadcrumb.vue +1 -1
- package/src/client/app/components/base/BaseListItemLink.vue +1 -1
- package/src/client/app/components/base/BaseTab.vue +1 -1
- package/src/client/app/components/exposed/Story.vue +5 -0
- package/src/client/app/components/exposed/Variant.vue +7 -0
- package/src/client/app/components/search/SearchItem.vue +1 -0
- package/src/client/app/components/search/SearchModal.vue +7 -6
- package/src/client/app/components/story/StoryResponsivePreview.vue +72 -77
- package/src/client/app/components/story/StorySidePanel.vue +1 -1
- package/src/client/app/components/story/StorySourceCode.vue +3 -17
- package/src/client/app/components/story/StoryVariantGridItem.vue +3 -3
- package/src/client/app/components/story/StoryVariantSingleView.vue +10 -11
- package/src/client/app/components/story/StoryViewer.vue +2 -0
- package/src/client/app/components/story/{variant → toolbar}/StoryVariantBackground.vue +4 -4
- package/src/client/app/components/story/{variant → toolbar}/StoryVariantNewTab.vue +2 -2
- package/src/client/app/components/story/{variant → toolbar}/StoryVariantResponsiveSize.vue +5 -5
- package/src/client/app/components/story/{variant → toolbar}/StoryVariantTitle.vue +0 -0
- package/src/client/app/components/tree/StoryGroup.vue +75 -0
- package/src/client/app/components/{story → tree}/StoryList.vue +8 -2
- package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListFolder.vue +6 -4
- package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListItem.vue +3 -3
- package/src/client/app/stores/preview-settings.ts +17 -0
- package/src/client/app/stores/story.ts +13 -9
- package/src/client/app/style/floating-vue.pcss +3 -1
- package/src/client/app/types.ts +20 -2
- package/src/client/app/util/mapping.ts +10 -5
- package/src/client/app/util/preview-settings.ts +1 -19
- package/src/client/server/Story.server.vue +8 -2
- package/src/node/collect/index.ts +3 -3
- package/src/node/config.ts +9 -2
- package/src/node/plugin.ts +16 -7
- package/src/node/stories.ts +6 -1
- package/src/node/tree.spec.ts +35 -17
- package/src/node/tree.ts +64 -10
- package/src/node/types.ts +11 -0
- package/tsconfig.json +2 -0
- package/dist/client/app/codegen/vue3.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/sandbox.js.map +0 -1
- package/dist/client/app/stores/story.js.map +0 -1
- package/dist/client/app/util/keyboard.js.map +0 -1
- package/dist/client/app/util/mapping.js.map +0 -1
- package/dist/client/app/util/preview-settings.js.map +0 -1
- package/dist/client/app/util/reactivity.js.map +0 -1
- package/dist/client/app/util/scroll.js.map +0 -1
- package/dist/client/app/util/variant.js.map +0 -1
- package/dist/client/index.js.map +0 -1
- package/dist/client/server/index.js.map +0 -1
- package/dist/controls.js.map +0 -1
|
@@ -15,14 +15,15 @@ export function mapFile(file, existingFile) {
|
|
|
15
15
|
const variant = result.story.variants[index];
|
|
16
16
|
const existingVariant = existingFile.story.variants[index];
|
|
17
17
|
if (existingVariant) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
for (const key in existingVariant) {
|
|
19
|
+
if (typeof existingVariant[key] !== 'undefined') {
|
|
20
|
+
if (key === 'state') {
|
|
21
|
+
Object.assign(variant.state, existingVariant.state);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
variant[key] = existingVariant[key];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
if (existingFile.story.lastSelectedVariant) {
|
|
@@ -37,7 +38,6 @@ export function mapVariant(variant) {
|
|
|
37
38
|
state: {},
|
|
38
39
|
initState: null,
|
|
39
40
|
slots: () => ({}),
|
|
40
|
-
|
|
41
|
+
previewReady: false,
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
|
-
//# sourceMappingURL=mapping.js.map
|
|
@@ -18,10 +18,15 @@ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
|
|
|
18
18
|
const variant = result.story.variants[index]
|
|
19
19
|
const existingVariant = existingFile.story.variants[index]
|
|
20
20
|
if (existingVariant) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
for (const key in existingVariant) {
|
|
22
|
+
if (typeof existingVariant[key] !== 'undefined') {
|
|
23
|
+
if (key === 'state') {
|
|
24
|
+
Object.assign(variant.state, existingVariant.state)
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
variant[key] = existingVariant[key]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
if (existingFile.story.lastSelectedVariant) {
|
|
@@ -38,6 +43,6 @@ export function mapVariant (variant: Variant): Variant {
|
|
|
38
43
|
state: {},
|
|
39
44
|
initState: null,
|
|
40
45
|
slots: () => ({}),
|
|
41
|
-
|
|
46
|
+
previewReady: false,
|
|
42
47
|
}
|
|
43
48
|
}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
responsiveWidth: number;
|
|
3
|
-
responsiveHeight: number;
|
|
4
|
-
rotate: boolean;
|
|
5
|
-
backgroundColor: string;
|
|
6
|
-
checkerboard: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare function usePreviewSettings(): import("@vueuse/shared").RemovableRef<PreviewSettings>;
|
|
1
|
+
import type { PreviewSettings } from '../types';
|
|
9
2
|
export declare const receivedSettings: {
|
|
10
3
|
responsiveWidth: number;
|
|
11
4
|
responsiveHeight: number;
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
import { useStorage } from '@vueuse/core';
|
|
2
1
|
import { reactive } from 'vue';
|
|
3
|
-
export function usePreviewSettings() {
|
|
4
|
-
return useStorage('_histoire-sandbox-settings-v1', {
|
|
5
|
-
responsiveWidth: 720,
|
|
6
|
-
responsiveHeight: null,
|
|
7
|
-
rotate: false,
|
|
8
|
-
backgroundColor: 'transparent',
|
|
9
|
-
checkerboard: false,
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
2
|
export const receivedSettings = reactive({});
|
|
13
3
|
export function applyPreviewSettings(settings) {
|
|
14
4
|
Object.assign(receivedSettings, settings);
|
|
15
5
|
}
|
|
16
|
-
//# sourceMappingURL=preview-settings.js.map
|
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
import { useStorage } from '@vueuse/core'
|
|
2
1
|
import { reactive } from 'vue'
|
|
3
|
-
|
|
4
|
-
export interface PreviewSettings {
|
|
5
|
-
responsiveWidth: number
|
|
6
|
-
responsiveHeight: number
|
|
7
|
-
rotate: boolean
|
|
8
|
-
backgroundColor: string
|
|
9
|
-
checkerboard: boolean
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function usePreviewSettings () {
|
|
13
|
-
return useStorage<PreviewSettings>('_histoire-sandbox-settings-v1', {
|
|
14
|
-
responsiveWidth: 720,
|
|
15
|
-
responsiveHeight: null,
|
|
16
|
-
rotate: false,
|
|
17
|
-
backgroundColor: 'transparent',
|
|
18
|
-
checkerboard: false,
|
|
19
|
-
})
|
|
20
|
-
}
|
|
2
|
+
import type { PreviewSettings } from '../types'
|
|
21
3
|
|
|
22
4
|
export const receivedSettings = reactive<PreviewSettings>({} as PreviewSettings)
|
|
23
5
|
|
package/dist/client/index.js
CHANGED
|
@@ -8,7 +8,12 @@ export default defineComponent({
|
|
|
8
8
|
props: {
|
|
9
9
|
title: {
|
|
10
10
|
type: String,
|
|
11
|
-
|
|
11
|
+
default: null,
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
group: {
|
|
15
|
+
type: String,
|
|
16
|
+
default: null,
|
|
12
17
|
},
|
|
13
18
|
|
|
14
19
|
layout: {
|
|
@@ -36,7 +41,8 @@ export default defineComponent({
|
|
|
36
41
|
|
|
37
42
|
const story: Story = {
|
|
38
43
|
id: attrs.data.id,
|
|
39
|
-
title: props.title,
|
|
44
|
+
title: props.title ?? attrs.data.fileName,
|
|
45
|
+
group: props.group,
|
|
40
46
|
layout: props.layout,
|
|
41
47
|
icon: props.icon,
|
|
42
48
|
iconColor: props.iconColor,
|
package/dist/controls.js
CHANGED
|
@@ -59,11 +59,11 @@ export function useCollectStories(options, ctx) {
|
|
|
59
59
|
console.warn(pc.yellow(`⚠️ Multiple stories not supported: ${storyFile.path}`));
|
|
60
60
|
}
|
|
61
61
|
storyFile.story = storyData[0];
|
|
62
|
-
|
|
62
|
+
storyFile.treeFile = {
|
|
63
63
|
title: storyData[0].title,
|
|
64
64
|
path: relative(server.config.root, storyFile.path),
|
|
65
65
|
};
|
|
66
|
-
storyFile.treePath = createPath(ctx.config,
|
|
66
|
+
storyFile.treePath = createPath(ctx.config, storyFile.treeFile);
|
|
67
67
|
storyFile.story.title = storyFile.treePath[storyFile.treePath.length - 1];
|
|
68
68
|
}
|
|
69
69
|
catch (e) {
|
package/dist/node/config.d.ts
CHANGED
|
@@ -4,15 +4,20 @@ import type MarkdownIt from 'markdown-it';
|
|
|
4
4
|
declare type CustomizableColors = 'primary' | 'gray';
|
|
5
5
|
declare type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
|
|
6
6
|
declare type GrayColorKeys = ColorKeys | '750' | '850' | '950';
|
|
7
|
-
interface ResponsivePreset {
|
|
7
|
+
export interface ResponsivePreset {
|
|
8
8
|
label: string;
|
|
9
9
|
width: number;
|
|
10
10
|
height: number;
|
|
11
11
|
}
|
|
12
|
-
interface BackgroundPreset {
|
|
12
|
+
export interface BackgroundPreset {
|
|
13
13
|
label: string;
|
|
14
14
|
color: string;
|
|
15
15
|
}
|
|
16
|
+
export interface TreeGroupConfig {
|
|
17
|
+
title: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
include?: (file: TreeFile) => boolean;
|
|
20
|
+
}
|
|
16
21
|
export interface HistoireConfig {
|
|
17
22
|
/**
|
|
18
23
|
* Output directory.
|
|
@@ -37,6 +42,7 @@ export interface HistoireConfig {
|
|
|
37
42
|
*/
|
|
38
43
|
file?: 'title' | 'path' | ((file: TreeFile) => string[]);
|
|
39
44
|
order?: 'asc' | ((a: string, b: string) => number);
|
|
45
|
+
groups?: TreeGroupConfig[];
|
|
40
46
|
};
|
|
41
47
|
/**
|
|
42
48
|
* Customize the look of the histoire book.
|
package/dist/node/plugin.js
CHANGED
|
@@ -89,7 +89,7 @@ export async function createVitePlugins(ctx) {
|
|
|
89
89
|
return `import { defineAsyncComponent } from 'vue'
|
|
90
90
|
${resolvedStories.map((file, index) => `const Comp${index} = defineAsyncComponent(() => import('${file.path}'))`).join('\n')}
|
|
91
91
|
export let files = [${files.map((file) => `{${JSON.stringify(file).slice(1, -1)}, component: Comp${file.index}}`).join(',\n')}]
|
|
92
|
-
export let tree = ${JSON.stringify(makeTree(ctx.config,
|
|
92
|
+
export let tree = ${JSON.stringify(makeTree(ctx.config, resolvedStories))}
|
|
93
93
|
const handlers = []
|
|
94
94
|
export function onUpdate (cb) {
|
|
95
95
|
handlers.push(cb)
|
|
@@ -137,10 +137,10 @@ if (import.meta.hot) {
|
|
|
137
137
|
}
|
|
138
138
|
},
|
|
139
139
|
configureServer(server) {
|
|
140
|
-
server.middlewares.use((req, res, next) => {
|
|
140
|
+
server.middlewares.use(async (req, res, next) => {
|
|
141
141
|
if (req.url.startsWith('/__sandbox')) {
|
|
142
142
|
res.statusCode = 200;
|
|
143
|
-
|
|
143
|
+
let html = `
|
|
144
144
|
<!DOCTYPE html>
|
|
145
145
|
<html>
|
|
146
146
|
<head>
|
|
@@ -162,17 +162,21 @@ if (import.meta.hot) {
|
|
|
162
162
|
</script>
|
|
163
163
|
<script type="module" src="/@fs/${APP_PATH}/sandbox.js"></script>
|
|
164
164
|
</body>
|
|
165
|
-
</html
|
|
165
|
+
</html>`;
|
|
166
|
+
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
|
167
|
+
// also applies HTML transforms from Vite plugins
|
|
168
|
+
html = await server.transformIndexHtml(req.url, html);
|
|
169
|
+
res.end(html);
|
|
166
170
|
return;
|
|
167
171
|
}
|
|
168
172
|
next();
|
|
169
173
|
});
|
|
170
174
|
// serve our index.html after vite history fallback
|
|
171
175
|
return () => {
|
|
172
|
-
server.middlewares.use((req, res, next) => {
|
|
176
|
+
server.middlewares.use(async (req, res, next) => {
|
|
173
177
|
if (req.url.endsWith('.html')) {
|
|
174
178
|
res.statusCode = 200;
|
|
175
|
-
|
|
179
|
+
let html = `
|
|
176
180
|
<!DOCTYPE html>
|
|
177
181
|
<html>
|
|
178
182
|
<head>
|
|
@@ -187,7 +191,11 @@ if (import.meta.hot) {
|
|
|
187
191
|
<div id="app"></div>
|
|
188
192
|
<script type="module" src="/@fs/${APP_PATH}/index.js"></script>
|
|
189
193
|
</body>
|
|
190
|
-
</html
|
|
194
|
+
</html>`;
|
|
195
|
+
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
|
196
|
+
// also applies HTML transforms from Vite plugins
|
|
197
|
+
html = await server.transformIndexHtml(req.url, html);
|
|
198
|
+
res.end(html);
|
|
191
199
|
return;
|
|
192
200
|
}
|
|
193
201
|
next();
|
package/dist/node/stories.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import chokidar from 'chokidar';
|
|
2
2
|
import { globby } from 'globby';
|
|
3
3
|
import Case from 'case';
|
|
4
|
-
import { join } from 'pathe';
|
|
4
|
+
import { join, basename } from 'pathe';
|
|
5
5
|
const handlers = [];
|
|
6
6
|
let context;
|
|
7
7
|
export function onStoryChange(handler) {
|
|
@@ -35,9 +35,14 @@ function getAbsoluteFilePath(relativeFilePath) {
|
|
|
35
35
|
function addStory(relativeFilePath) {
|
|
36
36
|
const absoluteFilePath = getAbsoluteFilePath(relativeFilePath);
|
|
37
37
|
const fileId = Case.kebab(relativeFilePath);
|
|
38
|
+
let fileName = basename(relativeFilePath);
|
|
39
|
+
if (fileName.includes('.')) {
|
|
40
|
+
fileName = fileName.substring(0, fileName.indexOf('.'));
|
|
41
|
+
}
|
|
38
42
|
const file = {
|
|
39
43
|
id: fileId,
|
|
40
44
|
path: absoluteFilePath,
|
|
45
|
+
fileName,
|
|
41
46
|
moduleId: `/${relativeFilePath}`,
|
|
42
47
|
};
|
|
43
48
|
context.storyFiles.push(file);
|
package/dist/node/tree.d.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import { HistoireConfig } from './config.js';
|
|
2
|
-
|
|
1
|
+
import type { HistoireConfig } from './config.js';
|
|
2
|
+
import type { StoryFile } from './types.js';
|
|
3
|
+
export interface TreeFile {
|
|
3
4
|
title: string;
|
|
4
5
|
path: string;
|
|
5
|
-
}
|
|
6
|
-
export
|
|
6
|
+
}
|
|
7
|
+
export interface TreeLeaf {
|
|
7
8
|
title: string;
|
|
8
9
|
index: number;
|
|
9
|
-
}
|
|
10
|
-
export
|
|
10
|
+
}
|
|
11
|
+
export interface TreeFolder {
|
|
11
12
|
title: string;
|
|
12
13
|
children: (TreeFolder | TreeLeaf)[];
|
|
13
|
-
}
|
|
14
|
-
export
|
|
14
|
+
}
|
|
15
|
+
export interface TreeGroup {
|
|
16
|
+
group: true;
|
|
17
|
+
id: string;
|
|
18
|
+
title: string;
|
|
19
|
+
children: (TreeFolder | TreeLeaf)[];
|
|
20
|
+
}
|
|
21
|
+
export declare type Tree = (TreeGroup | TreeFolder | TreeLeaf)[];
|
|
15
22
|
export declare function createPath(config: HistoireConfig, file: TreeFile): string[];
|
|
16
|
-
export declare function makeTree(config: HistoireConfig, files:
|
|
17
|
-
path: string[];
|
|
18
|
-
index: number;
|
|
19
|
-
}[]): Tree;
|
|
23
|
+
export declare function makeTree(config: HistoireConfig, files: StoryFile[]): Tree;
|
package/dist/node/tree.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import pc from 'picocolors';
|
|
1
2
|
export function createPath(config, file) {
|
|
2
3
|
if (config.tree.file === 'title') {
|
|
3
4
|
return file.title.split('/');
|
|
@@ -11,15 +12,54 @@ export function createPath(config, file) {
|
|
|
11
12
|
return config.tree.file(file);
|
|
12
13
|
}
|
|
13
14
|
export function makeTree(config, files) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
15
|
+
const groups = config.tree?.groups?.map(g => ({
|
|
16
|
+
groupConfig: g,
|
|
17
|
+
treeObject: {},
|
|
18
|
+
})) || [];
|
|
19
|
+
const defaultGroup = {
|
|
20
|
+
treeObject: {},
|
|
21
|
+
};
|
|
22
|
+
groups.push(defaultGroup);
|
|
23
|
+
files.forEach((file, index) => {
|
|
24
|
+
const group = getGroup(file);
|
|
25
|
+
setPath(file.treePath, index, group.treeObject);
|
|
26
|
+
});
|
|
18
27
|
let sortingFunction = (a, b) => a.localeCompare(b);
|
|
19
28
|
if (config.tree.order !== 'asc') {
|
|
20
29
|
sortingFunction = config.tree.order;
|
|
21
30
|
}
|
|
22
|
-
|
|
31
|
+
const result = [];
|
|
32
|
+
for (const group of groups) {
|
|
33
|
+
if (group === defaultGroup) {
|
|
34
|
+
result.push(...buildTree(group.treeObject));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
result.push({
|
|
38
|
+
group: true,
|
|
39
|
+
id: group.groupConfig.id,
|
|
40
|
+
title: group.groupConfig.title,
|
|
41
|
+
children: buildTree(group.treeObject),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
function getGroup(file) {
|
|
47
|
+
if (file.story?.group) {
|
|
48
|
+
const group = groups.find(g => g.groupConfig?.id === file.story.group);
|
|
49
|
+
if (group) {
|
|
50
|
+
return group;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.error(pc.red(`Group ${file.story.group} not found for story ${file.path}`));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const group of groups) {
|
|
57
|
+
if (group.groupConfig?.include && group.groupConfig.include(file.treeFile)) {
|
|
58
|
+
return group;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return defaultGroup;
|
|
62
|
+
}
|
|
23
63
|
function setPath(path, value, tree) {
|
|
24
64
|
path.reduce((subtree, key, i) => {
|
|
25
65
|
if (i === path.length - 1) {
|
package/dist/node/types.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import type { TreeFile } from './tree.js';
|
|
1
2
|
export interface StoryFile {
|
|
2
3
|
id: string;
|
|
3
4
|
/**
|
|
4
5
|
* Absolute path
|
|
5
6
|
*/
|
|
6
7
|
path: string;
|
|
8
|
+
/**
|
|
9
|
+
* File name without extension
|
|
10
|
+
*/
|
|
11
|
+
fileName: string;
|
|
7
12
|
/**
|
|
8
13
|
* Generated path for tree UI
|
|
9
14
|
*/
|
|
@@ -16,10 +21,15 @@ export interface StoryFile {
|
|
|
16
21
|
* Resolved story data from story file execution
|
|
17
22
|
*/
|
|
18
23
|
story?: Story;
|
|
24
|
+
/**
|
|
25
|
+
* Data sent to user tree config functions
|
|
26
|
+
*/
|
|
27
|
+
treeFile?: TreeFile;
|
|
19
28
|
}
|
|
20
29
|
export interface Story {
|
|
21
30
|
id: string;
|
|
22
31
|
title: string;
|
|
32
|
+
group?: string;
|
|
23
33
|
variants: Variant[];
|
|
24
34
|
layout?: {
|
|
25
35
|
type: 'single';
|