Add support for optional pairs.

This commit is contained in:
Tom Alexander 2024-01-27 20:49:43 -05:00
parent 49905f1273
commit bb15dbcbaf
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 22 additions and 1 deletions

View File

@ -54,7 +54,8 @@
} }
.OrgAstProperties, .OrgAstProperties,
.OrgAstObjectTree { .OrgAstObjectTree,
.OrgAstOptionalPair {
border: 1px solid #000000; border: 1px solid #000000;
margin: 5px; margin: 5px;

View File

@ -6,3 +6,4 @@ export const selected: string;
export const hovered: string; export const hovered: string;
export const OrgAstProperties: string; export const OrgAstProperties: string;
export const OrgAstObjectTree: string; export const OrgAstObjectTree: string;
export const OrgAstOptionalPair: string;

View File

@ -258,6 +258,21 @@ const OrgPropertyValue = (props: {
/> />
</div> </div>
); );
} else if (is_optional_pair(props.value)) {
return (
<table className={styles.OrgAstOptionalPair}>
<tbody>
<tr>
<th scope="row">Optional value:</th>
<td>{JSON.stringify(props.value.optval)}</td>
</tr>
<tr>
<th scope="row">Value:</th>
<td>{JSON.stringify(props.value.val)}</td>
</tr>
</tbody>
</table>
);
} else if (is_object_tree(props.value)) { } else if (is_object_tree(props.value)) {
return ( return (
<OrgObjectTree <OrgObjectTree
@ -350,6 +365,10 @@ function is_list_of_ast_nodes(val: any): boolean {
}); });
} }
function is_optional_pair(val: any): boolean {
return is_object(val) && val.hasOwnProperty("optval") && val.hasOwnProperty("val");
}
function is_object_tree(val: any): boolean { function is_object_tree(val: any): boolean {
return is_object(val) && val.hasOwnProperty("object-tree"); return is_object(val) && val.hasOwnProperty("object-tree");
} }