@@ -7,41 +7,24 @@ import { SKIP, visit } from 'unist-util-visit';
77import createQueries from '../../../utils/queries/index.mjs' ;
88import { createJSXElement } from './ast.mjs' ;
99import {
10- ICON_SYMBOL_MAP ,
10+ API_ICONS ,
11+ AST_NODE_TYPES ,
1112 STABILITY_LEVELS ,
12- CHANGE_TYPES ,
13+ LIFECYCLE_LABELS ,
14+ INTERNATIONALIZABLE ,
1315} from '../constants.mjs' ;
1416import { DOC_NODE_BLOB_BASE_URL } from '../../../constants.mjs' ;
1517import { enforceArray , sortChanges } from '../../../utils/generators.mjs' ;
1618import { buildMetaBarProps } from './buildBarProps.mjs' ;
1719
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-
3620/**
3721 * Creates a history of changes for an API element
38- *
3922 * @param {ApiDocMetadataEntry } entry - The metadata entry containing change information
4023 * @returns {import('unist').Node|null } JSX element representing change history or null if no changes
4124 */
4225const 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 )
4528 // Do we have this field?
4629 . filter ( ( [ field ] ) => entry [ field ] )
4730 // Get the versions as an array
@@ -59,6 +42,7 @@ const createChangeElement = entry => {
5942 label : change . description ,
6043 url : change [ 'pr-url' ] ,
6144 } ) ) ;
45+
6246 changeEntries . push ( ...explicitChanges ) ;
6347 }
6448
@@ -67,14 +51,13 @@ const createChangeElement = entry => {
6751 }
6852
6953 // Sort by version, newest first and create the JSX element
70- return createJSXElement ( 'ChangeHistory' , {
54+ return createJSXElement ( AST_NODE_TYPES . JSX . CHANGE_HISTORY , {
7155 changes : sortChanges ( changeEntries , 'versions' ) ,
7256 } ) ;
7357} ;
7458
7559/**
7660 * Creates a source link element if a source link is available
77- *
7861 * @param {string|undefined } sourceLink - The source link path
7962 * @returns {import('hastscript').Element|null } The source link element or null if no source link
8063 */
@@ -84,7 +67,7 @@ const createSourceLink = sourceLink => {
8467 }
8568
8669 return createElement ( 'span' , [
87- 'Source Code: ' ,
70+ INTERNATIONALIZABLE . sourceCode ,
8871 createElement (
8972 'a' ,
9073 { href : `${ DOC_NODE_BLOB_BASE_URL } ${ sourceLink } ` } ,
@@ -93,9 +76,25 @@ const createSourceLink = sourceLink => {
9376 ] ) ;
9477} ;
9578
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+
9696/**
9797 * Enhances a heading node with metadata, source links, and styling
98- *
9998 * @param {ApiDocMetadataEntry } entry - The API metadata entry
10099 * @param {import('mdast').Heading } node - The heading node to transform
101100 * @param {number } index - The index of the node in its parent's children array
@@ -106,14 +105,15 @@ const transformHeadingNode = (entry, node, index, parent) => {
106105 const { data, children } = node ;
107106 const headerChildren = [
108107 createElement ( `h${ data . depth + 1 } ` , [
109- createElement ( `a.mark #${ data . slug } ` , { href : `#${ data . slug } ` } , children ) ,
108+ createElement ( `a#${ data . slug } ` , { href : `#${ data . slug } ` } , children ) ,
110109 ] ) ,
111110 ] ;
112111
113112 // 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+ ) ;
117117 }
118118
119119 // Add change history if available
@@ -136,7 +136,6 @@ const transformHeadingNode = (entry, node, index, parent) => {
136136
137137/**
138138 * Processes an API documentation entry by applying transformations to its content
139- *
140139 * @param {ApiDocMetadataEntry } entry - The API metadata entry to process
141140 * @returns {import('unist').Node } The processed content
142141 */
@@ -155,31 +154,29 @@ const processEntry = entry => {
155154
156155/**
157156 * Creates the overall content structure with processed entries
158- *
159157 * @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
162160 * @returns {import('unist').Node } The root node of the content tree
163161 */
164162const createContentStructure = ( entries , sideBarProps , metaBarProps ) => {
165163 return createTree ( 'root' , [
166- createJSXElement ( 'NavBar' ) ,
167- createJSXElement ( 'Article' , {
164+ createJSXElement ( AST_NODE_TYPES . JSX . NAV_BAR ) ,
165+ createJSXElement ( AST_NODE_TYPES . JSX . ARTICLE , {
168166 children : [
169- createJSXElement ( 'SideBar' , sideBarProps ) ,
167+ createJSXElement ( AST_NODE_TYPES . JSX . SIDE_BAR , sideBarProps ) ,
170168 createElement ( 'div' , [
171169 createElement ( 'main' , entries . map ( processEntry ) ) ,
172- createJSXElement ( 'MetaBar' , metaBarProps ) ,
170+ createJSXElement ( AST_NODE_TYPES . JSX . META_BAR , metaBarProps ) ,
173171 ] ) ,
174- createJSXElement ( 'Footer' ) ,
172+ createJSXElement ( AST_NODE_TYPES . JSX . FOOTER ) ,
175173 ] ,
176174 } ) ,
177175 ] ) ;
178176} ;
179177
180178/**
181179 * Transforms API metadata entries into processed MDX content
182- *
183180 * @param {Array<ApiDocMetadataEntry> } metadataEntries - API documentation metadata entries
184181 * @param {ApiDocMetadataEntry } head - Main API metadata entry with version information
185182 * @param {Object } sideBarProps - Props for the sidebar component
0 commit comments