Skip to content

Commit c6ae127

Browse files
author
Chris Sloop
committedJun 15, 2021
feat: add table markup support
1 parent 0ba8197 commit c6ae127

14 files changed

+6069
-1537
lines changed
 

‎packages/rich-text-types/package-lock.json

+4,885-1,533
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/rich-text-types/src/blocks.ts

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ enum BLOCKS {
2121

2222
EMBEDDED_ENTRY = 'embedded-entry-block',
2323
EMBEDDED_ASSET = 'embedded-asset-block',
24+
25+
TABLE = 'table',
26+
TABLE_ROW = 'table-row',
27+
TABLE_CELL = 'table-cell',
2428
}
2529

2630
export default BLOCKS;

‎packages/rich-text-types/src/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import INLINES from './inlines';
66
* Checks if the node is an instance of Inline.
77
*/
88
export function isInline(node: Node): node is Inline {
9-
return Object.values(INLINES).includes(node.nodeType);
9+
return Object.values(INLINES).includes(node.nodeType as INLINES);
1010
}
1111

1212
/**
1313
* Checks if the node is an instance of Block.
1414
*/
1515
export function isBlock(node: Node): node is Block {
16-
return Object.values(BLOCKS).includes(node.nodeType);
16+
return Object.values(BLOCKS).includes(node.nodeType as BLOCKS);
1717
}
1818

1919
/**

‎packages/rich-text-types/src/nodeTypes.ts

+18
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,21 @@ export interface EntryHyperlink extends Inline {
155155
};
156156
content: Text[];
157157
}
158+
159+
export interface TableCell extends Block {
160+
nodeType: BLOCKS.TABLE_CELL;
161+
data: { colspan?: number };
162+
content: Paragraph[];
163+
}
164+
165+
export interface TableRow extends Block {
166+
nodeType: BLOCKS.TABLE_ROW;
167+
data: EmptyNodeData;
168+
content: TableCell[];
169+
}
170+
171+
export interface Table extends Block {
172+
nodeType: BLOCKS.TABLE;
173+
data: EmptyNodeData;
174+
content: TableRow[];
175+
}

‎packages/rich-text-types/src/schemaConstraints.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export type TopLevelBlockEnum =
1313
| BLOCKS.HR
1414
| BLOCKS.QUOTE
1515
| BLOCKS.EMBEDDED_ENTRY
16-
| BLOCKS.EMBEDDED_ASSET;
16+
| BLOCKS.EMBEDDED_ASSET
17+
| BLOCKS.TABLE;
1718

1819
/**
1920
* Array of all top level block types.
@@ -27,13 +28,13 @@ export const TOP_LEVEL_BLOCKS: TopLevelBlockEnum[] = [
2728
BLOCKS.HEADING_4,
2829
BLOCKS.HEADING_5,
2930
BLOCKS.HEADING_6,
30-
3131
BLOCKS.OL_LIST,
3232
BLOCKS.UL_LIST,
3333
BLOCKS.HR,
3434
BLOCKS.QUOTE,
3535
BLOCKS.EMBEDDED_ENTRY,
3636
BLOCKS.EMBEDDED_ASSET,
37+
BLOCKS.TABLE,
3738
];
3839

3940
/**
@@ -49,4 +50,7 @@ export const CONTAINERS = {
4950
[BLOCKS.UL_LIST]: [BLOCKS.LIST_ITEM],
5051
[BLOCKS.LIST_ITEM]: [...TOP_LEVEL_BLOCKS],
5152
[BLOCKS.QUOTE]: [BLOCKS.PARAGRAPH],
53+
[BLOCKS.TABLE]: [BLOCKS.TABLE_ROW],
54+
[BLOCKS.TABLE_ROW]: [BLOCKS.TABLE_CELL],
55+
[BLOCKS.TABLE_CELL]: [BLOCKS.PARAGRAPH],
5256
};

‎packages/rich-text-types/src/schemas/__test__/__snapshots__/schemas.test.ts.snap

+580
Large diffs are not rendered by default.

‎packages/rich-text-types/src/schemas/generated/document.json

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"hr",
7575
"ordered-list",
7676
"paragraph",
77+
"table",
7778
"unordered-list"
7879
],
7980
"type": "string"
@@ -128,6 +129,9 @@
128129
"list-item",
129130
"ordered-list",
130131
"paragraph",
132+
"table",
133+
"table-cell",
134+
"table-row",
131135
"unordered-list"
132136
],
133137
"type": "string"

‎packages/rich-text-types/src/schemas/generated/list-item.json

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"hr",
7676
"ordered-list",
7777
"paragraph",
78+
"table",
7879
"unordered-list"
7980
],
8081
"type": "string"
@@ -129,6 +130,9 @@
129130
"list-item",
130131
"ordered-list",
131132
"paragraph",
133+
"table",
134+
"table-cell",
135+
"table-row",
132136
"unordered-list"
133137
],
134138
"type": "string"

‎packages/rich-text-types/src/schemas/generated/ordered-list.json

+4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"hr",
103103
"ordered-list",
104104
"paragraph",
105+
"table",
105106
"unordered-list"
106107
],
107108
"type": "string"
@@ -156,6 +157,9 @@
156157
"list-item",
157158
"ordered-list",
158159
"paragraph",
160+
"table",
161+
"table-cell",
162+
"table-row",
159163
"unordered-list"
160164
],
161165
"type": "string"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"$ref": "#/definitions/TableCell",
3+
"definitions": {
4+
"TableCell": {
5+
"type": "object",
6+
"properties": {
7+
"nodeType": {
8+
"type": "string",
9+
"enum": [
10+
"table-cell"
11+
]
12+
},
13+
"data": {
14+
"type": "object",
15+
"properties": {
16+
"colspan": {
17+
"type": "number"
18+
}
19+
},
20+
"additionalProperties": false
21+
},
22+
"content": {
23+
"type": "array",
24+
"items": {
25+
"$ref": "#/definitions/Paragraph"
26+
}
27+
}
28+
},
29+
"additionalProperties": false,
30+
"required": [
31+
"content",
32+
"data",
33+
"nodeType"
34+
]
35+
},
36+
"Paragraph": {
37+
"type": "object",
38+
"properties": {
39+
"nodeType": {
40+
"type": "string",
41+
"enum": [
42+
"paragraph"
43+
]
44+
},
45+
"data": {
46+
"type": "object",
47+
"properties": {}
48+
},
49+
"content": {
50+
"type": "array",
51+
"items": {
52+
"anyOf": [
53+
{
54+
"$ref": "#/definitions/Inline"
55+
},
56+
{
57+
"$ref": "#/definitions/Text"
58+
}
59+
]
60+
}
61+
}
62+
},
63+
"additionalProperties": false,
64+
"required": [
65+
"content",
66+
"data",
67+
"nodeType"
68+
]
69+
},
70+
"Inline": {
71+
"type": "object",
72+
"properties": {
73+
"nodeType": {
74+
"$ref": "#/definitions/INLINES"
75+
},
76+
"content": {
77+
"type": "array",
78+
"items": {
79+
"anyOf": [
80+
{
81+
"$ref": "#/definitions/Inline"
82+
},
83+
{
84+
"$ref": "#/definitions/Text"
85+
}
86+
]
87+
}
88+
},
89+
"data": {
90+
"$ref": "#/definitions/Record<string,any>"
91+
}
92+
},
93+
"additionalProperties": false,
94+
"required": [
95+
"content",
96+
"data",
97+
"nodeType"
98+
]
99+
},
100+
"INLINES": {
101+
"description": "Map of all Contentful inline types. Inline contain inline or text nodes.",
102+
"enum": [
103+
"asset-hyperlink",
104+
"embedded-entry-inline",
105+
"entry-hyperlink",
106+
"hyperlink"
107+
],
108+
"type": "string"
109+
},
110+
"Text": {
111+
"type": "object",
112+
"properties": {
113+
"nodeType": {
114+
"type": "string",
115+
"enum": [
116+
"text"
117+
]
118+
},
119+
"value": {
120+
"type": "string"
121+
},
122+
"marks": {
123+
"type": "array",
124+
"items": {
125+
"$ref": "#/definitions/Mark"
126+
}
127+
},
128+
"data": {
129+
"$ref": "#/definitions/Record<string,any>"
130+
}
131+
},
132+
"additionalProperties": false,
133+
"required": [
134+
"data",
135+
"marks",
136+
"nodeType",
137+
"value"
138+
]
139+
},
140+
"Mark": {
141+
"type": "object",
142+
"properties": {
143+
"type": {
144+
"type": "string"
145+
}
146+
},
147+
"additionalProperties": false,
148+
"required": [
149+
"type"
150+
]
151+
},
152+
"Record<string,any>": {
153+
"additionalProperties": true,
154+
"type": "object"
155+
}
156+
},
157+
"$schema": "http://json-schema.org/draft-07/schema#"
158+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
{
2+
"$ref": "#/definitions/TableRow",
3+
"definitions": {
4+
"TableRow": {
5+
"type": "object",
6+
"properties": {
7+
"nodeType": {
8+
"type": "string",
9+
"enum": [
10+
"table-row"
11+
]
12+
},
13+
"data": {
14+
"type": "object",
15+
"properties": {}
16+
},
17+
"content": {
18+
"type": "array",
19+
"items": {
20+
"$ref": "#/definitions/TableCell"
21+
}
22+
}
23+
},
24+
"additionalProperties": false,
25+
"required": [
26+
"content",
27+
"data",
28+
"nodeType"
29+
]
30+
},
31+
"TableCell": {
32+
"type": "object",
33+
"properties": {
34+
"nodeType": {
35+
"type": "string",
36+
"enum": [
37+
"table-cell"
38+
]
39+
},
40+
"data": {
41+
"type": "object",
42+
"properties": {
43+
"colspan": {
44+
"type": "number"
45+
}
46+
},
47+
"additionalProperties": false
48+
},
49+
"content": {
50+
"type": "array",
51+
"items": {
52+
"$ref": "#/definitions/Paragraph"
53+
}
54+
}
55+
},
56+
"additionalProperties": false,
57+
"required": [
58+
"content",
59+
"data",
60+
"nodeType"
61+
]
62+
},
63+
"Paragraph": {
64+
"type": "object",
65+
"properties": {
66+
"nodeType": {
67+
"type": "string",
68+
"enum": [
69+
"paragraph"
70+
]
71+
},
72+
"data": {
73+
"type": "object",
74+
"properties": {}
75+
},
76+
"content": {
77+
"type": "array",
78+
"items": {
79+
"anyOf": [
80+
{
81+
"$ref": "#/definitions/Inline"
82+
},
83+
{
84+
"$ref": "#/definitions/Text"
85+
}
86+
]
87+
}
88+
}
89+
},
90+
"additionalProperties": false,
91+
"required": [
92+
"content",
93+
"data",
94+
"nodeType"
95+
]
96+
},
97+
"Inline": {
98+
"type": "object",
99+
"properties": {
100+
"nodeType": {
101+
"$ref": "#/definitions/INLINES"
102+
},
103+
"content": {
104+
"type": "array",
105+
"items": {
106+
"anyOf": [
107+
{
108+
"$ref": "#/definitions/Inline"
109+
},
110+
{
111+
"$ref": "#/definitions/Text"
112+
}
113+
]
114+
}
115+
},
116+
"data": {
117+
"$ref": "#/definitions/Record<string,any>"
118+
}
119+
},
120+
"additionalProperties": false,
121+
"required": [
122+
"content",
123+
"data",
124+
"nodeType"
125+
]
126+
},
127+
"INLINES": {
128+
"description": "Map of all Contentful inline types. Inline contain inline or text nodes.",
129+
"enum": [
130+
"asset-hyperlink",
131+
"embedded-entry-inline",
132+
"entry-hyperlink",
133+
"hyperlink"
134+
],
135+
"type": "string"
136+
},
137+
"Text": {
138+
"type": "object",
139+
"properties": {
140+
"nodeType": {
141+
"type": "string",
142+
"enum": [
143+
"text"
144+
]
145+
},
146+
"value": {
147+
"type": "string"
148+
},
149+
"marks": {
150+
"type": "array",
151+
"items": {
152+
"$ref": "#/definitions/Mark"
153+
}
154+
},
155+
"data": {
156+
"$ref": "#/definitions/Record<string,any>"
157+
}
158+
},
159+
"additionalProperties": false,
160+
"required": [
161+
"data",
162+
"marks",
163+
"nodeType",
164+
"value"
165+
]
166+
},
167+
"Mark": {
168+
"type": "object",
169+
"properties": {
170+
"type": {
171+
"type": "string"
172+
}
173+
},
174+
"additionalProperties": false,
175+
"required": [
176+
"type"
177+
]
178+
},
179+
"Record<string,any>": {
180+
"additionalProperties": true,
181+
"type": "object"
182+
}
183+
},
184+
"$schema": "http://json-schema.org/draft-07/schema#"
185+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
{
2+
"$ref": "#/definitions/Table",
3+
"definitions": {
4+
"Table": {
5+
"type": "object",
6+
"properties": {
7+
"nodeType": {
8+
"type": "string",
9+
"enum": [
10+
"table"
11+
]
12+
},
13+
"data": {
14+
"type": "object",
15+
"properties": {}
16+
},
17+
"content": {
18+
"type": "array",
19+
"items": {
20+
"$ref": "#/definitions/TableRow"
21+
}
22+
}
23+
},
24+
"additionalProperties": false,
25+
"required": [
26+
"content",
27+
"data",
28+
"nodeType"
29+
]
30+
},
31+
"TableRow": {
32+
"type": "object",
33+
"properties": {
34+
"nodeType": {
35+
"type": "string",
36+
"enum": [
37+
"table-row"
38+
]
39+
},
40+
"data": {
41+
"type": "object",
42+
"properties": {}
43+
},
44+
"content": {
45+
"type": "array",
46+
"items": {
47+
"$ref": "#/definitions/TableCell"
48+
}
49+
}
50+
},
51+
"additionalProperties": false,
52+
"required": [
53+
"content",
54+
"data",
55+
"nodeType"
56+
]
57+
},
58+
"TableCell": {
59+
"type": "object",
60+
"properties": {
61+
"nodeType": {
62+
"type": "string",
63+
"enum": [
64+
"table-cell"
65+
]
66+
},
67+
"data": {
68+
"type": "object",
69+
"properties": {
70+
"colspan": {
71+
"type": "number"
72+
}
73+
},
74+
"additionalProperties": false
75+
},
76+
"content": {
77+
"type": "array",
78+
"items": {
79+
"$ref": "#/definitions/Paragraph"
80+
}
81+
}
82+
},
83+
"additionalProperties": false,
84+
"required": [
85+
"content",
86+
"data",
87+
"nodeType"
88+
]
89+
},
90+
"Paragraph": {
91+
"type": "object",
92+
"properties": {
93+
"nodeType": {
94+
"type": "string",
95+
"enum": [
96+
"paragraph"
97+
]
98+
},
99+
"data": {
100+
"type": "object",
101+
"properties": {}
102+
},
103+
"content": {
104+
"type": "array",
105+
"items": {
106+
"anyOf": [
107+
{
108+
"$ref": "#/definitions/Inline"
109+
},
110+
{
111+
"$ref": "#/definitions/Text"
112+
}
113+
]
114+
}
115+
}
116+
},
117+
"additionalProperties": false,
118+
"required": [
119+
"content",
120+
"data",
121+
"nodeType"
122+
]
123+
},
124+
"Inline": {
125+
"type": "object",
126+
"properties": {
127+
"nodeType": {
128+
"$ref": "#/definitions/INLINES"
129+
},
130+
"content": {
131+
"type": "array",
132+
"items": {
133+
"anyOf": [
134+
{
135+
"$ref": "#/definitions/Inline"
136+
},
137+
{
138+
"$ref": "#/definitions/Text"
139+
}
140+
]
141+
}
142+
},
143+
"data": {
144+
"$ref": "#/definitions/Record<string,any>"
145+
}
146+
},
147+
"additionalProperties": false,
148+
"required": [
149+
"content",
150+
"data",
151+
"nodeType"
152+
]
153+
},
154+
"INLINES": {
155+
"description": "Map of all Contentful inline types. Inline contain inline or text nodes.",
156+
"enum": [
157+
"asset-hyperlink",
158+
"embedded-entry-inline",
159+
"entry-hyperlink",
160+
"hyperlink"
161+
],
162+
"type": "string"
163+
},
164+
"Text": {
165+
"type": "object",
166+
"properties": {
167+
"nodeType": {
168+
"type": "string",
169+
"enum": [
170+
"text"
171+
]
172+
},
173+
"value": {
174+
"type": "string"
175+
},
176+
"marks": {
177+
"type": "array",
178+
"items": {
179+
"$ref": "#/definitions/Mark"
180+
}
181+
},
182+
"data": {
183+
"$ref": "#/definitions/Record<string,any>"
184+
}
185+
},
186+
"additionalProperties": false,
187+
"required": [
188+
"data",
189+
"marks",
190+
"nodeType",
191+
"value"
192+
]
193+
},
194+
"Mark": {
195+
"type": "object",
196+
"properties": {
197+
"type": {
198+
"type": "string"
199+
}
200+
},
201+
"additionalProperties": false,
202+
"required": [
203+
"type"
204+
]
205+
},
206+
"Record<string,any>": {
207+
"additionalProperties": true,
208+
"type": "object"
209+
}
210+
},
211+
"$schema": "http://json-schema.org/draft-07/schema#"
212+
}

‎packages/rich-text-types/src/schemas/generated/unordered-list.json

+4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"hr",
103103
"ordered-list",
104104
"paragraph",
105+
"table",
105106
"unordered-list"
106107
],
107108
"type": "string"
@@ -156,6 +157,9 @@
156157
"list-item",
157158
"ordered-list",
158159
"paragraph",
160+
"table",
161+
"table-cell",
162+
"table-row",
159163
"unordered-list"
160164
],
161165
"type": "string"

‎packages/rich-text-types/tools/jsonSchemaGen.ts

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const blockSymbolsMap = new Map([
5353
[BLOCKS.QUOTE, 'Quote'],
5454
[BLOCKS.EMBEDDED_ENTRY, 'EntryLinkBlock'],
5555
[BLOCKS.EMBEDDED_ASSET, 'AssetLinkBlock'],
56+
[BLOCKS.TABLE, 'Table'],
57+
[BLOCKS.TABLE_ROW, 'TableRow'],
58+
[BLOCKS.TABLE_CELL, 'TableCell'],
5659
]);
5760

5861
const inlineSymbolsMap = new Map([

0 commit comments

Comments
 (0)
Please sign in to comment.