-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathutils.ts
More file actions
107 lines (92 loc) · 2.66 KB
/
Copy pathutils.ts
File metadata and controls
107 lines (92 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { type DocsContextProps } from '@storybook/addon-docs/blocks';
import { type FluentParameters } from '../hooks';
const docsDefaults = {
copyAsMarkdown: true,
tableOfContents: true,
dirSwitcher: true,
themePicker: true,
visualLanguagePicker: true,
argTable: {
slotsApi: true,
nativePropsApi: true,
},
};
function getDocsParametersConfig(
context: DocsContextProps,
): NonNullable<FluentParameters['reactStorybookAddon']>['docs'] {
return context?.projectAnnotations?.parameters?.reactStorybookAddon?.docs;
}
/**
* Checks if the docs page is enabled
*/
export function isDocsEnabled(context: DocsContextProps): boolean {
const docsConfig = getDocsParametersConfig(context);
// If docs is true, enable page
if (docsConfig === true) {
return true;
}
// If docs is an object, page is enabled
if (typeof docsConfig === 'object' && docsConfig !== null) {
return true;
}
// Default: disabled
return false;
}
/**
* Gets the docs page configuration from context
*/
export function getDocsPageConfig(context: DocsContextProps): {
tableOfContents: boolean;
dirSwitcher: boolean;
themePicker: boolean;
visualLanguagePicker: boolean;
copyAsMarkdown: boolean;
argTable: {
slotsApi: boolean;
nativePropsApi: boolean;
};
} | null {
const docsConfig = getDocsParametersConfig(context);
// If docs is true, return default config (all enabled)
if (docsConfig === true) {
return docsDefaults;
}
// If docs is an object, extract the configuration directly
if (typeof docsConfig === 'object' && docsConfig !== null) {
return {
copyAsMarkdown: docsConfig.copyAsMarkdown !== false,
tableOfContents: docsConfig.tableOfContents !== false,
dirSwitcher: docsConfig.dirSwitcher !== false,
themePicker: docsConfig.themePicker !== false,
visualLanguagePicker: docsConfig.visualLanguagePicker !== false,
argTable: getArgTableConfig(docsConfig.argTable),
};
}
// Fallback
return null;
}
/**
* Gets the argTable configuration with early exit pattern
*/
function getArgTableConfig(argTableConfig: boolean | { slotsApi?: boolean; nativePropsApi?: boolean } | undefined) {
if (argTableConfig === false) {
return {
slotsApi: false,
nativePropsApi: false,
};
}
if (argTableConfig === true || argTableConfig === undefined) {
return {
slotsApi: true,
nativePropsApi: true,
};
}
if (typeof argTableConfig === 'object' && argTableConfig !== null) {
return {
slotsApi: argTableConfig.slotsApi !== false,
nativePropsApi: argTableConfig.nativePropsApi !== false,
};
}
// Fallback to default
return docsDefaults.argTable;
}