-
Notifications
You must be signed in to change notification settings - Fork 5
/
savetest.tsx
164 lines (158 loc) · 4.47 KB
/
savetest.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/** @jsx API.JSX */
import API, {
Break,
Cell,
Document,
Paragraph,
Row,
Table,
Text,
TextAddition,
TextDeletion,
} from './mod.ts';
const api = new API();
api.styles.add({
id: 'Normal',
type: 'paragraph',
name: 'Normal',
paragraphProperties: {
spacing: {
before: 150,
after: 150,
},
},
});
const $skeet = api.styles.add({
type: 'paragraph',
name: 'Skeet of the boop',
paragraphProperties: {
alignment: 'right',
},
textProperties: {
isItalic: true,
isBold: true,
},
});
api.styles.add({
id: 'TableGrid',
type: 'table',
name: 'Table Grid',
basedOn: 'TableNormal',
isDefault: null,
paragraphProperties: { change: null },
textProperties: {},
tableProperties: {
style: null,
look: null,
borders: {
left: { type: 'single', spacing: 0, width: 4, color: 'auto' },
right: { type: 'single', spacing: 0, width: 4, color: 'auto' },
top: { type: 'single', spacing: 0, width: 4, color: 'auto' },
bottom: { type: 'single', spacing: 0, width: 4, color: 'auto' },
insideH: { type: 'single', spacing: 0, width: 4, color: 'auto' },
insideV: { type: 'single', spacing: 0, width: 4, color: 'auto' },
},
},
});
api.document.set(
<Document>
<Paragraph>
<Text>
This is the first paragraph of a test document, and it is the only paragraph devoid of all
styling. Notice that it still has spacing around it, because the "Normal" paragraph template
is overwritten in this test.
</Text>
</Paragraph>
<Paragraph>
<Text isItalic>This document was generated at:</Text>
<Text isBold>{' ' + new Date().toISOString()}</Text>
</Paragraph>
<Paragraph isBold isItalic>
The text in this paragraph is unstyled, but it's pilcrow sign (you can display it by enabling
the "¶" toolbar button) is bold and italic.
</Paragraph>
<Paragraph alignment="center" spacing={{ before: 96 * 20, after: 96 * 20 }}>
This text is center aligned, and the paragraph is given a lot of space before/after it
</Paragraph>
<Paragraph>
This paragraph has no styles, but the text in it is <Text isBold>bold</Text>,{' '}
<Text isItalic>italic</Text>, <Text verticalAlign={'superscript'}>superscript</Text>,{' '}
<Text verticalAlign={'subscript'}>subscript</Text>,{' '}
<Text verticalAlign={'baseline'}>baseline</Text> or{' '}
<Text isSmallCaps>small capital letters</Text>.
</Paragraph>
<Paragraph>
Could use <Text color="red">different</Text> <Text color="#0000FF">colors</Text> or{' '}
<Text isUnderlined>different</Text> <Text isUnderlined="dashDotDotHeavy">kinds</Text>{' '}
<Text isUnderlined="wave">underline</Text> <Text isUnderlined="double">underline</Text>
</Paragraph>
<Paragraph style={$skeet}>
This is a paragraph with a named style "skeet", shown in UI as "Skeet of the boop".
</Paragraph>
<Paragraph />
<Paragraph change={{ id: 0, author: 'Wybe', date: new Date(), style: $skeet }}>
This paragraph went from "Skeet of the boop" to being a normal paragraph.
</Paragraph>
<Paragraph />
<Paragraph style={$skeet} change={{ id: 0, author: 'Hans Pannekoek', date: new Date() }}>
This paragraph went from a normal paragraph to "Skeet of the boop".
</Paragraph>
<Paragraph>
This paragraph has{' '}
<TextAddition author={'Wybe the Builder'} date={new Date()} id={5}>
additions
</TextAddition>
<TextDeletion author={'Wybe the Destroyer'} date={new Date()} id={6}>
{' '}
and removals
</TextDeletion>
.
</Paragraph>
<Paragraph>
<Text>
There are two
<Break />
line breaks
<Break type="textWrapping" />
in this paragraph
</Text>
</Paragraph>
<Paragraph
indentation={{
left: 24 * 20,
firstLine: 48 * 20,
}}
alignment="both"
>
This is a paragraph with indentation, and more indentation on the first line. This is a
paragraph with indentation, and more indentation on the first line. This is a paragraph with
indentation, and more indentation on the first line. This is a paragraph with indentation, and
more indentation on the first line.
</Paragraph>
<Table
style="TableGrid"
borders={{ top: { type: 'wave' } }}
columnWidths={[4500, 4500]}
// @TODO make this work, fuksake
// width={{ length: 0, unit: 'auto' }}
>
<Row>
<Cell>
<Paragraph>A1</Paragraph>
</Cell>
<Cell>
<Paragraph>B1</Paragraph>
</Cell>
</Row>
<Row>
<Cell>
<Paragraph>A2</Paragraph>
</Cell>
<Cell>
<Paragraph>B2</Paragraph>
</Cell>
</Row>
</Table>
</Document>,
);
api.docx.toArchive().toFile('y.docx');