From c6f23801c326d8b688b9bc669aa1dfe1ff12919a Mon Sep 17 00:00:00 2001 From: Kudakwashe Mupeni Date: Wed, 17 Jul 2024 13:10:06 +0200 Subject: [PATCH 01/13] feat: update schema for rich text types --- packages/rich-text-types/src/nodeTypes.ts | 2 +- .../rich-text-types/src/schemas/generated/table-cell.json | 4 +++- packages/rich-text-types/src/schemas/generated/table-row.json | 4 +++- packages/rich-text-types/src/schemas/generated/table.json | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/rich-text-types/src/nodeTypes.ts b/packages/rich-text-types/src/nodeTypes.ts index 8b7e01d6..d4428525 100644 --- a/packages/rich-text-types/src/nodeTypes.ts +++ b/packages/rich-text-types/src/nodeTypes.ts @@ -198,7 +198,7 @@ export interface ResourceHyperlink extends Inline { } export interface TableCell extends Block { - nodeType: BLOCKS.TABLE_HEADER_CELL | BLOCKS.TABLE_CELL; + nodeType: BLOCKS.TABLE_HEADER_CELL | BLOCKS.TABLE_CELL | BLOCKS.OL_LIST | BLOCKS.UL_LIST; data: { colspan?: number; rowspan?: number; 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..b3a09576 100644 --- a/packages/rich-text-types/src/schemas/generated/table-cell.json +++ b/packages/rich-text-types/src/schemas/generated/table-cell.json @@ -6,8 +6,10 @@ "properties": { "nodeType": { "enum": [ + "ordered-list", "table-cell", - "table-header-cell" + "table-header-cell", + "unordered-list" ], "type": "string" }, 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..7234f03f 100644 --- a/packages/rich-text-types/src/schemas/generated/table-row.json +++ b/packages/rich-text-types/src/schemas/generated/table-row.json @@ -34,8 +34,10 @@ "properties": { "nodeType": { "enum": [ + "ordered-list", "table-cell", - "table-header-cell" + "table-header-cell", + "unordered-list" ], "type": "string" }, diff --git a/packages/rich-text-types/src/schemas/generated/table.json b/packages/rich-text-types/src/schemas/generated/table.json index 9fa8def8..cef0e428 100644 --- a/packages/rich-text-types/src/schemas/generated/table.json +++ b/packages/rich-text-types/src/schemas/generated/table.json @@ -62,8 +62,10 @@ "properties": { "nodeType": { "enum": [ + "ordered-list", "table-cell", - "table-header-cell" + "table-header-cell", + "unordered-list" ], "type": "string" }, From 6617c214fb8d92d3a37ab0a83bc39c615c40e58b Mon Sep 17 00:00:00 2001 From: Kudakwashe Mupeni Date: Wed, 17 Jul 2024 13:19:04 +0200 Subject: [PATCH 02/13] chore: update snapshots --- .../src/schemas/__test__/__snapshots__/schemas.test.ts.snap | 6 ++++++ 1 file changed, 6 insertions(+) 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..a4251eac 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 @@ -3330,8 +3330,10 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] }, "nodeType": { "enum": [ + "ordered-list", "table-cell", "table-header-cell", + "unordered-list", ], "type": "string", }, @@ -3526,8 +3528,10 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell }, "nodeType": { "enum": [ + "ordered-list", "table-cell", "table-header-cell", + "unordered-list", ], "type": "string", }, @@ -3861,8 +3865,10 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row }, "nodeType": { "enum": [ + "ordered-list", "table-cell", "table-header-cell", + "unordered-list", ], "type": "string", }, From 36cced0a539b3042217eeb59e14c55a1cc1fd3d2 Mon Sep 17 00:00:00 2001 From: Kudakwashe Mupeni Date: Wed, 17 Jul 2024 13:28:24 +0200 Subject: [PATCH 03/13] chore: update schema --- packages/rich-text-types/src/nodeTypes.ts | 9 +- .../src/schemas/generated/table-cell.json | 225 +++++++++++++++++- .../schemas/generated/table-header-cell.json | 14 +- .../src/schemas/generated/table-row.json | 225 +++++++++++++++++- .../src/schemas/generated/table.json | 225 +++++++++++++++++- 5 files changed, 659 insertions(+), 39 deletions(-) diff --git a/packages/rich-text-types/src/nodeTypes.ts b/packages/rich-text-types/src/nodeTypes.ts index d4428525..a3279ef0 100644 --- a/packages/rich-text-types/src/nodeTypes.ts +++ b/packages/rich-text-types/src/nodeTypes.ts @@ -198,7 +198,7 @@ export interface ResourceHyperlink extends Inline { } export interface TableCell extends Block { - nodeType: BLOCKS.TABLE_HEADER_CELL | BLOCKS.TABLE_CELL | BLOCKS.OL_LIST | BLOCKS.UL_LIST; + nodeType: BLOCKS.TABLE_HEADER_CELL; data: { colspan?: number; rowspan?: number; @@ -207,11 +207,16 @@ export interface TableCell extends Block { /** * @minItems 1 */ - content: Paragraph[]; + content: Paragraph[] | OrderedList[] | UnorderedList[]; } export interface TableHeaderCell extends TableCell { nodeType: BLOCKS.TABLE_HEADER_CELL; + + /** + * @minItems 1 + */ + content: Paragraph[]; } // An abstract table row can have both table cell types 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 b3a09576..42d55fe8 100644 --- a/packages/rich-text-types/src/schemas/generated/table-cell.json +++ b/packages/rich-text-types/src/schemas/generated/table-cell.json @@ -5,13 +5,10 @@ "type": "object", "properties": { "nodeType": { + "type": "string", "enum": [ - "ordered-list", - "table-cell", - "table-header-cell", - "unordered-list" - ], - "type": "string" + "table-header-cell" + ] }, "data": { "type": "object", @@ -27,10 +24,26 @@ }, "content": { "minItems": 1, - "type": "array", - "items": { - "$ref": "#/definitions/Paragraph" - } + "anyOf": [ + { + "type": "array", + "items": { + "$ref": "#/definitions/Paragraph" + } + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/OrderedList" + } + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/UnorderedList" + } + } + ] } }, "additionalProperties": false, @@ -161,6 +174,198 @@ "NodeData": { "additionalProperties": true, "type": "object" + }, + "OrderedList": { + "type": "object", + "properties": { + "nodeType": { + "type": "string", + "enum": [ + "ordered-list" + ] + }, + "data": { + "type": "object", + "properties": {} + }, + "content": { + "type": "array", + "items": { + "$ref": "#/definitions/ListItem" + } + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] + }, + "ListItem": { + "type": "object", + "properties": { + "nodeType": { + "type": "string", + "enum": [ + "list-item" + ] + }, + "data": { + "type": "object", + "properties": {} + }, + "content": { + "type": "array", + "items": { + "$ref": "#/definitions/ListItemBlock" + } + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] + }, + "ListItemBlock": { + "type": "object", + "properties": { + "nodeType": { + "$ref": "#/definitions/ListItemBlockEnum" + }, + "content": { + "type": "array", + "items": { + "anyOf": [ + { + "$ref": "#/definitions/Block" + }, + { + "$ref": "#/definitions/Inline" + }, + { + "$ref": "#/definitions/Text" + } + ] + } + }, + "data": { + "$ref": "#/definitions/NodeData" + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] + }, + "ListItemBlockEnum": { + "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" + }, + { + "$ref": "#/definitions/Text" + } + ] + } + }, + "data": { + "$ref": "#/definitions/NodeData" + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "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" + ] + }, + "UnorderedList": { + "type": "object", + "properties": { + "nodeType": { + "type": "string", + "enum": [ + "unordered-list" + ] + }, + "data": { + "type": "object", + "properties": {} + }, + "content": { + "type": "array", + "items": { + "$ref": "#/definitions/ListItem" + } + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] } }, "$schema": "http://json-schema.org/draft-07/schema#" 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..cff9b742 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 @@ -10,6 +10,13 @@ "table-header-cell" ] }, + "content": { + "minItems": 1, + "type": "array", + "items": { + "$ref": "#/definitions/Paragraph" + } + }, "data": { "type": "object", "properties": { @@ -21,13 +28,6 @@ } }, "additionalProperties": false - }, - "content": { - "minItems": 1, - "type": "array", - "items": { - "$ref": "#/definitions/Paragraph" - } } }, "additionalProperties": false, 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 7234f03f..45398175 100644 --- a/packages/rich-text-types/src/schemas/generated/table-row.json +++ b/packages/rich-text-types/src/schemas/generated/table-row.json @@ -33,13 +33,10 @@ "type": "object", "properties": { "nodeType": { + "type": "string", "enum": [ - "ordered-list", - "table-cell", - "table-header-cell", - "unordered-list" - ], - "type": "string" + "table-header-cell" + ] }, "data": { "type": "object", @@ -55,10 +52,26 @@ }, "content": { "minItems": 1, - "type": "array", - "items": { - "$ref": "#/definitions/Paragraph" - } + "anyOf": [ + { + "type": "array", + "items": { + "$ref": "#/definitions/Paragraph" + } + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/OrderedList" + } + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/UnorderedList" + } + } + ] } }, "additionalProperties": false, @@ -189,6 +202,198 @@ "NodeData": { "additionalProperties": true, "type": "object" + }, + "OrderedList": { + "type": "object", + "properties": { + "nodeType": { + "type": "string", + "enum": [ + "ordered-list" + ] + }, + "data": { + "type": "object", + "properties": {} + }, + "content": { + "type": "array", + "items": { + "$ref": "#/definitions/ListItem" + } + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] + }, + "ListItem": { + "type": "object", + "properties": { + "nodeType": { + "type": "string", + "enum": [ + "list-item" + ] + }, + "data": { + "type": "object", + "properties": {} + }, + "content": { + "type": "array", + "items": { + "$ref": "#/definitions/ListItemBlock" + } + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] + }, + "ListItemBlock": { + "type": "object", + "properties": { + "nodeType": { + "$ref": "#/definitions/ListItemBlockEnum" + }, + "content": { + "type": "array", + "items": { + "anyOf": [ + { + "$ref": "#/definitions/Block" + }, + { + "$ref": "#/definitions/Inline" + }, + { + "$ref": "#/definitions/Text" + } + ] + } + }, + "data": { + "$ref": "#/definitions/NodeData" + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] + }, + "ListItemBlockEnum": { + "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" + }, + { + "$ref": "#/definitions/Text" + } + ] + } + }, + "data": { + "$ref": "#/definitions/NodeData" + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "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" + ] + }, + "UnorderedList": { + "type": "object", + "properties": { + "nodeType": { + "type": "string", + "enum": [ + "unordered-list" + ] + }, + "data": { + "type": "object", + "properties": {} + }, + "content": { + "type": "array", + "items": { + "$ref": "#/definitions/ListItem" + } + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] } }, "$schema": "http://json-schema.org/draft-07/schema#" diff --git a/packages/rich-text-types/src/schemas/generated/table.json b/packages/rich-text-types/src/schemas/generated/table.json index cef0e428..c243e18e 100644 --- a/packages/rich-text-types/src/schemas/generated/table.json +++ b/packages/rich-text-types/src/schemas/generated/table.json @@ -61,13 +61,10 @@ "type": "object", "properties": { "nodeType": { + "type": "string", "enum": [ - "ordered-list", - "table-cell", - "table-header-cell", - "unordered-list" - ], - "type": "string" + "table-header-cell" + ] }, "data": { "type": "object", @@ -83,10 +80,26 @@ }, "content": { "minItems": 1, - "type": "array", - "items": { - "$ref": "#/definitions/Paragraph" - } + "anyOf": [ + { + "type": "array", + "items": { + "$ref": "#/definitions/Paragraph" + } + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/OrderedList" + } + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/UnorderedList" + } + } + ] } }, "additionalProperties": false, @@ -217,6 +230,198 @@ "NodeData": { "additionalProperties": true, "type": "object" + }, + "OrderedList": { + "type": "object", + "properties": { + "nodeType": { + "type": "string", + "enum": [ + "ordered-list" + ] + }, + "data": { + "type": "object", + "properties": {} + }, + "content": { + "type": "array", + "items": { + "$ref": "#/definitions/ListItem" + } + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] + }, + "ListItem": { + "type": "object", + "properties": { + "nodeType": { + "type": "string", + "enum": [ + "list-item" + ] + }, + "data": { + "type": "object", + "properties": {} + }, + "content": { + "type": "array", + "items": { + "$ref": "#/definitions/ListItemBlock" + } + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] + }, + "ListItemBlock": { + "type": "object", + "properties": { + "nodeType": { + "$ref": "#/definitions/ListItemBlockEnum" + }, + "content": { + "type": "array", + "items": { + "anyOf": [ + { + "$ref": "#/definitions/Block" + }, + { + "$ref": "#/definitions/Inline" + }, + { + "$ref": "#/definitions/Text" + } + ] + } + }, + "data": { + "$ref": "#/definitions/NodeData" + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] + }, + "ListItemBlockEnum": { + "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" + }, + { + "$ref": "#/definitions/Text" + } + ] + } + }, + "data": { + "$ref": "#/definitions/NodeData" + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "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" + ] + }, + "UnorderedList": { + "type": "object", + "properties": { + "nodeType": { + "type": "string", + "enum": [ + "unordered-list" + ] + }, + "data": { + "type": "object", + "properties": {} + }, + "content": { + "type": "array", + "items": { + "$ref": "#/definitions/ListItem" + } + } + }, + "additionalProperties": false, + "required": [ + "content", + "data", + "nodeType" + ] } }, "$schema": "http://json-schema.org/draft-07/schema#" From a366d2c82be1789c166bee1fec6fea51a6a0f72f Mon Sep 17 00:00:00 2001 From: Kudakwashe Mupeni Date: Wed, 17 Jul 2024 13:30:59 +0200 Subject: [PATCH 04/13] chore: update snapshots --- .../__snapshots__/schemas.test.ts.snap | 667 +++++++++++++++++- 1 file changed, 641 insertions(+), 26 deletions(-) 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 a4251eac..f4499381 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,6 +3186,65 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "$ref": "#/definitions/Table", "$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": [ @@ -3228,6 +3287,85 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, + "ListItem": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "$ref": "#/definitions/ListItemBlock", + }, + "type": "array", + }, + "data": { + "properties": {}, + "type": "object", + }, + "nodeType": { + "enum": [ + "list-item", + ], + "type": "string", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, + "ListItemBlock": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "anyOf": [ + { + "$ref": "#/definitions/Block", + }, + { + "$ref": "#/definitions/Inline", + }, + { + "$ref": "#/definitions/Text", + }, + ], + }, + "type": "array", + }, + "data": { + "$ref": "#/definitions/NodeData", + }, + "nodeType": { + "$ref": "#/definitions/ListItemBlockEnum", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, + "ListItemBlockEnum": { + "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", + }, "Mark": { "additionalProperties": false, "properties": { @@ -3244,6 +3382,33 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "additionalProperties": true, "type": "object", }, + "OrderedList": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "$ref": "#/definitions/ListItem", + }, + "type": "array", + }, + "data": { + "properties": {}, + "type": "object", + }, + "nodeType": { + "enum": [ + "ordered-list", + ], + "type": "string", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, "Paragraph": { "additionalProperties": false, "properties": { @@ -3310,11 +3475,27 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "additionalProperties": false, "properties": { "content": { - "items": { - "$ref": "#/definitions/Paragraph", - }, + "anyOf": [ + { + "items": { + "$ref": "#/definitions/Paragraph", + }, + "type": "array", + }, + { + "items": { + "$ref": "#/definitions/OrderedList", + }, + "type": "array", + }, + { + "items": { + "$ref": "#/definitions/UnorderedList", + }, + "type": "array", + }, + ], "minItems": 1, - "type": "array", }, "data": { "additionalProperties": false, @@ -3330,10 +3511,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] }, "nodeType": { "enum": [ - "ordered-list", - "table-cell", "table-header-cell", - "unordered-list", ], "type": "string", }, @@ -3403,6 +3581,33 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, + "UnorderedList": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "$ref": "#/definitions/ListItem", + }, + "type": "array", + }, + "data": { + "properties": {}, + "type": "object", + }, + "nodeType": { + "enum": [ + "unordered-list", + ], + "type": "string", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, }, } `; @@ -3412,6 +3617,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": [ @@ -3454,6 +3718,85 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell ], "type": "object", }, + "ListItem": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "$ref": "#/definitions/ListItemBlock", + }, + "type": "array", + }, + "data": { + "properties": {}, + "type": "object", + }, + "nodeType": { + "enum": [ + "list-item", + ], + "type": "string", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, + "ListItemBlock": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "anyOf": [ + { + "$ref": "#/definitions/Block", + }, + { + "$ref": "#/definitions/Inline", + }, + { + "$ref": "#/definitions/Text", + }, + ], + }, + "type": "array", + }, + "data": { + "$ref": "#/definitions/NodeData", + }, + "nodeType": { + "$ref": "#/definitions/ListItemBlockEnum", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, + "ListItemBlockEnum": { + "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", + }, "Mark": { "additionalProperties": false, "properties": { @@ -3462,14 +3805,41 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell }, }, "required": [ - "type", + "type", + ], + "type": "object", + }, + "NodeData": { + "additionalProperties": true, + "type": "object", + }, + "OrderedList": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "$ref": "#/definitions/ListItem", + }, + "type": "array", + }, + "data": { + "properties": {}, + "type": "object", + }, + "nodeType": { + "enum": [ + "ordered-list", + ], + "type": "string", + }, + }, + "required": [ + "content", + "data", + "nodeType", ], "type": "object", }, - "NodeData": { - "additionalProperties": true, - "type": "object", - }, "Paragraph": { "additionalProperties": false, "properties": { @@ -3508,11 +3878,27 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell "additionalProperties": false, "properties": { "content": { - "items": { - "$ref": "#/definitions/Paragraph", - }, + "anyOf": [ + { + "items": { + "$ref": "#/definitions/Paragraph", + }, + "type": "array", + }, + { + "items": { + "$ref": "#/definitions/OrderedList", + }, + "type": "array", + }, + { + "items": { + "$ref": "#/definitions/UnorderedList", + }, + "type": "array", + }, + ], "minItems": 1, - "type": "array", }, "data": { "additionalProperties": false, @@ -3528,10 +3914,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell }, "nodeType": { "enum": [ - "ordered-list", - "table-cell", "table-header-cell", - "unordered-list", ], "type": "string", }, @@ -3573,6 +3956,33 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell ], "type": "object", }, + "UnorderedList": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "$ref": "#/definitions/ListItem", + }, + "type": "array", + }, + "data": { + "properties": {}, + "type": "object", + }, + "nodeType": { + "enum": [ + "unordered-list", + ], + "type": "string", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, }, } `; @@ -3749,6 +4159,65 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "$ref": "#/definitions/TableRow", "$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": [ @@ -3791,6 +4260,85 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row ], "type": "object", }, + "ListItem": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "$ref": "#/definitions/ListItemBlock", + }, + "type": "array", + }, + "data": { + "properties": {}, + "type": "object", + }, + "nodeType": { + "enum": [ + "list-item", + ], + "type": "string", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, + "ListItemBlock": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "anyOf": [ + { + "$ref": "#/definitions/Block", + }, + { + "$ref": "#/definitions/Inline", + }, + { + "$ref": "#/definitions/Text", + }, + ], + }, + "type": "array", + }, + "data": { + "$ref": "#/definitions/NodeData", + }, + "nodeType": { + "$ref": "#/definitions/ListItemBlockEnum", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, + "ListItemBlockEnum": { + "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", + }, "Mark": { "additionalProperties": false, "properties": { @@ -3807,6 +4355,33 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "additionalProperties": true, "type": "object", }, + "OrderedList": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "$ref": "#/definitions/ListItem", + }, + "type": "array", + }, + "data": { + "properties": {}, + "type": "object", + }, + "nodeType": { + "enum": [ + "ordered-list", + ], + "type": "string", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, "Paragraph": { "additionalProperties": false, "properties": { @@ -3845,11 +4420,27 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "additionalProperties": false, "properties": { "content": { - "items": { - "$ref": "#/definitions/Paragraph", - }, + "anyOf": [ + { + "items": { + "$ref": "#/definitions/Paragraph", + }, + "type": "array", + }, + { + "items": { + "$ref": "#/definitions/OrderedList", + }, + "type": "array", + }, + { + "items": { + "$ref": "#/definitions/UnorderedList", + }, + "type": "array", + }, + ], "minItems": 1, - "type": "array", }, "data": { "additionalProperties": false, @@ -3865,10 +4456,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row }, "nodeType": { "enum": [ - "ordered-list", - "table-cell", "table-header-cell", - "unordered-list", ], "type": "string", }, @@ -3938,6 +4526,33 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row ], "type": "object", }, + "UnorderedList": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "$ref": "#/definitions/ListItem", + }, + "type": "array", + }, + "data": { + "properties": {}, + "type": "object", + }, + "nodeType": { + "enum": [ + "unordered-list", + ], + "type": "string", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, }, } `; From 73eb5530f2ca163ad786ac48ba343700099decf6 Mon Sep 17 00:00:00 2001 From: Kudakwashe Mupeni Date: Wed, 17 Jul 2024 13:42:10 +0200 Subject: [PATCH 05/13] chore: update table cell nodetype --- packages/rich-text-types/src/nodeTypes.ts | 8 ++++++-- .../__test__/__snapshots__/schemas.test.ts.snap | 6 +++--- .../src/schemas/generated/table-cell.json | 2 +- .../src/schemas/generated/table-header-cell.json | 14 +++++++------- .../src/schemas/generated/table-row.json | 2 +- .../src/schemas/generated/table.json | 2 +- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/rich-text-types/src/nodeTypes.ts b/packages/rich-text-types/src/nodeTypes.ts index a3279ef0..00649a21 100644 --- a/packages/rich-text-types/src/nodeTypes.ts +++ b/packages/rich-text-types/src/nodeTypes.ts @@ -198,7 +198,7 @@ export interface ResourceHyperlink extends Inline { } export interface TableCell extends Block { - nodeType: BLOCKS.TABLE_HEADER_CELL; + nodeType: BLOCKS.TABLE_CELL; data: { colspan?: number; rowspan?: number; @@ -210,8 +210,12 @@ export interface TableCell extends Block { content: Paragraph[] | OrderedList[] | UnorderedList[]; } -export interface TableHeaderCell extends TableCell { +export interface TableHeaderCell extends Block { nodeType: BLOCKS.TABLE_HEADER_CELL; + data: { + colspan?: number; + rowspan?: number; + }; /** * @minItems 1 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 f4499381..e8f4d54e 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 @@ -3511,7 +3511,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] }, "nodeType": { "enum": [ - "table-header-cell", + "table-cell", ], "type": "string", }, @@ -3914,7 +3914,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell }, "nodeType": { "enum": [ - "table-header-cell", + "table-cell", ], "type": "string", }, @@ -4456,7 +4456,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row }, "nodeType": { "enum": [ - "table-header-cell", + "table-cell", ], "type": "string", }, 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 42d55fe8..0225b4db 100644 --- a/packages/rich-text-types/src/schemas/generated/table-cell.json +++ b/packages/rich-text-types/src/schemas/generated/table-cell.json @@ -7,7 +7,7 @@ "nodeType": { "type": "string", "enum": [ - "table-header-cell" + "table-cell" ] }, "data": { 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 cff9b742..8151797a 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 @@ -10,13 +10,6 @@ "table-header-cell" ] }, - "content": { - "minItems": 1, - "type": "array", - "items": { - "$ref": "#/definitions/Paragraph" - } - }, "data": { "type": "object", "properties": { @@ -28,6 +21,13 @@ } }, "additionalProperties": false + }, + "content": { + "minItems": 1, + "type": "array", + "items": { + "$ref": "#/definitions/Paragraph" + } } }, "additionalProperties": false, 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 45398175..ce8fe6e4 100644 --- a/packages/rich-text-types/src/schemas/generated/table-row.json +++ b/packages/rich-text-types/src/schemas/generated/table-row.json @@ -35,7 +35,7 @@ "nodeType": { "type": "string", "enum": [ - "table-header-cell" + "table-cell" ] }, "data": { diff --git a/packages/rich-text-types/src/schemas/generated/table.json b/packages/rich-text-types/src/schemas/generated/table.json index c243e18e..edac574d 100644 --- a/packages/rich-text-types/src/schemas/generated/table.json +++ b/packages/rich-text-types/src/schemas/generated/table.json @@ -63,7 +63,7 @@ "nodeType": { "type": "string", "enum": [ - "table-header-cell" + "table-cell" ] }, "data": { From b3f4bd2cf8afe6ac43d08ae182acdd964e048336 Mon Sep 17 00:00:00 2001 From: Aodhagan Murphy Date: Fri, 19 Jul 2024 10:48:18 +0100 Subject: [PATCH 06/13] feat: adjusting table cell/header schemas [TOL-2249] --- packages/rich-text-types/src/nodeTypes.ts | 10 +- .../__snapshots__/schemas.test.ts.snap | 152 +++++++++++++----- .../src/schemas/generated/table-cell.json | 33 ++-- .../schemas/generated/table-header-cell.json | 14 +- .../src/schemas/generated/table-row.json | 33 ++-- .../src/schemas/generated/table.json | 33 ++-- 6 files changed, 162 insertions(+), 113 deletions(-) diff --git a/packages/rich-text-types/src/nodeTypes.ts b/packages/rich-text-types/src/nodeTypes.ts index 00649a21..33876e47 100644 --- a/packages/rich-text-types/src/nodeTypes.ts +++ b/packages/rich-text-types/src/nodeTypes.ts @@ -198,7 +198,7 @@ export interface ResourceHyperlink extends Inline { } export interface TableCell extends Block { - nodeType: BLOCKS.TABLE_CELL; + nodeType: BLOCKS.TABLE_HEADER_CELL | BLOCKS.TABLE_CELL; data: { colspan?: number; rowspan?: number; @@ -207,15 +207,11 @@ export interface TableCell extends Block { /** * @minItems 1 */ - content: Paragraph[] | OrderedList[] | UnorderedList[]; + content: (Paragraph | OrderedList | UnorderedList)[]; } -export interface TableHeaderCell extends Block { +export interface TableHeaderCell extends TableCell { nodeType: BLOCKS.TABLE_HEADER_CELL; - data: { - colspan?: number; - rowspan?: number; - }; /** * @minItems 1 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 e8f4d54e..4fe1b6e5 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 @@ -3475,27 +3475,57 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "additionalProperties": false, "properties": { "content": { - "anyOf": [ - { - "items": { + "items": { + "anyOf": [ + { "$ref": "#/definitions/Paragraph", }, - "type": "array", - }, - { - "items": { + { "$ref": "#/definitions/OrderedList", }, - "type": "array", - }, - { - "items": { + { "$ref": "#/definitions/UnorderedList", }, - "type": "array", + ], + }, + "minItems": 1, + "type": "array", + }, + "data": { + "additionalProperties": false, + "properties": { + "colspan": { + "type": "number", }, + "rowspan": { + "type": "number", + }, + }, + "type": "object", + }, + "nodeType": { + "enum": [ + "table-cell", ], + "type": "string", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, + "TableHeaderCell": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "$ref": "#/definitions/Paragraph", + }, "minItems": 1, + "type": "array", }, "data": { "additionalProperties": false, @@ -3511,7 +3541,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] }, "nodeType": { "enum": [ - "table-cell", + "table-header-cell", ], "type": "string", }, @@ -3528,7 +3558,14 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "properties": { "content": { "items": { - "$ref": "#/definitions/TableCell", + "anyOf": [ + { + "$ref": "#/definitions/TableCell", + }, + { + "$ref": "#/definitions/TableHeaderCell", + }, + ], }, "minItems": 1, "type": "array", @@ -3878,27 +3915,21 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell "additionalProperties": false, "properties": { "content": { - "anyOf": [ - { - "items": { + "items": { + "anyOf": [ + { "$ref": "#/definitions/Paragraph", }, - "type": "array", - }, - { - "items": { + { "$ref": "#/definitions/OrderedList", }, - "type": "array", - }, - { - "items": { + { "$ref": "#/definitions/UnorderedList", }, - "type": "array", - }, - ], + ], + }, "minItems": 1, + "type": "array", }, "data": { "additionalProperties": false, @@ -4420,27 +4451,57 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "additionalProperties": false, "properties": { "content": { - "anyOf": [ - { - "items": { + "items": { + "anyOf": [ + { "$ref": "#/definitions/Paragraph", }, - "type": "array", - }, - { - "items": { + { "$ref": "#/definitions/OrderedList", }, - "type": "array", - }, - { - "items": { + { "$ref": "#/definitions/UnorderedList", }, - "type": "array", + ], + }, + "minItems": 1, + "type": "array", + }, + "data": { + "additionalProperties": false, + "properties": { + "colspan": { + "type": "number", + }, + "rowspan": { + "type": "number", }, + }, + "type": "object", + }, + "nodeType": { + "enum": [ + "table-cell", ], + "type": "string", + }, + }, + "required": [ + "content", + "data", + "nodeType", + ], + "type": "object", + }, + "TableHeaderCell": { + "additionalProperties": false, + "properties": { + "content": { + "items": { + "$ref": "#/definitions/Paragraph", + }, "minItems": 1, + "type": "array", }, "data": { "additionalProperties": false, @@ -4456,7 +4517,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row }, "nodeType": { "enum": [ - "table-cell", + "table-header-cell", ], "type": "string", }, @@ -4473,7 +4534,14 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "properties": { "content": { "items": { - "$ref": "#/definitions/TableCell", + "anyOf": [ + { + "$ref": "#/definitions/TableCell", + }, + { + "$ref": "#/definitions/TableHeaderCell", + }, + ], }, "minItems": 1, "type": "array", 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 0225b4db..552c75ca 100644 --- a/packages/rich-text-types/src/schemas/generated/table-cell.json +++ b/packages/rich-text-types/src/schemas/generated/table-cell.json @@ -5,10 +5,11 @@ "type": "object", "properties": { "nodeType": { - "type": "string", "enum": [ - "table-cell" - ] + "table-cell", + "table-header-cell" + ], + "type": "string" }, "data": { "type": "object", @@ -24,26 +25,20 @@ }, "content": { "minItems": 1, - "anyOf": [ - { - "type": "array", - "items": { + "type": "array", + "items": { + "anyOf": [ + { "$ref": "#/definitions/Paragraph" - } - }, - { - "type": "array", - "items": { + }, + { "$ref": "#/definitions/OrderedList" - } - }, - { - "type": "array", - "items": { + }, + { "$ref": "#/definitions/UnorderedList" } - } - ] + ] + } } }, "additionalProperties": false, 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..cff9b742 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 @@ -10,6 +10,13 @@ "table-header-cell" ] }, + "content": { + "minItems": 1, + "type": "array", + "items": { + "$ref": "#/definitions/Paragraph" + } + }, "data": { "type": "object", "properties": { @@ -21,13 +28,6 @@ } }, "additionalProperties": false - }, - "content": { - "minItems": 1, - "type": "array", - "items": { - "$ref": "#/definitions/Paragraph" - } } }, "additionalProperties": false, 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 ce8fe6e4..69fe9315 100644 --- a/packages/rich-text-types/src/schemas/generated/table-row.json +++ b/packages/rich-text-types/src/schemas/generated/table-row.json @@ -33,10 +33,11 @@ "type": "object", "properties": { "nodeType": { - "type": "string", "enum": [ - "table-cell" - ] + "table-cell", + "table-header-cell" + ], + "type": "string" }, "data": { "type": "object", @@ -52,26 +53,20 @@ }, "content": { "minItems": 1, - "anyOf": [ - { - "type": "array", - "items": { + "type": "array", + "items": { + "anyOf": [ + { "$ref": "#/definitions/Paragraph" - } - }, - { - "type": "array", - "items": { + }, + { "$ref": "#/definitions/OrderedList" - } - }, - { - "type": "array", - "items": { + }, + { "$ref": "#/definitions/UnorderedList" } - } - ] + ] + } } }, "additionalProperties": false, diff --git a/packages/rich-text-types/src/schemas/generated/table.json b/packages/rich-text-types/src/schemas/generated/table.json index edac574d..c6db1e89 100644 --- a/packages/rich-text-types/src/schemas/generated/table.json +++ b/packages/rich-text-types/src/schemas/generated/table.json @@ -61,10 +61,11 @@ "type": "object", "properties": { "nodeType": { - "type": "string", "enum": [ - "table-cell" - ] + "table-cell", + "table-header-cell" + ], + "type": "string" }, "data": { "type": "object", @@ -80,26 +81,20 @@ }, "content": { "minItems": 1, - "anyOf": [ - { - "type": "array", - "items": { + "type": "array", + "items": { + "anyOf": [ + { "$ref": "#/definitions/Paragraph" - } - }, - { - "type": "array", - "items": { + }, + { "$ref": "#/definitions/OrderedList" - } - }, - { - "type": "array", - "items": { + }, + { "$ref": "#/definitions/UnorderedList" } - } - ] + ] + } } }, "additionalProperties": false, From 0cacfdf97376713da29b65f01b74763acdfc3686 Mon Sep 17 00:00:00 2001 From: Aodhagan Murphy Date: Fri, 19 Jul 2024 11:39:26 +0100 Subject: [PATCH 07/13] feat: adding comment to explain reason for coupling [TOL-2249] --- packages/rich-text-types/src/nodeTypes.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/rich-text-types/src/nodeTypes.ts b/packages/rich-text-types/src/nodeTypes.ts index 33876e47..cba776c3 100644 --- a/packages/rich-text-types/src/nodeTypes.ts +++ b/packages/rich-text-types/src/nodeTypes.ts @@ -210,6 +210,10 @@ export interface TableCell extends Block { content: (Paragraph | OrderedList | UnorderedList)[]; } +// Notice that this is only exported and not reused anywhere else in this file +// this is because this we only want this interface to generate the schema +// if we end up decouping the header cell from the regular cell we +// end up with unwanted side effects when validating the schema in @contentful/validation export interface TableHeaderCell extends TableCell { nodeType: BLOCKS.TABLE_HEADER_CELL; From e4eeae2ee4fefe60003f79159b366df6cf662bc0 Mon Sep 17 00:00:00 2001 From: Aodhagan Murphy Date: Fri, 19 Jul 2024 13:05:16 +0100 Subject: [PATCH 08/13] chore: adjusting table schema [TOL-2249] --- packages/rich-text-types/src/nodeTypes.ts | 6 +- .../src/schemas/generated/table-cell.json | 269 +++++------------- .../src/schemas/generated/table-row.json | 269 +++++------------- .../src/schemas/generated/table.json | 269 +++++------------- 4 files changed, 200 insertions(+), 613 deletions(-) diff --git a/packages/rich-text-types/src/nodeTypes.ts b/packages/rich-text-types/src/nodeTypes.ts index cba776c3..717f1cc3 100644 --- a/packages/rich-text-types/src/nodeTypes.ts +++ b/packages/rich-text-types/src/nodeTypes.ts @@ -197,6 +197,10 @@ export interface ResourceHyperlink extends Inline { content: Text[]; } +interface TableCellContent extends Block { + nodeType: BLOCKS.PARAGRAPH | BLOCKS.UL_LIST | BLOCKS.OL_LIST; +} + export interface TableCell extends Block { nodeType: BLOCKS.TABLE_HEADER_CELL | BLOCKS.TABLE_CELL; data: { @@ -207,7 +211,7 @@ export interface TableCell extends Block { /** * @minItems 1 */ - content: (Paragraph | OrderedList | UnorderedList)[]; + content: TableCellContent[]; } // Notice that this is only exported and not reused anywhere else in this file 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 552c75ca..c2ca68a1 100644 --- a/packages/rich-text-types/src/schemas/generated/table-cell.json +++ b/packages/rich-text-types/src/schemas/generated/table-cell.json @@ -27,17 +27,7 @@ "minItems": 1, "type": "array", "items": { - "anyOf": [ - { - "$ref": "#/definitions/Paragraph" - }, - { - "$ref": "#/definitions/OrderedList" - }, - { - "$ref": "#/definitions/UnorderedList" - } - ] + "$ref": "#/definitions/TableCellContent" } } }, @@ -48,50 +38,24 @@ "nodeType" ] }, - "Paragraph": { + "TableCellContent": { "type": "object", "properties": { "nodeType": { - "type": "string", "enum": [ - "paragraph" - ] - }, - "data": { - "type": "object", - "properties": {} + "ordered-list", + "paragraph", + "unordered-list" + ], + "type": "string" }, "content": { "type": "array", "items": { "anyOf": [ { - "$ref": "#/definitions/Inline" + "$ref": "#/definitions/Block" }, - { - "$ref": "#/definitions/Text" - } - ] - } - } - }, - "additionalProperties": false, - "required": [ - "content", - "data", - "nodeType" - ] - }, - "Inline": { - "type": "object", - "properties": { - "nodeType": { - "$ref": "#/definitions/INLINES" - }, - "content": { - "type": "array", - "items": { - "anyOf": [ { "$ref": "#/definitions/Inline" }, @@ -112,123 +76,11 @@ "nodeType" ] }, - "INLINES": { - "description": "Map of all Contentful inline types. Inline contain inline or text nodes.", - "type": "string", - "enum": [ - "asset-hyperlink", - "embedded-entry-inline", - "embedded-resource-inline", - "entry-hyperlink", - "hyperlink", - "resource-hyperlink" - ] - }, - "Text": { - "type": "object", - "properties": { - "nodeType": { - "type": "string", - "enum": [ - "text" - ] - }, - "value": { - "type": "string" - }, - "marks": { - "type": "array", - "items": { - "$ref": "#/definitions/Mark" - } - }, - "data": { - "$ref": "#/definitions/NodeData" - } - }, - "additionalProperties": false, - "required": [ - "data", - "marks", - "nodeType", - "value" - ] - }, - "Mark": { - "type": "object", - "properties": { - "type": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - "NodeData": { - "additionalProperties": true, - "type": "object" - }, - "OrderedList": { - "type": "object", - "properties": { - "nodeType": { - "type": "string", - "enum": [ - "ordered-list" - ] - }, - "data": { - "type": "object", - "properties": {} - }, - "content": { - "type": "array", - "items": { - "$ref": "#/definitions/ListItem" - } - } - }, - "additionalProperties": false, - "required": [ - "content", - "data", - "nodeType" - ] - }, - "ListItem": { - "type": "object", - "properties": { - "nodeType": { - "type": "string", - "enum": [ - "list-item" - ] - }, - "data": { - "type": "object", - "properties": {} - }, - "content": { - "type": "array", - "items": { - "$ref": "#/definitions/ListItemBlock" - } - } - }, - "additionalProperties": false, - "required": [ - "content", - "data", - "nodeType" - ] - }, - "ListItemBlock": { + "Block": { "type": "object", "properties": { "nodeType": { - "$ref": "#/definitions/ListItemBlockEnum" + "$ref": "#/definitions/BLOCKS" }, "content": { "type": "array", @@ -257,38 +109,42 @@ "nodeType" ] }, - "ListItemBlockEnum": { + "BLOCKS": { + "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "type": "string", "enum": [ - "blockquote", - "embedded-asset-block", - "embedded-entry-block", - "embedded-resource-block", + "document", + "paragraph", "heading-1", "heading-2", "heading-3", "heading-4", "heading-5", "heading-6", - "hr", "ordered-list", - "paragraph", - "unordered-list" - ], - "type": "string" + "unordered-list", + "list-item", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "embedded-resource-block", + "table", + "table-row", + "table-cell", + "table-header-cell" + ] }, - "Block": { + "Inline": { "type": "object", "properties": { "nodeType": { - "$ref": "#/definitions/BLOCKS" + "$ref": "#/definitions/INLINES" }, "content": { "type": "array", "items": { "anyOf": [ - { - "$ref": "#/definitions/Block" - }, { "$ref": "#/definitions/Inline" }, @@ -309,58 +165,63 @@ "nodeType" ] }, - "BLOCKS": { - "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "INLINES": { + "description": "Map of all Contentful inline types. Inline contain inline or text 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" + "asset-hyperlink", + "embedded-entry-inline", + "embedded-resource-inline", + "entry-hyperlink", + "hyperlink", + "resource-hyperlink" ] }, - "UnorderedList": { + "Text": { "type": "object", "properties": { "nodeType": { "type": "string", "enum": [ - "unordered-list" + "text" ] }, - "data": { - "type": "object", - "properties": {} + "value": { + "type": "string" }, - "content": { + "marks": { "type": "array", "items": { - "$ref": "#/definitions/ListItem" + "$ref": "#/definitions/Mark" } + }, + "data": { + "$ref": "#/definitions/NodeData" } }, "additionalProperties": false, "required": [ - "content", "data", - "nodeType" + "marks", + "nodeType", + "value" + ] + }, + "Mark": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "type" ] + }, + "NodeData": { + "additionalProperties": true, + "type": "object" } }, "$schema": "http://json-schema.org/draft-07/schema#" 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 69fe9315..5e7cae7a 100644 --- a/packages/rich-text-types/src/schemas/generated/table-row.json +++ b/packages/rich-text-types/src/schemas/generated/table-row.json @@ -55,17 +55,7 @@ "minItems": 1, "type": "array", "items": { - "anyOf": [ - { - "$ref": "#/definitions/Paragraph" - }, - { - "$ref": "#/definitions/OrderedList" - }, - { - "$ref": "#/definitions/UnorderedList" - } - ] + "$ref": "#/definitions/TableCellContent" } } }, @@ -76,50 +66,24 @@ "nodeType" ] }, - "Paragraph": { + "TableCellContent": { "type": "object", "properties": { "nodeType": { - "type": "string", "enum": [ - "paragraph" - ] - }, - "data": { - "type": "object", - "properties": {} + "ordered-list", + "paragraph", + "unordered-list" + ], + "type": "string" }, "content": { "type": "array", "items": { "anyOf": [ { - "$ref": "#/definitions/Inline" + "$ref": "#/definitions/Block" }, - { - "$ref": "#/definitions/Text" - } - ] - } - } - }, - "additionalProperties": false, - "required": [ - "content", - "data", - "nodeType" - ] - }, - "Inline": { - "type": "object", - "properties": { - "nodeType": { - "$ref": "#/definitions/INLINES" - }, - "content": { - "type": "array", - "items": { - "anyOf": [ { "$ref": "#/definitions/Inline" }, @@ -140,123 +104,11 @@ "nodeType" ] }, - "INLINES": { - "description": "Map of all Contentful inline types. Inline contain inline or text nodes.", - "type": "string", - "enum": [ - "asset-hyperlink", - "embedded-entry-inline", - "embedded-resource-inline", - "entry-hyperlink", - "hyperlink", - "resource-hyperlink" - ] - }, - "Text": { - "type": "object", - "properties": { - "nodeType": { - "type": "string", - "enum": [ - "text" - ] - }, - "value": { - "type": "string" - }, - "marks": { - "type": "array", - "items": { - "$ref": "#/definitions/Mark" - } - }, - "data": { - "$ref": "#/definitions/NodeData" - } - }, - "additionalProperties": false, - "required": [ - "data", - "marks", - "nodeType", - "value" - ] - }, - "Mark": { - "type": "object", - "properties": { - "type": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - "NodeData": { - "additionalProperties": true, - "type": "object" - }, - "OrderedList": { - "type": "object", - "properties": { - "nodeType": { - "type": "string", - "enum": [ - "ordered-list" - ] - }, - "data": { - "type": "object", - "properties": {} - }, - "content": { - "type": "array", - "items": { - "$ref": "#/definitions/ListItem" - } - } - }, - "additionalProperties": false, - "required": [ - "content", - "data", - "nodeType" - ] - }, - "ListItem": { - "type": "object", - "properties": { - "nodeType": { - "type": "string", - "enum": [ - "list-item" - ] - }, - "data": { - "type": "object", - "properties": {} - }, - "content": { - "type": "array", - "items": { - "$ref": "#/definitions/ListItemBlock" - } - } - }, - "additionalProperties": false, - "required": [ - "content", - "data", - "nodeType" - ] - }, - "ListItemBlock": { + "Block": { "type": "object", "properties": { "nodeType": { - "$ref": "#/definitions/ListItemBlockEnum" + "$ref": "#/definitions/BLOCKS" }, "content": { "type": "array", @@ -285,38 +137,42 @@ "nodeType" ] }, - "ListItemBlockEnum": { + "BLOCKS": { + "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "type": "string", "enum": [ - "blockquote", - "embedded-asset-block", - "embedded-entry-block", - "embedded-resource-block", + "document", + "paragraph", "heading-1", "heading-2", "heading-3", "heading-4", "heading-5", "heading-6", - "hr", "ordered-list", - "paragraph", - "unordered-list" - ], - "type": "string" + "unordered-list", + "list-item", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "embedded-resource-block", + "table", + "table-row", + "table-cell", + "table-header-cell" + ] }, - "Block": { + "Inline": { "type": "object", "properties": { "nodeType": { - "$ref": "#/definitions/BLOCKS" + "$ref": "#/definitions/INLINES" }, "content": { "type": "array", "items": { "anyOf": [ - { - "$ref": "#/definitions/Block" - }, { "$ref": "#/definitions/Inline" }, @@ -337,58 +193,63 @@ "nodeType" ] }, - "BLOCKS": { - "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "INLINES": { + "description": "Map of all Contentful inline types. Inline contain inline or text 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" + "asset-hyperlink", + "embedded-entry-inline", + "embedded-resource-inline", + "entry-hyperlink", + "hyperlink", + "resource-hyperlink" ] }, - "UnorderedList": { + "Text": { "type": "object", "properties": { "nodeType": { "type": "string", "enum": [ - "unordered-list" + "text" ] }, - "data": { - "type": "object", - "properties": {} + "value": { + "type": "string" }, - "content": { + "marks": { "type": "array", "items": { - "$ref": "#/definitions/ListItem" + "$ref": "#/definitions/Mark" } + }, + "data": { + "$ref": "#/definitions/NodeData" } }, "additionalProperties": false, "required": [ - "content", "data", - "nodeType" + "marks", + "nodeType", + "value" + ] + }, + "Mark": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "type" ] + }, + "NodeData": { + "additionalProperties": true, + "type": "object" } }, "$schema": "http://json-schema.org/draft-07/schema#" diff --git a/packages/rich-text-types/src/schemas/generated/table.json b/packages/rich-text-types/src/schemas/generated/table.json index c6db1e89..936e1aab 100644 --- a/packages/rich-text-types/src/schemas/generated/table.json +++ b/packages/rich-text-types/src/schemas/generated/table.json @@ -83,17 +83,7 @@ "minItems": 1, "type": "array", "items": { - "anyOf": [ - { - "$ref": "#/definitions/Paragraph" - }, - { - "$ref": "#/definitions/OrderedList" - }, - { - "$ref": "#/definitions/UnorderedList" - } - ] + "$ref": "#/definitions/TableCellContent" } } }, @@ -104,50 +94,24 @@ "nodeType" ] }, - "Paragraph": { + "TableCellContent": { "type": "object", "properties": { "nodeType": { - "type": "string", "enum": [ - "paragraph" - ] - }, - "data": { - "type": "object", - "properties": {} + "ordered-list", + "paragraph", + "unordered-list" + ], + "type": "string" }, "content": { "type": "array", "items": { "anyOf": [ { - "$ref": "#/definitions/Inline" + "$ref": "#/definitions/Block" }, - { - "$ref": "#/definitions/Text" - } - ] - } - } - }, - "additionalProperties": false, - "required": [ - "content", - "data", - "nodeType" - ] - }, - "Inline": { - "type": "object", - "properties": { - "nodeType": { - "$ref": "#/definitions/INLINES" - }, - "content": { - "type": "array", - "items": { - "anyOf": [ { "$ref": "#/definitions/Inline" }, @@ -168,123 +132,11 @@ "nodeType" ] }, - "INLINES": { - "description": "Map of all Contentful inline types. Inline contain inline or text nodes.", - "type": "string", - "enum": [ - "asset-hyperlink", - "embedded-entry-inline", - "embedded-resource-inline", - "entry-hyperlink", - "hyperlink", - "resource-hyperlink" - ] - }, - "Text": { - "type": "object", - "properties": { - "nodeType": { - "type": "string", - "enum": [ - "text" - ] - }, - "value": { - "type": "string" - }, - "marks": { - "type": "array", - "items": { - "$ref": "#/definitions/Mark" - } - }, - "data": { - "$ref": "#/definitions/NodeData" - } - }, - "additionalProperties": false, - "required": [ - "data", - "marks", - "nodeType", - "value" - ] - }, - "Mark": { - "type": "object", - "properties": { - "type": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "type" - ] - }, - "NodeData": { - "additionalProperties": true, - "type": "object" - }, - "OrderedList": { - "type": "object", - "properties": { - "nodeType": { - "type": "string", - "enum": [ - "ordered-list" - ] - }, - "data": { - "type": "object", - "properties": {} - }, - "content": { - "type": "array", - "items": { - "$ref": "#/definitions/ListItem" - } - } - }, - "additionalProperties": false, - "required": [ - "content", - "data", - "nodeType" - ] - }, - "ListItem": { - "type": "object", - "properties": { - "nodeType": { - "type": "string", - "enum": [ - "list-item" - ] - }, - "data": { - "type": "object", - "properties": {} - }, - "content": { - "type": "array", - "items": { - "$ref": "#/definitions/ListItemBlock" - } - } - }, - "additionalProperties": false, - "required": [ - "content", - "data", - "nodeType" - ] - }, - "ListItemBlock": { + "Block": { "type": "object", "properties": { "nodeType": { - "$ref": "#/definitions/ListItemBlockEnum" + "$ref": "#/definitions/BLOCKS" }, "content": { "type": "array", @@ -313,38 +165,42 @@ "nodeType" ] }, - "ListItemBlockEnum": { + "BLOCKS": { + "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "type": "string", "enum": [ - "blockquote", - "embedded-asset-block", - "embedded-entry-block", - "embedded-resource-block", + "document", + "paragraph", "heading-1", "heading-2", "heading-3", "heading-4", "heading-5", "heading-6", - "hr", "ordered-list", - "paragraph", - "unordered-list" - ], - "type": "string" + "unordered-list", + "list-item", + "hr", + "blockquote", + "embedded-entry-block", + "embedded-asset-block", + "embedded-resource-block", + "table", + "table-row", + "table-cell", + "table-header-cell" + ] }, - "Block": { + "Inline": { "type": "object", "properties": { "nodeType": { - "$ref": "#/definitions/BLOCKS" + "$ref": "#/definitions/INLINES" }, "content": { "type": "array", "items": { "anyOf": [ - { - "$ref": "#/definitions/Block" - }, { "$ref": "#/definitions/Inline" }, @@ -365,58 +221,63 @@ "nodeType" ] }, - "BLOCKS": { - "description": "Map of all Contentful block types. Blocks contain inline or block nodes.", + "INLINES": { + "description": "Map of all Contentful inline types. Inline contain inline or text 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" + "asset-hyperlink", + "embedded-entry-inline", + "embedded-resource-inline", + "entry-hyperlink", + "hyperlink", + "resource-hyperlink" ] }, - "UnorderedList": { + "Text": { "type": "object", "properties": { "nodeType": { "type": "string", "enum": [ - "unordered-list" + "text" ] }, - "data": { - "type": "object", - "properties": {} + "value": { + "type": "string" }, - "content": { + "marks": { "type": "array", "items": { - "$ref": "#/definitions/ListItem" + "$ref": "#/definitions/Mark" } + }, + "data": { + "$ref": "#/definitions/NodeData" } }, "additionalProperties": false, "required": [ - "content", "data", - "nodeType" + "marks", + "nodeType", + "value" + ] + }, + "Mark": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "type" ] + }, + "NodeData": { + "additionalProperties": true, + "type": "object" } }, "$schema": "http://json-schema.org/draft-07/schema#" From 3d02a7d14dd5b5fc98ca9cecd3fc09b3e4062d5d Mon Sep 17 00:00:00 2001 From: Aodhagan Murphy Date: Fri, 19 Jul 2024 13:36:41 +0100 Subject: [PATCH 09/13] chore: updating snapshot tests [TOL-2249] --- packages/rich-text-types/README.md | 14 + packages/rich-text-types/package.json | 3 +- .../__snapshots__/schemas.test.ts.snap | 618 ++---------------- 3 files changed, 75 insertions(+), 560 deletions(-) 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 30d5eba6..48b2c138 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/schemas/__test__/__snapshots__/schemas.test.ts.snap b/packages/rich-text-types/src/schemas/__test__/__snapshots__/schemas.test.ts.snap index 4fe1b6e5..a2d8faf7 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 @@ -3287,85 +3287,6 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, - "ListItem": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "$ref": "#/definitions/ListItemBlock", - }, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "list-item", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, - "ListItemBlock": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "anyOf": [ - { - "$ref": "#/definitions/Block", - }, - { - "$ref": "#/definitions/Inline", - }, - { - "$ref": "#/definitions/Text", - }, - ], - }, - "type": "array", - }, - "data": { - "$ref": "#/definitions/NodeData", - }, - "nodeType": { - "$ref": "#/definitions/ListItemBlockEnum", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, - "ListItemBlockEnum": { - "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", - }, "Mark": { "additionalProperties": false, "properties": { @@ -3382,67 +3303,6 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "additionalProperties": true, "type": "object", }, - "OrderedList": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "$ref": "#/definitions/ListItem", - }, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "ordered-list", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, - "Paragraph": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "anyOf": [ - { - "$ref": "#/definitions/Inline", - }, - { - "$ref": "#/definitions/Text", - }, - ], - }, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "paragraph", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, "Table": { "additionalProperties": false, "properties": { @@ -3476,17 +3336,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "properties": { "content": { "items": { - "anyOf": [ - { - "$ref": "#/definitions/Paragraph", - }, - { - "$ref": "#/definitions/OrderedList", - }, - { - "$ref": "#/definitions/UnorderedList", - }, - ], + "$ref": "#/definitions/TableCellContent", }, "minItems": 1, "type": "array", @@ -3506,6 +3356,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "nodeType": { "enum": [ "table-cell", + "table-header-cell", ], "type": "string", }, @@ -3517,31 +3368,33 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, - "TableHeaderCell": { + "TableCellContent": { "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", + "ordered-list", + "paragraph", + "unordered-list", ], "type": "string", }, @@ -3558,14 +3411,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "properties": { "content": { "items": { - "anyOf": [ - { - "$ref": "#/definitions/TableCell", - }, - { - "$ref": "#/definitions/TableHeaderCell", - }, - ], + "$ref": "#/definitions/TableCell", }, "minItems": 1, "type": "array", @@ -3618,33 +3464,6 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, - "UnorderedList": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "$ref": "#/definitions/ListItem", - }, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "unordered-list", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, }, } `; @@ -3755,85 +3574,6 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell ], "type": "object", }, - "ListItem": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "$ref": "#/definitions/ListItemBlock", - }, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "list-item", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, - "ListItemBlock": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "anyOf": [ - { - "$ref": "#/definitions/Block", - }, - { - "$ref": "#/definitions/Inline", - }, - { - "$ref": "#/definitions/Text", - }, - ], - }, - "type": "array", - }, - "data": { - "$ref": "#/definitions/NodeData", - }, - "nodeType": { - "$ref": "#/definitions/ListItemBlockEnum", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, - "ListItemBlockEnum": { - "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", - }, "Mark": { "additionalProperties": false, "properties": { @@ -3850,56 +3590,32 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell "additionalProperties": true, "type": "object", }, - "OrderedList": { + "TableCell": { "additionalProperties": false, "properties": { "content": { "items": { - "$ref": "#/definitions/ListItem", + "$ref": "#/definitions/TableCellContent", }, + "minItems": 1, "type": "array", }, "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "ordered-list", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, - "Paragraph": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "anyOf": [ - { - "$ref": "#/definitions/Inline", - }, - { - "$ref": "#/definitions/Text", - }, - ], + "additionalProperties": false, + "properties": { + "colspan": { + "type": "number", + }, + "rowspan": { + "type": "number", + }, }, - "type": "array", - }, - "data": { - "properties": {}, "type": "object", }, "nodeType": { "enum": [ - "paragraph", + "table-cell", + "table-header-cell", ], "type": "string", }, @@ -3911,41 +3627,33 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell ], "type": "object", }, - "TableCell": { + "TableCellContent": { "additionalProperties": false, "properties": { "content": { "items": { "anyOf": [ { - "$ref": "#/definitions/Paragraph", + "$ref": "#/definitions/Block", }, { - "$ref": "#/definitions/OrderedList", + "$ref": "#/definitions/Inline", }, { - "$ref": "#/definitions/UnorderedList", + "$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", + "ordered-list", + "paragraph", + "unordered-list", ], "type": "string", }, @@ -3987,33 +3695,6 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell ], "type": "object", }, - "UnorderedList": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "$ref": "#/definitions/ListItem", - }, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "unordered-list", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, }, } `; @@ -4291,85 +3972,6 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row ], "type": "object", }, - "ListItem": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "$ref": "#/definitions/ListItemBlock", - }, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "list-item", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, - "ListItemBlock": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "anyOf": [ - { - "$ref": "#/definitions/Block", - }, - { - "$ref": "#/definitions/Inline", - }, - { - "$ref": "#/definitions/Text", - }, - ], - }, - "type": "array", - }, - "data": { - "$ref": "#/definitions/NodeData", - }, - "nodeType": { - "$ref": "#/definitions/ListItemBlockEnum", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, - "ListItemBlockEnum": { - "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", - }, "Mark": { "additionalProperties": false, "properties": { @@ -4386,83 +3988,12 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "additionalProperties": true, "type": "object", }, - "OrderedList": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "$ref": "#/definitions/ListItem", - }, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "ordered-list", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, - "Paragraph": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "anyOf": [ - { - "$ref": "#/definitions/Inline", - }, - { - "$ref": "#/definitions/Text", - }, - ], - }, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "paragraph", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, "TableCell": { "additionalProperties": false, "properties": { "content": { "items": { - "anyOf": [ - { - "$ref": "#/definitions/Paragraph", - }, - { - "$ref": "#/definitions/OrderedList", - }, - { - "$ref": "#/definitions/UnorderedList", - }, - ], + "$ref": "#/definitions/TableCellContent", }, "minItems": 1, "type": "array", @@ -4482,6 +4013,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "nodeType": { "enum": [ "table-cell", + "table-header-cell", ], "type": "string", }, @@ -4493,31 +4025,33 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row ], "type": "object", }, - "TableHeaderCell": { + "TableCellContent": { "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", + "ordered-list", + "paragraph", + "unordered-list", ], "type": "string", }, @@ -4534,14 +4068,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "properties": { "content": { "items": { - "anyOf": [ - { - "$ref": "#/definitions/TableCell", - }, - { - "$ref": "#/definitions/TableHeaderCell", - }, - ], + "$ref": "#/definitions/TableCell", }, "minItems": 1, "type": "array", @@ -4594,33 +4121,6 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row ], "type": "object", }, - "UnorderedList": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "$ref": "#/definitions/ListItem", - }, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "unordered-list", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", - ], - "type": "object", - }, }, } `; From 7b248ab153631033bf7320336bb5dd00d6e8f095 Mon Sep 17 00:00:00 2001 From: Aodhagan Murphy Date: Fri, 19 Jul 2024 13:42:48 +0100 Subject: [PATCH 10/13] chore: updating comment [TOL-2249] --- packages/rich-text-types/src/nodeTypes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rich-text-types/src/nodeTypes.ts b/packages/rich-text-types/src/nodeTypes.ts index 717f1cc3..d5307b90 100644 --- a/packages/rich-text-types/src/nodeTypes.ts +++ b/packages/rich-text-types/src/nodeTypes.ts @@ -217,7 +217,7 @@ export interface TableCell extends Block { // Notice that this is only exported and not reused anywhere else in this file // this is because this we only want this interface to generate the schema // if we end up decouping the header cell from the regular cell we -// end up with unwanted side effects when validating the schema in @contentful/validation +// end up with unwanted side effects when validating the schema export interface TableHeaderCell extends TableCell { nodeType: BLOCKS.TABLE_HEADER_CELL; From e5ea01615b508ea27cef0029313338ac6954ca74 Mon Sep 17 00:00:00 2001 From: Aodhagan Murphy Date: Sun, 21 Jul 2024 22:17:09 +0100 Subject: [PATCH 11/13] chore: adjusting table blocks schemas to follow list block pattern [TOL-2249] --- packages/rich-text-types/src/nodeTypes.ts | 32 ++- .../rich-text-types/src/schemaConstraints.ts | 6 + .../__snapshots__/schemas.test.ts.snap | 245 +++++++++--------- .../src/schemas/generated/table-cell.json | 26 +- .../schemas/generated/table-header-cell.json | 81 +++++- .../src/schemas/generated/table-row.json | 55 +--- .../src/schemas/generated/table.json | 55 +--- packages/rich-text-types/src/types.ts | 20 +- 8 files changed, 267 insertions(+), 253 deletions(-) diff --git a/packages/rich-text-types/src/nodeTypes.ts b/packages/rich-text-types/src/nodeTypes.ts index d5307b90..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 = {}; @@ -197,12 +205,8 @@ export interface ResourceHyperlink extends Inline { content: Text[]; } -interface TableCellContent extends Block { - nodeType: BLOCKS.PARAGRAPH | BLOCKS.UL_LIST | BLOCKS.OL_LIST; -} - export interface TableCell extends Block { - nodeType: BLOCKS.TABLE_HEADER_CELL | BLOCKS.TABLE_CELL; + nodeType: BLOCKS.TABLE_CELL; data: { colspan?: number; rowspan?: number; @@ -211,20 +215,20 @@ export interface TableCell extends Block { /** * @minItems 1 */ - content: TableCellContent[]; + content: TableCellBlock[]; } -// Notice that this is only exported and not reused anywhere else in this file -// this is because this we only want this interface to generate the schema -// if we end up decouping the header cell from the regular cell we -// end up with unwanted side effects when validating the schema -export interface TableHeaderCell extends TableCell { +export interface TableHeaderCell extends Block { nodeType: BLOCKS.TABLE_HEADER_CELL; + data: { + colspan?: number; + rowspan?: number; + }; /** * @minItems 1 */ - content: Paragraph[]; + content: TableHeaderCellBlock[]; } // An abstract table row can have both table cell types @@ -236,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..9820b628 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 = BLOCKS.PARAGRAPH | BLOCKS.UL_LIST | BLOCKS.OL_LIST; + +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 a2d8faf7..572b8f15 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 @@ -3331,32 +3331,23 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, - "TableCell": { + "TableRow": { "additionalProperties": false, "properties": { "content": { "items": { - "$ref": "#/definitions/TableCellContent", + "$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", }, @@ -3368,7 +3359,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, - "TableCellContent": { + "TableRowBlock": { "additionalProperties": false, "properties": { "content": { @@ -3391,12 +3382,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] "$ref": "#/definitions/NodeData", }, "nodeType": { - "enum": [ - "ordered-list", - "paragraph", - "unordered-list", - ], - "type": "string", + "$ref": "#/definitions/TableRowBlockEnum", }, }, "required": [ @@ -3406,33 +3392,12 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table 1`] ], "type": "object", }, - "TableRow": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "$ref": "#/definitions/TableCell", - }, - "minItems": 1, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "table-row", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", + "TableRowBlockEnum": { + "enum": [ + "table-cell", + "table-header-cell", ], - "type": "object", + "type": "string", }, "Text": { "additionalProperties": false, @@ -3595,7 +3560,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell "properties": { "content": { "items": { - "$ref": "#/definitions/TableCellContent", + "$ref": "#/definitions/TableCellBlock", }, "minItems": 1, "type": "array", @@ -3615,7 +3580,6 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell "nodeType": { "enum": [ "table-cell", - "table-header-cell", ], "type": "string", }, @@ -3627,7 +3591,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell ], "type": "object", }, - "TableCellContent": { + "TableCellBlock": { "additionalProperties": false, "properties": { "content": { @@ -3650,12 +3614,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell "$ref": "#/definitions/NodeData", }, "nodeType": { - "enum": [ - "ordered-list", - "paragraph", - "unordered-list", - ], - "type": "string", + "$ref": "#/definitions/TableCellEnum", }, }, "required": [ @@ -3665,6 +3624,14 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell ], "type": "object", }, + "TableCellEnum": { + "enum": [ + "ordered-list", + "paragraph", + "unordered-list", + ], + "type": "string", + }, "Text": { "additionalProperties": false, "properties": { @@ -3704,6 +3671,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": [ @@ -3762,29 +3788,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", }, @@ -3796,31 +3824,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", }, @@ -3988,32 +4016,23 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "additionalProperties": true, "type": "object", }, - "TableCell": { + "TableRow": { "additionalProperties": false, "properties": { "content": { "items": { - "$ref": "#/definitions/TableCellContent", + "$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", }, @@ -4025,7 +4044,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row ], "type": "object", }, - "TableCellContent": { + "TableRowBlock": { "additionalProperties": false, "properties": { "content": { @@ -4048,12 +4067,7 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row "$ref": "#/definitions/NodeData", }, "nodeType": { - "enum": [ - "ordered-list", - "paragraph", - "unordered-list", - ], - "type": "string", + "$ref": "#/definitions/TableRowBlockEnum", }, }, "required": [ @@ -4063,33 +4077,12 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-row ], "type": "object", }, - "TableRow": { - "additionalProperties": false, - "properties": { - "content": { - "items": { - "$ref": "#/definitions/TableCell", - }, - "minItems": 1, - "type": "array", - }, - "data": { - "properties": {}, - "type": "object", - }, - "nodeType": { - "enum": [ - "table-row", - ], - "type": "string", - }, - }, - "required": [ - "content", - "data", - "nodeType", + "TableRowBlockEnum": { + "enum": [ + "table-cell", + "table-header-cell", ], - "type": "object", + "type": "string", }, "Text": { "additionalProperties": false, 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 c2ca68a1..2646ad19 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/TableCellContent" + "$ref": "#/definitions/TableCellBlock" } } }, @@ -38,16 +37,11 @@ "nodeType" ] }, - "TableCellContent": { + "TableCellBlock": { "type": "object", "properties": { "nodeType": { - "enum": [ - "ordered-list", - "paragraph", - "unordered-list" - ], - "type": "string" + "$ref": "#/definitions/TableCellEnum" }, "content": { "type": "array", @@ -76,6 +70,14 @@ "nodeType" ] }, + "TableCellEnum": { + "enum": [ + "ordered-list", + "paragraph", + "unordered-list" + ], + "type": "string" + }, "Block": { "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 cff9b742..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 @@ -10,13 +10,6 @@ "table-header-cell" ] }, - "content": { - "minItems": 1, - "type": "array", - "items": { - "$ref": "#/definitions/Paragraph" - } - }, "data": { "type": "object", "properties": { @@ -28,6 +21,13 @@ } }, "additionalProperties": false + }, + "content": { + "minItems": 1, + "type": "array", + "items": { + "$ref": "#/definitions/TableHeaderCellBlock" + } } }, "additionalProperties": false, @@ -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 5e7cae7a..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,53 +29,11 @@ "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 - }, - "content": { - "minItems": 1, - "type": "array", - "items": { - "$ref": "#/definitions/TableCellContent" - } - } - }, - "additionalProperties": false, - "required": [ - "content", - "data", - "nodeType" - ] - }, - "TableCellContent": { - "type": "object", - "properties": { - "nodeType": { - "enum": [ - "ordered-list", - "paragraph", - "unordered-list" - ], - "type": "string" + "$ref": "#/definitions/TableRowBlockEnum" }, "content": { "type": "array", @@ -104,6 +62,13 @@ "nodeType" ] }, + "TableRowBlockEnum": { + "enum": [ + "table-cell", + "table-header-cell" + ], + "type": "string" + }, "Block": { "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 936e1aab..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,53 +57,11 @@ "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 - }, - "content": { - "minItems": 1, - "type": "array", - "items": { - "$ref": "#/definitions/TableCellContent" - } - } - }, - "additionalProperties": false, - "required": [ - "content", - "data", - "nodeType" - ] - }, - "TableCellContent": { - "type": "object", - "properties": { - "nodeType": { - "enum": [ - "ordered-list", - "paragraph", - "unordered-list" - ], - "type": "string" + "$ref": "#/definitions/TableRowBlockEnum" }, "content": { "type": "array", @@ -132,6 +90,13 @@ "nodeType" ] }, + "TableRowBlockEnum": { + "enum": [ + "table-cell", + "table-header-cell" + ], + "type": "string" + }, "Block": { "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; +} From 12c40df72fd5ddedeb25a5ce7a3f211c81089cf5 Mon Sep 17 00:00:00 2001 From: Aodhagan Murphy Date: Tue, 23 Jul 2024 14:17:44 +0100 Subject: [PATCH 12/13] chore: adding same rules as list item for table cell [TOL-2249] --- packages/rich-text-types/src/schemaConstraints.ts | 2 +- .../src/schemas/generated/table-cell.json | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/rich-text-types/src/schemaConstraints.ts b/packages/rich-text-types/src/schemaConstraints.ts index 9820b628..bce093d0 100644 --- a/packages/rich-text-types/src/schemaConstraints.ts +++ b/packages/rich-text-types/src/schemaConstraints.ts @@ -59,7 +59,7 @@ export type ListItemBlockEnum = export type TableRowBlockEnum = BLOCKS.TABLE_CELL | BLOCKS.TABLE_HEADER_CELL; -export type TableCellEnum = BLOCKS.PARAGRAPH | BLOCKS.UL_LIST | BLOCKS.OL_LIST; +export type TableCellEnum = ListItemBlockEnum; export type TableHeaderCellEnum = BLOCKS.PARAGRAPH; 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 2646ad19..1ae72432 100644 --- a/packages/rich-text-types/src/schemas/generated/table-cell.json +++ b/packages/rich-text-types/src/schemas/generated/table-cell.json @@ -72,6 +72,17 @@ }, "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" From 6b3ea053f9af7fcc7362ce6c17fb05d4dec875a5 Mon Sep 17 00:00:00 2001 From: Aodhagan Murphy Date: Tue, 23 Jul 2024 14:23:37 +0100 Subject: [PATCH 13/13] chore: updating snapshots [TOL-2249] --- .../__test__/__snapshots__/schemas.test.ts.snap | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 572b8f15..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 @@ -3626,6 +3626,17 @@ exports[`getSchemaWithNodeType returns json schema for each nodeType: table-cell }, "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",