@@ -19,8 +19,8 @@ import { createHyperlinkClick } from "./doc-properties-children";
19
19
20
20
export type DocPropertiesOptions = {
21
21
readonly name : string ;
22
- readonly description : string ;
23
- readonly title : string ;
22
+ readonly description ? : string ;
23
+ readonly title ? : string ;
24
24
} ;
25
25
26
26
export class DocProperties extends XmlComponent {
@@ -29,26 +29,32 @@ export class DocProperties extends XmlComponent {
29
29
public constructor ( { name, description, title } : DocPropertiesOptions = { name : "" , description : "" , title : "" } ) {
30
30
super ( "wp:docPr" ) ;
31
31
32
- this . root . push (
33
- new NextAttributeComponent ( {
34
- id : {
35
- key : "id" ,
36
- value : this . docPropertiesUniqueNumericId ( ) ,
37
- } ,
38
- name : {
39
- key : "name" ,
40
- value : name ,
41
- } ,
42
- description : {
43
- key : "descr" ,
44
- value : description ,
45
- } ,
46
- title : {
47
- key : "title" ,
48
- value : title ,
49
- } ,
50
- } ) ,
51
- ) ;
32
+ const attributes : Record < string , { readonly key : string ; readonly value : string | number } > = {
33
+ id : {
34
+ key : "id" ,
35
+ value : this . docPropertiesUniqueNumericId ( ) ,
36
+ } ,
37
+ name : {
38
+ key : "name" ,
39
+ value : name ,
40
+ } ,
41
+ } ;
42
+
43
+ if ( description !== null && description !== undefined ) {
44
+ attributes . description = {
45
+ key : "descr" ,
46
+ value : description ,
47
+ } ;
48
+ }
49
+
50
+ if ( title !== null && title !== undefined ) {
51
+ attributes . title = {
52
+ key : "title" ,
53
+ value : title ,
54
+ } ;
55
+ }
56
+
57
+ this . root . push ( new NextAttributeComponent ( attributes ) ) ;
52
58
}
53
59
54
60
public prepForXml ( context : IContext ) : IXmlableObject | undefined {
@@ -59,7 +65,6 @@ export class DocProperties extends XmlComponent {
59
65
}
60
66
61
67
this . root . push ( createHyperlinkClick ( element . linkId , true ) ) ;
62
-
63
68
break ;
64
69
}
65
70
0 commit comments