Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reintroducing table cell schema changes [TOL-2249] #622

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/rich-text-types/README.md
Original file line number Diff line number Diff line change
@@ -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
```
3 changes: 2 additions & 1 deletion packages/rich-text-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 22 additions & 5 deletions packages/rich-text-types/src/nodeTypes.ts
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand Down Expand Up @@ -198,7 +206,7 @@ export interface ResourceHyperlink extends Inline {
}

export interface TableCell extends Block {
nodeType: BLOCKS.TABLE_HEADER_CELL | BLOCKS.TABLE_CELL;
nodeType: BLOCKS.TABLE_CELL;
data: {
colspan?: number;
rowspan?: number;
Expand All @@ -207,11 +215,20 @@ export interface TableCell extends Block {
/**
* @minItems 1
*/
content: Paragraph[];
content: TableCellBlock[];
}

export interface TableHeaderCell extends TableCell {
export interface TableHeaderCell extends Block {
nodeType: BLOCKS.TABLE_HEADER_CELL;
data: {
colspan?: number;
rowspan?: number;
};

/**
* @minItems 1
*/
content: TableHeaderCellBlock[];
}

// An abstract table row can have both table cell types
Expand All @@ -223,7 +240,7 @@ export interface TableRow extends Block {
/**
* @minItems 1
*/
content: TableCell[];
content: TableRowBlock[];
}

export interface Table extends Block {
Expand Down
6 changes: 6 additions & 0 deletions packages/rich-text-types/src/schemaConstraints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export type ListItemBlockEnum =
| BLOCKS.EMBEDDED_ASSET
| BLOCKS.EMBEDDED_RESOURCE;

export type TableRowBlockEnum = BLOCKS.TABLE_CELL | BLOCKS.TABLE_HEADER_CELL;

export type TableCellEnum = ListItemBlockEnum;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Nit: Can we have a dedicated enum here? it would be handy when adjusting the normalisation logic in the editor
  • You also need to adjust the entry for table cell in the CONTAINERS below


export type TableHeaderCellEnum = BLOCKS.PARAGRAPH;

/**
* Array of all allowed block types inside list items
*/
Expand Down
Loading
Loading