Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Making DraftBlockType less restrictive #1480

Closed
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion src/model/constants/DraftBlockType.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* The list of default valid block types.
*/
export type DraftBlockType =
export type CoreDraftBlockType =
| 'unstyled'
| 'paragraph'
| 'header-one'
Expand All @@ -30,3 +30,10 @@ export type DraftBlockType =
| 'blockquote'
| 'code-block'
| 'atomic';

/**
* User defined types can be of any valid string.
*/
export type CustomBlockType = string;

export type DraftBlockType = CoreDraftBlockType | CustomBlockType;
2 changes: 1 addition & 1 deletion src/model/immutable/ContentBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const {List, Map, OrderedSet, Record, Repeat} = Immutable;
const EMPTY_SET = OrderedSet();

type ContentBlockConfig = {
key?: string,
key?: DraftBlockType,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just adding back, had removed this temporarily while shipping the other PR internally, but now since DraftBlockType is more permissive we wont run in the same problem again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My mistake in here, this should have been added to type not key but fixing it on a follow up PR #1485

type?: string,
text?: string,
characterList?: List<CharacterMetadata>,
Expand Down
13 changes: 9 additions & 4 deletions src/model/immutable/DefaultDraftBlockRenderMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@

'use strict';

import type {DraftBlockRenderMap} from 'DraftBlockRenderMap';

const {Map} = require('immutable');
const React = require('React');

const cx = require('cx');

import type {CoreDraftBlockType} from 'DraftBlockType';
import type {DraftBlockRenderConfig} from 'DraftBlockRenderConfig';

type DefaultCoreDraftBlockRenderMap = Map<
CoreDraftBlockType,
DraftBlockRenderConfig,
>;

const UL_WRAP = <ul className={cx('public/DraftStyleDefault/ul')} />;
const OL_WRAP = <ol className={cx('public/DraftStyleDefault/ol')} />;
const PRE_WRAP = <pre className={cx('public/DraftStyleDefault/pre')} />;

const DefaultDraftBlockRenderMap: DraftBlockRenderMap = Map({
const DefaultDraftBlockRenderMap: DefaultCoreDraftBlockRenderMap = Map({
'header-one': {
element: 'h1',
},
Expand Down