-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathtypes.ts
325 lines (294 loc) · 7.28 KB
/
types.ts
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/**
*
* Copyright (c) 2020, Sam Wight
* https://github.com/samwightt/chorale-renderer/blob/1e2c1415166e298c1ce72a1a15db927bebf2b5c8/types/notion.ts
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
/**
* Base properties that all blocks share.
*/
interface BaseValueType {
id: string;
version: number;
created_time: number;
last_edited_time: number;
parent_id: string;
parent_table: string;
alive: boolean;
created_by_table: string;
created_by_id: string;
last_edited_by_table: string;
last_edited_by_id: string;
space_id?: string;
properties?: any;
content?: string[];
}
/**
* Colors and backgrounds a given block can have in Notion.
*/
export type ColorType =
| "gray"
| "brown"
| "orange"
| "yellow"
| "teal"
| "blue"
| "purple"
| "pink"
| "red"
| "gray_background"
| "brown_background"
| "orange_background"
| "yellow_background"
| "teal_background"
| "blue_background"
| "purple_background"
| "pink_background"
| "red_background";
type BoldFormatType = ["b"];
type ItalicFormatType = ["i"];
type StrikeFormatType = ["s"];
type CodeFormatType = ["c"];
type LinkFormatType = ["a", string];
type ColorFormatType = ["h", ColorType];
type DateFormatType = [
"d",
{
type: "date";
start_date: string;
date_format: string;
}
];
type UserFormatType = ["u", string];
type PageFormatType = ["p", string];
type SubDecorationType =
| BoldFormatType
| ItalicFormatType
| StrikeFormatType
| CodeFormatType
| LinkFormatType
| ColorFormatType
| DateFormatType
| UserFormatType
| PageFormatType;
type BaseDecorationType = [string];
type AdditionalDecorationType = [string, SubDecorationType[]];
export type DecorationType = BaseDecorationType | AdditionalDecorationType;
export interface PageValueType extends BaseValueType {
type: "page";
properties?: {
title: DecorationType[];
};
format: {
page_full_width?: boolean;
page_small_text?: boolean;
page_cover_position?: number;
block_locked?: boolean;
block_locked_by?: string;
page_cover?: string;
page_icon?: string;
};
permissions: { role: string; type: string }[];
file_ids?: string[];
}
export interface BaseTextValueType extends BaseValueType {
properties?: {
title: DecorationType[];
};
format?: {
block_color: ColorType;
};
}
interface BookmarkValueType extends BaseValueType {
type: "bookmark";
properties: {
link: DecorationType[];
title?: DecorationType[];
description?: DecorationType[];
};
format?: {
block_color?: string;
bookmark_icon: string;
bookmark_cover: string;
};
}
interface TextValueType extends BaseTextValueType {
type: "text";
}
interface BulletedListValueType extends BaseTextValueType {
type: "bulleted_list";
}
interface NumberedListValueType extends BaseTextValueType {
type: "numbered_list";
}
interface HeaderValueType extends BaseTextValueType {
type: "header";
}
interface SubHeaderValueType extends BaseTextValueType {
type: "sub_header";
}
interface SubSubHeaderValueType extends BaseTextValueType {
type: "sub_sub_header";
}
interface QuoteValueType extends BaseTextValueType {
type: "quote";
}
interface TodoValueType extends BaseTextValueType {
type: "to_do";
properties: {
title: DecorationType[];
checked: (["Yes"] | ["No"])[];
};
}
interface DividerValueType extends BaseValueType {
type: "divider";
}
interface ColumnListValueType extends BaseValueType {
type: "column_list";
}
interface ColumnValueType extends BaseValueType {
type: "column";
format: {
column_ratio: number;
};
}
export interface CalloutValueType extends BaseValueType {
type: "callout";
format: {
page_icon: string;
block_color: ColorType;
};
properties: {
title: DecorationType[];
};
}
interface ToggleValueType extends BaseValueType {
type: "toggle";
properties: {
title: DecorationType[];
};
}
export interface ContentValueType extends BaseValueType {
properties: {
source: string[][];
caption?: DecorationType[];
};
format: {
block_width: number;
block_height: number;
display_source: string;
block_full_width: boolean;
block_page_width: boolean;
block_aspect_ratio: number;
block_preserve_scale: boolean;
};
file_ids?: string[];
}
interface ImageValueType extends ContentValueType {
type: "image";
}
interface EmbedValueType extends ContentValueType {
type: "embed";
}
interface VideoValueType extends ContentValueType {
type: "video";
}
interface CodeValueType extends BaseValueType {
type: "code";
properties: {
title: DecorationType[];
language: DecorationType[];
};
}
interface CollectionValueType extends ContentValueType {
type: "collection_view";
}
interface TableGalleryType extends BaseValueType {
type: "gallery";
format: {
gallery_cover: {
type: "page_cover";
};
gallery_cover_aspect: "cover";
gallery_properties: Array<{ visible: boolean; property: string }>;
};
}
interface TableCollectionType extends BaseValueType {
type: "table";
format: {
table_wrap: boolean;
table_properties: Array<{
visible: boolean;
property: string;
width: number;
}>;
};
}
export type CollectionViewType = TableGalleryType | TableCollectionType;
/**
* The different block values a block can have.
*/
export type BlockValueType =
| TextValueType
| PageValueType
| BulletedListValueType
| NumberedListValueType
| HeaderValueType
| SubHeaderValueType
| SubSubHeaderValueType
| TodoValueType
| DividerValueType
| ColumnListValueType
| ColumnValueType
| QuoteValueType
| CodeValueType
| ImageValueType
| VideoValueType
| EmbedValueType
| CalloutValueType
| BookmarkValueType
| ToggleValueType
| CollectionValueType;
export interface BlockType {
role: string;
value: BlockValueType;
collection?: {
title: DecorationType[];
types: CollectionViewType[];
data: Array<{ [key: string]: DecorationType[] }>;
schema: { [key: string]: { name: string; type: string } };
};
}
export interface NotionUserType {
role: string;
value: {
id: string;
version: number;
email: string;
given_name: string;
family_name: string;
profile_photo: string;
onboarding_completed: boolean;
mobile_onboarding_completed: boolean;
};
}
export type BlockMapType = {
[key: string]: BlockType;
};
export interface RecordMapType {
block: BlockMapType;
notion_user: {
[key: string]: NotionUserType;
};
}
export interface LoadPageChunkData {
recordMap: RecordMapType;
cursor: {
stack: any[];
};
}
export type MapPageUrl = (pageId: string) => string;
export type MapImageUrl = (image: string, block?: BlockType) => string;