histoire 0.2.4 → 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 +1 -1
- package/dist/client/app/codegen/vue3.js +1 -1
- package/dist/client/app/codegen/vue3.ts +1 -1
- package/dist/client/app/components/app/Breadcrumb.vue +1 -1
- package/dist/client/app/components/search/SearchItem.vue +1 -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/dist/client/app/components/{story → tree}/StoryListItem.vue +3 -3
- package/dist/client/app/stores/story.d.ts +12 -6
- package/dist/client/app/stores/story.js +13 -8
- 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 +8 -1
- package/dist/client/app/types.ts +9 -1
- package/dist/client/server/Story.server.vue +8 -2
- package/dist/node/collect/index.js +2 -2
- package/dist/node/config.d.ts +8 -2
- package/dist/node/plugin.js +1 -1
- 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 +103 -29
- package/package.json +2 -2
- package/src/client/app/App.vue +1 -1
- package/src/client/app/codegen/vue3.ts +1 -1
- package/src/client/app/components/app/Breadcrumb.vue +1 -1
- package/src/client/app/components/search/SearchItem.vue +1 -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/src/client/app/components/{story → tree}/StoryListItem.vue +3 -3
- 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 +9 -1
- 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 +1 -1
- 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/src/node/tree.spec.ts
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
|
+
import { describe, test, expect } from '@peeky/test'
|
|
1
2
|
import { makeTree } from './tree'
|
|
2
3
|
import { getDefaultConfig } from './config'
|
|
4
|
+
import type { StoryFile } from './types'
|
|
5
|
+
|
|
6
|
+
let id = 0
|
|
7
|
+
|
|
8
|
+
interface StoryFileFactoryOptions {
|
|
9
|
+
treePath: string[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function storyFileFactory (options: StoryFileFactoryOptions): StoryFile {
|
|
13
|
+
return {
|
|
14
|
+
id: `id_${id++}`,
|
|
15
|
+
path: options.treePath.join('/'),
|
|
16
|
+
treePath: options.treePath,
|
|
17
|
+
fileName: 'fileName',
|
|
18
|
+
moduleId: 'moduleId',
|
|
19
|
+
}
|
|
20
|
+
}
|
|
3
21
|
|
|
4
22
|
describe('makeTree', () => {
|
|
5
23
|
test('should create an ascending ordered tree', () => {
|
|
6
24
|
const config = getDefaultConfig()
|
|
7
25
|
const files = [
|
|
8
|
-
{
|
|
9
|
-
{
|
|
10
|
-
{
|
|
11
|
-
{
|
|
26
|
+
{ treePath: ['hi'] },
|
|
27
|
+
{ treePath: ['hey'] },
|
|
28
|
+
{ treePath: ['hello', 'world'] },
|
|
29
|
+
{ treePath: ['hello', 'mom'] },
|
|
12
30
|
]
|
|
13
31
|
|
|
14
|
-
const tree = makeTree(config, files)
|
|
32
|
+
const tree = makeTree(config, files.map(storyFileFactory))
|
|
15
33
|
|
|
16
34
|
expect(tree).toEqual([
|
|
17
35
|
{
|
|
@@ -29,12 +47,12 @@ describe('makeTree', () => {
|
|
|
29
47
|
test('should handle title conflict', () => {
|
|
30
48
|
const config = getDefaultConfig()
|
|
31
49
|
const files = [
|
|
32
|
-
{
|
|
33
|
-
{
|
|
34
|
-
{
|
|
50
|
+
{ treePath: ['hi'] },
|
|
51
|
+
{ treePath: ['hi'] },
|
|
52
|
+
{ treePath: ['hi'] },
|
|
35
53
|
]
|
|
36
54
|
|
|
37
|
-
const tree = makeTree(config, files)
|
|
55
|
+
const tree = makeTree(config, files.map(storyFileFactory))
|
|
38
56
|
|
|
39
57
|
expect(tree).toEqual([
|
|
40
58
|
{ title: 'hi', index: 0 },
|
|
@@ -46,12 +64,12 @@ describe('makeTree', () => {
|
|
|
46
64
|
test('should handle file-folder conflict when folder in first', () => {
|
|
47
65
|
const config = getDefaultConfig()
|
|
48
66
|
const files = [
|
|
49
|
-
{
|
|
50
|
-
{
|
|
51
|
-
{
|
|
67
|
+
{ treePath: ['hi', 'dad'] },
|
|
68
|
+
{ treePath: ['hi'] },
|
|
69
|
+
{ treePath: ['hi', 'mom'] },
|
|
52
70
|
]
|
|
53
71
|
|
|
54
|
-
const tree = makeTree(config, files)
|
|
72
|
+
const tree = makeTree(config, files.map(storyFileFactory))
|
|
55
73
|
|
|
56
74
|
expect(tree).toEqual([
|
|
57
75
|
{
|
|
@@ -68,12 +86,12 @@ describe('makeTree', () => {
|
|
|
68
86
|
test('should handle file-folder conflict when file in first', () => {
|
|
69
87
|
const config = getDefaultConfig()
|
|
70
88
|
const files = [
|
|
71
|
-
{
|
|
72
|
-
{
|
|
73
|
-
{
|
|
89
|
+
{ treePath: ['hi'] },
|
|
90
|
+
{ treePath: ['hi', 'dad'] },
|
|
91
|
+
{ treePath: ['hi', 'mom'] },
|
|
74
92
|
]
|
|
75
93
|
|
|
76
|
-
const tree = makeTree(config, files)
|
|
94
|
+
const tree = makeTree(config, files.map(storyFileFactory))
|
|
77
95
|
|
|
78
96
|
expect(tree).toEqual([
|
|
79
97
|
{
|
package/src/node/tree.ts
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pc from 'picocolors'
|
|
2
|
+
import type { HistoireConfig, TreeGroupConfig } from './config.js'
|
|
3
|
+
import type { StoryFile } from './types.js'
|
|
2
4
|
|
|
3
|
-
export
|
|
5
|
+
export interface TreeFile {
|
|
4
6
|
title: string
|
|
5
7
|
path: string
|
|
6
8
|
}
|
|
7
9
|
|
|
8
|
-
export
|
|
10
|
+
export interface TreeLeaf {
|
|
9
11
|
title: string
|
|
10
12
|
index: number
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export
|
|
15
|
+
export interface TreeFolder {
|
|
14
16
|
title: string
|
|
15
17
|
children: (TreeFolder | TreeLeaf)[]
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
export
|
|
20
|
+
export interface TreeGroup {
|
|
21
|
+
group: true
|
|
22
|
+
id: string
|
|
23
|
+
title: string
|
|
24
|
+
children: (TreeFolder | TreeLeaf)[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type Tree = (TreeGroup | TreeFolder | TreeLeaf)[]
|
|
19
28
|
|
|
20
29
|
export function createPath (config: HistoireConfig, file: TreeFile) {
|
|
21
30
|
if (config.tree.file === 'title') {
|
|
@@ -32,16 +41,29 @@ export function createPath (config: HistoireConfig, file: TreeFile) {
|
|
|
32
41
|
return config.tree.file(file)
|
|
33
42
|
}
|
|
34
43
|
|
|
35
|
-
export function makeTree (config: HistoireConfig, files:
|
|
44
|
+
export function makeTree (config: HistoireConfig, files: StoryFile[]) {
|
|
36
45
|
interface ITreeObject {
|
|
37
46
|
[index: string]: number | ITreeObject
|
|
38
47
|
}
|
|
39
48
|
|
|
40
|
-
|
|
49
|
+
interface ITreeGroup {
|
|
50
|
+
groupConfig?: TreeGroupConfig
|
|
51
|
+
treeObject: ITreeObject
|
|
52
|
+
}
|
|
41
53
|
|
|
42
|
-
|
|
43
|
-
|
|
54
|
+
const groups: ITreeGroup[] = config.tree?.groups?.map(g => ({
|
|
55
|
+
groupConfig: g,
|
|
56
|
+
treeObject: {},
|
|
57
|
+
})) || []
|
|
58
|
+
const defaultGroup = {
|
|
59
|
+
treeObject: {},
|
|
44
60
|
}
|
|
61
|
+
groups.push(defaultGroup)
|
|
62
|
+
|
|
63
|
+
files.forEach((file, index) => {
|
|
64
|
+
const group = getGroup(file)
|
|
65
|
+
setPath(file.treePath, index, group.treeObject)
|
|
66
|
+
})
|
|
45
67
|
|
|
46
68
|
let sortingFunction = (a: string, b: string) => a.localeCompare(b)
|
|
47
69
|
|
|
@@ -49,7 +71,39 @@ export function makeTree (config: HistoireConfig, files: { path: string[], index
|
|
|
49
71
|
sortingFunction = config.tree.order
|
|
50
72
|
}
|
|
51
73
|
|
|
52
|
-
|
|
74
|
+
const result: Tree = []
|
|
75
|
+
|
|
76
|
+
for (const group of groups) {
|
|
77
|
+
if (group === defaultGroup) {
|
|
78
|
+
result.push(...buildTree(group.treeObject))
|
|
79
|
+
} else {
|
|
80
|
+
result.push({
|
|
81
|
+
group: true,
|
|
82
|
+
id: group.groupConfig.id,
|
|
83
|
+
title: group.groupConfig.title,
|
|
84
|
+
children: buildTree(group.treeObject),
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return result
|
|
90
|
+
|
|
91
|
+
function getGroup (file: StoryFile): ITreeGroup {
|
|
92
|
+
if (file.story?.group) {
|
|
93
|
+
const group = groups.find(g => g.groupConfig?.id === file.story.group)
|
|
94
|
+
if (group) {
|
|
95
|
+
return group
|
|
96
|
+
} else {
|
|
97
|
+
console.error(pc.red(`Group ${file.story.group} not found for story ${file.path}`))
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
for (const group of groups) {
|
|
101
|
+
if (group.groupConfig?.include && group.groupConfig.include(file.treeFile)) {
|
|
102
|
+
return group
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return defaultGroup
|
|
106
|
+
}
|
|
53
107
|
|
|
54
108
|
function setPath (path: string[], value: unknown, tree: unknown) {
|
|
55
109
|
path.reduce((subtree, key, i) => {
|
package/src/node/types.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import type { TreeFile } from './tree.js'
|
|
2
|
+
|
|
1
3
|
export interface StoryFile {
|
|
2
4
|
id: string
|
|
3
5
|
/**
|
|
4
6
|
* Absolute path
|
|
5
7
|
*/
|
|
6
8
|
path: string
|
|
9
|
+
/**
|
|
10
|
+
* File name without extension
|
|
11
|
+
*/
|
|
12
|
+
fileName: string
|
|
7
13
|
/**
|
|
8
14
|
* Generated path for tree UI
|
|
9
15
|
*/
|
|
@@ -16,11 +22,16 @@ export interface StoryFile {
|
|
|
16
22
|
* Resolved story data from story file execution
|
|
17
23
|
*/
|
|
18
24
|
story?: Story
|
|
25
|
+
/**
|
|
26
|
+
* Data sent to user tree config functions
|
|
27
|
+
*/
|
|
28
|
+
treeFile?: TreeFile
|
|
19
29
|
}
|
|
20
30
|
|
|
21
31
|
export interface Story {
|
|
22
32
|
id: string
|
|
23
33
|
title: string
|
|
34
|
+
group?: string
|
|
24
35
|
variants: Variant[]
|
|
25
36
|
layout?: {
|
|
26
37
|
type: 'single'
|