diff --git a/packages/rich-text-types/README.md b/packages/rich-text-types/README.md index 37e2900a..9a668f16 100644 --- a/packages/rich-text-types/README.md +++ b/packages/rich-text-types/README.md @@ -1,3 +1,17 @@ # rich-text-types Type definitions and constants for the Contentful rich text field type. + +## Updating test snapshots + +If you want to update the test snapshots simply run + +```properties +npm run test:update-snapshots +``` + +or + +```properties +yarn test:update-snapshots +``` diff --git a/packages/rich-text-types/package.json b/packages/rich-text-types/package.json index 51d509b1..b65c401d 100644 --- a/packages/rich-text-types/package.json +++ b/packages/rich-text-types/package.json @@ -23,7 +23,8 @@ "build": "yarn generate-json-schema && tsc --module commonjs && rollup -c --bundleConfigAsCjs rollup.config.js", "start": "tsc && rollup -c --bundleConfigAsCjs rollup.config.js -w", "generate-json-schema": "ts-node -O '{\"module\": \"commonjs\"}' ./tools/jsonSchemaGen", - "test": "jest" + "test": "jest", + "test:update-snapshots": "jest -u" }, "devDependencies": { "@cspotcode/source-map-consumer": "^0.8.0", diff --git a/packages/rich-text-types/src/nodeTypes.ts b/packages/rich-text-types/src/nodeTypes.ts index 8b7e01d6..a6c5fede 100644 --- a/packages/rich-text-types/src/nodeTypes.ts +++ b/packages/rich-text-types/src/nodeTypes.ts @@ -1,6 +1,14 @@ import { BLOCKS } from './blocks'; import { INLINES } from './inlines'; -import { Block, Inline, ListItemBlock, Text } from './types'; +import { + Block, + Inline, + ListItemBlock, + TableCellBlock, + TableHeaderCellBlock, + TableRowBlock, + Text, +} from './types'; // eslint-disable-next-line @typescript-eslint/ban-types type EmptyNodeData = {}; @@ -198,7 +206,7 @@ export interface ResourceHyperlink extends Inline { } export interface TableCell extends Block { - nodeType: BLOCKS.TABLE_HEADER_CELL | BLOCKS.TABLE_CELL; + nodeType: BLOCKS.TABLE_CELL; data: { colspan?: number; rowspan?: number; @@ -207,11 +215,20 @@ export interface TableCell extends Block { /** * @minItems 1 */ - content: Paragraph[]; + content: TableCellBlock[]; } -export interface TableHeaderCell extends TableCell { +export interface TableHeaderCell extends Block { nodeType: BLOCKS.TABLE_HEADER_CELL; + data: { + colspan?: number; + rowspan?: number; + }; + + /** + * @minItems 1 + */ + content: TableHeaderCellBlock[]; } // An abstract table row can have both table cell types @@ -223,7 +240,7 @@ export interface TableRow extends Block { /** * @minItems 1 */ - content: TableCell[]; + content: TableRowBlock[]; } export interface Table extends Block { diff --git a/packages/rich-text-types/src/schemaConstraints.ts b/packages/rich-text-types/src/schemaConstraints.ts index 17ac8381..bce093d0 100644 --- a/packages/rich-text-types/src/schemaConstraints.ts +++ b/packages/rich-text-types/src/schemaConstraints.ts @@ -57,6 +57,12 @@ export type ListItemBlockEnum = | BLOCKS.EMBEDDED_ASSET | BLOCKS.EMBEDDED_RESOURCE; +export type TableRowBlockEnum = BLOCKS.TABLE_CELL | BLOCKS.TABLE_HEADER_CELL; + +export type TableCellEnum = ListItemBlockEnum; + +export type TableHeaderCellEnum = BLOCKS.PARAGRAPH; + /** * Array of all allowed block types inside list items */ diff --git a/packages/rich-text-types/src/schemas/__test__/__snapshots__/schemas.test.ts.snap b/packages/rich-text-types/src/schemas/__test__/__snapshots__/schemas.test.ts.snap index 8245aaab..cf3996b7 100644 --- a/packages/rich-text-types/src/schemas/__test__/__snapshots__/schemas.test.ts.snap +++ b/packages/rich-text-types/src/schemas/__test__/__snapshots__/schemas.test.ts.snap @@ -3186,24 +3186,41 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "$ref": "#/definitions/Table", "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { - "INLINES": { - "description": "Map of all Contentful inline types. Inline contain inline or text nodes.", + "BLOCKS": { + "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", "enum": [ - "asset-hyperlink", - "embedded-entry-inline", - "embedded-resource-inline", - "entry-hyperlink", - "hyperlink", - "resource-hyperlink", + "document", + "paragraph", + "heading-1", + "heading-2", + "heading-3", + "heading-4", + "heading-5", + "heading-6", + "ordered-list", + "unordered-list", + "list-item", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "embedded-resource-block", + "table", + "table-row", + "table-cell", + "table-header-cell", ], "type": "string", }, - "Inline": { + "Block": { "additionalProperties": false, "properties": { "content": { "items": { "anyOf": [ + { + "$ref": "#/definitions/Block", + }, { "$ref": "#/definitions/Inline", }, @@ -3218,7 +3235,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "$ref": "#/definitions/NodeData", }, "nodeType": { - "$ref": "#/definitions/INLINES", + "$ref": "#/definitions/BLOCKS", }, }, "required": [ @@ -3228,23 +3245,19 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, - "Mark": { - "additionalProperties": false, - "properties": { - "type": { - "type": "string", - }, - }, - "required": [ - "type", + "INLINES": { + "description": "Map of all Contentful inline types. Inline contain inline or text nodes.", + "enum": [ + "asset-hyperlink", + "embedded-entry-inline", + "embedded-resource-inline", + "entry-hyperlink", + "hyperlink", + "resource-hyperlink", ], - "type": "object", - }, - "NodeData": { - "additionalProperties": true, - "type": "object", + "type": "string", }, - "Paragraph": { + "Inline": { "additionalProperties": false, "properties": { "content": { @@ -3261,14 +3274,10 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "type": "array", }, "data": { - "properties": {}, - "type": "object", + "$ref": "#/definitions/NodeData", }, "nodeType": { - "enum": [ - "paragraph", - ], - "type": "string", + "$ref": "#/definitions/INLINES", }, }, "required": [ @@ -3278,6 +3287,22 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, + "Mark": { + "additionalProperties": false, + "properties": { + "type": { + "type": "string", + }, + }, + "required": [ + "type", + ], + "type": "object", + }, + "NodeData": { + "additionalProperties": true, + "type": "object", + }, "Table": { "additionalProperties": false, "properties": { @@ -3306,32 +3331,23 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, - "TableCell": { + "TableRow": { "additionalProperties": false, "properties": { "content": { "items": { - "$ref": "#/definitions/Paragraph", + "$ref": "#/definitions/TableRowBlock", }, "minItems": 1, "type": "array", }, "data": { - "additionalProperties": false, - "properties": { - "colspan": { - "type": "number", - }, - "rowspan": { - "type": "number", - }, - }, + "properties": {}, "type": "object", }, "nodeType": { "enum": [ - "table-cell", - "table-header-cell", + "table-row", ], "type": "string", }, @@ -3343,25 +3359,30 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, - "TableRow": { + "TableRowBlock": { "additionalProperties": false, "properties": { "content": { "items": { - "$ref": "#/definitions/TableCell", + "anyOf": [ + { + "$ref": "#/definitions/Block", + }, + { + "$ref": "#/definitions/Inline", + }, + { + "$ref": "#/definitions/Text", + }, + ], }, - "minItems": 1, "type": "array", }, "data": { - "properties": {}, - "type": "object", + "$ref": "#/definitions/NodeData", }, "nodeType": { - "enum": [ - "table-row", - ], - "type": "string", + "$ref": "#/definitions/TableRowBlockEnum", }, }, "required": [ @@ -3371,6 +3392,13 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, + "TableRowBlockEnum": { + "enum": [ + "table-cell", + "table-header-cell", + ], + "type": "string", + }, "Text": { "additionalProperties": false, "properties": { @@ -3410,6 +3438,65 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell "$ref": "#/definitions/TableCell", "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { + "BLOCKS": { + "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "enum": [ + "document", + "paragraph", + "heading-1", + "heading-2", + "heading-3", + "heading-4", + "heading-5", + "heading-6", + "ordered-list", + "unordered-list", + "list-item", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "embedded-resource-block", + "table", + "table-row", + "table-cell", + "table-header-cell", + ], + "type": "string", + }, + "Block": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "anyOf": [ + { + "$ref": "#/definitions/Block", + }, + { + "$ref": "#/definitions/Inline", + }, + { + "$ref": "#/definitions/Text", + }, + ], + }, + "type": "array", + }, + "data": { + "$ref": "#/definitions/NodeData", + }, + "nodeType": { + "$ref": "#/definitions/BLOCKS", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, "INLINES": { "description": "Map of all Contentful inline types. Inline contain inline or text nodes.", "enum": [ @@ -3468,29 +3555,31 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell "additionalProperties": true, "type": "object", }, - "Paragraph": { + "TableCell": { "additionalProperties": false, "properties": { "content": { "items": { - "anyOf": [ - { - "$ref": "#/definitions/Inline", - }, - { - "$ref": "#/definitions/Text", - }, - ], + "$ref": "#/definitions/TableCellBlock", }, + "minItems": 1, "type": "array", }, "data": { - "properties": {}, + "additionalProperties": false, + "properties": { + "colspan": { + "type": "number", + }, + "rowspan": { + "type": "number", + }, + }, "type": "object", }, "nodeType": { "enum": [ - "paragraph", + "table-cell", ], "type": "string", }, @@ -3502,34 +3591,30 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell ], "type": "object", }, - "TableCell": { + "TableCellBlock": { "additionalProperties": false, "properties": { "content": { "items": { - "$ref": "#/definitions/Paragraph", + "anyOf": [ + { + "$ref": "#/definitions/Block", + }, + { + "$ref": "#/definitions/Inline", + }, + { + "$ref": "#/definitions/Text", + }, + ], }, - "minItems": 1, "type": "array", }, "data": { - "additionalProperties": false, - "properties": { - "colspan": { - "type": "number", - }, - "rowspan": { - "type": "number", - }, - }, - "type": "object", + "$ref": "#/definitions/NodeData", }, "nodeType": { - "enum": [ - "table-cell", - "table-header-cell", - ], - "type": "string", + "$ref": "#/definitions/TableCellEnum", }, }, "required": [ @@ -3539,6 +3624,25 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell ], "type": "object", }, + "TableCellEnum": { + "enum": [ + "blockquote", + "embedded-asset-block", + "embedded-entry-block", + "embedded-resource-block", + "heading-1", + "heading-2", + "heading-3", + "heading-4", + "heading-5", + "heading-6", + "hr", + "ordered-list", + "paragraph", + "unordered-list", + ], + "type": "string", + }, "Text": { "additionalProperties": false, "properties": { @@ -3578,6 +3682,65 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-head "$ref": "#/definitions/TableHeaderCell", "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { + "BLOCKS": { + "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "enum": [ + "document", + "paragraph", + "heading-1", + "heading-2", + "heading-3", + "heading-4", + "heading-5", + "heading-6", + "ordered-list", + "unordered-list", + "list-item", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "embedded-resource-block", + "table", + "table-row", + "table-cell", + "table-header-cell", + ], + "type": "string", + }, + "Block": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "anyOf": [ + { + "$ref": "#/definitions/Block", + }, + { + "$ref": "#/definitions/Inline", + }, + { + "$ref": "#/definitions/Text", + }, + ], + }, + "type": "array", + }, + "data": { + "$ref": "#/definitions/NodeData", + }, + "nodeType": { + "$ref": "#/definitions/BLOCKS", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, "INLINES": { "description": "Map of all Contentful inline types. Inline contain inline or text nodes.", "enum": [ @@ -3636,29 +3799,31 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-head "additionalProperties": true, "type": "object", }, - "Paragraph": { + "TableHeaderCell": { "additionalProperties": false, "properties": { "content": { "items": { - "anyOf": [ - { - "$ref": "#/definitions/Inline", - }, - { - "$ref": "#/definitions/Text", - }, - ], + "$ref": "#/definitions/TableHeaderCellBlock", }, + "minItems": 1, "type": "array", }, "data": { - "properties": {}, + "additionalProperties": false, + "properties": { + "colspan": { + "type": "number", + }, + "rowspan": { + "type": "number", + }, + }, "type": "object", }, "nodeType": { "enum": [ - "paragraph", + "table-header-cell", ], "type": "string", }, @@ -3670,31 +3835,31 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-head ], "type": "object", }, - "TableHeaderCell": { + "TableHeaderCellBlock": { "additionalProperties": false, "properties": { "content": { "items": { - "$ref": "#/definitions/Paragraph", + "anyOf": [ + { + "$ref": "#/definitions/Block", + }, + { + "$ref": "#/definitions/Inline", + }, + { + "$ref": "#/definitions/Text", + }, + ], }, - "minItems": 1, "type": "array", }, "data": { - "additionalProperties": false, - "properties": { - "colspan": { - "type": "number", - }, - "rowspan": { - "type": "number", - }, - }, - "type": "object", + "$ref": "#/definitions/NodeData", }, "nodeType": { "enum": [ - "table-header-cell", + "paragraph", ], "type": "string", }, @@ -3745,24 +3910,41 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "$ref": "#/definitions/TableRow", "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { - "INLINES": { - "description": "Map of all Contentful inline types. Inline contain inline or text nodes.", + "BLOCKS": { + "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", "enum": [ - "asset-hyperlink", - "embedded-entry-inline", - "embedded-resource-inline", - "entry-hyperlink", - "hyperlink", - "resource-hyperlink", + "document", + "paragraph", + "heading-1", + "heading-2", + "heading-3", + "heading-4", + "heading-5", + "heading-6", + "ordered-list", + "unordered-list", + "list-item", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "embedded-resource-block", + "table", + "table-row", + "table-cell", + "table-header-cell", ], "type": "string", }, - "Inline": { + "Block": { "additionalProperties": false, "properties": { "content": { "items": { "anyOf": [ + { + "$ref": "#/definitions/Block", + }, { "$ref": "#/definitions/Inline", }, @@ -3777,7 +3959,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "$ref": "#/definitions/NodeData", }, "nodeType": { - "$ref": "#/definitions/INLINES", + "$ref": "#/definitions/BLOCKS", }, }, "required": [ @@ -3787,23 +3969,19 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row ], "type": "object", }, - "Mark": { - "additionalProperties": false, - "properties": { - "type": { - "type": "string", - }, - }, - "required": [ - "type", + "INLINES": { + "description": "Map of all Contentful inline types. Inline contain inline or text nodes.", + "enum": [ + "asset-hyperlink", + "embedded-entry-inline", + "embedded-resource-inline", + "entry-hyperlink", + "hyperlink", + "resource-hyperlink", ], - "type": "object", - }, - "NodeData": { - "additionalProperties": true, - "type": "object", + "type": "string", }, - "Paragraph": { + "Inline": { "additionalProperties": false, "properties": { "content": { @@ -3820,14 +3998,10 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "type": "array", }, "data": { - "properties": {}, - "type": "object", + "$ref": "#/definitions/NodeData", }, "nodeType": { - "enum": [ - "paragraph", - ], - "type": "string", + "$ref": "#/definitions/INLINES", }, }, "required": [ @@ -3837,32 +4011,39 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row ], "type": "object", }, - "TableCell": { + "Mark": { + "additionalProperties": false, + "properties": { + "type": { + "type": "string", + }, + }, + "required": [ + "type", + ], + "type": "object", + }, + "NodeData": { + "additionalProperties": true, + "type": "object", + }, + "TableRow": { "additionalProperties": false, "properties": { "content": { "items": { - "$ref": "#/definitions/Paragraph", + "$ref": "#/definitions/TableRowBlock", }, "minItems": 1, "type": "array", }, "data": { - "additionalProperties": false, - "properties": { - "colspan": { - "type": "number", - }, - "rowspan": { - "type": "number", - }, - }, + "properties": {}, "type": "object", }, "nodeType": { "enum": [ - "table-cell", - "table-header-cell", + "table-row", ], "type": "string", }, @@ -3874,25 +4055,30 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row ], "type": "object", }, - "TableRow": { + "TableRowBlock": { "additionalProperties": false, "properties": { "content": { "items": { - "$ref": "#/definitions/TableCell", + "anyOf": [ + { + "$ref": "#/definitions/Block", + }, + { + "$ref": "#/definitions/Inline", + }, + { + "$ref": "#/definitions/Text", + }, + ], }, - "minItems": 1, "type": "array", }, "data": { - "properties": {}, - "type": "object", + "$ref": "#/definitions/NodeData", }, "nodeType": { - "enum": [ - "table-row", - ], - "type": "string", + "$ref": "#/definitions/TableRowBlockEnum", }, }, "required": [ @@ -3902,6 +4088,13 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row ], "type": "object", }, + "TableRowBlockEnum": { + "enum": [ + "table-cell", + "table-header-cell", + ], + "type": "string", + }, "Text": { "additionalProperties": false, "properties": { diff --git a/packages/rich-text-types/src/schemas/generated/table-cell.json b/packages/rich-text-types/src/schemas/generated/table-cell.json index c58070e5..1ae72432 100644 --- a/packages/rich-text-types/src/schemas/generated/table-cell.json +++ b/packages/rich-text-types/src/schemas/generated/table-cell.json @@ -5,11 +5,10 @@ "type": "object", "properties": { "nodeType": { + "type": "string", "enum": [ - "table-cell", - "table-header-cell" - ], - "type": "string" + "table-cell" + ] }, "data": { "type": "object", @@ -27,7 +26,7 @@ "minItems": 1, "type": "array", "items": { - "$ref": "#/definitions/Paragraph" + "$ref": "#/definitions/TableCellBlock" } } }, @@ -38,23 +37,71 @@ "nodeType" ] }, - "Paragraph": { + "TableCellBlock": { "type": "object", "properties": { "nodeType": { - "type": "string", - "enum": [ - "paragraph" - ] + "$ref": "#/definitions/TableCellEnum" + }, + "content": { + "type": "array", + "items": { + "anyOf": [ + { + "$ref": "#/definitions/Block" + }, + { + "$ref": "#/definitions/Inline" + }, + { + "$ref": "#/definitions/Text" + } + ] + } }, "data": { - "type": "object", - "properties": {} + "$ref": "#/definitions/NodeData" + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] + }, + "TableCellEnum": { + "enum": [ + "blockquote", + "embedded-asset-block", + "embedded-entry-block", + "embedded-resource-block", + "heading-1", + "heading-2", + "heading-3", + "heading-4", + "heading-5", + "heading-6", + "hr", + "ordered-list", + "paragraph", + "unordered-list" + ], + "type": "string" + }, + "Block": { + "type": "object", + "properties": { + "nodeType": { + "$ref": "#/definitions/BLOCKS" }, "content": { "type": "array", "items": { "anyOf": [ + { + "$ref": "#/definitions/Block" + }, { "$ref": "#/definitions/Inline" }, @@ -63,6 +110,9 @@ } ] } + }, + "data": { + "$ref": "#/definitions/NodeData" } }, "additionalProperties": false, @@ -72,6 +122,32 @@ "nodeType" ] }, + "BLOCKS": { + "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "type": "string", + "enum": [ + "document", + "paragraph", + "heading-1", + "heading-2", + "heading-3", + "heading-4", + "heading-5", + "heading-6", + "ordered-list", + "unordered-list", + "list-item", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "embedded-resource-block", + "table", + "table-row", + "table-cell", + "table-header-cell" + ] + }, "Inline": { "type": "object", "properties": { diff --git a/packages/rich-text-types/src/schemas/generated/table-header-cell.json b/packages/rich-text-types/src/schemas/generated/table-header-cell.json index 8151797a..3b617ced 100644 --- a/packages/rich-text-types/src/schemas/generated/table-header-cell.json +++ b/packages/rich-text-types/src/schemas/generated/table-header-cell.json @@ -26,7 +26,7 @@ "minItems": 1, "type": "array", "items": { - "$ref": "#/definitions/Paragraph" + "$ref": "#/definitions/TableHeaderCellBlock" } } }, @@ -37,7 +37,7 @@ "nodeType" ] }, - "Paragraph": { + "TableHeaderCellBlock": { "type": "object", "properties": { "nodeType": { @@ -46,14 +46,46 @@ "paragraph" ] }, + "content": { + "type": "array", + "items": { + "anyOf": [ + { + "$ref": "#/definitions/Block" + }, + { + "$ref": "#/definitions/Inline" + }, + { + "$ref": "#/definitions/Text" + } + ] + } + }, "data": { - "type": "object", - "properties": {} + "$ref": "#/definitions/NodeData" + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] + }, + "Block": { + "type": "object", + "properties": { + "nodeType": { + "$ref": "#/definitions/BLOCKS" }, "content": { "type": "array", "items": { "anyOf": [ + { + "$ref": "#/definitions/Block" + }, { "$ref": "#/definitions/Inline" }, @@ -62,6 +94,9 @@ } ] } + }, + "data": { + "$ref": "#/definitions/NodeData" } }, "additionalProperties": false, @@ -71,6 +106,32 @@ "nodeType" ] }, + "BLOCKS": { + "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "type": "string", + "enum": [ + "document", + "paragraph", + "heading-1", + "heading-2", + "heading-3", + "heading-4", + "heading-5", + "heading-6", + "ordered-list", + "unordered-list", + "list-item", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "embedded-resource-block", + "table", + "table-row", + "table-cell", + "table-header-cell" + ] + }, "Inline": { "type": "object", "properties": { diff --git a/packages/rich-text-types/src/schemas/generated/table-row.json b/packages/rich-text-types/src/schemas/generated/table-row.json index 98f27854..302b5440 100644 --- a/packages/rich-text-types/src/schemas/generated/table-row.json +++ b/packages/rich-text-types/src/schemas/generated/table-row.json @@ -18,7 +18,7 @@ "minItems": 1, "type": "array", "items": { - "$ref": "#/definitions/TableCell" + "$ref": "#/definitions/TableRowBlock" } } }, @@ -29,34 +29,30 @@ "nodeType" ] }, - "TableCell": { + "TableRowBlock": { "type": "object", "properties": { "nodeType": { - "enum": [ - "table-cell", - "table-header-cell" - ], - "type": "string" - }, - "data": { - "type": "object", - "properties": { - "colspan": { - "type": "number" - }, - "rowspan": { - "type": "number" - } - }, - "additionalProperties": false + "$ref": "#/definitions/TableRowBlockEnum" }, "content": { - "minItems": 1, "type": "array", "items": { - "$ref": "#/definitions/Paragraph" + "anyOf": [ + { + "$ref": "#/definitions/Block" + }, + { + "$ref": "#/definitions/Inline" + }, + { + "$ref": "#/definitions/Text" + } + ] } + }, + "data": { + "$ref": "#/definitions/NodeData" } }, "additionalProperties": false, @@ -66,23 +62,26 @@ "nodeType" ] }, - "Paragraph": { + "TableRowBlockEnum": { + "enum": [ + "table-cell", + "table-header-cell" + ], + "type": "string" + }, + "Block": { "type": "object", "properties": { "nodeType": { - "type": "string", - "enum": [ - "paragraph" - ] - }, - "data": { - "type": "object", - "properties": {} + "$ref": "#/definitions/BLOCKS" }, "content": { "type": "array", "items": { "anyOf": [ + { + "$ref": "#/definitions/Block" + }, { "$ref": "#/definitions/Inline" }, @@ -91,6 +90,9 @@ } ] } + }, + "data": { + "$ref": "#/definitions/NodeData" } }, "additionalProperties": false, @@ -100,6 +102,32 @@ "nodeType" ] }, + "BLOCKS": { + "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "type": "string", + "enum": [ + "document", + "paragraph", + "heading-1", + "heading-2", + "heading-3", + "heading-4", + "heading-5", + "heading-6", + "ordered-list", + "unordered-list", + "list-item", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "embedded-resource-block", + "table", + "table-row", + "table-cell", + "table-header-cell" + ] + }, "Inline": { "type": "object", "properties": { diff --git a/packages/rich-text-types/src/schemas/generated/table.json b/packages/rich-text-types/src/schemas/generated/table.json index 9fa8def8..b8ea642a 100644 --- a/packages/rich-text-types/src/schemas/generated/table.json +++ b/packages/rich-text-types/src/schemas/generated/table.json @@ -46,7 +46,7 @@ "minItems": 1, "type": "array", "items": { - "$ref": "#/definitions/TableCell" + "$ref": "#/definitions/TableRowBlock" } } }, @@ -57,34 +57,30 @@ "nodeType" ] }, - "TableCell": { + "TableRowBlock": { "type": "object", "properties": { "nodeType": { - "enum": [ - "table-cell", - "table-header-cell" - ], - "type": "string" - }, - "data": { - "type": "object", - "properties": { - "colspan": { - "type": "number" - }, - "rowspan": { - "type": "number" - } - }, - "additionalProperties": false + "$ref": "#/definitions/TableRowBlockEnum" }, "content": { - "minItems": 1, "type": "array", "items": { - "$ref": "#/definitions/Paragraph" + "anyOf": [ + { + "$ref": "#/definitions/Block" + }, + { + "$ref": "#/definitions/Inline" + }, + { + "$ref": "#/definitions/Text" + } + ] } + }, + "data": { + "$ref": "#/definitions/NodeData" } }, "additionalProperties": false, @@ -94,23 +90,26 @@ "nodeType" ] }, - "Paragraph": { + "TableRowBlockEnum": { + "enum": [ + "table-cell", + "table-header-cell" + ], + "type": "string" + }, + "Block": { "type": "object", "properties": { "nodeType": { - "type": "string", - "enum": [ - "paragraph" - ] - }, - "data": { - "type": "object", - "properties": {} + "$ref": "#/definitions/BLOCKS" }, "content": { "type": "array", "items": { "anyOf": [ + { + "$ref": "#/definitions/Block" + }, { "$ref": "#/definitions/Inline" }, @@ -119,6 +118,9 @@ } ] } + }, + "data": { + "$ref": "#/definitions/NodeData" } }, "additionalProperties": false, @@ -128,6 +130,32 @@ "nodeType" ] }, + "BLOCKS": { + "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "type": "string", + "enum": [ + "document", + "paragraph", + "heading-1", + "heading-2", + "heading-3", + "heading-4", + "heading-5", + "heading-6", + "ordered-list", + "unordered-list", + "list-item", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "embedded-resource-block", + "table", + "table-row", + "table-cell", + "table-header-cell" + ] + }, "Inline": { "type": "object", "properties": { diff --git a/packages/rich-text-types/src/types.ts b/packages/rich-text-types/src/types.ts index fc9c10cf..db6d6b07 100644 --- a/packages/rich-text-types/src/types.ts +++ b/packages/rich-text-types/src/types.ts @@ -1,6 +1,12 @@ import { BLOCKS } from './blocks'; import { INLINES } from './inlines'; -import { ListItemBlockEnum, TopLevelBlockEnum } from './schemaConstraints'; +import { + ListItemBlockEnum, + TableCellEnum, + TableHeaderCellEnum, + TableRowBlockEnum, + TopLevelBlockEnum, +} from './schemaConstraints'; /** * @additionalProperties true @@ -44,3 +50,15 @@ export interface Mark { export interface ListItemBlock extends Block { nodeType: ListItemBlockEnum; } + +export interface TableRowBlock extends Block { + nodeType: TableRowBlockEnum; +} + +export interface TableCellBlock extends Block { + nodeType: TableCellEnum; +} + +export interface TableHeaderCellBlock extends Block { + nodeType: TableHeaderCellEnum; +}