Make .addSection fully declarative

This commit is contained in:
Dolan
2021-03-19 20:53:56 +00:00
parent 4783812044
commit 3299c557a0
86 changed files with 3341 additions and 3278 deletions

View File

@ -6,21 +6,23 @@
To make a bullet point, simply make a paragraph into a bullet point:
```ts
doc.addSection({
children: [
new Paragraph({
text: "Bullet points",
bullet: {
level: 0 //How deep you want the bullet to be
}
}),
new Paragraph({
text: "Are awesome",
bullet: {
level: 0
}
})
],
const doc = new Document({
sections: [{
children: [
new Paragraph({
text: "Bullet points",
bullet: {
level: 0 //How deep you want the bullet to be
}
}),
new Paragraph({
text: "Are awesome",
bullet: {
level: 0
}
})
],
}];
});
```

View File

@ -5,30 +5,32 @@
Every Section has a sections which you can define its Headers and Footers:
```ts
doc.addSection({
headers: {
default: new Header({ // The standard default header
children: [],
}),
first: new Header({ // The first header
children: [],
}),
even: new Header({ // The header on every other page
children: [],
}),
},
footers: {
default: new Footer({ // The standard default footer
children: [],
}),
first: new Footer({ // The first footer
children: [],
}),
even: new Footer({ // The footer on every other page
children: [],
}),
},
children: [],
const doc = new Document({
sections: [{
headers: {
default: new Header({ // The standard default header
children: [],
}),
first: new Header({ // The first header
children: [],
}),
even: new Header({ // The header on every other page
children: [],
}),
},
footers: {
default: new Footer({ // The standard default footer
children: [],
}),
first: new Footer({ // The first footer
children: [],
}),
even: new Footer({ // The footer on every other page
children: [],
}),
},
children: [],
}];
});
```

View File

@ -37,20 +37,14 @@ const image = new ImageRun({
Add it into the document by adding the image into a paragraph:
```ts
doc.addSection({
children: [new Paragraph(image)],
});
```
Or:
```ts
doc.addSection({
children: [
new Paragraph({
children: [image],
}),
],
const doc = new Document({
sections: [{
children: [
new Paragraph({
children: [image],
}),
],
}];
});
```
@ -59,16 +53,22 @@ doc.addSection({
Adding images can be easily done by creating an instance of `ImageRun`. This can be added in a `Paragraph` or `Hyperlink`:
```ts
const image = new ImageRun({
data: [IMAGE_BUFFER],
transformation: {
width: [IMAGE_SIZE],
height: [IMAGE_SIZE],
},
});
doc.addSection({
children: [new Paragraph(image)],
const doc = new Document({
sections: [{
children: [
new Paragraph({
children: [
new ImageRun({
data: [IMAGE_BUFFER],
transformation: {
width: [IMAGE_SIZE],
height: [IMAGE_SIZE],
},
}),
],
}),
],
}];
});
```

View File

@ -35,20 +35,24 @@ const paragraph = new Paragraph({
After you create the paragraph, you must add the paragraph into a `section`:
```ts
doc.addSection({
children: [paragraph],
const doc = new Document({
sections: [{
children: [paragraph],
}];
});
```
Or the preferred convension, define the paragraph inside the section and remove the usage of variables:
```ts
doc.addSection({
children: [
new Paragraph({
children: [new TextRun("Lorem Ipsum Foo Bar"), new TextRun("Hello World")],
}),
],
const doc = new Document({
sections: [{
children: [
new Paragraph({
children: [new TextRun("Lorem Ipsum Foo Bar"), new TextRun("Hello World")],
}),
],
}];
});
```

View File

@ -11,12 +11,14 @@ For example, you could have one section which is portrait with a header and foot
This creates a simple section in a document with one paragraph inside:
```ts
doc.addSection({
children: [
new Paragraph({
children: [new TextRun("Hello World")],
}),
],
const doc = new Document({
sections: [{
children: [
new Paragraph({
children: [new TextRun("Hello World")],
}),
],
}];
});
```
@ -35,14 +37,16 @@ Setting the section type determines how the contents of the section will be plac
- `ODD_PAGE`
```ts
doc.addSection({
properties: {
type: SectionType.CONTINUOUS,
}
children: [
new Paragraph({
children: [new TextRun("Hello World")],
}),
],
const doc = new Document({
sections: [{
properties: {
type: SectionType.CONTINUOUS,
}
children: [
new Paragraph({
children: [new TextRun("Hello World")],
}),
],
}];
});
```

View File

@ -19,8 +19,10 @@ const table = new Table({
Then add the table in the `section`
```ts
doc.addSection({
children: [table],
const doc = new Document({
sections: [{
children: [table],
}];
});
```