@@ -7,41 +7,24 @@ import { SKIP, visit } from 'unist-util-visit';
7
7
import createQueries from '../../../utils/queries/index.mjs' ;
8
8
import { createJSXElement } from './ast.mjs' ;
9
9
import {
10
- ICON_SYMBOL_MAP ,
10
+ API_ICONS ,
11
+ AST_NODE_TYPES ,
11
12
STABILITY_LEVELS ,
12
- CHANGE_TYPES ,
13
+ LIFECYCLE_LABELS ,
14
+ INTERNATIONALIZABLE ,
13
15
} from '../constants.mjs' ;
14
16
import { DOC_NODE_BLOB_BASE_URL } from '../../../constants.mjs' ;
15
17
import { enforceArray , sortChanges } from '../../../utils/generators.mjs' ;
16
18
import { buildMetaBarProps } from './buildBarProps.mjs' ;
17
19
18
- /**
19
- * Transforms a stability node into an AlertBox JSX element
20
- *
21
- * @param {import('mdast').Blockquote } node - The stability node to transform
22
- * @param {number } index - The index of the node in its parent's children array
23
- * @param {import('unist').Parent } parent - The parent node containing the stability node
24
- * @returns {[typeof SKIP] } Visitor instruction to skip the node
25
- */
26
- const transformStabilityNode = ( { data } , index , parent ) => {
27
- parent . children [ index ] = createJSXElement ( 'AlertBox' , {
28
- children : data . description ,
29
- level : STABILITY_LEVELS [ data . index ] ,
30
- title : data . index ,
31
- } ) ;
32
-
33
- return [ SKIP ] ;
34
- } ;
35
-
36
20
/**
37
21
* Creates a history of changes for an API element
38
- *
39
22
* @param {ApiDocMetadataEntry } entry - The metadata entry containing change information
40
23
* @returns {import('unist').Node|null } JSX element representing change history or null if no changes
41
24
*/
42
25
const createChangeElement = entry => {
43
- // Collect changes from version fields (added, deprecated, etc.)
44
- const changeEntries = Object . entries ( CHANGE_TYPES )
26
+ // Collect lifecycle changes (added, deprecated, etc.)
27
+ const changeEntries = Object . entries ( LIFECYCLE_LABELS )
45
28
// Do we have this field?
46
29
. filter ( ( [ field ] ) => entry [ field ] )
47
30
// Get the versions as an array
@@ -59,6 +42,7 @@ const createChangeElement = entry => {
59
42
label : change . description ,
60
43
url : change [ 'pr-url' ] ,
61
44
} ) ) ;
45
+
62
46
changeEntries . push ( ...explicitChanges ) ;
63
47
}
64
48
@@ -67,14 +51,13 @@ const createChangeElement = entry => {
67
51
}
68
52
69
53
// Sort by version, newest first and create the JSX element
70
- return createJSXElement ( 'ChangeHistory' , {
54
+ return createJSXElement ( AST_NODE_TYPES . JSX . CHANGE_HISTORY , {
71
55
changes : sortChanges ( changeEntries , 'versions' ) ,
72
56
} ) ;
73
57
} ;
74
58
75
59
/**
76
60
* Creates a source link element if a source link is available
77
- *
78
61
* @param {string|undefined } sourceLink - The source link path
79
62
* @returns {import('hastscript').Element|null } The source link element or null if no source link
80
63
*/
@@ -84,7 +67,7 @@ const createSourceLink = sourceLink => {
84
67
}
85
68
86
69
return createElement ( 'span' , [
87
- 'Source Code: ' ,
70
+ INTERNATIONALIZABLE . sourceCode ,
88
71
createElement (
89
72
'a' ,
90
73
{ href : `${ DOC_NODE_BLOB_BASE_URL } ${ sourceLink } ` } ,
@@ -93,9 +76,25 @@ const createSourceLink = sourceLink => {
93
76
] ) ;
94
77
} ;
95
78
79
+ /**
80
+ * Transforms a stability node into an AlertBox JSX element
81
+ * @param {import('mdast').Blockquote } node - The stability node to transform
82
+ * @param {number } index - The index of the node in its parent's children array
83
+ * @param {import('unist').Parent } parent - The parent node containing the stability node
84
+ * @returns {[typeof SKIP] } Visitor instruction to skip the node
85
+ */
86
+ const transformStabilityNode = ( { data } , index , parent ) => {
87
+ parent . children [ index ] = createJSXElement ( AST_NODE_TYPES . JSX . ALERT_BOX , {
88
+ children : data . description ,
89
+ level : STABILITY_LEVELS [ data . index ] ,
90
+ title : data . index ,
91
+ } ) ;
92
+
93
+ return [ SKIP ] ;
94
+ } ;
95
+
96
96
/**
97
97
* Enhances a heading node with metadata, source links, and styling
98
- *
99
98
* @param {ApiDocMetadataEntry } entry - The API metadata entry
100
99
* @param {import('mdast').Heading } node - The heading node to transform
101
100
* @param {number } index - The index of the node in its parent's children array
@@ -106,14 +105,15 @@ const transformHeadingNode = (entry, node, index, parent) => {
106
105
const { data, children } = node ;
107
106
const headerChildren = [
108
107
createElement ( `h${ data . depth + 1 } ` , [
109
- createElement ( `a.mark #${ data . slug } ` , { href : `#${ data . slug } ` } , children ) ,
108
+ createElement ( `a#${ data . slug } ` , { href : `#${ data . slug } ` } , children ) ,
110
109
] ) ,
111
110
] ;
112
111
113
112
// Add type icon if available
114
- const iconSymbol = ICON_SYMBOL_MAP [ data . type ] ;
115
- if ( iconSymbol ) {
116
- headerChildren . unshift ( createJSXElement ( 'CircularIcon' , iconSymbol ) ) ;
113
+ if ( data . type in API_ICONS ) {
114
+ headerChildren . unshift (
115
+ createJSXElement ( AST_NODE_TYPES . JSX . CIRCULAR_ICON , API_ICONS [ data . type ] )
116
+ ) ;
117
117
}
118
118
119
119
// Add change history if available
@@ -136,7 +136,6 @@ const transformHeadingNode = (entry, node, index, parent) => {
136
136
137
137
/**
138
138
* Processes an API documentation entry by applying transformations to its content
139
- *
140
139
* @param {ApiDocMetadataEntry } entry - The API metadata entry to process
141
140
* @returns {import('unist').Node } The processed content
142
141
*/
@@ -155,31 +154,29 @@ const processEntry = entry => {
155
154
156
155
/**
157
156
* Creates the overall content structure with processed entries
158
- *
159
157
* @param {Array<ApiDocMetadataEntry> } entries - API documentation metadata entries
160
- * @param {Object } sideBarProps - Props for the sidebar component
161
- * @param {Object } metaBarProps - Props for the meta bar component
158
+ * @param {Record<string, any> } sideBarProps - Props for the sidebar component
159
+ * @param {Record<string, any> } metaBarProps - Props for the meta bar component
162
160
* @returns {import('unist').Node } The root node of the content tree
163
161
*/
164
162
const createContentStructure = ( entries , sideBarProps , metaBarProps ) => {
165
163
return createTree ( 'root' , [
166
- createJSXElement ( 'NavBar' ) ,
167
- createJSXElement ( 'Article' , {
164
+ createJSXElement ( AST_NODE_TYPES . JSX . NAV_BAR ) ,
165
+ createJSXElement ( AST_NODE_TYPES . JSX . ARTICLE , {
168
166
children : [
169
- createJSXElement ( 'SideBar' , sideBarProps ) ,
167
+ createJSXElement ( AST_NODE_TYPES . JSX . SIDE_BAR , sideBarProps ) ,
170
168
createElement ( 'div' , [
171
169
createElement ( 'main' , entries . map ( processEntry ) ) ,
172
- createJSXElement ( 'MetaBar' , metaBarProps ) ,
170
+ createJSXElement ( AST_NODE_TYPES . JSX . META_BAR , metaBarProps ) ,
173
171
] ) ,
174
- createJSXElement ( 'Footer' ) ,
172
+ createJSXElement ( AST_NODE_TYPES . JSX . FOOTER ) ,
175
173
] ,
176
174
} ) ,
177
175
] ) ;
178
176
} ;
179
177
180
178
/**
181
179
* Transforms API metadata entries into processed MDX content
182
- *
183
180
* @param {Array<ApiDocMetadataEntry> } metadataEntries - API documentation metadata entries
184
181
* @param {ApiDocMetadataEntry } head - Main API metadata entry with version information
185
182
* @param {Object } sideBarProps - Props for the sidebar component
0 commit comments